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

#include <valueRef.h>

+ Inheritance diagram for VtValueRef:

Classes

struct  _IsArrayEditHelper
 
struct  _IsArrayHelper
 
struct  _NonArrayHelper
 
union  _RefdObjPtr
 
struct  _TypeInfo
 
struct  _TypeInfoImpl
 

Public Member Functions

 VtValueRef ()
 Default ctor gives empty VtValueRef. More...
 
 VtValueRef (VtValueRef const &)=default
 
 VtValueRef (VtValueRef &&)=default
 
template<class T >
 VtValueRef (T &&obj, std::enable_if_t< !std::is_same_v< std::decay_t< T >, VtValueRef > &&!std::is_same_v< std::decay_t< T >, VtValue >> *=0)
 
VtValueRefoperator= (VtValueRef const &ref)=default
 Rebind to view the same object as another VtValueRef. More...
 
VtValueRefoperator= (VtValueRef &&ref)=default
 
template<class T >
VtValueRefoperator= (T &&)=delete
 
template<class T >
bool IsHolding () const
 
bool IsRValue () const
 
VT_API bool IsArrayValued () const
 Return true if this views a VtArray instance, false otherwise. More...
 
VT_API bool IsArrayEditValued () const
 Return true if this views a VtArrayEdit instance, false otherwise. More...
 
size_t GetArraySize () const
 
std::type_info const & GetTypeid () const
 Return the typeid of the type viewed by this value. More...
 
std::type_info const & GetElementTypeid () const
 
VT_API TfType GetType () const
 Returns the TfType of the type viewed by this value. More...
 
VT_API std::string GetTypeName () const
 Return the type name of the viewed typeid. More...
 
int GetKnownValueTypeIndex () const
 
template<class T >
_TypeInfoFor< T >::GetObjResultType UncheckedGet () const
 
template<class T >
_TypeInfoFor< T >::GetObjResultType Get () const
 
template<class T >
T GetWithDefault (T const &def=T()) const
 
template<class T >
T Remove ()
 
template<class T >
T UncheckedRemove ()
 
bool IsEmpty () const
 Returns true iff this value is empty. More...
 
VT_API operator VtValue () const
 Implicitly convert to a VtValue by copying the viewed object. More...
 
VT_API bool CanHash () const
 Return true if the viewed object provides a hash implementation. More...
 
VT_API size_t GetHash () const
 Return a hash code for the viewed object by calling VtHashValue() on it. More...
 
bool CanComposeOver () const
 
bool CanTransform () const
 
bool operator== (const VtValueRef &rhs) const
 Test two values for equality. More...
 
bool operator!= (const VtValueRef &rhs) const
 
template<>
VtValueRef const & Get () const
 
template<>
VtValueRef const & UncheckedGet () const
 
template<>
bool IsHolding () const
 
template<>
bool IsHolding () const
 

Protected Types

template<class T >
using _ArrayHelper = TfConditionalType< VtIsArray< T >::value, _IsArrayHelper< T >, TfConditionalType< VtIsArrayEdit< T >::value, _IsArrayEditHelper< T >, _NonArrayHelper< T >> >
 
template<class T >
using _TypeInfoFor = _TypeInfoImpl< std::decay_t< T >, std::is_reference_v< T > &&std::is_const_v< T >>
 

Protected Member Functions

VT_API size_t _GetNumElements () const
 
template<class T >
bool _TypeIs () const
 
template<class T >
_TypeInfoFor< T >
::GetMutableObjResultType 
_GetMutable ()
 
template<class T >
_TypeInfoFor< T >::GetObjResultType _Get () const
 
VT_API void const * _FailGet (Vt_DefaultValueHolder(*factory)(), std::type_info const &queryType) const
 
VT_API void _FailRemove (std::type_info const &)
 
VT_API TfPyObjWrapper _GetPythonObject () const
 

Protected Attributes

_RefdObjPtr _ptr
 
_TypeInfo const * _info
 

Friends

void swap (VtValueRef &lhs, VtValueRef &rhs)
 Overloaded swap() for generic code/stl/etc. Swaps the viewed objects. More...
 
