CollectionVariant.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_COLLECTION_VARIANT_H
24 #define VARIANT_TOPIC_TOOLS_COLLECTION_VARIANT_H
25 
27 
28 namespace variant_topic_tools {
32  public Variant {
33  friend class Variant;
34  public:
38 
42 
45  CollectionVariant(const Variant& src);
46 
50 
53  size_t getNumMembers() const;
54 
57  void setMember(int index, const Variant& member);
58 
61  void setMember(const std::string& name, const Variant& member);
62 
65  Variant getMember(int index) const;
66 
69  Variant getMember(const std::string& name) const;
70 
74  template <typename T> T& getValue(int index);
75 
79  template <typename T> const T& getValue(int index) const;
80 
84  template <typename T> T& getValue(const std::string& name);
85 
89  template <typename T> const T& getValue(const std::string& name) const;
90 
91  using Variant::getValue;
92 
96  bool hasMember(const std::string& name) const;
97 
100  bool isEmpty() const;
101 
105  Variant operator[](int index) const;
106 
110  Variant operator[](const char* name) const;
111 
112  protected:
115  class Value :
116  public virtual Variant::Value {
117  public:
120  Value();
121 
124  virtual ~Value();
125 
129  virtual size_t getNumMembers() const = 0;
130 
134  virtual void setMember(int index, const Variant& member) = 0;
135 
139  virtual void setMember(const std::string& name, const Variant&
140  member) = 0;
141 
144  void setMember(const std::string& name, const Variant& member,
145  size_t pos);
146 
150  virtual Variant getMember(int index) const = 0;
151 
155  virtual Variant getMember(const std::string& name) const = 0;
156 
160  Variant getMember(const std::string& name, size_t pos) const;
161 
165  virtual bool hasMember(const std::string& name) const = 0;
166 
170  bool hasMember(const std::string& name, size_t pos) const;
171 
175  bool isEqual(const Variant::Value& value) const;
176 
179  void read(std::istream& stream);
180 
184  virtual void writeMember(std::ostream& stream, int index) const = 0;
185 
188  void write(std::ostream& stream) const;
189  };
190 
194  };
195 };
196 
197 #include <variant_topic_tools/CollectionVariant.tpp>
198 
199 #endif
bool hasMember(const std::string &name) const
True, if the collection contains the member with the specified name.
Variant operator[](int index) const
Operator for retrieving the members of the collection by index.
void write(std::ostream &stream) const
Write this variant value to a stream (implementation)
Variant value (abstract base)
Definition: Variant.h:167
void setMember(int index, const Variant &member)
Set a member of the collection by index.
virtual Variant getMember(int index) const =0
Retrieve a member of the collection by index (abstract declaration)
Variant getMember(int index) const
Retrieve a member of the collection by index.
void read(std::istream &stream)
Read the variant from a stream (implementation)
Header file providing the Variant class interface.
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) ...
virtual void writeMember(std::ostream &stream, int index) const =0
Write the collection member with the specified index to a stream (abstract declaration) ...
bool isEmpty() const
True, if the collection is empty.
size_t getNumMembers() const
Retrieve the number of members of the collection.
virtual size_t getNumMembers() const =0
Retrieve the number of members of the collection (abstract declaration)
bool isEqual(const Variant::Value &value) const
True, if this variant value equals another variant value (implementation)
Collection variant value (abstract base)
virtual void setMember(int index, const Variant &member)=0
Set a member of the collection by index (abstract declaration)


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