23 #include <interfaces/generator/field.h>
24 #include <interfaces/generator/type_checker.h>
25 #include <interfaces/generator/exceptions.h>
42 this->enum_constants = enum_constants;
85 if (type ==
"string") {
91 }
else if (type ==
"float" || type ==
"double" || type ==
"bool" || is_enum_type) {
99 }
else if (type ==
"float" || type ==
"double" || type ==
"bool" || is_enum_type) {
115 if (type ==
"string") {
117 }
else if (type ==
"byte") {
119 }
else if (type ==
"float" || type ==
"double" || type ==
"bool" || is_enum_type) {
133 if (type ==
"string") {
135 }
else if (type ==
"byte") {
137 }
else if (type ==
"float" || type ==
"double" || type ==
"bool") {
139 }
else if (is_enum_type) {
195 return default_value;
202 std::vector<std::string>
215 is_enum_type =
false;
216 if ( enum_constants != NULL ) {
217 std::vector<InterfaceEnumConstant>::iterator i;
218 for (i = enum_constants->begin(); i != enum_constants->end(); ++i) {
219 if ( type == (*i).get_name() ) {
244 this->comment = comment;
254 this->length_value = (
unsigned int)atoi(length.c_str());
255 this->length = length;
265 this->validfor = validfor;
275 this->default_value = default_value;
295 InterfaceField::tokenize(
const std::string& str,
296 std::vector<std::string>& tokens,
297 const std::string& delimiters)
300 std::string::size_type last_pos = str.find_first_not_of(delimiters, 0);
302 std::string::size_type pos = str.find_first_of(delimiters, last_pos);
304 while (std::string::npos != pos || std::string::npos != last_pos) {
306 tokens.push_back(str.substr(last_pos, pos - last_pos));
308 last_pos = str.find_first_not_of(delimiters, pos);
310 pos = str.find_first_of(delimiters, last_pos);
322 if ( attr_name ==
"name" ) {
324 }
else if ( attr_name ==
"type" ) {
326 }
else if ( attr_name ==
"length" ) {
328 }
else if ( attr_name ==
"validfor" ) {
330 }
else if ( attr_name ==
"default" ) {
332 }
else if ( attr_name ==
"flags" ) {
333 tokenize(attr_value, flags,
",");
353 if ( (name.length() == 0) || (name.find(
" ") != std::string::npos) ) {
362 if ( (default_value.length() > 0) &&
366 for (std::vector<std::string>::iterator i = flags.begin(); i != flags.end(); ++i) {
367 if ( *i !=
"changed_indicator" ) {
396 if ( (type ==
"unsigned int") ) {
397 return (f.type !=
"unsigned int");
399 }
else if ( type ==
"int" ) {
400 return ( (f.type !=
"int") &&
401 (f.type !=
"unsigned int") );
404 }
else if ( type ==
"unsigned long int" ) {
405 return ( (f.type !=
"unsigned long int") &&
406 (f.type !=
"unsigned int") &&
409 }
else if ( type ==
"long int" ) {
410 return ( (f.type !=
"long int") &&
411 (f.type !=
"unsigned int") &&
413 (f.type !=
"unsigned long int") );
415 }
else if ( type ==
"float" ) {
416 return ( (f.type !=
"float") &&
417 (f.type !=
"unsigned int") &&
420 }
else if ( type ==
"double" ) {
421 return ( (f.type !=
"double") &&
422 (f.type !=
"unsigned int") &&
424 (f.type !=
"float") );
426 }
else if ( type ==
"bool" ) {
427 return ( (f.type !=
"bool") &&
428 (f.type !=
"double") &&
429 (f.type !=
"unsigned int") &&
431 (f.type !=
"float") );
433 }
else if ( type ==
"byte" ) {
434 return ( (f.type !=
"byte") &&
435 (f.type !=
"bool") &&
436 (f.type !=
"double") &&
437 (f.type !=
"unsigned int") &&
439 (f.type !=
"float") );
std::string getDefaultValue() const
Get default value.
void setFlags(const std::vector< std::string > &flags)
Set flags.
void setName(const std::string &name)
Set name of field.
std::string getName() const
Get name of field.
std::string getStructType() const
Get type used to formulate struct.
bool isEnumType() const
Check if type is an enum type.
static bool validValue(const std::string &type, const std::string &value)
Check value validity for given type.
Interface generator internal representation of a field as parsed from the XML template file...
void setType(const std::string &type)
Set type of field.
std::string getPlainAccessType() const
Get non-array accessor type.
std::string getAccessType() const
Get type as used for accessor methods of class.
unsigned int getLengthValue() const
Get length value.
Thrown if illegal value is supplied.
std::string getLength() const
Get field length.
void valid()
Assert validity.
InterfaceField(std::vector< InterfaceEnumConstant > *enum_constants=NULL)
Constructor.
std::string getValidFor() const
Get valid for time.
std::vector< std::string > getFlags() const
Get flags.
bool operator<(const InterfaceField &f) const
Check order of two elements.
std::string getType() const
Get type of field.
void setComment(const std::string &comment)
Set comment of field.
static bool validType(const std::string &type, std::vector< InterfaceEnumConstant > *enum_constants=0)
Check type validity.
void setValidFor(const std::string &validfor)
Set valid for time.
Thrown if illegal flag is supplied.
std::string getComment() const
Get comment of field.
void setDefaultValue(const std::string &default_value)
Set default value.
void setAttribute(const std::string &attr_name, const std::string &attr_value)
Set attribute.
Thrown if illegal type is supplied.
void setLength(const std::string &length)
Set length of field.