28 #ifndef __RTTR_VARIANT_H__
29 #define __RTTR_VARIANT_H__
34 #include <type_traits>
48 class array_container_base;
149 ,
typename std::enable_if<!std::is_same<variant&, T>::value >::
type* = 0
150 ,
typename std::enable_if<!std::is_const<T>::value >::
type* = 0
202 bool is_type()
const;
211 type get_type()
const;
220 bool is_valid()
const;
229 bool can_convert()
const;
237 bool can_convert(
const type& target_type)
const;
251 bool convert(
const type& target_type);
266 T& get_value()
const;
283 T convert(
bool* ok =
nullptr)
const;
296 int to_int(
bool *ok =
nullptr)
const;
309 std::string to_string(
bool *ok =
nullptr)
const;
325 bool to_bool()
const;
338 float to_float(
bool* ok =
nullptr);
351 double to_double(
bool* ok =
nullptr);
375 template<
typename T,
typename SourceType>
376 static T get_value_with_default_value(
const SourceType& source, T default_value,
bool* ok);
385 void* get_ptr()
const;
394 void* get_raw_ptr()
const;
403 type get_raw_type()
const;
405 class variant_container_base
408 virtual ~variant_container_base();
410 virtual type get_type()
const = 0;
412 virtual void* get_ptr()
const = 0;
414 virtual type get_raw_type()
const = 0;
416 virtual void* get_raw_ptr()
const = 0;
418 virtual bool is_array()
const = 0;
420 virtual detail::array_container_base* to_array()
const = 0;
422 virtual std::string to_string(
bool* ok)
const = 0;
423 virtual int to_int(
bool* ok)
const = 0;
424 virtual bool to_bool(
bool* ok)
const = 0;
425 virtual float to_float(
bool* ok)
const = 0;
426 virtual double to_double(
bool* ok)
const = 0;
428 std::size_t to_size_t(
bool* ok)
const;
430 virtual variant_container_base* clone()
const = 0;
432 virtual bool can_convert(
const type& target_type)
const = 0;
435 template<
typename T,
typename Enable =
void>
436 class variant_container :
public variant_container_base
439 variant_container(
const T& arg);
441 variant_container(T&& arg);
443 variant_container_base* clone()
const;
445 type get_type()
const;
447 void* get_ptr()
const;
449 type get_raw_type()
const;
451 void* get_raw_ptr()
const;
453 bool is_array()
const;
455 detail::array_container_base* to_array()
const;
457 bool can_convert(
const type& target_type)
const;
459 std::string to_string(
bool* ok)
const;
460 int to_int(
bool* ok)
const;
461 bool to_bool(
bool* ok)
const;
462 float to_float(
bool* ok)
const;
463 double to_double(
bool* ok)
const;
468 variant_container & operator=(
const variant_container &);
472 class variant_container<T, typename std::enable_if<detail::is_array_and_not_one_dim_char_array<T>::value>
::type> :
public variant_container_base
475 variant_container(
const T& arg);
477 variant_container_base* clone()
const;
479 type get_type()
const;
481 void* get_ptr()
const;
483 type get_raw_type()
const;
485 void* get_raw_ptr()
const;
487 bool can_convert(
const type& target_type)
const;
489 bool is_array()
const;
491 detail::array_container_base* to_array()
const;
493 std::string to_string(
bool* ok)
const;
494 int to_int(
bool* ok)
const;
495 bool to_bool(
bool* ok)
const;
496 float to_float(
bool* ok)
const;
497 double to_double(
bool* ok)
const;
502 variant_container & operator=(
const variant_container &);
505 template<std::
size_t N>
506 class variant_container<char[N]> :
public variant_container_base
509 variant_container(
const char (&arg)[N]);
511 variant_container_base* clone()
const;
513 type get_type()
const;
515 void* get_ptr()
const;
517 type get_raw_type()
const;
519 void* get_raw_ptr()
const;
521 bool can_convert(
const type& target_type)
const;
523 bool is_array()
const;
525 detail::array_container_base* to_array()
const;
527 std::string to_string(
bool* ok)
const;
528 int to_int(
bool* ok)
const;
529 bool to_bool(
bool* ok)
const;
530 float to_float(
bool* ok)
const;
531 double to_double(
bool* ok)
const;
536 variant_container & operator=(
const variant_container &);
540 friend variant detail::create_void_variant();
541 friend detail::argument;
542 friend detail::instance;
543 variant_container_base* _holder;
547 template<>
RTTR_API std::string variant::convert<std::string>(
bool* ok)
const;
548 template<>
RTTR_API int variant::convert<int>(
bool* ok)
const;
549 template<>
RTTR_API bool variant::convert<bool>(
bool* ok)
const;
550 template<>
RTTR_API float variant::convert<float>(
bool* ok)
const;
551 template<>
RTTR_API double variant::convert<double>(
bool* ok)
const;
554 template<>
RTTR_API bool variant::can_convert<variant_array>()
const;
564 #include "rttr/impl/variant_impl.h"
565 #include "rttr/impl/variant_default_types_impl.h"
567 #endif // __RTTR_VARIANT_H__
This class holds the type information for any arbitrary object.
Definition: type.h:165
#define RTTR_LOCAL
Definition: core_prerequisites.h:125
The variant class allows to store data of any type and convert between these types transparently...
Definition: variant.h:125
The variant_array class is a specialization of a variant, but for array types.
Definition: variant_array.h:169
#define RTTR_API
Definition: core_prerequisites.h:124