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 const std::vector<InterfaceEnumConstant> *
205 return enum_constants;
219 std::vector<InterfaceEnumConstant>::const_iterator i;
220 for (i = enum_constants->begin(); i != enum_constants->end(); ++i) {
221 if ( type == i->get_name() ) {
233 std::vector<std::string>
246 is_enum_type =
false;
247 if ( enum_constants != NULL ) {
248 std::vector<InterfaceEnumConstant>::iterator i;
249 for (i = enum_constants->begin(); i != enum_constants->end(); ++i) {
250 if ( type == (*i).get_name() ) {
275 this->comment = comment;
285 this->length_value = (
unsigned int)atoi(length.c_str());
286 this->length = length;
296 this->validfor = validfor;
306 this->default_value = default_value;
326 InterfaceField::tokenize(
const std::string& str,
327 std::vector<std::string>& tokens,
328 const std::string& delimiters)
331 std::string::size_type last_pos = str.find_first_not_of(delimiters, 0);
333 std::string::size_type pos = str.find_first_of(delimiters, last_pos);
335 while (std::string::npos != pos || std::string::npos != last_pos) {
337 tokens.push_back(str.substr(last_pos, pos - last_pos));
339 last_pos = str.find_first_not_of(delimiters, pos);
341 pos = str.find_first_of(delimiters, last_pos);
353 if ( attr_name ==
"name" ) {
355 }
else if ( attr_name ==
"type" ) {
357 }
else if ( attr_name ==
"length" ) {
359 }
else if ( attr_name ==
"validfor" ) {
361 }
else if ( attr_name ==
"default" ) {
363 }
else if ( attr_name ==
"flags" ) {
364 tokenize(attr_value, flags,
",");
384 if ( (name.length() == 0) || (name.find(
" ") != std::string::npos) ) {
393 if ( (default_value.length() > 0) &&
397 for (std::vector<std::string>::iterator i = flags.begin(); i != flags.end(); ++i) {
398 if ( *i !=
"changed_indicator" ) {
427 if ( (type ==
"unsigned int") ) {
428 return (f.type !=
"unsigned int");
430 }
else if ( type ==
"int" ) {
431 return ( (f.type !=
"int") &&
432 (f.type !=
"unsigned int") );
435 }
else if ( type ==
"unsigned long int" ) {
436 return ( (f.type !=
"unsigned long int") &&
437 (f.type !=
"unsigned int") &&
440 }
else if ( type ==
"long int" ) {
441 return ( (f.type !=
"long int") &&
442 (f.type !=
"unsigned int") &&
444 (f.type !=
"unsigned long int") );
446 }
else if ( type ==
"float" ) {
447 return ( (f.type !=
"float") &&
448 (f.type !=
"unsigned int") &&
451 }
else if ( type ==
"double" ) {
452 return ( (f.type !=
"double") &&
453 (f.type !=
"unsigned int") &&
455 (f.type !=
"float") );
457 }
else if ( type ==
"bool" ) {
458 return ( (f.type !=
"bool") &&
459 (f.type !=
"double") &&
460 (f.type !=
"unsigned int") &&
462 (f.type !=
"float") );
464 }
else if ( type ==
"byte" ) {
465 return ( (f.type !=
"byte") &&
466 (f.type !=
"bool") &&
467 (f.type !=
"double") &&
468 (f.type !=
"unsigned int") &&
470 (f.type !=
"float") );
std::string getType() const
Get type of field.
const InterfaceEnumConstant & getEnumConstant(const std::string &name) const
Get specific enum constant.
void setFlags(const std::vector< std::string > &flags)
Set flags.
void setName(const std::string &name)
Set name of field.
unsigned int getLengthValue() const
Get length value.
Interface generator internal representation of a enum constant as parsed from the XML template file...
std::vector< std::string > getFlags() const
Get flags.
std::string getDefaultValue() const
Get default value.
const std::vector< InterfaceEnumConstant > * getEnumConstants() const
Get vector of enum constants.
std::string getName() const
Get name of field.
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 getValidFor() const
Get valid for time.
std::string getPlainAccessType() const
Get non-array accessor type.
Thrown if illegal value is supplied.
void valid()
Assert validity.
std::string getAccessType() const
Get type as used for accessor methods of class.
InterfaceField(std::vector< InterfaceEnumConstant > *enum_constants=NULL)
Constructor.
Base class for exceptions in Fawkes.
std::string getComment() const
Get comment of field.
void setComment(const std::string &comment)
Set comment of field.
bool operator<(const InterfaceField &f) const
Check order of two elements.
static bool validType(const std::string &type, std::vector< InterfaceEnumConstant > *enum_constants=0)
Check type validity.
std::string getLength() const
Get field length.
void setValidFor(const std::string &validfor)
Set valid for time.
Thrown if illegal flag is supplied.
bool isEnumType() const
Check if type is an enum type.
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.
std::string getStructType() const
Get type used to formulate struct.