HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
VtValue Class Reference

#include <value.h>

Public Member Functions

 VtValue ()
 Default ctor gives empty VtValue. More...
 
 VtValue (VtValue const &other)
 Copy construct with other. More...
 
 VtValue (VtValue &&other) noexcept
 Move construct with other. More...
 
template<class T >
 VtValue (T const &obj)
 
 ~VtValue ()
 Destructor. More...
 
VtValueoperator= (VtValue const &other)
 Copy assignment from another VtValue. More...
 
VtValueoperator= (VtValue &&other) noexcept
 Move assignment from another VtValue. More...
 
template<class T >
hboost::enable_if_c
< _TypeInfoFor< T >
::Type::IsLocal &&_TypeInfoFor
< T >::Type::HasTrivialCopy,
VtValue & >::type 
operator= (T obj)
 Assignment operator from any type. More...
 
template<class T >
hboost::disable_if_c
< _TypeInfoFor< T >
::Type::IsLocal &&_TypeInfoFor
< T >::Type::HasTrivialCopy,
VtValue & >::type 
operator= (T const &obj)
 Assignment operator from any type. More...
 
VtValueoperator= (char const *cstr)
 Assigning a char const * gives a VtValue holding a std::string. More...
 
VtValueoperator= (char *cstr)
 Assigning a char * gives a VtValue holding a std::string. More...
 
VtValueSwap (VtValue &rhs) noexcept
 Swap this with rhs. More...
 
template<class T >
hboost::enable_if
< hboost::is_same< T, typename
Vt_ValueGetStored< T >::Type >
>::type 
Swap (T &rhs)
 Swap the held value with rhs. If this value is holding a T,. More...
 
template<class T >
hboost::enable_if
< hboost::is_same< T, typename
Vt_ValueGetStored< T >::Type >
>::type 
UncheckedSwap (T &rhs)
 
void UncheckedSwap (VtValue &rhs)
 
template<class T >
T Remove ()
 
template<class T >
T UncheckedRemove ()
 
template<class T >
bool IsHolding () const
 
VT_API bool IsArrayValued () const
 Returns true iff this is holding an array type (see VtIsArray<>). More...
 
size_t GetArraySize () const
 
VT_API std::type_info constGetTypeid () const
 Returns the typeid of the type held by this value. More...
 
VT_API std::type_info constGetElementTypeid () const
 
VT_API TfType GetType () const
 Returns the TfType of the type held by this value. More...
 
VT_API std::string GetTypeName () const
 Return the type name of the held typeid. More...
 
template<class T >
T constUncheckedGet () const
 
template<class T >
T constGet () const
 
template<class T >
T GetWithDefault (T const &def=T()) const
 
template<typename T >
VtValueCast ()
 
VtValueCastToTypeOf (VtValue const &other)
 
VtValueCastToTypeid (std::type_info const &type)
 
template<typename T >
bool CanCast () const
 
bool CanCastToTypeOf (VtValue const &other) const
 
bool CanCastToTypeid (std::type_info const &type) const
 
bool IsEmpty () const
 Returns true iff this value is empty. More...
 
VT_API bool CanHash () const
 Return true if the held object provides a hash implementation. More...
 
VT_API size_t GetHash () const
 Return a hash code for the held object by calling VtHashValue() on it. More...
 
bool operator== (const VtValue &rhs) const
 Test two values for equality. More...
 
bool operator!= (const VtValue &rhs) const
 
template<>
bool IsHolding () const
 
template<>
bool IsHolding () const
 

Static Public Member Functions

template<class T >
static VtValue Take (T &obj)
 
template<typename From , typename To >
static void RegisterCast (VtValue(*castFn)(VtValue const &))
 Register a cast from VtValue holding From to VtValue holding To. More...
 
template<typename From , typename To >
static void RegisterSimpleCast ()
 Register a simple cast from VtValue holding From to VtValue. More...
 
template<typename From , typename To >
static void RegisterSimpleBidirectionalCast ()
 
template<typename T >
static VtValue Cast (VtValue const &val)
 
static VT_API VtValue CastToTypeOf (VtValue const &val, VtValue const &other)
 
static VT_API VtValue CastToTypeid (VtValue const &val, std::type_info const &type)
 
static bool CanCastFromTypeidToTypeid (std::type_info const &from, std::type_info const &to)
 

Friends

struct _HoldAside
 
struct Vt_ValueShapeDataAccess
 