size_t hash_value (VtValueRef const &val)
 
VT_API friend std::ostream & operator<< (std::ostream &out, const VtValueRef &self)
 Calls through to operator << on the viewed object. More...
 
TfPyObjWrapper Vt_GetPythonObjectFromHeldValue (VtValueRef const &self)
 

Detailed Description

A non-owning type-erased view of a value, interoperating with VtValue. Since VtValueRef is non-owning it must not persist beyond the lifetime of the value it views, and so it is typically best used as a function argument or an automatic variable.

Both ordinary typed values and VtValues are implicitly convertible to VtValueRef. This makes it convenient to use when writing a function that can take an object of any type. Since it's non-owning, it is relatively light-weight, incurring no heap allocations or reference counting operations. In addition, VtValueRef remembers if it is viewing an rvalue-reference, in which case the underlying object can be removed by a move() operation rather than a copy. See Remove().

VtValueRef supports much of the same API as VtValue, including implicitly converting back to VtValue if needed.

Definition at line 64 of file valueRef.h.

Member Typedef Documentation

template<class T >
using VtValueRef::_TypeInfoFor = _TypeInfoImpl< std::decay_t<T>, std::is_reference_v<T> && std::is_const_v<T>>
protected

Definition at line 361 of file valueRef.h.

Constructor & Destructor Documentation

VtValueRef::VtValueRef ( )
inline

Default ctor gives empty VtValueRef.

Definition at line 366 of file valueRef.h.

VtValueRef::VtValueRef ( VtValueRef const &  )
default
VtValueRef::VtValueRef ( VtValueRef &&  )
default
template<class T >
VtValueRef::VtValueRef ( T &&  obj,
std::enable_if_t< !std::is_same_v< std::decay_t< T >, VtValueRef > &&!std::is_same_v< std::decay_t< T >, VtValue >> *  = 0 
)
inline

Implicitly convert or construct a VtValueRef referring to obj. The passed obj must outlive this VtValueRef instance.

Definition at line 374 of file valueRef.h.

Member Function Documentation

VT_API void const* VtValueRef::_FailGet ( Vt_DefaultValueHolder(*)()  factory,
std::type_info const &  queryType 
) const
protected
VT_API void VtValueRef::_FailRemove ( std::type_info const &  )
protected
template<class T >
_TypeInfoFor<T>::GetObjResultType VtValueRef::_Get ( ) const
inlineprotected

Definition at line 591 of file valueRef.h.

template<class T >
_TypeInfoFor<T>::GetMutableObjResultType VtValueRef::_GetMutable ( )
inlineprotected

Definition at line 584 of file valueRef.h.

VT_API size_t VtValueRef::_GetNumElements ( ) const
protected
VT_API TfPyObjWrapper VtValueRef::_GetPythonObject ( ) const
protected
template<class T >
bool VtValueRef::_TypeIs ( ) const
inlineprotected

Definition at line 572 of file valueRef.h.

bool VtValueRef::CanComposeOver ( ) const
inline

Return true if this value holds a type that has been declared at compile time to support composing over other types. This is a fast check that can be used to avoid calling VtValueComposeOver(strong, weak) if strong does not support composing over. Empty VtValue always can compose over.

Definition at line 535 of file valueRef.h.

VT_API bool VtValueRef::CanHash ( ) const

Return true if the viewed object provides a hash implementation.

bool VtValueRef::CanTransform ( ) const
inline

Return true if this value holds a type that has been declared to support value transforms at compile time. This is a fast check that can be used to avoid calling the relatively slower VtValueTryTransform(obj, xform) if obj does not support transforms at all. Empty VtValue does not support transforms.

Definition at line 544 of file valueRef.h.

template<class T >
_TypeInfoFor<T>::GetObjResultType VtValueRef::Get ( ) const
inline

Return a const reference to the viewed object if the viewed object is of type T. Issues an error and return a const reference to a default value if the viewed 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 464 of file valueRef.h.

template<>
VtValueRef const& VtValueRef::Get ( ) const
inline

Definition at line 626 of file valueRef.h.

