BuiltinVariant.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_BUILTIN_VARIANT_H
00024 #define VARIANT_TOPIC_TOOLS_BUILTIN_VARIANT_H
00025 
00026 #include <boost/type_traits.hpp>
00027 
00028 #include <variant_topic_tools/BuiltinTypeTraits.h>
00029 #include <variant_topic_tools/Pointer.h>
00030 #include <variant_topic_tools/Variant.h>
00031 
00032 namespace variant_topic_tools {
00035   class BuiltinVariant :
00036     public Variant {
00037   friend class BuiltinDataType;
00038   friend class Variant;
00039   public:
00042     BuiltinVariant();
00043     
00046     BuiltinVariant(const BuiltinVariant& src);
00047     
00050     BuiltinVariant(const Variant& src);
00051     
00054     ~BuiltinVariant();
00055 
00058     double getNumericValue() const;
00059       
00060     using Variant::operator=;
00061     
00062   protected:
00065     class Value :
00066       public virtual Variant::Value {
00067     public:
00070       Value();
00071       
00074       virtual ~Value();
00075       
00079       virtual double getNumericValue() const = 0;
00080     };
00081     
00084     template <typename T> class ValueImplT :
00085       public Variant::ValueT<typename type_traits::BuiltinType<T>::ValueType>,
00086       public Value {
00087     public:
00088       BOOST_STATIC_ASSERT(type_traits::IsBuiltin<T>::value);
00089       
00092       typedef typename type_traits::BuiltinType<T>::ValueType ValueType;
00093       
00096       ValueImplT(const Pointer<ValueType>& value = Pointer<ValueType>());
00097       
00100       ValueImplT(const ValueImplT<T>& src);
00101       
00104       virtual ~ValueImplT();
00105       
00108       void set(const Pointer<ValueType>& value);
00109       
00112       void setValue(const Variant::Value& value);
00113       
00117       ValueType& getValue();
00118       
00122       const ValueType& getValue() const;
00123       
00127       double getNumericValue() const;
00128     
00132       bool isEqual(const Variant::Value& value) const;
00133       
00136       ValuePtr clone() const;
00137       
00140       void read(std::istream& stream);
00141     
00144       void write(std::ostream& stream) const;
00145       
00148       Serializer createSerializer(const DataType& type) const;
00149       
00152       Pointer<ValueType> value;
00153     };
00154     
00157     template <typename T> static BuiltinVariant create(const DataType& type);
00158     
00162     template <typename T> static double getNumericValue(const T& value,
00163       typename boost::enable_if<boost::type_traits::ice_or<boost::is_base_of<
00164       ros::Duration, T>::value, boost::is_base_of<ros::Time, T>::value> >::
00165       type* = 0);
00166       
00171     template <typename T> static double getNumericValue(const T& value,
00172       typename boost::enable_if<typename type_traits::BuiltinType<T>::
00173       IsNumeric>::type* = 0, typename boost::disable_if<boost::type_traits::
00174       ice_or<boost::is_base_of<ros::Duration, T>::value, boost::is_base_of<
00175       ros::Time, T>::value> >::type* = 0);
00176       
00180     template <typename T> static double getNumericValue(const T& value,
00181       typename boost::disable_if<typename type_traits::BuiltinType<T>::
00182       IsNumeric>::type* = 0);
00183     
00187     template <typename T> static bool isEqual(const typename type_traits::
00188       BuiltinType<T>::ValueType& lhs, const typename type_traits::
00189       BuiltinType<T>::ValueType& rhs, typename boost::enable_if<boost::
00190       has_equal_to<typename type_traits::BuiltinType<T>::ValueType,
00191       typename type_traits::BuiltinType<T>::ValueType, bool> >::type* = 0);
00192     
00196     template <typename T> static bool isEqual(const typename type_traits::
00197       BuiltinType<T>::ValueType& lhs, const typename type_traits::
00198       BuiltinType<T>::ValueType& rhs, typename boost::disable_if<boost::
00199       has_equal_to<typename type_traits::BuiltinType<T>::ValueType,
00200       typename type_traits::BuiltinType<T>::ValueType, bool> >::type* = 0);
00201     
00205     template <typename T> static void read(std::istream& stream,
00206       typename type_traits::BuiltinType<T>::ValueType& value, typename
00207       boost::enable_if<boost::is_same<T, bool> >::type* = 0);
00208     
00212     template <typename T> static void read(std::istream& stream,
00213       typename type_traits::BuiltinType<T>::ValueType& value, typename
00214       boost::disable_if<boost::is_same<T, bool> >::type* = 0, typename
00215       boost::enable_if<boost::has_right_shift<std::istream, typename
00216       type_traits::BuiltinType<T>::ValueType&> >::type* = 0);
00217     
00221     template <typename T> static void read(std::istream& stream,
00222       typename type_traits::BuiltinType<T>::ValueType& value, typename
00223       boost::disable_if<boost::is_same<T, bool> >::type* = 0, typename
00224       boost::disable_if<boost::has_right_shift<std::istream, typename
00225       type_traits::BuiltinType<T>::ValueType&> >::type* = 0);
00226 
00230     template <typename T> static void write(std::ostream& stream, const
00231       typename type_traits::BuiltinType<T>::ValueType& value, typename
00232       boost::enable_if<boost::is_same<T, bool> >::type* = 0);
00233     
00237     template <typename T> static void write(std::ostream& stream, const
00238       typename type_traits::BuiltinType<T>::ValueType& value, typename
00239       boost::disable_if<boost::is_same<T, bool> >::type* = 0, typename
00240       boost::enable_if<boost::has_left_shift<std::ostream, const typename
00241       type_traits::BuiltinType<T>::ValueType&> >::type* = 0);
00242     
00246     template <typename T> static void write(std::ostream& stream, const
00247       typename type_traits::BuiltinType<T>::ValueType& value, typename
00248       boost::disable_if<boost::is_same<T, bool> >::type* = 0, typename
00249       boost::disable_if<boost::has_left_shift<std::ostream, const typename
00250       type_traits::BuiltinType<T>::ValueType&> >::type* = 0);
00251   };
00252 };
00253 
00254 #include <variant_topic_tools/BuiltinVariant.tpp>
00255 
00256 #endif


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