void swap (VtValue &lhs, VtValue &rhs)
 Overloaded swap() for generic code/stl/etc. More...
 
size_t hash_value (VtValue const &val)
 
template<typename T >
bool operator== (VtValue const &lhs, T const &rhs)
 Tests for equality. More...
 
template<typename T >
bool operator== (T const &lhs, VtValue const &rhs)
 
template<typename T >
bool operator!= (VtValue const &lhs, T const &rhs)
 Tests for inequality. More...
 
template<typename T >
bool operator!= (T const &lhs, VtValue const &rhs)
 
VT_API friend std::ostream & operator<< (std::ostream &out, const VtValue &self)
 Calls through to operator << on the held object. More...
 

Detailed Description

Provides a container which may hold any type, and provides introspection and iteration over array types. See VtIsArray for more info.

Held-type Conversion with VtValue::Cast

VtValue provides a suite of "Cast" methods that convert or create a VtValue holding a requested type (via template parameter, typeid, or type-matching to another VtValue) from the type of the currently-held value. Clients can add conversions between their own types using the RegisterCast(), RegisterSimpleCast(), and RegisterSimpleBidirectionalCast() methods. Conversions from plugins can be guaranteed to be registered before they are needed by registering them from within a

block.

Builtin Type Conversion

Conversions between most of the basic "value types" that are intrinsically convertible are builtin, including all numeric types (including Gf's half), std::string/TfToken, GfVec* (for vecs of the same dimension), and VtArray<T> for floating-point POD and GfVec of the preceding.

Numeric Conversion Safety

The conversions between all scalar numeric types are performed with range checks such as provided by hboost::numeric_cast(), and will fail, returning an empty VtValue if the source value is out of range of the destination type.

Conversions between GfVec and other compound-numeric types provide no more or less safety or checking than the conversion constructors of the types themselves. This includes VtArray, even VtArray<T> for T in scalar types that are range-checked when held singly.

Definition at line 182 of file value.h.

Constructor & Destructor Documentation

VtValue::VtValue ( )
inline

Default ctor gives empty VtValue.

Definition at line 637 of file value.h.

VtValue::VtValue ( VtValue const other)
inline

Copy construct with other.

Definition at line 640 of file value.h.

VtValue::VtValue ( VtValue &&  other)
inlinenoexcept

Move construct with other.

Definition at line 645 of file value.h.

template<class T >
VtValue::VtValue ( T const obj)
inlineexplicit

Construct a VtValue holding a copy of obj.

If T is a char pointer or array, produce a VtValue holding a std::string. If T is hboost::python::object, produce a VtValue holding a TfPyObjWrapper.

Definition at line 655 of file value.h.

VtValue::~VtValue ( )
inline

Destructor.

Definition at line 686 of file value.h.

Member Function Documentation

template<typename T >
bool VtValue::CanCast ( ) const
inline

Return if this can be cast to T.

See Also
Held-type Conversion with VtValue::Cast

Definition at line 971 of file value.h.

static bool VtValue::CanCastFromTypeidToTypeid ( std::type_info const from,
std::type_info const to 
)
inlinestatic

Return if a value of type from can be cast to type to.

See Also
Held-type Conversion with VtValue::Cast

Definition at line 926 of file value.h.

bool VtValue::CanCastToTypeid ( std::type_info const type) const
inline

Return if this can be cast to type.

See Also
Held-type Conversion with VtValue::Cast

Definition at line 985 of file value.h.

bool VtValue::CanCastToTypeOf ( VtValue const other) const
inline

Return if this can be cast to type.

See Also
Held-type Conversion with VtValue::Cast

Definition at line 978 of file value.h.

VT_API bool VtValue::CanHash ( ) const

Return true if the held object provides a hash implementation.

template<typename T >
static VtValue VtValue::Cast ( VtValue const val)
inlinestatic

Return a VtValue holding val cast to hold T. Return empty VtValue if cast fails.

This Cast() function is safe to call in multiple threads as it does not mutate the operant val.

See Also
Held-type Conversion with VtValue::Cast

Definition at line 898 of file value.h.

template<typename T >
VtValue& VtValue::Cast ( )
inline

Return this holding value type cast to T. This value is left empty if the cast fails.

Note
Since this method mutates this value, it is not safe to invoke on the same VtValue in multiple threads simultaneously.
See Also
Held-type Conversion with VtValue::Cast

Definition at line 939 of file value.h.

static VT_API VtValue VtValue::CastToTypeid ( VtValue const val,
std::type_info const type 
)
static

Return a VtValue holding val cast to type. Return empty VtValue if cast fails.

This Cast() function is safe to call in multiple threads as it does not mutate the operant val.

See Also
Held-type Conversion with VtValue::Cast
VtValue& VtValue::CastToTypeid ( std::type_info const type)
inline

Return this holding value type cast to type. This value is left empty if the cast fails.

Note
Since this method mutates this value, it is not safe to invoke on the same VtValue in multiple threads simultaneously.
See Also
Held-type Conversion with VtValue::Cast

Definition at line 963 of file value.h.

static VT_API VtValue VtValue::CastToTypeOf ( VtValue const val,
VtValue const other 
)
static

Return a VtValue holding val cast to same type that other is holding. Return empty VtValue if cast fails.

This Cast() function is safe to call in multiple threads as it does not mutate the operant val.

See Also
Held-type Conversion with VtValue::Cast
VtValue& VtValue::CastToTypeOf ( VtValue const other)
inline

Return this holding value type cast to same type that other is holding. This value is left empty if the cast fails.

Note
Since this method mutates this value, it is not safe to invoke on the same VtValue in multiple threads simultaneously.
See Also
Held-type Conversion with VtValue::Cast

Definition at line 952 of file value.h.

template<class T >
T const& VtValue::Get ( ) const
inline

Returns a const reference to the held object if the held object is of type T. Issues an error and returns a const reference to a default value if the held object is not of type T. Use IsHolding to verify correct type before calling this function. The default value returned in case of type mismatch is constructed using Vt_DefaultValueFactory<T>. That may be specialized for client types. The default implementation of the default value factory produces a value-initialized T.

Definition at line 847 of file value.h.

size_t VtValue::GetArraySize ( ) const
inline

Return the number of elements in the held value if IsArrayValued(), return 0 otherwise.

Definition at line 817 of file value.h.

VT_API std::type_info const& VtValue::GetElementTypeid ( ) const

Return the typeid of elements in a array valued type. If not holding an array valued type, return typeid(void).

VT_API size_t VtValue::GetHash ( ) const

Return a hash code for the held object by calling VtHashValue() on it.

VT_API TfType VtValue::GetType ( ) const

Returns the TfType of the type held by this value.

VT_API std::type_info const& VtValue::GetTypeid ( ) const

Returns the typeid of the type held by this value.

VT_API std::string VtValue::GetTypeName ( ) const

Return the type name of the held typeid.

template<class T >
T VtValue::GetWithDefault ( T const def = T()) const
inline

Return a copy of the held object if the held object is of type T. Return a copy of the default value def otherwise. Note that this always returns a copy, as opposed to Get() which always returns a reference.

Definition at line 865 of file value.h.

VT_API bool VtValue::IsArrayValued ( ) const

Returns true iff this is holding an array type (see VtIsArray<>).

bool VtValue::IsEmpty ( ) const
inline

Returns true iff this value is empty.

Definition at line 990 of file value.h.

template<class T >
bool VtValue::IsHolding ( ) const
inline

Return true if this value is holding an object of type T, false otherwise.

Definition at line 808 of file value.h.

template<>
bool VtValue::IsHolding ( ) const
inline

Definition at line 1240 of file value.h.

template<>
bool VtValue::IsHolding ( ) const
inline

Definition at line 1247 of file value.h.

bool VtValue::operator!= ( const VtValue rhs) const
inline

Definition at line 1032 of file value.h.

VtValue& VtValue::operator= ( VtValue const other)
inline

Copy assignment from another VtValue.

Definition at line 689 of file value.h.

VtValue& VtValue::operator= ( VtValue &&  other)
inlinenoexcept

Move assignment from another VtValue.

Definition at line 696 of file value.h.

template<class T >
hboost::enable_if_c< _TypeInfoFor<T>::Type::IsLocal && _TypeInfoFor<T>::Type::HasTrivialCopy, VtValue &>::type VtValue::operator= ( T  obj)
inline

Assignment operator from any type.

Definition at line 709 of file value.h.

template<class T >
hboost::disable_if_c< _TypeInfoFor<T>::Type::IsLocal && _TypeInfoFor<T>::Type::HasTrivialCopy, VtValue &>::type VtValue::operator= ( T const obj)
inline

Assignment operator from any type.

Definition at line 721 of file value.h.

VtValue& VtValue::operator= ( char const cstr)
inline

Assigning a char const * gives a VtValue holding a std::string.

Definition at line 728 of file value.h.

VtValue& VtValue::operator= ( char *  cstr)
inline

Assigning a char * gives a VtValue holding a std::string.

Definition at line 736 of file value.h.

bool VtValue::operator== ( const VtValue rhs) const
inline

Test two values for equality.

Definition at line 1024 of file value.h.

template<typename From , typename To >
static void VtValue::RegisterCast ( VtValue(*)(VtValue const &)  castFn)
inlinestatic

Register a cast from VtValue holding From to VtValue holding To.

Definition at line 871 of file value.h.

template<typename From , typename To >
static void VtValue::RegisterSimpleBidirectionalCast ( )
inlinestatic

Register a two-way cast from VtValue holding From to VtValue holding To.

Definition at line 885 of file value.h.

template<typename From , typename To >
static void VtValue::RegisterSimpleCast ( )
inlinestatic

Register a simple cast from VtValue holding From to VtValue.

Definition at line 878 of file value.h.

template<class T >
T VtValue::Remove ( )
inline

Make this value empty and return the held T instance. If this value does not hold a T instance, make this value empty and return a default-constructed T.

Definition at line 787 of file value.h.

VtValue& VtValue::Swap ( VtValue rhs)
inlinenoexcept

Swap this with rhs.

Definition at line 741 of file value.h.

template<class T >
hboost::enable_if< hboost::is_same<T, typename Vt_ValueGetStored<T>::Type> >::type VtValue::Swap ( T rhs)
inline

Swap the held value with rhs. If this value is holding a T,.

Definition at line 762 of file value.h.

template<class T >
static VtValue VtValue::Take ( T obj)
inlinestatic

Create a new VtValue, taking its contents from obj.

This is equivalent to creating a VtValue holding a value-initialized T instance, then invoking swap(<held-value>, obj), leaving obj in a default-constructed (value-initialized) state. In the case that obj is expensive to copy, it may be significantly faster to use this idiom when obj need not retain its contents:

MyExpensiveObject obj = CreateObject();
return VtValue::Take(obj);

Rather than:

MyExpensiveObject obj = CreateObject();
return VtValue(obj);

Definition at line 679 of file value.h.

template<class T >
T const& VtValue::UncheckedGet ( ) const
inline

Returns a const reference to the held object if the held object is of type T. Invokes undefined behavior otherwise. This is the fastest Get() method to use after a successful IsHolding() check.

Definition at line 836 of file value.h.

template<class T >
T VtValue::UncheckedRemove ( )
inline

Make this value empty and return the held T instance. If this value does not hold a T instance, this method invokes undefined behavior.

Definition at line 798 of file value.h.

template<class T >
hboost::enable_if< hboost::is_same<T, typename Vt_ValueGetStored<T>::Type> >::type VtValue::UncheckedSwap ( T rhs)
inline

Swap the held value with rhs. This VtValue must be holding an object of type T. If it does not, this invokes undefined behavior. Use Swap() if this VtValue is not known to contain an object of type T.

Definition at line 775 of file value.h.

void VtValue::UncheckedSwap ( VtValue rhs)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 781 of file value.h.

Friends And Related Function Documentation

friend struct _HoldAside
friend

Definition at line 602 of file value.h.

size_t hash_value ( VtValue const val)
friend

Definition at line 998 of file value.h.

template<typename T >
bool operator!= ( VtValue const lhs,
T const rhs 
)
friend

Tests for inequality.

Definition at line 1015 of file value.h.

template<typename T >
bool operator!= ( T const lhs,
VtValue const rhs 
)
friend

Definition at line 1019 of file value.h.

VT_API friend std::ostream& operator<< ( std::ostream &  out,
const VtValue self 
)
friend

Calls through to operator << on the held object.

template<typename T >
bool operator== ( VtValue const lhs,
T const rhs 
)
friend

Tests for equality.

Definition at line 1004 of file value.h.

template<typename T >
bool operator== ( T const lhs,
VtValue const rhs 
)
friend

Definition at line 1009 of file value.h.

void swap ( VtValue lhs,
VtValue rhs 
)
friend

Overloaded swap() for generic code/stl/etc.

Definition at line 753 of file value.h.

friend struct Vt_ValueShapeDataAccess
friend

Definition at line 1041 of file value.h.


The documentation for this class was generated from the following file: