00001 #ifndef ROS_BUILTIN_TYPES_HPP 00002 #define ROS_BUILTIN_TYPES_HPP 00003 00004 #include <stdint.h> 00005 #include <string> 00006 #include <ros/ros.h> 00007 00008 namespace RosIntrospection{ 00009 00010 00011 enum BuiltinType { 00012 BOOL , BYTE, CHAR, 00013 UINT8, UINT16, UINT32, UINT64, 00014 INT8, INT16, INT32, INT64, 00015 FLOAT32, FLOAT64, 00016 TIME, DURATION, 00017 STRING, OTHER 00018 }; 00019 00020 inline const char* toStr(const BuiltinType& c) 00021 { 00022 static const char* names[] = 00023 { 00024 "BOOL" , "BYTE", "CHAR", 00025 "UINT8", "UINT16", "UINT32", "UINT64", 00026 "INT8", "INT16", "INT32", "INT64", 00027 "FLOAT32", "FLOAT64", 00028 "TIME", "DURATION", 00029 "STRING", "OTHER" 00030 }; 00031 00032 return names[ static_cast<int>(c) ]; 00033 } 00034 00035 inline std::ostream& operator<<(std::ostream& os, const BuiltinType& c) 00036 { 00037 os << toStr(c); 00038 return os; 00039 } 00040 00041 const int BuiltinTypeSize[OTHER] = { 00042 1, 1, 1, 00043 1, 2, 4, 8, 00044 1, 2, 4, 8, 00045 4, 8, 00046 8, 8, 00047 -1 00048 }; 00049 00050 template <typename T> BuiltinType getType() 00051 { 00052 return OTHER; 00053 } 00054 00055 template <> inline BuiltinType getType<bool>() { return BOOL; } 00056 00057 template <> inline BuiltinType getType<int8_t>() { return INT8; } 00058 template <> inline BuiltinType getType<int16_t>() { return INT16; } 00059 template <> inline BuiltinType getType<int32_t>() { return INT32; } 00060 template <> inline BuiltinType getType<int64_t>() { return INT64; } 00061 00062 template <> inline BuiltinType getType<uint8_t>() { return UINT8; } 00063 template <> inline BuiltinType getType<uint16_t>() { return UINT16; } 00064 template <> inline BuiltinType getType<uint32_t>() { return UINT32; } 00065 template <> inline BuiltinType getType<uint64_t>() { return UINT64; } 00066 00067 template <> inline BuiltinType getType<float>() { return FLOAT32; } 00068 template <> inline BuiltinType getType<double>() { return FLOAT64; } 00069 00070 template <> inline BuiltinType getType<std::string>() { return STRING; } 00071 00072 template <> inline BuiltinType getType<ros::Time>() { return TIME; } 00073 template <> inline BuiltinType getType<ros::Duration>() { return DURATION; } 00074 00075 } 00076 00077 #endif // ROS_BUILTIN_TYPES_HPP