message_expansion.h
Go to the documentation of this file.
1 //=================================================================================================
2 // Copyright (c) 2012, Johannes Meyer, TU Darmstadt
3 // All rights reserved.
4 
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are met:
7 // * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 // * Redistributions in binary form must reproduce the above copyright
10 // notice, this list of conditions and the following disclaimer in the
11 // documentation and/or other materials provided with the distribution.
12 // * Neither the name of the Flight Systems and Automatic Control group,
13 // TU Darmstadt, nor the names of its contributors may be used to
14 // endorse or promote products derived from this software without
15 // specific prior written permission.
16 
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
21 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 //=================================================================================================
28 
29 #ifndef CPP_INTROSPECTION_MESSAGE_EXPANSION_H
30 #define CPP_INTROSPECTION_MESSAGE_EXPANSION_H
31 
32 #include <introspection/message.h>
33 
34 namespace cpp_introspection {
35 
36 class MessageForwarder : public Message {
37 protected:
39 
40 public:
41  MessageForwarder(const MessagePtr& parent) : parent_(parent) {}
42  virtual ~MessageForwarder() {}
43 
44  virtual PackagePtr package() const { return parent_->package(); }
45  virtual const char* getPackageName() const { return parent_->getPackageName(); }
46 
47  virtual const char* getName() const { return parent_->getName(); }
48  virtual const char* getDataType() const { return parent_->getDataType(); }
49  virtual const char* getMD5Sum() const { return parent_->getMD5Sum(); }
50  virtual const char* getDefinition() const { return parent_->getDefinition(); }
51  virtual const std::type_info& getTypeId() const { return parent_->getTypeId(); }
52 
53  virtual bool isMessage() const { return parent_->isMessage(); }
54  virtual bool isSimple() const { return parent_->isSimple(); }
55  virtual bool isFixedSize() const { return parent_->isFixedSize(); }
56  virtual bool hasHeader() const { return parent_->hasHeader(); }
57 
58  virtual std_msgs::Header* getHeader(const VoidPtr& instance) const { return parent_->getHeader(instance); }
59  virtual const std_msgs::Header* getHeader(const VoidConstPtr& instance) const { return parent_->getHeader(instance); }
60  virtual std::string* getFrameId(const VoidPtr& instance) const { return parent_->getFrameId(instance); }
61  virtual const std::string* getFrameId(const VoidConstPtr& instance) const { return parent_->getFrameId(instance); }
62  virtual ros::Time* getTimeStamp(const VoidPtr& instance) const { return parent_->getTimeStamp(instance); }
63  virtual const ros::Time* getTimeStamp(const VoidConstPtr& instance) const { return parent_->getTimeStamp(instance); }
64 
65  virtual VoidPtr createInstance() const { return parent_->createInstance(); }
66  virtual void serialize(ros::serialization::OStream& stream, const VoidConstPtr& instance = VoidConstPtr()) const { parent_->serialize(stream, instance); }
67  virtual ros::SerializedMessage serialize(const VoidConstPtr& instance = VoidConstPtr()) const { return parent_->serialize(instance); }
68  virtual std::size_t serializationLength(const VoidConstPtr& instance = VoidConstPtr()) const { return parent_->serializationLength(instance); }
69  virtual VoidPtr deserialize(ros::serialization::IStream& stream, const VoidPtr& instance = VoidPtr()) const { return parent_->deserialize(stream, instance); }
70 
71  virtual bool hasInstance() const { return parent_->hasInstance(); }
72  virtual VoidPtr getInstance() const { return parent_->getInstance(); }
73  virtual VoidConstPtr getConstInstance() const { return parent_->getConstInstance(); }
74 
75  virtual MessagePtr introspect(const VoidPtr& instance) const { return parent_->introspect(instance); }
76  virtual MessagePtr introspect(void *instance) const { return parent_->introspect(instance); }
77  virtual MessagePtr introspect(const VoidConstPtr& instance) const { return parent_->introspect(instance); }
78  virtual MessagePtr introspect(void const *instance) const { return parent_->introspect(instance); }
79 };
80 
82 private:
86 
87  std::string separator_;
88  std::string prefix_;
89 
90 public:
91  ExpandedMessage(const MessagePtr& parent, const std::string &separator = ".", const std::string &prefix = std::string())
92  : MessageForwarder(parent)
93  , separator_(separator)
94  , prefix_(prefix)
95  {
96  expand(parent, prefix);
97  }
98  virtual ~ExpandedMessage() {}
99 
100  virtual const V_Field& fields() const { return fields_; }
101  virtual FieldWPtr field(const std::string& name) const { return fields_by_name_.at(name); }
102  virtual const V_FieldName& getFieldNames() const { return field_names_; }
103 
104  virtual MessagePtr introspect(void *instance) const { return MessagePtr(new ExpandedMessage(parent_->introspect(instance), separator_, prefix_)); }
105  virtual MessagePtr introspect(void const *instance) const { return MessagePtr(new ExpandedMessage(parent_->introspect(instance), separator_, prefix_)); }
106 
107 private:
108  void expand(const MessagePtr& message, const std::string& prefix);
109 };
110 
111 class ExpandedField : public Field {
112 private:
113  const Field& parent_;
114  std::size_t index_;
115  std::string name_;
116 
117 public:
118  ExpandedField(const Field& parent, std::string name = std::string(), std::size_t index = 0)
119  : parent_(parent), index_(index), name_(!name.empty() ? name : parent_.getName())
120  {}
121  virtual ~ExpandedField() {}
122 
123  virtual const Message& message() const { return parent_.message(); }
124 
125  virtual const char* getName() const { return name_.c_str(); }
126  virtual const char* getDataType() const { return parent_.getValueType(); }
127  virtual const char* getValueType() const { return parent_.getValueType(); }
128  virtual std::size_t getIndex() const { return parent_.getIndex(); }
129  virtual const std::type_info& getTypeId() const { return parent_.getTypeId(); }
130  virtual TypePtr getType() const { return parent_.getType(); }
131 
132  virtual bool isArray() const { return false; }
133  virtual bool isVector() const { return false; }
134  virtual bool isContainer() const { return false; }
135  virtual bool isSimple() const { return parent_.isSimple(); }
136  virtual bool isFixedSize() const { return parent_.isFixedSize(); }
137  virtual bool isMessage() const { return parent_.isMessage(); }
138 
139  virtual bool hasInstance() const { return parent_.hasInstance(); }
140  virtual boost::any get(std::size_t i = 0) const { return parent_.get(index_); }
141  virtual void setAny(const boost::any& value, std::size_t i = 0) const { parent_.setAny(value, index_); }
142 
143  virtual FieldPtr access(AccessorBase& accessor) const { return FieldPtr(); }
144 };
145 
146 } // namespace cpp_introspection
147 
148 #endif // CPP_INTROSPECTION_MESSAGE_EXPANSION_H
virtual ros::Time * getTimeStamp(const VoidPtr &instance) const
virtual const std::type_info & getTypeId() const =0
virtual VoidConstPtr getConstInstance() const
virtual TypePtr getType() const
Definition: field.h:49
virtual bool isSimple() const =0
virtual boost::any get(std::size_t i=0) const
Definition: field.h:59
std::vector< FieldPtr > V_Field
Definition: forwards.h:57
virtual const ros::Time * getTimeStamp(const VoidConstPtr &instance) const
virtual bool isFixedSize() const =0
virtual const char * getValueType() const
virtual const char * getDefinition() const
boost::weak_ptr< Field const > FieldWPtr
Definition: forwards.h:51
virtual const char * getPackageName() const
std::map< std::string, FieldWPtr > M_Field
Definition: forwards.h:63
virtual bool isMessage() const =0
virtual VoidPtr createInstance() const
virtual const std::string * getFrameId(const VoidConstPtr &instance) const
virtual const char * getDataType() const
virtual void serialize(ros::serialization::OStream &stream, const VoidConstPtr &instance=VoidConstPtr()) const
virtual VoidPtr deserialize(ros::serialization::IStream &stream, const VoidPtr &instance=VoidPtr()) const
virtual ros::SerializedMessage serialize(const VoidConstPtr &instance=VoidConstPtr()) const
MessagePtr expand(const MessagePtr &message, const std::string &separator=".", const std::string &prefix="")
virtual const V_FieldName & getFieldNames() const
ExpandedField(const Field &parent, std::string name=std::string(), std::size_t index=0)
virtual std::string * getFrameId(const VoidPtr &instance) const
virtual void setAny(const boost::any &value, std::size_t i=0) const
virtual FieldWPtr field(const std::string &name) const
boost::shared_ptr< void > VoidPtr
Definition: forwards.h:69
virtual const char * getValueType() const =0
virtual const Message & message() const
virtual MessagePtr introspect(void *instance) const
virtual std::size_t serializationLength(const VoidConstPtr &instance=VoidConstPtr()) const
virtual TypePtr getType() const
virtual MessagePtr introspect(const VoidConstPtr &instance) const
virtual MessagePtr introspect(void *instance) const
virtual bool hasInstance() const
Definition: field.h:58
ExpandedMessage(const MessagePtr &parent, const std::string &separator=".", const std::string &prefix=std::string())
virtual const std_msgs::Header * getHeader(const VoidConstPtr &instance) const
boost::shared_ptr< Field const > FieldPtr
Definition: forwards.h:50
virtual const std::type_info & getTypeId() const
boost::shared_ptr< void const > VoidConstPtr
Definition: forwards.h:71
virtual const V_Field & fields() const
virtual const std::type_info & getTypeId() const
virtual void setAny(const boost::any &value, std::size_t i=0) const
Definition: field.h:62
virtual VoidPtr getInstance() const
virtual PackagePtr package() const
virtual MessagePtr introspect(void const *instance) const
virtual MessagePtr introspect(void const *instance) const
virtual std::size_t getIndex() const
virtual const char * getName() const
virtual const char * getDataType() const
virtual const char * getMD5Sum() const
MessageForwarder(const MessagePtr &parent)
boost::shared_ptr< Message const > MessagePtr
Definition: forwards.h:48
virtual const Message & message() const =0
virtual std_msgs::Header * getHeader(const VoidPtr &instance) const
virtual FieldPtr access(AccessorBase &accessor) const
std::vector< const char * > V_FieldName
Definition: forwards.h:58
virtual const char * getName() const
virtual std::size_t getIndex() const =0
virtual MessagePtr introspect(const VoidPtr &instance) const


cpp_introspection
Author(s): Johannes Meyer
autogenerated on Mon Jun 10 2019 12:56:17