Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #ifndef ROS_BUILTIN_TYPES_HPP
00037 #define ROS_BUILTIN_TYPES_HPP
00038
00039 #include <stdint.h>
00040 #include <string>
00041 #include <ros/ros.h>
00042 #include <unordered_map>
00043
00044 namespace RosIntrospection{
00045
00046
00047 enum BuiltinType {
00048 BOOL , BYTE, CHAR,
00049 UINT8, UINT16, UINT32, UINT64,
00050 INT8, INT16, INT32, INT64,
00051 FLOAT32, FLOAT64,
00052 TIME, DURATION,
00053 STRING, OTHER
00054 };
00055
00056
00057
00058 inline int builtinSize(const BuiltinType c) {
00059 switch (c) {
00060 case BOOL:
00061 case BYTE:
00062 case INT8:
00063 case CHAR:
00064 case UINT8: return 1;
00065 case UINT16:
00066 case INT16: return 2;
00067 case UINT32:
00068 case INT32:
00069 case FLOAT32: return 4;
00070 case UINT64:
00071 case INT64:
00072 case FLOAT64:
00073 case TIME:
00074 case DURATION: return 8;
00075 case STRING:
00076 case OTHER: return -1;
00077 }
00078 throw std::runtime_error( "unsupported builtin type value");
00079 }
00080
00081 inline const char* toStr(const BuiltinType& c)
00082 {
00083 switch (c) {
00084 case BOOL: return "BOOL";
00085 case BYTE: return "BYTE";
00086 case INT8: return "INT8";
00087 case CHAR: return "CHAR";
00088 case UINT8: return "UINT8";
00089 case UINT16: return "UINT16";
00090 case UINT32: return "UINT32";
00091 case UINT64: return "UINT64";
00092 case INT16: return "INT16";
00093 case INT32: return "INT32";
00094 case INT64: return "INT64";
00095 case FLOAT32: return "FLOAT32";
00096 case FLOAT64: return "FLOAT64";
00097 case TIME: return "TIME";
00098 case DURATION: return "DURATION";
00099 case STRING: return "STRING";
00100 case OTHER: return "OTHER";
00101 }
00102 throw std::runtime_error( "unsupported builtin type value");
00103 }
00104
00105 inline std::ostream& operator<<(std::ostream& os, const BuiltinType& c)
00106 {
00107 os << toStr(c);
00108 return os;
00109 }
00110
00111 template <typename T> BuiltinType getType()
00112 {
00113 return OTHER;
00114 }
00115
00116 template <> inline BuiltinType getType<bool>() { return BOOL; }
00117
00118 template <> inline BuiltinType getType<char>() { return CHAR; }
00119
00120 template <> inline BuiltinType getType<int8_t>() { return INT8; }
00121 template <> inline BuiltinType getType<int16_t>() { return INT16; }
00122 template <> inline BuiltinType getType<int32_t>() { return INT32; }
00123 template <> inline BuiltinType getType<int64_t>() { return INT64; }
00124
00125 template <> inline BuiltinType getType<uint8_t>() { return UINT8; }
00126 template <> inline BuiltinType getType<uint16_t>() { return UINT16; }
00127 template <> inline BuiltinType getType<uint32_t>() { return UINT32; }
00128 template <> inline BuiltinType getType<uint64_t>() { return UINT64; }
00129
00130 template <> inline BuiltinType getType<float>() { return FLOAT32; }
00131 template <> inline BuiltinType getType<double>() { return FLOAT64; }
00132
00133 template <> inline BuiltinType getType<std::string>() { return STRING; }
00134
00135 template <> inline BuiltinType getType<ros::Time>() { return TIME; }
00136 template <> inline BuiltinType getType<ros::Duration>() { return DURATION; }
00137
00138 }
00139
00140 #endif // ROS_BUILTIN_TYPES_HPP