MessageVariant.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_VARIANT_H
24 #define VARIANT_TOPIC_TOOLS_MESSAGE_VARIANT_H
25 
26 #include <vector>
27 
31 
32 namespace variant_topic_tools {
36  public CollectionVariant {
37  friend class MessageDataType;
38  friend class Variant;
39  public:
43 
46  MessageVariant(const MessageVariant& src);
47 
50  MessageVariant(const Variant& src);
51 
55 
56  using Variant::operator=;
57 
58  protected:
61  class Value :
63  public:
66  Value();
67 
70  virtual ~Value();
71 
74  void setValue(const Variant::Value& value);
75 
79  virtual const std::string& getMemberName(int index) const = 0;
80 
84  void writeMember(std::ostream& stream, int index) const;
85  };
86 
89  class ValueImplV :
90  public Value {
91  public:
96 
99  ValueImplV(const ValueImplV& src);
100 
103  virtual ~ValueImplV();
104 
108  size_t getNumMembers() const;
109 
113  void setMember(int index, const Variant& member);
114 
118  void setMember(const std::string& name, const Variant& member);
119 
123  Variant getMember(int index) const;
124 
128  Variant getMember(const std::string& name) const;
129 
133  const std::string& getMemberName(int index) const;
134 
138  bool hasMember(const std::string& name) const;
139 
142  ValuePtr clone() const;
143 
147 
151  };
152 
155  template <typename T> class ValueImplT :
156  public Variant::ValueT<typename type_traits::MessageType<T>::ValueType>,
157  public Value {
158  public:
159  BOOST_STATIC_ASSERT(type_traits::IsMessage<T>::value);
160 
164 
169  message = Pointer<ValueType>());
170 
173  ValueImplT(const ValueImplT<T>& src);
174 
177  virtual ~ValueImplT();
178 
181  void set(const Pointer<ValueType>& value);
182 
186  ValueType& getValue();
187 
191  const ValueType& getValue() const;
192 
196  size_t getNumMembers() const;
197 
201  void setMember(int index, const Variant& member);
202 
206  void setMember(const std::string& name, const Variant& member);
207 
211  Variant getMember(int index) const;
212 
216  Variant getMember(const std::string& name) const;
217 
221  const std::string& getMemberName(int index) const;
222 
226  bool hasMember(const std::string& name) const;
227 
230  ValuePtr clone() const;
231 
235 
239 
243  };
244 
249  Variant>& members);
250 
253  template <typename T> static MessageVariant create(const DataType& type,
255  };
256 };
257 
258 #include <variant_topic_tools/MessageVariant.tpp>
259 
260 #endif
Message variant value (templated implementation)
Variant value (abstract base)
Definition: Variant.h:167
virtual Variant getMember(int index) const =0
Retrieve a member of the collection by index (abstract declaration)
Header file providing the CollectionVariant class interface.
Header file providing the MessageFieldCollection class interface.
MessageFieldCollection< Variant > members
The message members.
DataType type
The variant&#39;s data type.
Definition: Variant.h:247
ValuePtr value
The variant&#39;s data value.
Definition: Variant.h:251
type_traits::DataType< T >::ValueType & getValue()
Retrieve the variant&#39;s value (non-const version)
virtual bool hasMember(const std::string &name) const =0
True, if the collection contains the member with the specified name (abstract declaration) ...
void setValue(const Variant::Value &value)
Set the variant&#39;s value (implementation)
Pointer< ValueType > message
The strong-typed message.
virtual const std::string & getMemberName(int index) const =0
Retrieve the name of the message member with the specified index (abstract declaration) ...
Message variant value (variant-typed implementation)
virtual Serializer createSerializer(const DataType &type) const =0
Create a serializer for this variant (abstract declaration)
Header file providing the message type traits.
virtual size_t getNumMembers() const =0
Retrieve the number of members of the collection (abstract declaration)
type_traits::MessageType< T >::ValueType ValueType
Definition of the value type.
Message variant value (abstract base)
Collection variant value (abstract base)
MessageVariant()
Default constructor.
Variant value (templated abstract base)
Definition: Variant.h:209
virtual void setMember(int index, const Variant &member)=0
Set a member of the collection by index (abstract declaration)
virtual ValuePtr clone() const =0
Clone this variant value (abstract declaration)
Forward declaration of the message field collection.
Definition: Forwards.h:64
static MessageVariant create(const DataType &type, const MessageFieldCollection< MessageVariable > &members)
Create a message variant.
void writeMember(std::ostream &stream, int index) const
Write the variant collection member with the specified index to a stream (implementation) ...
MessageFieldCollection< MessageVariable > members
The message members.


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