11 #ifndef __UT_Variant__
12 #define __UT_Variant__
22 #include <type_traits>
123 UT_VariantMap(std::initializer_list<container_type::value_type> init);
176 iterator erase(const_iterator it);
182 const_iterator
begin()
const;
188 const_iterator
end()
const;
234 static constexpr
bool is_trivial =
false;
235 static constexpr
bool is_complex =
false; };
253 !std::is_same<typename TypeConversion<T>::From,
void>
::value;
369 static const char *typeName(
Type type);
411 get()
const {
bool ok;
return get<T>(ok); }
416 get()
const {
bool ok;
return get<T>(ok); }
422 get()
const {
bool ok;
return get<T>(ok); }
427 template<
typename T>
void set(
const T &
v)
438 const T *valueGet()
const;
447 T valueConvert(
bool &ok)
const;
449 bool parseBool(
bool &ok)
const;
450 int64 parseInt(
bool &ok)
const;
451 uint64 parseUInt(
bool &ok)
const;
452 fpreal64 parseFloat(
bool &ok)
const;
491 std::initializer_list<container_type::value_type> init) :
501 return *m_map == *o.m_map;
507 return m_map->operator [](key);
513 return m_map->operator [](key);
519 return m_map->find(key);
525 return m_map->find(key);
531 return m_map->erase(key);
537 return m_map->erase(it);
543 return m_map->begin();
549 return m_map->begin();
567 #define UT_VARIANT_TYPE_ID(_T_, _ID_, _TRV_, _CPL_) \
568 template<> struct UT_Variant::TypeInfo<_T_> { \
569 static constexpr UT_Variant::Type typeId = UT_Variant::Type::_ID_; \
570 static constexpr bool is_trivial = _TRV_; \
571 static constexpr bool is_complex = _CPL_; \
590 #undef UT_VARIANT_TYPE_ID
594 UT_Variant::valueConvert<bool>(
bool &ok)
const
597 if (m_type == Type::Bool)
598 return m_value.m_bool;
599 else if (m_type ==
Type::Int || m_type == Type::UInt)
600 return m_value.m_int != 0;
601 else if (m_type == Type::Float)
602 return m_value.m_float != 0;
603 else if (m_type == Type::String)
604 return parseBool(ok);
614 UT_Variant::valueConvert<int64>(
bool &ok)
const
617 if (m_type == Type::Bool)
618 return m_value.m_bool ? 1 : 0;
619 else if (m_type ==
Type::Int || m_type == Type::UInt)
620 return m_value.m_int;
621 else if (m_type == Type::Float)
622 return static_cast<int64>(m_value.m_float);
623 else if (m_type == Type::String)
634 UT_Variant::valueConvert<uint64>(
bool &ok)
const
637 if (m_type == Type::Bool)
638 return m_value.m_bool ? 1 : 0;
639 else if (m_type ==
Type::Int || m_type == Type::UInt)
640 return uint64(m_value.m_int);
641 else if (m_type == Type::Float)
642 return static_cast<uint64>(m_value.m_float);
643 else if (m_type == Type::String)
644 return uint64(parseInt(ok));
654 UT_Variant::valueConvert<fpreal64>(
bool &ok)
const
657 if (m_type == Type::Bool)
658 return m_value.m_bool ? 1 : 0;
661 else if (m_type == Type::UInt)
663 else if (m_type == Type::Float)
664 return m_value.m_float;
665 else if (m_type == Type::String)
666 return parseFloat(ok);
676 UT_Variant::valueConvert<UT_StringHolder>(
bool &ok)
const
679 if (m_type == Type::Bool)
683 else if (m_type == Type::UInt)
685 else if (m_type == Type::Float)
686 return formatFloat();
687 else if (m_type == Type::String)
688 return *valueGet<UT_StringHolder>();
699 UT_Variant::valueConvert<void *>(
bool &ok)
const
701 if (m_type == Type::Pointer)
704 return m_value.m_ptr;
716 UT_Variant::valueConvert<UT_VariantArray>(
bool &ok)
const
721 return *valueGet<UT_VariantArray>();
732 UT_Variant::valueConvert<UT_VariantMap>(
bool &ok)
const
734 if (m_type == Type::Map)
737 return *valueGet<UT_VariantMap>();
752 return valueConvert<T>(ok);
760 const T *
v = this->valueGet<T>();
793 return static_cast<T>(this->get<typename TypeConversion<T>::From>(ok));
799 #endif // __UT_Variant__
UT_Matrix4T< fpreal64 > UT_Matrix4D
UT_Variant()
Construct an unknown variant.
iterator begin()
Return a writable iterator to the beginning of the map container.
UT_Variant(void *v)
Construct a Type::Pointer variant with the given value.
const UT_Variant & operator[](exint index) const
UT_Variant(fpreal32 v)
Construct a float variant with the given value.
OIIO_UTIL_API bool copy(string_view from, string_view to, std::string &err)
UT_Vector2T< fpreal64 > UT_Vector2D
GLsizei const GLfloat * value
UT_Variant(int32 v)
Construct an integer variant with the given value.
const_iterator begin() const
Return a read-only iterator to the beginning of the array container.
iterator begin()
Return a writable iterator to the beginning of the array container.
void setNull()
An explicit method of setting the variant type to null.
iterator end()
Return a writable iterator to the end of the map container.
bool erase(const UT_StringRef &key)
exint append(const UT_Variant &t)
container_type::iterator iterator
UT_VariantMap()
Construct a default, empty container.
Tto convert(const Tfrom &source)
unsigned long long uint64
const container_type & container() const
Returns a read-only reference to the underlying map container.
UT_Variant(uint32 v)
Construct an unsigned integer variant with the given value.
std::array< unsigned char, 24 > m_storage
Parent::iterator iterator
bool operator!=(const UT_VariantArray &o) const
Item-wise non-equality comparison of the variants of the two arrays.
bool operator==(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
UT_Variant(uint64 v)
Construct an unsigned integer variant with the given value.
std::enable_if< IsTrivialType< T >::value &&!IsConvertibleType< T >::value, T >::type get() const
exint append(UT_Variant &&t)
const char * typeName() const
bool operator==(const UT_VariantArray &o) const
Item-wise equality comparison of the variants of the two arrays.
UT_VariantArray(exint size=0)
OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER class IMF_EXPORT_TEMPLATE_TYPE Array
std::shared_ptr< T > UT_SharedPtr
Wrapper around std::shared_ptr.
container_type & container()
Returns a writable reference to the underlying map container.
iterator end()
Return a writable iterator to the end of the array container.
bool operator==(const UT_VariantMap &o) const
Item-wise equality comparison of the keys and variants of the two maps.
exint size() const
Returns the number of items in the array container.
UT_Vector3T< fpreal64 > UT_Vector3D
UT_Variant & operator[](exint index)
container_type::const_iterator const_iterator
container_type & container()
Returns a writable reference to the underlying array container.
Parent::const_iterator const_iterator
UT_Matrix2T< fpreal64 > UT_Matrix2D
bool operator!=(const UT_VariantMap &o) const
const container_type & container() const
Returns a read-only reference to the underlying array container.
LeafData & operator=(const LeafData &)=delete
bool contains(const UT_StringRef &key) const
SYS_FORCE_INLINE ITEM_T get(const UT_StringRef &key, const ITEM_T &defval) const
UT_Variant(bool v)
Construct a boolean variant with the given value.
const UT_Variant & operator[](const UT_StringRef &key) const
UT_Variant(fpreal64 v)
Construct a float variant with the given value.
#define UT_VARIANT_TYPE_ID(_T_, _ID_, _TRV_, _CPL_)
const_iterator find(const UT_StringRef &key) const
UT_Variant(int64 v)
Construct an integer variant with the given value.
UT_Vector4T< fpreal64 > UT_Vector4D
UT_API size_t format(char *buffer, size_t buffer_size, const UT_Variant &v)
const_iterator end() const
Return a read-only iterator to the end of the array container.
FMT_CONSTEXPR auto find(Ptr first, Ptr last, T value, Ptr &out) -> bool
UT_Matrix3T< fpreal64 > UT_Matrix3D
PcpNodeRef_ChildrenIterator begin(const PcpNodeRef::child_const_range &r)
Support for range-based for loops for PcpNodeRef children ranges.