ArrayVariant.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_ARRAY_VARIANT_H
00024 #define VARIANT_TOPIC_TOOLS_ARRAY_VARIANT_H
00025 
00026 #include <vector>
00027 
00028 #include <variant_topic_tools/ArrayTypeTraits.h>
00029 #include <variant_topic_tools/CollectionVariant.h>
00030 
00031 namespace variant_topic_tools {
00034   class ArrayVariant :
00035     public CollectionVariant {
00036   friend class ArrayDataType;
00037   friend class Variant;
00038   public:
00041     ArrayVariant();
00042 
00045     ArrayVariant(const ArrayVariant& src);
00046 
00049     ArrayVariant(const Variant& src);
00050 
00053     ~ArrayVariant();
00054 
00061     void addMember(const Variant& member);
00062 
00068     void resize(size_t numMembers);
00069 
00075     void clear();
00076 
00079     ArrayVariant& operator+=(const Variant& member);
00080 
00081     using Variant::operator=;
00082 
00083   protected:
00086     class Value :
00087       public CollectionVariant::Value {
00088     public:
00091       Value();
00092 
00095       virtual ~Value();
00096 
00099       void setValue(const Variant::Value& value);
00100 
00104       void setMember(const std::string& name, const Variant& member);
00105 
00106       using CollectionVariant::Value::setMember;
00107 
00111       Variant getMember(const std::string& name) const;
00112 
00113       using CollectionVariant::Value::getMember;
00114 
00118       bool hasMember(const std::string& name) const;
00119 
00123       void writeMember(std::ostream& stream, int index) const;
00124 
00127       virtual void addMember(const Variant& member) = 0;
00128 
00131       virtual void resize(size_t numMembers) = 0;
00132 
00135       virtual void clear() = 0;
00136     };
00137 
00140     class ValueImplV :
00141       public Value {
00142     public:
00145       ValueImplV(const DataType& memberType = DataType(), size_t
00146         numMembers = 0);
00147 
00150       ValueImplV(const ValueImplV& src);
00151 
00154       virtual ~ValueImplV();
00155 
00159       size_t getNumMembers() const;
00160 
00164       void setMember(int index, const Variant& member);
00165 
00169       Variant getMember(int index) const;
00170 
00173       void addMember(const Variant& member);
00174 
00177       void resize(size_t numMembers);
00178 
00181       void clear();
00182 
00185       ValuePtr clone() const;
00186 
00189       Serializer createSerializer(const DataType& type) const;
00190 
00193       DataType memberType;
00194 
00197       size_t numMembers;
00198 
00201       std::vector<Variant> members;
00202     };
00203 
00206     template <typename T> class ValueImplT :
00207       public Variant::ValueT<typename type_traits::ArrayType<T>::ValueType>,
00208       public Value {
00209     public:
00210       BOOST_STATIC_ASSERT(type_traits::IsArray<T>::value);
00211 
00214       typedef typename type_traits::ArrayType<T>::ValueType ValueType;
00215 
00218       typedef typename type_traits::ArrayType<T>::MemberType MemberType;
00219 
00222       static const size_t NumMembers = type_traits::ArrayType<T>::NumMembers;
00223 
00226       ValueImplT(const DataType& memberType = DataType(), const
00227         Pointer<ValueType>& array = Pointer<ValueType>());
00228 
00231       ValueImplT(const ValueImplT<T>& src);
00232 
00235       virtual ~ValueImplT();
00236 
00239       void set(const Pointer<ValueType>& value);
00240 
00244       ValueType& getValue();
00245 
00249       const ValueType& getValue() const;
00250 
00254       size_t getNumMembers() const;
00255 
00259       void setMember(int index, const Variant& member);
00260 
00264       Variant getMember(int index) const;
00265 
00268       void addMember(const Variant& member);
00269 
00272       void resize(size_t numMembers);
00273 
00276       void clear();
00277 
00280       ValuePtr clone() const;
00281 
00284       Serializer createSerializer(const DataType& type) const;
00285 
00288       DataType memberType;
00289 
00292       mutable Pointer<ValueType> array;
00293     };
00294 
00298     ArrayVariant(const DataType& type, const DataType& memberType,
00299       size_t numMembers);
00300 
00303     template <typename T> static ArrayVariant create(const DataType& type,
00304       const DataType& memberType);
00305 
00309     template <typename T> static void initialize(typename type_traits::
00310       ArrayType<T>::ValueType& array, typename boost::enable_if<typename
00311       type_traits::ArrayType<T>::IsDynamic>::type* = 0);
00312 
00316     template <typename T> static void initialize(typename type_traits::
00317       ArrayType<T>::ValueType& array, typename boost::disable_if<typename
00318       type_traits::ArrayType<T>::IsDynamic>::type* = 0);
00319 
00323     template <typename T> static void add(typename type_traits::ArrayType<T>::
00324       ValueType& array, const typename type_traits::ArrayType<T>::MemberType&
00325       member, typename boost::enable_if<typename type_traits::ArrayType<T>::
00326       IsDynamic>::type* = 0);
00327 
00331     template <typename T> static void add(typename type_traits::ArrayType<T>::
00332       ValueType& array, const typename type_traits::ArrayType<T>::MemberType&
00333       member, typename boost::disable_if<typename type_traits::ArrayType<T>::
00334       IsDynamic>::type* = 0);
00335 
00338     template <typename T> static void resize(typename type_traits::
00339       ArrayType<T>::ValueType& array, size_t numMembers, typename
00340       boost::enable_if<typename type_traits::ArrayType<T>::IsDynamic>::
00341       type* = 0);
00342 
00345     template <typename T> static void resize(typename type_traits::
00346       ArrayType<T>::ValueType& array, size_t numMembers, typename
00347       boost::disable_if<typename type_traits::ArrayType<T>::IsDynamic>::
00348       type* = 0);
00349 
00352     template <typename T> static void clear(typename type_traits::
00353       ArrayType<T>::ValueType& array, typename boost::enable_if<typename
00354       type_traits::ArrayType<T>::IsDynamic>::type* = 0);
00355 
00358     template <typename T> static void clear(typename type_traits::
00359       ArrayType<T>::ValueType& array, typename boost::disable_if<typename
00360       type_traits::ArrayType<T>::IsDynamic>::type* = 0);
00361   };
00362 };
00363 
00364 #include <variant_topic_tools/ArrayVariant.tpp>
00365 
00366 #endif


variant_topic_tools
Author(s): Ralf Kaestner
autogenerated on Tue Jul 9 2019 03:18:42