BuiltinVariant.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_BUILTIN_VARIANT_H
24 #define VARIANT_TOPIC_TOOLS_BUILTIN_VARIANT_H
25 
26 #include <boost/type_traits.hpp>
27 
31 
32 namespace variant_topic_tools {
36  public Variant {
37  friend class BuiltinDataType;
38  friend class Variant;
39  public:
43 
46  BuiltinVariant(const BuiltinVariant& src);
47 
50  BuiltinVariant(const Variant& src);
51 
55 
58  double getNumericValue() const;
59 
60  using Variant::operator=;
61 
62  protected:
65  class Value :
66  public virtual Variant::Value {
67  public:
70  Value();
71 
74  virtual ~Value();
75 
79  virtual double getNumericValue() const = 0;
80  };
81 
84  template <typename T> class ValueImplT :
85  public Variant::ValueT<typename type_traits::BuiltinType<T>::ValueType>,
86  public Value {
87  public:
88  BOOST_STATIC_ASSERT(type_traits::IsBuiltin<T>::value);
89 
93 
97 
100  ValueImplT(const ValueImplT<T>& src);
101 
104  virtual ~ValueImplT();
105 
108  void set(const Pointer<ValueType>& value);
109 
112  void setValue(const Variant::Value& value);
113 
117  ValueType& getValue();
118 
122  const ValueType& getValue() const;
123 
127  double getNumericValue() const;
128 
132  bool isEqual(const Variant::Value& value) const;
133 
136  ValuePtr clone() const;
137 
140  void read(std::istream& stream);
141 
144  void write(std::ostream& stream) const;
145 
149 
153  };
154 
157  template <typename T> static BuiltinVariant create(const DataType& type);
158 
162  template <typename T> static double getNumericValue(const T& value,
163  typename boost::enable_if<boost::type_traits::ice_or<boost::is_base_of<
164  ros::Duration, T>::value, boost::is_base_of<ros::Time, T>::value> >::
165  type* = 0);
166 
171  template <typename T> static double getNumericValue(const T& value,
172  typename boost::enable_if<typename type_traits::BuiltinType<T>::
173  IsNumeric>::type* = 0, typename boost::disable_if<boost::type_traits::
174  ice_or<boost::is_base_of<ros::Duration, T>::value, boost::is_base_of<
175  ros::Time, T>::value> >::type* = 0);
176 
180  template <typename T> static double getNumericValue(const T& value,
181  typename boost::disable_if<typename type_traits::BuiltinType<T>::
182  IsNumeric>::type* = 0);
183 
187  template <typename T> static bool isEqual(const typename type_traits::
188  BuiltinType<T>::ValueType& lhs, const typename type_traits::
189  BuiltinType<T>::ValueType& rhs, typename boost::enable_if<boost::
190  has_equal_to<typename type_traits::BuiltinType<T>::ValueType,
191  typename type_traits::BuiltinType<T>::ValueType, bool> >::type* = 0);
192 
196  template <typename T> static bool isEqual(const typename type_traits::
197  BuiltinType<T>::ValueType& lhs, const typename type_traits::
198  BuiltinType<T>::ValueType& rhs, typename boost::disable_if<boost::
199  has_equal_to<typename type_traits::BuiltinType<T>::ValueType,
200  typename type_traits::BuiltinType<T>::ValueType, bool> >::type* = 0);
201 
205  template <typename T> static void read(std::istream& stream,
207  boost::enable_if<boost::is_same<T, bool> >::type* = 0);
208 
212  template <typename T> static void read(std::istream& stream,
214  boost::disable_if<boost::is_same<T, bool> >::type* = 0, typename
215  boost::enable_if<boost::has_right_shift<std::istream, typename
217 
221  template <typename T> static void read(std::istream& stream,
223  boost::disable_if<boost::is_same<T, bool> >::type* = 0, typename
224  boost::disable_if<boost::has_right_shift<std::istream, typename
226 
230  template <typename T> static void write(std::ostream& stream, const
232  boost::enable_if<boost::is_same<T, bool> >::type* = 0);
233 
237  template <typename T> static void write(std::ostream& stream, const
239  boost::disable_if<boost::is_same<T, bool> >::type* = 0, typename
240  boost::enable_if<boost::has_left_shift<std::ostream, const typename
242 
246  template <typename T> static void write(std::ostream& stream, const
248  boost::disable_if<boost::is_same<T, bool> >::type* = 0, typename
249  boost::disable_if<boost::has_left_shift<std::ostream, const typename
251  };
252 };
253 
254 #include <variant_topic_tools/BuiltinVariant.tpp>
255 
256 #endif
Built-in variant value (templated implementation)
BuiltinVariant()
Default constructor.
Variant value (abstract base)
Definition: Variant.h:167
double getNumericValue() const
Retrieve the built-in variant&#39;s numeric value.
Pointer< ValueType > value
The strong-typed value.
Header file providing the Variant class interface.
type_traits::BuiltinType< T >::ValueType ValueType
Declaration of the value type.
DataType type
The variant&#39;s data type.
Definition: Variant.h:247
ValuePtr value
The variant&#39;s data value.
Definition: Variant.h:251
Header file providing the built-in type traits.
type_traits::DataType< T >::ValueType & getValue()
Retrieve the variant&#39;s value (non-const version)
static BuiltinVariant create(const DataType &type)
Create a built-in variant.
virtual void read(std::istream &stream)=0
Read the variant from a stream (abstract declaration)
virtual Serializer createSerializer(const DataType &type) const =0
Create a serializer for this variant (abstract declaration)
Built-in variant value (abstract base)
virtual void write(std::ostream &stream) const =0
Write this variant value to a stream (abstract declaration)
Header file providing the Pointer class interface.
virtual bool isEqual(const Value &value) const =0
True, if this variant value equals another variant value (abstract declaration)
virtual void setValue(const Value &value)=0
Set the variant&#39;s value (abstract declaration)
Variant value (templated abstract base)
Definition: Variant.h:209
virtual double getNumericValue() const =0
Retrieve the built-in variant&#39;s numeric value (abstract declaration)
virtual ValuePtr clone() const =0
Clone this variant value (abstract declaration)


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