builtin_types.hpp
Go to the documentation of this file.
1 
2 /*********************************************************************
3 * Software License Agreement (BSD License)
4 *
5 * Copyright 2016-2017 Davide Faconti
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer in the documentation and/or other materials provided
17 * with the distribution.
18 * * Neither the name of Willow Garage, Inc. nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
34 * *******************************************************************/
35 
36 #ifndef ROS_BUILTIN_TYPES_HPP
37 #define ROS_BUILTIN_TYPES_HPP
38 
39 #include <stdint.h>
40 #include <string>
41 #include <ros/ros.h>
42 #include <unordered_map>
43 
44 namespace RosIntrospection{
45 
46 
54 };
55 
56 //---------------------------------------------------------
57 
58 inline int builtinSize(const BuiltinType c) {
59  switch (c) {
60  case BOOL:
61  case BYTE:
62  case INT8:
63  case CHAR:
64  case UINT8: return 1;
65  case UINT16:
66  case INT16: return 2;
67  case UINT32:
68  case INT32:
69  case FLOAT32: return 4;
70  case UINT64:
71  case INT64:
72  case FLOAT64:
73  case TIME:
74  case DURATION: return 8;
75  case STRING:
76  case OTHER: return -1;
77  }
78  throw std::runtime_error( "unsupported builtin type value");
79 }
80 
81 inline const char* toStr(const BuiltinType& c)
82 {
83  switch (c) {
84  case BOOL: return "BOOL";
85  case BYTE: return "BYTE";
86  case INT8: return "INT8";
87  case CHAR: return "CHAR";
88  case UINT8: return "UINT8";
89  case UINT16: return "UINT16";
90  case UINT32: return "UINT32";
91  case UINT64: return "UINT64";
92  case INT16: return "INT16";
93  case INT32: return "INT32";
94  case INT64: return "INT64";
95  case FLOAT32: return "FLOAT32";
96  case FLOAT64: return "FLOAT64";
97  case TIME: return "TIME";
98  case DURATION: return "DURATION";
99  case STRING: return "STRING";
100  case OTHER: return "OTHER";
101  }
102  throw std::runtime_error( "unsupported builtin type value");
103 }
104 
105 inline std::ostream& operator<<(std::ostream& os, const BuiltinType& c)
106 {
107  os << toStr(c);
108  return os;
109 }
110 
111 template <typename T> BuiltinType getType()
112 {
113  return OTHER;
114 }
115 
116 template <> inline BuiltinType getType<bool>() { return BOOL; }
117 
118 template <> inline BuiltinType getType<char>() { return CHAR; }
119 
120 template <> inline BuiltinType getType<int8_t>() { return INT8; }
121 template <> inline BuiltinType getType<int16_t>() { return INT16; }
122 template <> inline BuiltinType getType<int32_t>() { return INT32; }
123 template <> inline BuiltinType getType<int64_t>() { return INT64; }
124 
125 template <> inline BuiltinType getType<uint8_t>() { return UINT8; }
126 template <> inline BuiltinType getType<uint16_t>() { return UINT16; }
127 template <> inline BuiltinType getType<uint32_t>() { return UINT32; }
128 template <> inline BuiltinType getType<uint64_t>() { return UINT64; }
129 
130 template <> inline BuiltinType getType<float>() { return FLOAT32; }
131 template <> inline BuiltinType getType<double>() { return FLOAT64; }
132 
133 template <> inline BuiltinType getType<std::string>() { return STRING; }
134 
135 template <> inline BuiltinType getType<ros::Time>() { return TIME; }
136 template <> inline BuiltinType getType<ros::Duration>() { return DURATION; }
137 
138 }
139 
140 #endif // ROS_BUILTIN_TYPES_HPP
BuiltinType getType< uint16_t >()
BuiltinType getType< char >()
std::ostream & operator<<(std::ostream &os, const BuiltinType &c)
BuiltinType getType< bool >()
BuiltinType getType< int8_t >()
BuiltinType getType< int32_t >()
int builtinSize(const BuiltinType c)
BuiltinType getType< int64_t >()
const char * toStr(const BuiltinType &c)
BuiltinType getType< int16_t >()
BuiltinType getType< float >()
BuiltinType getType< double >()
BuiltinType getType< uint8_t >()
BuiltinType getType< uint64_t >()
BuiltinType getType()
BuiltinType getType< uint32_t >()


ros_type_introspection
Author(s): Davide Faconti
autogenerated on Thu May 16 2019 02:39:09