message_expansion.h
Go to the documentation of this file.
00001 //=================================================================================================
00002 // Copyright (c) 2012, 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_EXPANSION_H
00030 #define CPP_INTROSPECTION_MESSAGE_EXPANSION_H
00031 
00032 #include <introspection/message.h>
00033 
00034 namespace cpp_introspection {
00035 
00036 class MessageForwarder : public Message {
00037 protected:
00038   const MessagePtr& parent_;
00039 
00040 public:
00041   MessageForwarder(const MessagePtr& parent) : parent_(parent) {}
00042   virtual ~MessageForwarder() {}
00043 
00044   virtual PackagePtr package() const { return parent_->package(); }
00045   virtual const char* getPackageName() const { return parent_->getPackageName(); }
00046 
00047   virtual const char* getName() const { return parent_->getName(); }
00048   virtual const char* getDataType() const { return parent_->getDataType(); }
00049   virtual const char* getMD5Sum() const { return parent_->getMD5Sum(); }
00050   virtual const char* getDefinition() const { return parent_->getDefinition(); }
00051   virtual const std::type_info& getTypeId() const { return parent_->getTypeId(); }
00052 
00053   virtual bool isMessage() const { return parent_->isMessage(); }
00054   virtual bool isSimple() const { return parent_->isSimple(); }
00055   virtual bool isFixedSize() const { return parent_->isFixedSize(); }
00056   virtual bool hasHeader() const { return parent_->hasHeader(); }
00057 
00058   virtual std_msgs::Header* getHeader(const VoidPtr& instance) const { return parent_->getHeader(instance); }
00059   virtual const std_msgs::Header* getHeader(const VoidConstPtr& instance) const { return parent_->getHeader(instance); }
00060   virtual std::string* getFrameId(const VoidPtr& instance) const { return parent_->getFrameId(instance); }
00061   virtual const std::string* getFrameId(const VoidConstPtr& instance) const { return parent_->getFrameId(instance); }
00062   virtual ros::Time* getTimeStamp(const VoidPtr& instance) const { return parent_->getTimeStamp(instance); }
00063   virtual const ros::Time* getTimeStamp(const VoidConstPtr& instance) const { return parent_->getTimeStamp(instance); }
00064 
00065   virtual VoidPtr createInstance() const { return parent_->createInstance(); }
00066   virtual void serialize(ros::serialization::OStream& stream, const VoidConstPtr& instance = VoidConstPtr()) const { parent_->serialize(stream, instance); }
00067   virtual ros::SerializedMessage serialize(const VoidConstPtr& instance = VoidConstPtr()) const { return parent_->serialize(instance); }
00068   virtual std::size_t serializationLength(const VoidConstPtr& instance = VoidConstPtr()) const { return parent_->serializationLength(instance); }
00069   virtual VoidPtr deserialize(ros::serialization::IStream& stream, const VoidPtr& instance = VoidPtr()) const { return parent_->deserialize(stream, instance); }
00070 
00071   virtual bool hasInstance() const { return parent_->hasInstance(); }
00072   virtual VoidPtr getInstance() const { return parent_->getInstance(); }
00073   virtual VoidConstPtr getConstInstance() const { return parent_->getConstInstance(); }
00074 
00075   virtual MessagePtr introspect(const VoidPtr& instance) const { return parent_->introspect(instance); }
00076   virtual MessagePtr introspect(void *instance) const { return parent_->introspect(instance); }
00077   virtual MessagePtr introspect(const VoidConstPtr& instance) const { return parent_->introspect(instance); }
00078   virtual MessagePtr introspect(void const *instance) const { return parent_->introspect(instance); }
00079 };
00080 
00081 class ExpandedMessage : public MessageForwarder {
00082 private:
00083   V_Field fields_;
00084   M_Field fields_by_name_;
00085   V_FieldName field_names_;
00086 
00087   std::string separator_;
00088   std::string prefix_;
00089 
00090 public:
00091   ExpandedMessage(const MessagePtr& parent, const std::string &separator = ".", const std::string &prefix = std::string())
00092     : MessageForwarder(parent)
00093     , separator_(separator)
00094     , prefix_(prefix)
00095   {
00096     expand(parent, prefix);
00097   }
00098   virtual ~ExpandedMessage() {}
00099 
00100   virtual const V_Field& fields() const { return fields_; }
00101   virtual FieldWPtr field(const std::string& name) const { return fields_by_name_.at(name); }
00102   virtual const V_FieldName& getFieldNames() const { return field_names_; }
00103 
00104   virtual MessagePtr introspect(void *instance) const { return MessagePtr(new ExpandedMessage(parent_->introspect(instance), separator_, prefix_)); }
00105   virtual MessagePtr introspect(void const *instance) const { return MessagePtr(new ExpandedMessage(parent_->introspect(instance), separator_, prefix_)); }
00106 
00107 private:
00108   void expand(const MessagePtr& message, const std::string& prefix);
00109 };
00110 
00111 class ExpandedField : public Field {
00112 private:
00113   const Field& parent_;
00114   std::size_t index_;
00115   std::string name_;
00116 
00117 public:
00118   ExpandedField(const Field& parent, std::string name = std::string(), std::size_t index = 0)
00119     : parent_(parent), index_(index), name_(!name.empty() ? name : parent_.getName())
00120   {}
00121   virtual ~ExpandedField() {}
00122 
00123   virtual const Message& message() const { return parent_.message(); }
00124 
00125   virtual const char* getName() const { return name_.c_str(); }
00126   virtual const char* getDataType() const { return parent_.getValueType(); }
00127   virtual const char* getValueType() const { return parent_.getValueType(); }
00128   virtual std::size_t getIndex() const { return parent_.getIndex(); }
00129   virtual const std::type_info& getTypeId() const { return parent_.getTypeId(); }
00130   virtual TypePtr getType() const { return parent_.getType(); }
00131 
00132   virtual bool isArray() const { return false; }
00133   virtual bool isVector() const { return false; }
00134   virtual bool isContainer() const { return false; }
00135   virtual bool isSimple() const { return parent_.isSimple(); }
00136   virtual bool isFixedSize() const { return parent_.isFixedSize(); }
00137   virtual bool isMessage() const { return parent_.isMessage(); }
00138 
00139   virtual bool hasInstance() const { return parent_.hasInstance(); }
00140   virtual boost::any get(std::size_t i = 0) const { return parent_.get(index_); }
00141   virtual void setAny(const boost::any& value, std::size_t i = 0) const { parent_.setAny(value, index_); }
00142 
00143   virtual FieldPtr access(AccessorBase& accessor) const { return FieldPtr(); }
00144 };
00145 
00146 } // namespace cpp_introspection
00147 
00148 #endif // CPP_INTROSPECTION_MESSAGE_EXPANSION_H


cpp_introspection
Author(s): Johannes Meyer
autogenerated on Wed Aug 26 2015 11:11:00