Message Traits
New in C Turtle
Message traits (and the message_traits namespace) allow you to query certain information about a message. They are mainly used to allow adapting of C++ types to ROS msg types, but can also be useful for retrieving information such as the datatype, md5sum or full message definition from a message.
All traits must be defined in the namespace ros::message_traits
Required traits for advertise/subscribe
1 template<typename M>
2 struct MD5Sum
3 {
4 static const char* value();
5 static const char* value(const M& m);
6 };
7
8 template<typename M>
9 struct DataType
10 {
11 static const char* value();
12 static const char* value(const M& m);
13 };
14
15 template<typename M>
16 struct Definition
17 {
18 static const char* value();
19 static const char* value(const M& m);
20 };
For backwards compatibility, these default to returning the values of e.g. __s_getMD5Sum()/__getMD5Sum().
Optional Traits
template<typename M> struct IsSimple;
A "simple" message is one which, given a vector/array of them, can be memcpy'd directly. Note that due to the padding rules of various compilers you need to be very careful about marking a struct as simple. For simple struct A, A must be a POD type and sizeof(A) must equal the sum of the length of serialization for each of its members.
template<typename M> struct IsFixedSize;
A fixed-size message is one which is always the same size. Used to optimize determining the size of a vector/array of M.
template<typename M> struct HasHeader;
Tells whether or not M has a header.
To change this to true you simply specialize for your message and inherit from TrueType instead of FalseType.
Returns a pointer to the header in the message. By default this returns &m.header if HasHeader<M>::value is true, or NULL if false.
- Returns the frame id of the message, as pointer or value type as requested.
- Returns the timestamp of the message, as pointer or value type as requested.
IsSimple, IsFixedSize and HasHeader can be used at compile time. Their default implementation is:
1 template<typename M> struct IsSimple : public FalseType {};
FalseType/TrueType provide a bool integral constant value and a type typedef to support use with boost mpl and enable_if
FalseType::value = false
FalseType::type = FalseType
TrueType::value = true
TrueType::type = TrueType
Function Accessors
Function |
Return Value |
md5sum<M>() |
MD5Sum<M>::value() |
md5sum<M>(const M& m) |
MD5Sum<M>::value(m) |
datatype<M>() |
DataType<M>::value() |
datatype<M>(const M& m) |
DataType<M>::value(m) |
definition<M>() |
Definition<M>::value() |
definition<M>(const M& m) |
Definition<M>::value(m) |
hasHeader<M>() |
HasHeader<M>::value |
isSimple<M>() |
IsSimple<M>::value |
isFixedSize<M>() |
IsFixedSize<M>::value |
header<M>(M& m) |
Header<M>::pointer(m) |
frameId<M>(M& m) |
FrameId<M>::pointer(m) |
timeStamp<M>(M& m) |
TimeStamp<M>::pointer(m) |