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) {
106 long long int rv = strtoll(value.c_str(), &endptr, 10);
107 if ( ((rv == LLONG_MIN) || (rv == LLONG_MAX)) && (errno == ERANGE) ) {
109 "long long int", value.c_str());
111 if ( (endptr != NULL) && (endptr[0] ==
'\0')) {
112 if (type ==
"uint8") {
113 return (rv >= 0) && (rv <= UINT8_MAX);
114 }
else if (type ==
"uint16") {
115 return (rv >= 0) && (rv <= UINT16_MAX);
116 }
else if (type ==
"uint32") {
117 return (rv >= 0) && (rv <= UINT32_MAX);
118 }
else if (type ==
"uint64") {
119 return (rv >= 0) && ((uint64_t)rv <= UINT64_MAX);
120 }
else if (type ==
"int8") {
121 return (rv >= INT8_MIN) && (rv <= INT8_MAX);
122 }
else if (type ==
"int16") {
123 return (rv >= INT16_MIN) && (rv <= INT16_MAX);
124 }
else if (type ==
"int32") {
125 return (rv >= INT32_MIN) && (rv <= INT32_MAX);
126 }
else if (type ==
"int64") {
127 return (rv >= INT64_MIN) && (rv <= INT64_MAX);
134 }
else if ( type ==
"bool" ) {
135 return ( (value ==
"true") ||
136 (value ==
"false") ||
141 }
else if ( (type ==
"float") ||
142 (type ==
"double") ) {
144 float rv = strtod(value.c_str(), &endptr);
145 if ((rv == HUGE_VAL) || (rv == -HUGE_VAL)) {
146 throw fawkes::Exception(
"Could not convert string '%s' to float", value.c_str());
148 return ((endptr != NULL) && (endptr[0] ==
'\0'));
149 }
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.