CollectionVariant.h
Go to the documentation of this file.
00001 /******************************************************************************
00002  * Copyright (C) 2014 by Ralf Kaestner                                        *
00003  * ralf.kaestner@gmail.com                                                    *
00004  *                                                                            *
00005  * This program is free software; you can redistribute it and/or modify       *
00006  * it under the terms of the Lesser GNU General Public License as published by*
00007  * the Free Software Foundation; either version 3 of the License, or          *
00008  * (at your option) any later version.                                        *
00009  *                                                                            *
00010  * This program is distributed in the hope that it will be useful,            *
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the               *
00013  * Lesser GNU General Public License for more details.                        *
00014  *                                                                            *
00015  * You should have received a copy of the Lesser GNU General Public License   *
00016  * along with this program. If not, see <http://www.gnu.org/licenses/>.       *
00017  ******************************************************************************/
00018 
00023 #ifndef VARIANT_TOPIC_TOOLS_COLLECTION_VARIANT_H
00024 #define VARIANT_TOPIC_TOOLS_COLLECTION_VARIANT_H
00025 
00026 #include <variant_topic_tools/Variant.h>
00027 
00028 namespace variant_topic_tools {
00031   class CollectionVariant :
00032     public Variant {
00033   friend class Variant;
00034   public:
00037     CollectionVariant();
00038 
00041     CollectionVariant(const CollectionVariant& src);
00042 
00045     CollectionVariant(const Variant& src);
00046 
00049     ~CollectionVariant();
00050 
00053     size_t getNumMembers() const;
00054 
00057     void setMember(int index, const Variant& member);
00058 
00061     void setMember(const std::string& name, const Variant& member);
00062 
00065     Variant getMember(int index) const;
00066 
00069     Variant getMember(const std::string& name) const;
00070 
00074     template <typename T> T& getValue(int index);
00075 
00079     template <typename T> const T& getValue(int index) const;
00080 
00084     template <typename T> T& getValue(const std::string& name);
00085 
00089     template <typename T> const T& getValue(const std::string& name) const;
00090 
00091     using Variant::getValue;
00092 
00096     bool hasMember(const std::string& name) const;
00097 
00100     bool isEmpty() const;
00101 
00105     Variant operator[](int index) const;
00106 
00110     Variant operator[](const char* name) const;
00111 
00112   protected:
00115     class Value :
00116       public virtual Variant::Value {
00117     public:
00120       Value();
00121 
00124       virtual ~Value();
00125 
00129       virtual size_t getNumMembers() const = 0;
00130 
00134       virtual void setMember(int index, const Variant& member) = 0;
00135 
00139       virtual void setMember(const std::string& name, const Variant&
00140         member) = 0;
00141 
00144       void setMember(const std::string& name, const Variant& member,
00145         size_t pos);
00146 
00150       virtual Variant getMember(int index) const = 0;
00151 
00155       virtual Variant getMember(const std::string& name) const = 0;
00156 
00160       Variant getMember(const std::string& name, size_t pos) const;
00161 
00165       virtual bool hasMember(const std::string& name) const = 0;
00166 
00170       bool hasMember(const std::string& name, size_t pos) const;
00171 
00175       bool isEqual(const Variant::Value& value) const;
00176 
00179       void read(std::istream& stream);
00180 
00184       virtual void writeMember(std::ostream& stream, int index) const = 0;
00185 
00188       void write(std::ostream& stream) const;
00189     };
00190 
00193     CollectionVariant(const DataType& type);
00194   };
00195 };
00196 
00197 #include <variant_topic_tools/CollectionVariant.tpp>
00198 
00199 #endif


variant_topic_tools
Author(s): Ralf Kaestner
autogenerated on Fri Aug 5 2016 06:06:27