23 #include <core/exception.h>
24 #include <interfaces/generator/checker.h>
25 #include <interfaces/generator/exceptions.h>
33 #ifndef __STDC_LIMIT_MACROS
34 # define __STDC_LIMIT_MACROS
62 std::vector<InterfaceEnumConstant> *enum_constants)
64 if ((type ==
"int8") || (type ==
"int16") || (type ==
"int32") || (type ==
"int64")
65 || (type ==
"uint8") || (type ==
"uint16") || (type ==
"uint32") || (type ==
"uint64")
66 || (type ==
"bool") || (type ==
"char") || (type ==
"float") || (type ==
"byte")
67 || (type ==
"string") || (type ==
"double")) {
69 }
else if (enum_constants != NULL) {
70 std::vector<InterfaceEnumConstant>::iterator i;
71 for (i = enum_constants->begin(); i != enum_constants->end(); ++i) {
72 if (type == (*i).get_name()) {
90 if (type.find(
"int") != std::string::npos) {
93 long long int rv = strtoll(value.c_str(), &endptr, 10);
94 if (((rv == LLONG_MIN) || (rv == LLONG_MAX)) && (errno == ERANGE)) {
99 if ((endptr != NULL) && (endptr[0] ==
'\0')) {
100 if (type ==
"uint8") {
101 return (rv >= 0) && (rv <= UINT8_MAX);
102 }
else if (type ==
"uint16") {
103 return (rv >= 0) && (rv <= UINT16_MAX);
104 }
else if (type ==
"uint32") {
105 return (rv >= 0) && (rv <= UINT32_MAX);
106 }
else if (type ==
"uint64") {
107 return (rv >= 0) && ((uint64_t)rv <= UINT64_MAX);
108 }
else if (type ==
"int8") {
109 return (rv >= INT8_MIN) && (rv <= INT8_MAX);
110 }
else if (type ==
"int16") {
111 return (rv >= INT16_MIN) && (rv <= INT16_MAX);
112 }
else if (type ==
"int32") {
113 return (rv >= INT32_MIN) && (rv <= INT32_MAX);
114 }
else if (type ==
"int64") {
115 return (rv >= INT64_MIN) && (rv <= INT64_MAX);
122 }
else if (type ==
"bool") {
123 return ((value ==
"true") || (value ==
"false") || (value ==
"yes") || (value ==
"no")
124 || (value ==
"0") || (value ==
"1"));
125 }
else if ((type ==
"float") || (type ==
"double")) {
127 float rv = strtod(value.c_str(), &endptr);
128 if ((rv == HUGE_VAL) || (rv == -HUGE_VAL)) {
129 throw fawkes::Exception(
"Could not convert string '%s' to float", value.c_str());
131 return ((endptr != NULL) && (endptr[0] ==
'\0'));
132 }
else if (type ==
"string") {
149 if (name.substr(0, 4) ==
"set_")
150 return reserved_names.find(name.substr(5)) == reserved_names.end();
151 if (name.substr(0, 3) ==
"is_")
152 return reserved_names.find(name.substr(4)) == reserved_names.end();
154 return reserved_names.find(name) == reserved_names.end();
157 const std::set<std::string>
158 reserved_names_interface()
182 "copy_shared_to_buffer",
183 "copy_private_to_buffer",
236 const std::set<std::string>
237 reserved_names_message()
244 "sender_thread_name",
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...
Base class for exceptions in Fawkes.