$search
00001 //================================================================================================= 00002 // Copyright (c) 2011, Johannes Meyer, TU Darmstadt 00003 // All rights reserved. 00004 00005 // Redistribution and use in source and binary forms, with or without 00006 // modification, are permitted provided that the following conditions are met: 00007 // * Redistributions of source code must retain the above copyright 00008 // notice, this list of conditions and the following disclaimer. 00009 // * Redistributions in binary form must reproduce the above copyright 00010 // notice, this list of conditions and the following disclaimer in the 00011 // documentation and/or other materials provided with the distribution. 00012 // * Neither the name of the Flight Systems and Automatic Control group, 00013 // TU Darmstadt, nor the names of its contributors may be used to 00014 // endorse or promote products derived from this software without 00015 // specific prior written permission. 00016 00017 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 00018 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00019 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00020 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY 00021 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00022 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00023 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00024 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00025 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00026 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 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 // virtual const Package& package() const = 0; 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 } // namespace cpp_introspection 00110 00111 #endif // CPP_INTROSPECTION_MESSAGE_H