message_template.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_TEMPLATE_H
30 #define CPP_INTROSPECTION_MESSAGE_TEMPLATE_H
31 
32 #include <introspection/message.h>
33 #include <ros/message_traits.h>
34 
35 #include <cstring>
36 
37 namespace cpp_introspection {
38 
39  template <typename T>
40  class MessageTemplate : public Message {
41  public:
42  typedef T MessageType;
43 
44  virtual ~MessageTemplate() {}
45 
49  const std::type_info& getTypeId() const { return typeid(MessageType); }
50 
51  bool isSimple() const { return ros::message_traits::isSimple<MessageType>(); }
52  bool isFixedSize() const { return ros::message_traits::isFixedSize<MessageType>(); }
53  bool hasHeader() const { return ros::message_traits::hasHeader<MessageType>(); }
54 
55  ::std_msgs::Header* getHeader(const VoidPtr& instance) const;
56  const ::std_msgs::Header* getHeader(const VoidConstPtr& instance) const;
57  std::string* getFrameId(const VoidPtr& instance) const;
58  const std::string* getFrameId(const VoidConstPtr& instance) const;
59  ros::Time* getTimeStamp(const VoidPtr& instance) const;
60  const ros::Time* getTimeStamp(const VoidConstPtr& instance) const;
61 
62  VoidPtr createInstance() const;
63  void serialize(ros::serialization::OStream& stream, const VoidConstPtr& instance = VoidConstPtr()) const;
64  ros::SerializedMessage serialize(const VoidConstPtr& instance = VoidConstPtr()) const;
65  std::size_t serializationLength(const VoidConstPtr& instance = VoidConstPtr()) const;
66  VoidPtr deserialize(ros::serialization::IStream& stream, const VoidPtr& instance = VoidPtr()) const;
67 
68  MessagePtr introspect(const VoidPtr& instance) const;
69  MessagePtr introspect(void *instance) const;
70  MessagePtr introspect(const VoidConstPtr& instance) const;
71  MessagePtr introspect(void const *instance) const;
72  };
73 
74  template <typename T>
75  ::std_msgs::Header* MessageTemplate<T>::getHeader(const VoidPtr& instance) const {
76  MessageType* x = static_cast<MessageType*>(instance.get());
77  if (!x) return 0;
79  }
80 
81  template <typename T>
82  const ::std_msgs::Header* MessageTemplate<T>::getHeader(const VoidConstPtr& instance) const {
83  const MessageType* x = static_cast<const MessageType*>(instance.get());
84  if (!x) return 0;
86  }
87 
88  template <typename T>
89  std::string* MessageTemplate<T>::getFrameId(const VoidPtr& instance) const {
90  MessageType* x = static_cast<MessageType*>(instance.get());
91  if (!x) return 0;
93  }
94 
95  template <typename T>
96  const std::string* MessageTemplate<T>::getFrameId(const VoidConstPtr& instance) const {
97  const MessageType* x = static_cast<const MessageType*>(instance.get());
98  if (!x) return 0;
100  }
101 
102  template <typename T>
104  MessageType* x = static_cast<MessageType*>(instance.get());
105  if (!x) return 0;
107  }
108 
109  template <typename T>
111  const MessageType* x = static_cast<const MessageType*>(instance.get());
112  if (!x) return 0;
114  }
115 
116  template <typename T>
118  {
119  return VoidPtr(new MessageType());
120  }
121 
122  template <typename T>
124  {
125  const MessageType* x = static_cast<const MessageType*>(instance.get());
126  if (!x) return;
127  ros::serialization::serialize(stream, *x);
128  }
129 
130  template <typename T>
132  {
133  const MessageType* x = static_cast<const MessageType*>(instance.get());
134  if (!x) return ros::SerializedMessage();
135  return ros::serialization::serializeMessage<T>(*x);
136  }
137 
138  template <typename T>
139  std::size_t MessageTemplate<T>::serializationLength(const VoidConstPtr& instance) const
140  {
141  const MessageType* x = static_cast<const MessageType*>(instance.get());
142  if (!x) return 0;
144  }
145 
146  template <typename T>
148  {
149  typename MessageType::Ptr x = boost::shared_static_cast<MessageType>(instance);
150  if (!x) x = boost::static_pointer_cast<MessageType>(createInstance());
152  return x;
153  }
154 
155 } // namespace
156 
157 #endif // CPP_INTROSPECTION_MESSAGE_TEMPLATE_H
VoidPtr deserialize(ros::serialization::IStream &stream, const VoidPtr &instance=VoidPtr()) const
static ros::Time * pointer(M &m)
void serialize(ros::serialization::OStream &stream, const VoidConstPtr &instance=VoidConstPtr()) const
virtual MessagePtr introspect() const
Definition: message.h:95
ros::Time * getTimeStamp(const VoidPtr &instance) const
boost::shared_ptr< void > VoidPtr
Definition: forwards.h:69
void serialize(Stream &stream, const T &t)
static const char * value()
boost::shared_ptr< void const > VoidConstPtr
Definition: forwards.h:71
static const char * value()
static const char * value()
static std::string * pointer(M &m)
std::size_t serializationLength(const VoidConstPtr &instance=VoidConstPtr()) const
const std::type_info & getTypeId() const
uint32_t serializationLength(const T &t)
const char * getDefinition() const
::std_msgs::Header * getHeader(const VoidPtr &instance) const
void deserialize(Stream &stream, T &t)
static std_msgs::Header * pointer(M &m)
std::string * getFrameId(const VoidPtr &instance) const


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