[Documentation] [TitleIndex] [WordIndex

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;

template<typename M> struct IsFixedSize;

template<typename M> struct HasHeader;

To change this to true you simply specialize for your message and inherit from TrueType instead of FalseType.

   1 template<typename M>
   2 struct Header
   3 {
   4   static roslib::Header* pointer(M& m);
   5   static roslib::Header const* pointer(const M& m);
   6 };

   1 template<typename M>
   2 struct FrameId
   3 {
   4   static std::string* pointer(M& m);
   5   static std::string const* pointer(const M& m);
   6   static std::string value(const M& m);
   7 };

   1 template<typename M>
   2 struct TimeStamp
   3 {
   4   static ros::Time* pointer(M& m);
   5   static ros::Time const* pointer(const M& m);
   6   static ros::Time value(const M& m);
   7 };

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

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)


2022-05-28 12:57