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.h" 37 #include <type_traits> 45 class variant_associative_view;
46 class variant_sequential_view;
55 RTTR_INLINE T* unsafe_variant_cast(variant* operand) RTTR_NOEXCEPT;
57 RTTR_INLINE
const T* unsafe_variant_cast(
const variant* operand) RTTR_NOEXCEPT;
59 struct data_address_container;
61 struct empty_type_converter;
63 template<
typename T,
typename Tp,
typename Converter = empty_type_converter<T>>
64 struct variant_data_base_policy;
65 struct variant_data_policy_nullptr_t;
67 enum class variant_policy_operation : uint8_t;
69 template<typename T, typename Decayed = decay_except_array_t<T>>
70 using decay_variant_t = enable_if_t<!std::is_same<Decayed, variant>::value, Decayed>;
72 using variant_policy_func = bool (*)(variant_policy_operation, const variant_data&, argument_wrapper);
211 template<
typename T,
typename Tp = detail::decay_variant_t<T>>
217 variant(
const variant& other);
222 variant(variant&& other);
227 RTTR_INLINE ~variant();
234 template<
typename T,
typename Tp = detail::decay_variant_t<T>>
235 variant& operator=(T&& other);
242 variant& operator=(variant&& other);
249 variant& operator=(
const variant& other);
267 RTTR_INLINE
bool operator==(
const variant& other)
const;
282 RTTR_INLINE
bool operator!=(
const variant& other)
const;
300 RTTR_INLINE
bool operator<(
const variant& other)
const;
316 RTTR_INLINE
bool operator<=(
const variant& other)
const;
331 RTTR_INLINE
bool operator>=(
const variant& other)
const;
345 RTTR_INLINE
bool operator>(
const variant& other)
const;
357 void swap(variant& other);
365 bool is_type()
const;
374 type get_type()
const;
387 bool is_valid()
const;
396 explicit operator bool()
const;
404 bool is_associative_container()
const;
412 bool is_sequential_container()
const;
464 const T& get_value()
const;
486 const T& get_wrapped_value()
const;
511 variant extract_wrapped_value()
const;
522 bool can_convert()
const;
537 bool can_convert(
const type& target_type)
const;
568 bool convert(
const type& target_type);
597 T convert(
bool* ok =
nullptr)
const;
628 bool convert(T&
value)
const;
708 bool to_bool()
const;
727 int to_int(
bool *ok =
nullptr)
const;
746 float to_float(
bool* ok =
nullptr)
const;
765 double to_double(
bool* ok =
nullptr)
const;
780 std::string to_string(
bool *ok =
nullptr)
const;
799 int8_t to_int8(
bool *ok =
nullptr)
const;
818 int16_t to_int16(
bool *ok =
nullptr)
const;
837 int32_t to_int32(
bool *ok =
nullptr)
const;
856 int64_t to_int64(
bool *ok =
nullptr)
const;
876 uint8_t to_uint8(
bool *ok =
nullptr)
const;
896 uint16_t to_uint16(
bool *ok =
nullptr)
const;
916 uint32_t to_uint32(
bool *ok =
nullptr)
const;
936 uint64_t to_uint64(
bool *ok =
nullptr)
const;
949 RTTR_INLINE
void* get_ptr()
const;
958 RTTR_INLINE
type get_raw_type()
const;
968 RTTR_INLINE
void* get_raw_ptr()
const;
987 RTTR_INLINE detail::data_address_container get_data_address_container()
const;
989 bool convert(
const type& target_type, variant& var)
const;
997 bool try_basic_type_conversion(T& to)
const;
1004 template<
typename T>
1006 try_pointer_conversion(T& to,
const type& source_type,
const type& target_type)
const;
1013 template<
typename T>
1015 try_pointer_conversion(T& to,
const type& source_type,
const type& target_type)
const;
1024 bool compare_equal(
const variant& other,
bool& ok)
const;
1033 bool compare_less(
const variant& other,
bool& ok)
const;
1040 RTTR_INLINE
bool is_nullptr()
const;
1043 variant create_wrapped_value(
const type& wrapped_type)
const;
1049 template<
typename T,
typename Tp,
typename Converter>
1050 friend struct detail::variant_data_base_policy;
1051 friend struct detail::variant_data_policy_nullptr_t;
1052 friend RTTR_API
bool detail::variant_compare_less(
const variant&,
const type&,
const variant&,
const type&,
bool& ok);
1054 friend RTTR_INLINE T* detail::unsafe_variant_cast(variant* operand) RTTR_NOEXCEPT;
1057 detail::variant_data m_data;
1058 detail::variant_policy_func m_policy;
1156 #include "rttr/detail/variant/variant_impl.h" 1158 #endif // RTTR_VARIANT_H_ constexpr bool operator>=(basic_string_view< CharT, Traits > lhs, basic_string_view< CharT, Traits > rhs) noexcept
Compares the two views lhs and rhs.
Definition: access_levels.h:33
The type class holds the type information for any arbitrary object.
Definition: type.h:170
constexpr bool operator==(basic_string_view< CharT, Traits > lhs, basic_string_view< CharT, Traits > rhs) noexcept
Compares the two views lhs and rhs.
constexpr bool operator<=(basic_string_view< CharT, Traits > lhs, basic_string_view< CharT, Traits > rhs) noexcept
Compares the two views lhs and rhs.
The variant_associative_view describes a class that refers to an associative container (e...
Definition: variant_associative_view.h:92
The instance class is used for forwarding the instance of an object to invoke a property or method...
Definition: instance.h:47
detail::enum_data< Enum_Type > value(string_view, Enum_Type value)
The value function should be used to add a mapping from enum name to value during the registration pr...
The variant_sequential_view describes a class that refers to an sequence container (e...
Definition: variant_sequential_view.h:95
constexpr bool operator!=(basic_string_view< CharT, Traits > lhs, basic_string_view< CharT, Traits > rhs) noexcept
Compares the two views lhs and rhs.
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:197
T variant_cast(const variant &operand)
Returns a reference to the containing value as type T.
constexpr bool operator>(basic_string_view< CharT, Traits > lhs, basic_string_view< CharT, Traits > rhs) noexcept
Compares the two views lhs and rhs.
constexpr bool operator<(basic_string_view< CharT, Traits > lhs, basic_string_view< CharT, Traits > rhs) noexcept
Compares the two views lhs and rhs.