MessageDataType.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright (C) 2014 by Ralf Kaestner *
3  * ralf.kaestner@gmail.com *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the Lesser GNU General Public License as published by*
7  * the Free Software Foundation; either version 3 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * Lesser GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the Lesser GNU General Public License *
16  * along with this program. If not, see <http://www.gnu.org/licenses/>. *
17  ******************************************************************************/
18 
23 #ifndef VARIANT_TOPIC_TOOLS_MESSAGE_DATA_TYPE_H
24 #define VARIANT_TOPIC_TOOLS_MESSAGE_DATA_TYPE_H
25 
31 
32 namespace variant_topic_tools {
36  public DataType {
37  friend class DataType;
38  friend class DataTypeRegistry;
39  friend class MessageVariant;
40  public:
44 
47  MessageDataType(const MessageDataType& src);
48 
51  MessageDataType(const DataType& src);
52 
55  virtual ~MessageDataType();
56 
59  std::string getMD5Sum() const;
60 
63  const std::string& getDefinition() const;
64 
67  size_t getNumMembers() const;
68 
72  size_t getNumConstantMembers() const;
73 
77  size_t getNumVariableMembers() const;
78 
81  const MessageMember& getMember(const std::string& name) const;
82 
85  const MessageMember& getMember(int index) const;
86 
89  const MessageConstant& getConstantMember(const std::string& name) const;
90 
93  const MessageConstant& getConstantMember(int index) const;
94 
97  const MessageVariable& getVariableMember(const std::string& name) const;
98 
101  const MessageVariable& getVariableMember(int index) const;
102 
106  bool hasMember(const std::string& name) const;
107 
111  bool hasConstantMember(const std::string& name) const;
112 
116  bool hasVariableMember(const std::string& name) const;
117 
120  bool hasHeader() const;
121 
125  void addConstantMember(const MessageConstant& member);
126 
130  MessageConstant addConstantMember(const std::string& name, const
131  Variant& value);
132 
136  template <typename T> MessageConstant addConstantMember(const
137  std::string& name, const T& value);
138 
142  void addVariableMember(const MessageVariable& member);
143 
147  MessageVariable addVariableMember(const std::string& name, const
148  DataType& type);
149 
153  template <typename T> MessageVariable addVariableMember(const
154  std::string& name);
155 
158  MessageDataType& operator=(const DataType& src);
159 
163  const MessageMember& operator[](int index) const;
164 
165  protected:
168  class Impl :
169  public DataType::Impl {
170  public:
176 
179  Impl(const std::string& identifier, const std::string& definition);
180 
183  virtual ~Impl();
184 
188  virtual std::string getMD5Sum() const = 0;
189 
193  virtual const std::string& getDefinition() const = 0;
194 
198  virtual void addConstantMember(const MessageConstant& member) = 0;
199 
203  virtual void addVariableMember(const MessageVariable& member) = 0;
204 
208 
212  };
213 
216  class ImplV :
217  public Impl {
218  public:
222  ImplV(const std::string& identifier, const MessageFieldCollection<
225 
229  ImplV(const std::string& identifier, const std::string& definition);
230 
233  virtual ~ImplV();
234 
238  const std::string& getIdentifier() const;
239 
243  std::string getMD5Sum() const;
244 
248  const std::string& getDefinition() const;
249 
253  size_t getSize() const;
254 
258  bool isFixedSize() const;
259 
263  bool isSimple() const;
264 
267  Serializer createSerializer(const DataType& type) const;
268 
271  Variant createVariant(const DataType& type) const;
272 
276  void addConstantMember(const MessageConstant& member);
277 
281  void addVariableMember(const MessageVariable& member);
282 
285  void recalculateMD5Sum();
286 
289  std::string identifier;
290 
294 
297  std::string definition;
298  };
299 
303  template <typename T> class ImplT :
304  public Impl {
305  public:
306  BOOST_STATIC_ASSERT(type_traits::IsMessage<T>::value);
307 
310  ImplT();
311 
314  virtual ~ImplT();
315 
319  const std::string& getIdentifier() const;
320 
324  const std::type_info& getTypeInfo() const;
325 
329  std::string getMD5Sum() const;
330 
334  const std::string& getDefinition() const;
335 
339  size_t getSize() const;
340 
344  bool isFixedSize() const;
345 
349  bool isSimple() const;
350 
353  Serializer createSerializer(const DataType& type) const;
354 
357  Variant createVariant(const DataType& type) const;
358 
362  void addConstantMember(const MessageConstant& member);
363 
367  void addVariableMember(const MessageVariable& member);
368 
372  template <typename M> void next(const M& member);
373 
378 
381  size_t memberIndex;
382  };
383 
387  MessageDataType(const std::string& identifier, const
390 
394  MessageDataType(const std::string& identifier, const std::string&
395  definition);
396 
400  template <typename T> static MessageDataType create();
401 
405  template <typename T, typename M> static void addMember(
406  MessageVariable& member, size_t offset, typename boost::enable_if<
407  type_traits::IsArray<M> >::type* = 0, typename boost::enable_if<
408  typename type_traits::ArrayType<M>::IsDynamic>::type* = 0);
409 
413  template <typename T, typename M> static void addMember(
414  MessageVariable& member, size_t offset, typename boost::enable_if<
415  type_traits::IsArray<M> >::type* = 0, typename boost::disable_if<
416  typename type_traits::ArrayType<M>::IsDynamic>::type* = 0);
417 
421  template <typename T, typename M> static void addMember(
422  MessageVariable& member, size_t offset, typename boost::
423  disable_if<type_traits::IsArray<M> >::type* = 0);
424  };
425 };
426 
427 #include <variant_topic_tools/MessageDataType.tpp>
428 
429 #endif
Header file providing the DataType class interface.
void addVariableMember(const MessageVariable &member)
Add a variable member to this message data type (overloaded version taking a message variable) ...
virtual Variant createVariant(const DataType &type) const =0
Create a variant from this data type (abstract declaration)
MD5Sum md5Sum
The MD5 sum of this message data type.
T message
The message used to determine the variable member memory offsets.
MessageFieldCollection< MessageConstant > constantMembers
The constant members of this message data type.
MessageDataType & operator=(const DataType &src)
Assignment operator.
MessageDataType()
Default constructor.
MD5 sum computation algorithm.
Definition: MD5Sum.h:36
MessageFieldCollection< MessageVariable > variableMembers
The variable members of this message data type.
bool hasMember(const std::string &name) const
True, if the message data type contains the member with the specified name.
Header file providing the MessageFieldCollection class interface.
size_t getNumVariableMembers() const
Retrieve the number of variable members of this message data type.
std::string getMD5Sum() const
Retrieve the MD5 sum of this message data type.
virtual Serializer createSerializer(const DataType &type) const =0
Create a serializer for this data type (abstract declaration)
virtual const std::string & getDefinition() const =0
Retrieve the definition this message data type (abstract declaration)
size_t getNumMembers() const
Retrieve the number of members of this message data type.
void addConstantMember(const MessageConstant &member)
Add a constant member to this message data type (overloaded version taking a message constant) ...
const MessageConstant & getConstantMember(const std::string &name) const
Access a constant member of the message data type by name.
const std::string & getDefinition() const
Retrieve the definition this message data type.
static void addMember(MessageVariable &member, size_t offset, typename boost::enable_if< type_traits::IsArray< M > >::type *=0, typename boost::enable_if< typename type_traits::ArrayType< M >::IsDynamic >::type *=0)
Add a variable message member (overloaded version for adding a dynamic array member) ...
Message data type implementation (variant-typed version)
Header file providing the data type traits.
virtual const std::type_info & getTypeInfo() const
Retrieve the type information associated with this data type.
Definition: DataType.cpp:144
static MessageDataType create()
Create a message data type (version templated on the message type)
const MessageVariable & getVariableMember(const std::string &name) const
Access a variable member of the message data type by name.
Header file providing the message type traits.
virtual bool isSimple() const =0
True, if this data type represents a simple data type (abstract declaration)
virtual void addConstantMember(const MessageConstant &member)=0
Add a constant member to this message data type (abstract declaration)
Data type implementation.
Definition: DataType.h:168
size_t memberIndex
The index of the currently processed variable member.
virtual void addVariableMember(const MessageVariable &member)=0
Add a variable member to this message data type (abstract declaration)
Header file providing the MD5Sum class interface.
bool hasVariableMember(const std::string &name) const
True, if the message data type contains the variable member with the specified name.
Message data type implementation.
const MessageMember & getMember(const std::string &name) const
Access a member of the message data type by name.
size_t getNumConstantMembers() const
Retrieve the number of constant members of this message data type.
bool hasConstantMember(const std::string &name) const
True, if the message data type contains the constant member with the specified name.
const MessageMember & operator[](int index) const
Operator for accessing the members of the message data type by index.
virtual std::string getMD5Sum() const =0
Retrieve the MD5 sum of this message data type (abstract declaration)
Message data type implementation (templated strong-typed version)
virtual const std::string & getIdentifier() const =0
Retrieve the identifier representing this data type (abstract declaration)
virtual bool isFixedSize() const =0
True, if this data type represents a fixed-size data type (abstract declaration)
bool hasHeader() const
True, if this message data type has a header.
const char * definition()
std::string definition
The definition of this message data type.
virtual size_t getSize() const =0
Retrieve the size of the instances of this data type (abstract declaration)
Forward declaration of the message field collection.
Definition: Forwards.h:64
std::string identifier
The identifier representing this message data type.


variant_topic_tools
Author(s): Ralf Kaestner
autogenerated on Sat Jan 9 2021 03:56:49