28 #ifndef RTTR_VARIANT_H_
29 #define RTTR_VARIANT_H_
31 #include "rttr/detail/base/core_prerequisites.h"
32 #include "rttr/detail/misc/misc_type_traits.h"
33 #include "rttr/detail/variant/variant_data.h"
34 #include "rttr/detail/misc/argument_wrapper.h"
35 #include "rttr/detail/variant/variant_compare_less.h"
37 #include <type_traits>
45 class variant_array_view;
53 struct data_address_container;
55 struct empty_type_converter;
57 template<
typename T,
typename Tp,
typename Converter = empty_type_converter<T>>
58 struct variant_data_base_policy;
59 struct variant_data_policy_nullptr_t;
61 enum class variant_policy_operation : uint8_t;
63 template<typename T, typename Decayed = decay_except_array_t<T>>
64 using decay_variant_t = enable_if_t<!std::is_same<Decayed, variant>::value &&
65 !std::is_same<Decayed, variant_array_view>::value, Decayed>;
67 using variant_policy_func = bool (*)(variant_policy_operation, const variant_data&, argument_wrapper);
206 template<
typename T,
typename Tp = detail::decay_variant_t<T>>
212 variant(
const variant& other);
217 variant(variant&& other);
222 RTTR_INLINE ~variant();
229 template<
typename T,
typename Tp = detail::decay_variant_t<T>>
230 variant& operator=(T&& other);
237 variant& operator=(variant&& other);
244 variant& operator=(
const variant& other);
260 RTTR_INLINE
bool operator==(
const variant& other)
const;
273 RTTR_INLINE
bool operator!=(
const variant& other)
const;
289 RTTR_INLINE
bool operator<(
const variant& other)
const;
301 void swap(variant& other);
309 bool is_type()
const;
318 type get_type()
const;
331 bool is_valid()
const;
340 explicit operator bool()
const;
349 bool is_array()
const;
375 const T& get_value()
const;
384 bool can_convert()
const;
397 bool can_convert(
const type& target_type)
const;
421 bool convert(
const type& target_type);
447 T convert(
bool* ok =
nullptr)
const;
475 bool convert(T&
value)
const;
516 bool to_bool()
const;
535 int to_int(
bool *ok =
nullptr)
const;
554 float to_float(
bool* ok =
nullptr)
const;
573 double to_double(
bool* ok =
nullptr)
const;
588 std::string to_string(
bool *ok =
nullptr)
const;
607 int8_t to_int8(
bool *ok =
nullptr)
const;
626 int16_t to_int16(
bool *ok =
nullptr)
const;
645 int32_t to_int32(
bool *ok =
nullptr)
const;
664 int64_t to_int64(
bool *ok =
nullptr)
const;
684 uint8_t to_uint8(
bool *ok =
nullptr)
const;
704 uint16_t to_uint16(
bool *ok =
nullptr)
const;
724 uint32_t to_uint32(
bool *ok =
nullptr)
const;
744 uint64_t to_uint64(
bool *ok =
nullptr)
const;
757 RTTR_INLINE
void* get_ptr()
const;
766 RTTR_INLINE
type get_raw_type()
const;
776 RTTR_INLINE
void* get_raw_ptr()
const;
792 RTTR_INLINE detail::data_address_container get_data_address_container()
const;
794 bool convert(
const type& target_type, variant& var)
const;
802 bool try_basic_type_conversion(T& to)
const;
811 try_pointer_conversion(T& to,
const type& source_type,
const type& target_type)
const;
820 try_pointer_conversion(T& to,
const type& source_type,
const type& target_type)
const;
827 bool compare_equal(
const variant& other)
const;
834 bool compare_less(
const variant& other)
const;
841 RTTR_INLINE
bool is_nullptr()
const;
847 template<
typename T,
typename Tp,
typename Converter>
848 friend struct detail::variant_data_base_policy;
849 friend struct detail::variant_data_policy_nullptr_t;
850 friend RTTR_API
bool detail::variant_compare_less(
const variant&,
const type&,
const variant&,
const type&);
852 detail::variant_data m_data;
853 detail::variant_policy_func m_policy;
860 #include "rttr/detail/variant/variant_impl.h"
862 #endif // RTTR_VARIANT_H_
Definition: access_levels.h:33
The type class holds the type information for any arbitrary object.
Definition: type.h:153
The instance class is used for forwarding the instance of an object to invoke a property or method...
Definition: instance.h:46
detail::enum_data< Enum_Type > value(const char *name, Enum_Type value)
The value function should be used to add a mapping from enum name to value during the registration pr...
The variant_array_view describes a class that refers to an array inside a variant.
Definition: variant_array_view.h:137
The argument class is used for forwarding arguments to properties or methods.
Definition: argument.h:51
The variant class allows to store data of any type and convert between these types transparently...
Definition: variant.h:192