23 #include <interfaces/generator/type_checker.h> 24 #include <interfaces/generator/exceptions.h> 25 #include <core/exception.h> 33 #ifndef __STDC_LIMIT_MACROS 34 #define __STDC_LIMIT_MACROS 66 if ( (type ==
"int8") ||
79 (type ==
"double") ) {
81 }
else if ( enum_constants != NULL ) {
82 std::vector<InterfaceEnumConstant>::iterator i;
83 for (i = enum_constants->begin(); i != enum_constants->end(); ++i) {
84 if ( type == (*i).get_name() ) {
103 if (type.find(
"int") != std::string::npos) {
105 long long int rv = strtoll(value.c_str(), &endptr, 10);
106 if ( ((rv == LLONG_MIN) || (rv == LLONG_MAX)) && (errno == ERANGE) ) {
108 "long long int", value.c_str());
110 if ( (endptr != NULL) && (endptr[0] ==
'\0')) {
111 if (type ==
"uint8") {
112 return (rv >= 0) && (rv <= UINT8_MAX);
113 }
else if (type ==
"uint16") {
114 return (rv >= 0) && (rv <= UINT16_MAX);
115 }
else if (type ==
"uint32") {
116 return (rv >= 0) && (rv <= UINT32_MAX);
117 }
else if (type ==
"uint64") {
118 return (rv >= 0) && ((uint64_t)rv <= UINT64_MAX);
119 }
else if (type ==
"int8") {
120 return (rv >= INT8_MIN) && (rv <= INT8_MAX);
121 }
else if (type ==
"int16") {
122 return (rv >= INT16_MIN) && (rv <= INT16_MAX);
123 }
else if (type ==
"int32") {
124 return (rv >= INT32_MIN) && (rv <= INT32_MAX);
125 }
else if (type ==
"int64") {
126 return (rv >= INT64_MIN) && (rv <= INT64_MAX);
133 }
else if ( type ==
"bool" ) {
134 return ( (value ==
"true") ||
135 (value ==
"false") ||
140 }
else if ( (type ==
"float") ||
141 (type ==
"double") ) {
143 float rv = strtod(value.c_str(), &endptr);
144 if ((rv == HUGE_VAL) || (rv == -HUGE_VAL)) {
145 throw fawkes::Exception(
"Could not convert string '%s' to float", value.c_str());
147 return ((endptr != NULL) && (endptr[0] ==
'\0'));
148 }
else if ( type ==
"string" ) {
static bool validValue(const std::string &type, const std::string &value)
Check value validity for given type.
Base class for exceptions in Fawkes.
static bool validType(const std::string &type, std::vector< InterfaceEnumConstant > *enum_constants=0)
Check type validity.