00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <interfaces/generator/constant.h>
00024 #include <interfaces/generator/type_checker.h>
00025 #include <interfaces/generator/exceptions.h>
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 InterfaceConstant::InterfaceConstant(const std::string &name, const std::string &type,
00044 const std::string &value, const std::string &comment)
00045 {
00046 if ( ! InterfaceDataTypeChecker::validType(type) ) {
00047 throw InterfaceGeneratorInvalidTypeException("constant", name.c_str(), type.c_str());
00048 }
00049 if ( ! InterfaceDataTypeChecker::validValue(type, value) ) {
00050 throw InterfaceGeneratorInvalidValueException(name.c_str(), type.c_str(), value.c_str());
00051 }
00052
00053 this->name = name;
00054 this->type = type;
00055 if ( type == "string" ) {
00056 this->value = std::string("\"") + value + "\"";
00057 } else {
00058 this->value = value;
00059 }
00060 this->comment = comment;
00061 }
00062
00063
00064
00065
00066
00067 std::string
00068 InterfaceConstant::getName()
00069 {
00070 return name;
00071 }
00072
00073
00074
00075
00076
00077 std::string
00078 InterfaceConstant::getValue()
00079 {
00080 return value;
00081 }
00082
00083
00084
00085
00086
00087 std::string
00088 InterfaceConstant::getType()
00089 {
00090 if (type == "string") {
00091 return "char *";
00092 } else if (type == "byte") {
00093 return "uint8_t";
00094 } else if (type == "float" || type == "double" || type == "bool") {
00095 return type;
00096 } else {
00097 return type + "_t";
00098 }
00099 }
00100
00101
00102
00103
00104
00105 std::string
00106 InterfaceConstant::getComment()
00107 {
00108 return comment;
00109 }