size_t VtValueRef::GetArraySize ( ) const
inline

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

Definition at line 421 of file valueRef.h.

std::type_info const& VtValueRef::GetElementTypeid ( ) const
inline

If this value views a VtArray or VtArrayEdit instance, return the typeid of its element type. For example, if this value views a VtIntArray or a VtIntArrayEdit, return typeid(int). Otherwise return typeid(void).

Definition at line 431 of file valueRef.h.

VT_API size_t VtValueRef::GetHash ( ) const

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

int VtValueRef::GetKnownValueTypeIndex ( ) const
inline

Return VtKnownValueTypeIndex<T> for the viewed type T. If this value is empty or views a type that is not 'known', return -1.

Definition at line 443 of file valueRef.h.

VT_API TfType VtValueRef::GetType ( ) const

Returns the TfType of the type viewed by this value.

std::type_info const& VtValueRef::GetTypeid ( ) const
inline

Return the typeid of the type viewed by this value.

Definition at line 424 of file valueRef.h.

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

Return the type name of the viewed typeid.

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

Return a copy of the viewed object if the viewed 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 482 of file valueRef.h.

VT_API bool VtValueRef::IsArrayEditValued ( ) const

Return true if this views a VtArrayEdit instance, false otherwise.

VT_API bool VtValueRef::IsArrayValued ( ) const

Return true if this views a VtArray instance, false otherwise.

bool VtValueRef::IsEmpty ( ) const
inline

Returns true iff this value is empty.

Definition at line 515 of file valueRef.h.

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

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

Definition at line 403 of file valueRef.h.

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

Definition at line 638 of file valueRef.h.

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

Definition at line 645 of file valueRef.h.

bool VtValueRef::IsRValue ( ) const
inline

Return true if this refers to an rvalue, and thus can be Remove()d by a move construction operation instead of a copy.

Definition at line 409 of file valueRef.h.

VT_API VtValueRef::operator VtValue ( ) const

Implicitly convert to a VtValue by copying the viewed object.

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

Definition at line 561 of file valueRef.h.

VtValueRef& VtValueRef::operator= ( VtValueRef const &  ref)
default

Rebind to view the same object as another VtValueRef.

VtValueRef& VtValueRef::operator= ( VtValueRef &&  ref)
default
template<class T >
VtValueRef& VtValueRef::operator= ( T &&  )
delete
bool VtValueRef::operator== ( const VtValueRef rhs) const
inline

Test two values for equality.

Definition at line 549 of file valueRef.h.

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

Return a move-constructed (if the viewed object is an rvalue) or copy-constructed T instance from the viewed object. If the viewed object is an rvalue then it is left in its moved-from state. If this value does not view a T instance, issue an error and return a default-constructed T.

Definition at line 492 of file valueRef.h.

template<class T >
_TypeInfoFor<T>::GetObjResultType VtValueRef::UncheckedGet ( ) const
inline

Return a const reference to the viewed object if the viewed 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 452 of file valueRef.h.

template<>
VtValueRef const& VtValueRef::UncheckedGet ( ) const
inline

Definition at line 632 of file valueRef.h.

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

Return a move-constructed (if the viewed object is an rvalue) or copy-constructed T instance from the viewed object. If the viewed object is an rvalue then it is left in its moved-from state. If this value does not view a T instance, invoke undefined behavior.

Definition at line 507 of file valueRef.h.

Friends And Related Function Documentation

size_t hash_value ( VtValueRef const &  val)
friend

Definition at line 526 of file valueRef.h.

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

Calls through to operator << on the viewed object.

void swap ( VtValueRef lhs,
VtValueRef rhs 
)
friend

Overloaded swap() for generic code/stl/etc. Swaps the viewed objects.

Definition at line 395 of file valueRef.h.

TfPyObjWrapper Vt_GetPythonObjectFromHeldValue ( VtValueRef const &  self)
friend

Member Data Documentation

_TypeInfo const* VtValueRef::_info
protected

Definition at line 614 of file valueRef.h.

_RefdObjPtr VtValueRef::_ptr
protected

Definition at line 613 of file valueRef.h.


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