23 #include <interfaces/generator/checker.h>
24 #include <interfaces/generator/exceptions.h>
25 #include <interfaces/generator/field.h>
40 this->enum_constants = enum_constants;
79 if (type ==
"string") {
85 }
else if (type ==
"float" || type ==
"double" || type ==
"bool" || is_enum_type) {
93 }
else if (type ==
"float" || type ==
"double" || type ==
"bool" || is_enum_type) {
108 if (type ==
"string") {
110 }
else if (type ==
"byte") {
112 }
else if (type ==
"float" || type ==
"double" || type ==
"bool" || is_enum_type) {
125 if (type ==
"string") {
127 }
else if (type ==
"byte") {
129 }
else if (type ==
"float" || type ==
"double" || type ==
"bool") {
131 }
else if (is_enum_type) {
192 return default_value;
198 const std::vector<InterfaceEnumConstant> *
201 return enum_constants;
216 std::vector<InterfaceEnumConstant>::const_iterator i;
217 for (i = enum_constants->begin(); i != enum_constants->end(); ++i) {
218 if (type == i->get_name()) {
229 std::vector<std::string>
241 is_enum_type =
false;
242 if (enum_constants != NULL) {
243 std::vector<InterfaceEnumConstant>::iterator i;
244 for (i = enum_constants->begin(); i != enum_constants->end(); ++i) {
245 if (type == (*i).get_name()) {
268 this->comment = comment;
277 this->length_value = (
unsigned int)atoi(length.c_str());
278 this->length = length;
279 this->max_idx = std::to_string(length_value - 1);
288 this->validfor = validfor;
297 this->default_value = default_value;
315 InterfaceField::tokenize(
const std::string & str,
316 std::vector<std::string> &tokens,
317 const std::string & delimiters)
320 std::string::size_type last_pos = str.find_first_not_of(delimiters, 0);
322 std::string::size_type pos = str.find_first_of(delimiters, last_pos);
324 while (std::string::npos != pos || std::string::npos != last_pos) {
326 tokens.push_back(str.substr(last_pos, pos - last_pos));
328 last_pos = str.find_first_not_of(delimiters, pos);
330 pos = str.find_first_of(delimiters, last_pos);
341 if (attr_name ==
"name") {
343 }
else if (attr_name ==
"type") {
345 }
else if (attr_name ==
"length") {
347 }
else if (attr_name ==
"validfor") {
349 }
else if (attr_name ==
"default") {
351 }
else if (attr_name ==
"flags") {
352 tokenize(attr_value, flags,
",");
378 if ((name.length() == 0) || (name.find(
" ") != std::string::npos)) {
390 for (std::vector<std::string>::iterator i = flags.begin(); i != flags.end(); ++i) {
391 if (*i !=
"changed_indicator") {
419 if ((type ==
"unsigned int")) {
420 return (f.type !=
"unsigned int");
422 }
else if (type ==
"int") {
423 return ((f.type !=
"int") && (f.type !=
"unsigned int"));
425 }
else if (type ==
"unsigned long int") {
426 return ((f.type !=
"unsigned long int") && (f.type !=
"unsigned int") && (f.type !=
"int"));
428 }
else if (type ==
"long int") {
429 return ((f.type !=
"long int") && (f.type !=
"unsigned int") && (f.type !=
"int")
430 && (f.type !=
"unsigned long int"));
432 }
else if (type ==
"float") {
433 return ((f.type !=
"float") && (f.type !=
"unsigned int") && (f.type !=
"int"));
435 }
else if (type ==
"double") {
436 return ((f.type !=
"double") && (f.type !=
"unsigned int") && (f.type !=
"int")
437 && (f.type !=
"float"));
439 }
else if (type ==
"bool") {
440 return ((f.type !=
"bool") && (f.type !=
"double") && (f.type !=
"unsigned int")
441 && (f.type !=
"int") && (f.type !=
"float"));
443 }
else if (type ==
"byte") {
444 return ((f.type !=
"byte") && (f.type !=
"bool") && (f.type !=
"double")
445 && (f.type !=
"unsigned int") && (f.type !=
"int") && (f.type !=
"float"));
static bool validValue(const std::string &type, const std::string &value)
Check value validity for given type.
static bool validName(const std::string &name, const std::set< std::string > &reserved_names)
Check identifiers.
static bool validType(const std::string &type, std::vector< InterfaceEnumConstant > *enum_constants=0)
Decide if a supplied type is correct and in the case of constants if the supplied value matches the f...
Interface generator internal representation of a enum constant as parsed from the XML template file.
Interface generator internal representation of a field as parsed from the XML template file.
const std::vector< InterfaceEnumConstant > * getEnumConstants() const
Get vector of enum constants.
void setAttribute(const std::string &attr_name, const std::string &attr_value)
Set attribute.
std::string getName() const
Get name of field.
std::string getValidFor() const
Get valid for time.
void setLength(const std::string &length)
Set length of field.
std::string getDefaultValue() const
Get default value.
void setDefaultValue(const std::string &default_value)
Set default value.
bool isEnumType() const
Check if type is an enum type.
bool operator<(const InterfaceField &f) const
Check order of two elements.
void setName(const std::string &name)
Set name of field.
std::vector< std::string > getFlags() const
Get flags.
void valid(const std::set< std::string > &reserved_names)
Assert validity.
std::string getPlainAccessType() const
Get non-array accessor type.
std::string getType() const
Get type of field.
const InterfaceEnumConstant & getEnumConstant(const std::string &name) const
Get specific enum constant.
void setComment(const std::string &comment)
Set comment of field.
std::string getComment() const
Get comment of field.
std::string getStructType() const
Get type used to formulate struct.
void setValidFor(const std::string &validfor)
Set valid for time.
std::string getAccessType() const
Get type as used for accessor methods of class.
void setFlags(const std::vector< std::string > &flags)
Set flags.
std::string getMaxIdx() const
Get maximum index (length - 1)
unsigned int getLengthValue() const
Get length value.
std::string getLength() const
Get field length.
void setType(const std::string &type)
Set type of field.
InterfaceField(std::vector< InterfaceEnumConstant > *enum_constants=NULL)
Constructor.
Thrown if illegal flag is supplied.
Thrown if illegal type is supplied.
Thrown if illegal value is supplied.
Thrown if something is a reserved identifier.
Base class for exceptions in Fawkes.