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) {
183 return default_value;
189 const std::vector<InterfaceEnumConstant> *
192 return enum_constants;
207 std::vector<InterfaceEnumConstant>::const_iterator i;
208 for (i = enum_constants->begin(); i != enum_constants->end(); ++i) {
209 if (type == i->get_name()) {
220 std::vector<std::string>
232 is_enum_type =
false;
233 if (enum_constants != NULL) {
234 std::vector<InterfaceEnumConstant>::iterator i;
235 for (i = enum_constants->begin(); i != enum_constants->end(); ++i) {
236 if (type == (*i).get_name()) {
259 this->comment = comment;
268 this->length_value = (
unsigned int)atoi(length.c_str());
269 this->length = length;
278 this->validfor = validfor;
287 this->default_value = default_value;
305 InterfaceField::tokenize(
const std::string & str,
306 std::vector<std::string> &tokens,
307 const std::string & delimiters)
310 std::string::size_type last_pos = str.find_first_not_of(delimiters, 0);
312 std::string::size_type pos = str.find_first_of(delimiters, last_pos);
314 while (std::string::npos != pos || std::string::npos != last_pos) {
316 tokens.push_back(str.substr(last_pos, pos - last_pos));
318 last_pos = str.find_first_not_of(delimiters, pos);
320 pos = str.find_first_of(delimiters, last_pos);
331 if (attr_name ==
"name") {
333 }
else if (attr_name ==
"type") {
335 }
else if (attr_name ==
"length") {
337 }
else if (attr_name ==
"validfor") {
339 }
else if (attr_name ==
"default") {
341 }
else if (attr_name ==
"flags") {
342 tokenize(attr_value, flags,
",");
368 if ((name.length() == 0) || (name.find(
" ") != std::string::npos)) {
380 for (std::vector<std::string>::iterator i = flags.begin(); i != flags.end(); ++i) {
381 if (*i !=
"changed_indicator") {
409 if ((type ==
"unsigned int")) {
410 return (f.type !=
"unsigned int");
412 }
else if (type ==
"int") {
413 return ((f.type !=
"int") && (f.type !=
"unsigned int"));
415 }
else if (type ==
"unsigned long int") {
416 return ((f.type !=
"unsigned long int") && (f.type !=
"unsigned int") && (f.type !=
"int"));
418 }
else if (type ==
"long int") {
419 return ((f.type !=
"long int") && (f.type !=
"unsigned int") && (f.type !=
"int")
420 && (f.type !=
"unsigned long int"));
422 }
else if (type ==
"float") {
423 return ((f.type !=
"float") && (f.type !=
"unsigned int") && (f.type !=
"int"));
425 }
else if (type ==
"double") {
426 return ((f.type !=
"double") && (f.type !=
"unsigned int") && (f.type !=
"int")
427 && (f.type !=
"float"));
429 }
else if (type ==
"bool") {
430 return ((f.type !=
"bool") && (f.type !=
"double") && (f.type !=
"unsigned int")
431 && (f.type !=
"int") && (f.type !=
"float"));
433 }
else if (type ==
"byte") {
434 return ((f.type !=
"byte") && (f.type !=
"bool") && (f.type !=
"double")
435 && (f.type !=
"unsigned int") && (f.type !=
"int") && (f.type !=
"float"));
std::string getType() const
Get type of field.
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...
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.
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.
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.
void valid(const std::set< std::string > &reserved_names)
Assert validity.
bool operator<(const InterfaceField &f) const
Check order of two elements.
static bool validValue(const std::string &type, const std::string &value)
Check value validity for given type.
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.
Thrown if something is a reserved identifier.
void setLength(const std::string &length)
Set length of field.
std::string getStructType() const
Get type used to formulate struct.