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 #ifndef CPP_INTROSPECTION_MESSAGE_H
00030 #define CPP_INTROSPECTION_MESSAGE_H
00031
00032 #include <introspection/forwards.h>
00033 #include <introspection/field.h>
00034
00035 #include <std_msgs/Header.h>
00036 #include <ros/time.h>
00037
00038 namespace cpp_introspection {
00039
00040 class Message
00041 {
00042 public:
00043 virtual ~Message() {}
00044
00045
00046
00047 virtual const char* getName() const = 0;
00048 virtual const char* getDataType() const = 0;
00049 virtual const char* getMD5Sum() const = 0;
00050 virtual const char* getDefinition() const = 0;
00051 virtual const std::type_info& getTypeId() const = 0;
00052
00053 virtual bool isMessage() const { return true; }
00054 virtual bool isSimple() const = 0;
00055 virtual bool isFixedSize() const = 0;
00056 virtual bool hasHeader() const = 0;
00057
00058 virtual std_msgs::Header* getHeader(const VoidPtr& instance) const = 0;
00059 virtual const std_msgs::Header* getHeader(const VoidConstPtr& instance) const = 0;
00060 virtual std::string* getFrameId(const VoidPtr& instance) const = 0;
00061 virtual const std::string* getFrameId(const VoidConstPtr& instance) const = 0;
00062 virtual ros::Time* getTimeStamp(const VoidPtr& instance) const = 0;
00063 virtual const ros::Time* getTimeStamp(const VoidConstPtr& instance) const = 0;
00064
00065 virtual const V_Field& fields() const = 0;
00066 virtual FieldWPtr field(const std::string& name) const = 0;
00067 virtual const V_FieldName& getFieldNames() const = 0;
00068
00069 V_string getFields(bool expand = false, const std::string& separator = ".", const std::string& prefix = std::string()) const;
00070 V_string& getFields(V_string& fields, bool expand = false, const std::string& separator = ".", const std::string& prefix = std::string()) const;
00071 V_string getTypes(bool expand = false) const;
00072 V_string& getTypes(V_string& types, bool expand = false) const;
00073 std::vector<boost::any> getValues(bool expand = false) const;
00074 std::vector<boost::any>& getValues(std::vector<boost::any>& values, bool expand = false) const;
00075
00076 virtual VoidPtr createInstance() const = 0;
00077 virtual void serialize(ros::serialization::OStream& stream, const VoidConstPtr& instance = VoidConstPtr()) const = 0;
00078 virtual ros::SerializedMessage serialize(const VoidConstPtr& instance = VoidConstPtr()) const = 0;
00079 virtual std::size_t serializationLength(const VoidConstPtr& instance = VoidConstPtr()) const = 0;
00080 virtual VoidPtr deserialize(ros::serialization::IStream& stream, const VoidPtr& instance = VoidPtr()) const = 0;
00081
00082 virtual bool hasInstance() const { return false; }
00083 virtual VoidPtr getInstance() const { return VoidPtr(); }
00084 virtual VoidConstPtr getConstInstance() const { return VoidConstPtr(); }
00085
00086 virtual MessagePtr introspect(const VoidPtr& instance) const = 0;
00087 virtual MessagePtr introspect(void *instance) const = 0;
00088 virtual MessagePtr introspect(const VoidConstPtr& instance) const = 0;
00089 virtual MessagePtr introspect(void const *instance) const = 0;
00090
00091 template <typename T> typename T::Ptr narrow(const VoidPtr& instance) const { return boost::shared_static_cast<T>(instance); }
00092 template <typename T> typename T::ConstPtr narrow(const VoidConstPtr& instance) const { return boost::shared_static_cast<T const>(instance); }
00093
00094 typedef V_Field::iterator iterator;
00095 typedef V_Field::const_iterator const_iterator;
00096 const_iterator begin() const { return fields().begin(); }
00097 const_iterator end() const { return fields().end(); }
00098 std::size_t size() const { return fields().size(); }
00099 };
00100
00101 MessagePtr messageByDataType(const std::string& data_type, const std::string& package = std::string());
00102 static inline MessagePtr messageByDataType(const char* data_type, const char* package) { return messageByDataType(std::string(data_type), std::string(package)); }
00103 MessagePtr messageByMD5Sum(const std::string& md5sum);
00104 static inline MessagePtr messageByMD5Sum(const char* md5sum) { return messageByMD5Sum(std::string(md5sum)); }
00105 MessagePtr messageByTypeId(const std::type_info& type_info);
00106
00107 MessagePtr expand(const MessagePtr& message, const std::string &separator = ".", const std::string &prefix = "");
00108
00109 }
00110
00111 #endif // CPP_INTROSPECTION_MESSAGE_H