ArrayVariant.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_ARRAY_VARIANT_H
24 #define VARIANT_TOPIC_TOOLS_ARRAY_VARIANT_H
25 
26 #include <vector>
27 
30 
31 namespace variant_topic_tools {
34  class ArrayVariant :
35  public CollectionVariant {
36  friend class ArrayDataType;
37  friend class Variant;
38  public:
41  ArrayVariant();
42 
45  ArrayVariant(const ArrayVariant& src);
46 
49  ArrayVariant(const Variant& src);
50 
53  ~ArrayVariant();
54 
61  void addMember(const Variant& member);
62 
68  void resize(size_t numMembers);
69 
75  void clear();
76 
79  ArrayVariant& operator+=(const Variant& member);
80 
81  using Variant::operator=;
82 
83  protected:
86  class Value :
88  public:
91  Value();
92 
95  virtual ~Value();
96 
99  void setValue(const Variant::Value& value);
100 
104  void setMember(const std::string& name, const Variant& member);
105 
107 
111  Variant getMember(const std::string& name) const;
112 
114 
118  bool hasMember(const std::string& name) const;
119 
123  void writeMember(std::ostream& stream, int index) const;
124 
127  virtual void addMember(const Variant& member) = 0;
128 
131  virtual void resize(size_t numMembers) = 0;
132 
135  virtual void clear() = 0;
136  };
137 
140  class ValueImplV :
141  public Value {
142  public:
145  ValueImplV(const DataType& memberType = DataType(), size_t
146  numMembers = 0);
147 
150  ValueImplV(const ValueImplV& src);
151 
154  virtual ~ValueImplV();
155 
159  size_t getNumMembers() const;
160 
164  void setMember(int index, const Variant& member);
165 
169  Variant getMember(int index) const;
170 
173  void addMember(const Variant& member);
174 
177  void resize(size_t numMembers);
178 
181  void clear();
182 
185  ValuePtr clone() const;
186 
190 
194 
197  size_t numMembers;
198 
201  std::vector<Variant> members;
202  };
203 
206  template <typename T> class ValueImplT :
207  public Variant::ValueT<typename type_traits::ArrayType<T>::ValueType>,
208  public Value {
209  public:
210  BOOST_STATIC_ASSERT(type_traits::IsArray<T>::value);
211 
215 
219 
222  static const size_t NumMembers = type_traits::ArrayType<T>::NumMembers;
223 
226  ValueImplT(const DataType& memberType = DataType(), const
228 
231  ValueImplT(const ValueImplT<T>& src);
232 
235  virtual ~ValueImplT();
236 
239  void set(const Pointer<ValueType>& value);
240 
244  ValueType& getValue();
245 
249  const ValueType& getValue() const;
250 
254  size_t getNumMembers() const;
255 
259  void setMember(int index, const Variant& member);
260 
264  Variant getMember(int index) const;
265 
268  void addMember(const Variant& member);
269 
272  void resize(size_t numMembers);
273 
276  void clear();
277 
280  ValuePtr clone() const;
281 
285 
289 
293  };
294 
298  ArrayVariant(const DataType& type, const DataType& memberType,
299  size_t numMembers);
300 
303  template <typename T> static ArrayVariant create(const DataType& type,
304  const DataType& memberType);
305 
309  template <typename T> static void initialize(typename type_traits::
310  ArrayType<T>::ValueType& array, typename boost::enable_if<typename
312 
316  template <typename T> static void initialize(typename type_traits::
317  ArrayType<T>::ValueType& array, typename boost::disable_if<typename
319 
323  template <typename T> static void add(typename type_traits::ArrayType<T>::
324  ValueType& array, const typename type_traits::ArrayType<T>::MemberType&
325  member, typename boost::enable_if<typename type_traits::ArrayType<T>::
326  IsDynamic>::type* = 0);
327 
331  template <typename T> static void add(typename type_traits::ArrayType<T>::
332  ValueType& array, const typename type_traits::ArrayType<T>::MemberType&
333  member, typename boost::disable_if<typename type_traits::ArrayType<T>::
334  IsDynamic>::type* = 0);
335 
338  template <typename T> static void resize(typename type_traits::
339  ArrayType<T>::ValueType& array, size_t numMembers, typename
340  boost::enable_if<typename type_traits::ArrayType<T>::IsDynamic>::
341  type* = 0);
342 
345  template <typename T> static void resize(typename type_traits::
346  ArrayType<T>::ValueType& array, size_t numMembers, typename
347  boost::disable_if<typename type_traits::ArrayType<T>::IsDynamic>::
348  type* = 0);
349 
352  template <typename T> static void clear(typename type_traits::
353  ArrayType<T>::ValueType& array, typename boost::enable_if<typename
355 
358  template <typename T> static void clear(typename type_traits::
359  ArrayType<T>::ValueType& array, typename boost::disable_if<typename
361  };
362 };
363 
364 #include <variant_topic_tools/ArrayVariant.tpp>
365 
366 #endif
static void add(typename type_traits::ArrayType< T >::ValueType &array, const typename type_traits::ArrayType< T >::MemberType &member, typename boost::enable_if< typename type_traits::ArrayType< T >::IsDynamic >::type *=0)
Add a member to an array (overloaded version taking a dynamic array)
static ArrayVariant create(const DataType &type, const DataType &memberType)
Create an array variant.
void clear()
Clear the array.
DataType memberType
The array member type.
Definition: ArrayVariant.h:288
void resize(size_t numMembers)
Resize the array.
static void initialize(typename type_traits::ArrayType< T >::ValueType &array, typename boost::enable_if< typename type_traits::ArrayType< T >::IsDynamic >::type *=0)
Initialize an array (overloaded version taking a dynamic array)
Variant value (abstract base)
Definition: Variant.h:167
ArrayVariant & operator+=(const Variant &member)
Operator for adding a member to the array.
virtual Variant getMember(int index) const =0
Retrieve a member of the collection by index (abstract declaration)
bool hasMember(const std::string &name) const
True, if the variant collection contains the member with the specified name (implementation) ...
Header file providing the CollectionVariant class interface.
DataType memberType
The array member type.
Definition: ArrayVariant.h:193
void writeMember(std::ostream &stream, int index) const
Write the variant collection member with the specified index to a stream (implementation) ...
Variant getMember(const std::string &name) const
Retrieve a member of the variant collection by name (implementation)
DataType type
The variant&#39;s data type.
Definition: Variant.h:247
Header file providing the array type traits.
ArrayVariant()
Default constructor.
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)
Pointer< ValueType > array
The strong-typed array.
Definition: ArrayVariant.h:292
std::vector< Variant > members
The array members.
Definition: ArrayVariant.h:201
size_t numMembers
The number of array members.
Definition: ArrayVariant.h:197
Array variant value (variant-typed implementation)
Definition: ArrayVariant.h:140
void setMember(const std::string &name, const Variant &member)
Set a member of the variant collection by name (implementation)
virtual Serializer createSerializer(const DataType &type) const =0
Create a serializer for this variant (abstract declaration)
type_traits::ArrayType< T >::MemberType MemberType
Definition of the member type.
Definition: ArrayVariant.h:218
void setValue(const Variant::Value &value)
Set the variant&#39;s value (implementation)
type_traits::ArrayType< T >::ValueType ValueType
Definition of the value type.
Definition: ArrayVariant.h:214
virtual size_t getNumMembers() const =0
Retrieve the number of members of the collection (abstract declaration)
virtual void addMember(const Variant &member)=0
Add a member to the array (abstract declaration)
Collection variant value (abstract base)
Variant value (templated abstract base)
Definition: Variant.h:209
Array variant value (abstract base)
Definition: ArrayVariant.h:86
virtual void setMember(int index, const Variant &member)=0
Set a member of the collection by index (abstract declaration)
virtual void clear()=0
Clear the array (abstract declaration)
void addMember(const Variant &member)
Add a member to the array.
virtual ValuePtr clone() const =0
Clone this variant value (abstract declaration)
Array variant value (templated implementation)
Definition: ArrayVariant.h:206
virtual void resize(size_t numMembers)=0
Resize the array (abstract declaration)


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