|
Provides a container which may hold any type, and provides introspection and iteration over array types. More...
#include <value.h>
Public Member Functions | |
VtValue () | |
Default ctor gives empty VtValue. | |
VtValue (VtValue const &other) | |
Copy construct with other . | |
VtValue (VtValue &&other) noexcept | |
Move construct with other . | |
template<class T > | |
VtValue (T const &obj) | |
Construct a VtValue holding a copy of obj . | |
~VtValue () | |
Destructor. | |
VtValue & | operator= (VtValue const &other) |
Copy assignment from another VtValue. | |
VtValue & | operator= (VtValue &&other) noexcept |
Move assignment from another VtValue. | |
template<class T > | |
VtValue & | operator= (T const &obj) |
Assignment operator from any type. | |
VtValue & | operator= (char const *cstr) |
Assigning a char const * gives a VtValue holding a std::string. | |
VtValue & | operator= (char *cstr) |
Assigning a char * gives a VtValue holding a std::string. | |
VtValue & | Swap (VtValue &rhs) noexcept |
Swap this with rhs. | |
template<class T > | |
void | Swap (T &rhs) |
Swap the held value with rhs. If this value is holding a T,. | |
template<class T > | |
void | UncheckedSwap (T &rhs) |
Swap the held value with rhs. | |
void | UncheckedSwap (VtValue &rhs) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
template<class T > | |
T | Remove () |
Make this value empty and return the held T instance. | |
template<class T > | |
T | UncheckedRemove () |
Make this value empty and return the held T instance. | |
template<class T , class Fn > | |
std::enable_if_t< std::is_same< T, typename Vt_ValueGetStored< T >::Type >::value, bool > | Mutate (Fn &&mutateFn) |
If this value holds an object of type T , invoke mutateFn , passing it a non-const reference to the held object and return true. | |
template<class T , class Fn > | |
std::enable_if_t< std::is_same< T, typename Vt_ValueGetStored< T >::Type >::value > | UncheckedMutate (Fn &&mutateFn) |
Invoke mutateFn , it a non-const reference to the held object which must be of type T . | |
template<class T > | |
bool | IsHolding () const |
Return true if this value is holding an object of type T , false otherwise. | |
VT_API bool | IsArrayValued () const |
Returns true iff this is holding an array type (see VtIsArray<>). | |
size_t | GetArraySize () const |
Return the number of elements in the held value if IsArrayValued(), return 0 otherwise. | |
VT_API std::type_info const & | GetTypeid () const |
Returns the typeid of the type held by this value. | |
VT_API std::type_info const & | GetElementTypeid () const |
Return the typeid of elements in a array valued type. | |
VT_API TfType | GetType () const |
Returns the TfType of the type held by this value. | |
VT_API std::string | GetTypeName () const |
Return the type name of the held typeid. | |
int | GetKnownValueTypeIndex () const |
Return VtKnownValueTypeIndex<T> for the held type T. | |
template<class T > | |
T const & | UncheckedGet () const & |
Returns a const reference to the held object if the held object is of type T. | |
template<class T > | |
T | UncheckedGet () && |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. In case *this is an rvalue, move the held value out and return by value. | |
template<class T > | |
T const & | Get () const & |
Returns a const reference to the held object if the held object is of type T. | |
template<class T > | |
T | Get () && |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. In case *this is an rvalue, move the held value out and return by value. | |
template<class T > | |
T | GetWithDefault (T const &def=T()) const |
Return a copy of the held object if the held object is of type T. | |
template<typename T > | |
VtValue & | Cast () |
Return this holding value type cast to T. | |
VtValue & | CastToTypeOf (VtValue const &other) |
Return this holding value type cast to same type that other is holding. | |
VtValue & | CastToTypeid (std::type_info const &type) |
Return this holding value type cast to type. | |
template<typename T > | |
bool | CanCast () const |
Return if this can be cast to T. | |
bool | CanCastToTypeOf (VtValue const &other) const |
Return if this can be cast to type. | |
bool | CanCastToTypeid (std::type_info const &type) const |
Return if this can be cast to type. | |
bool | IsEmpty () const |
Returns true iff this value is empty. | |
VT_API bool | CanHash () const |
Return true if the held object provides a hash implementation. | |
VT_API size_t | GetHash () const |
Return a hash code for the held object by calling VtHashValue() on it. | |
bool | operator== (const VtValue &rhs) const |
Test two values for equality. | |
bool | operator!= (const VtValue &rhs) const |
Static Public Member Functions | |
template<class T > | |
static VtValue | Take (T &obj) |
Create a new VtValue, taking its contents from obj . | |
template<typename From , typename To > | |
static void | RegisterCast (VtValue(*castFn)(VtValue const &)) |
Register a cast from VtValue holding From to VtValue holding To. | |
template<typename From , typename To > | |
static void | RegisterSimpleCast () |
Register a simple cast from VtValue holding From to VtValue. | |
template<typename From , typename To > | |
static void | RegisterSimpleBidirectionalCast () |
Register a two-way cast from VtValue holding From to VtValue holding To. | |
template<typename T > | |
static VtValue | Cast (VtValue const &val) |
Return a VtValue holding val cast to hold T. | |
static VT_API VtValue | CastToTypeOf (VtValue const &val, VtValue const &other) |
Return a VtValue holding val cast to same type that other is holding. | |
static VT_API VtValue | CastToTypeid (VtValue const &val, std::type_info const &type) |
Return a VtValue holding val cast to type. | |
static bool | CanCastFromTypeidToTypeid (std::type_info const &from, std::type_info const &to) |
Return if a value of type from can be cast to type to. | |
Friends | |
struct | _HoldAside |
void | swap (VtValue &lhs, VtValue &rhs) |
Overloaded swap() for generic code/stl/etc. | |
size_t | hash_value (VtValue const &val) |
template<typename T > | |
bool | operator== (VtValue const &lhs, T const &rhs) |
Tests for equality. | |
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. | |
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. | |
Provides a container which may hold any type, and provides introspection and iteration over array types.
See VtIsArray for more info.
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.
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.
The conversions between all scalar numeric types are performed with range checks such as provided by boost::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.
|
inlineexplicit |
|
inline |
Return if this
can be cast to T.
|
inlinestatic |
Return if a value of type from can be cast to type to.
|
inline |
Return if this
can be cast to type.
|
inline |
Return if this
can be cast to type.
VT_API bool CanHash | ( | ) | const |
Return true if the held object provides a hash implementation.
|
inline |
Return this
holding value type cast to T.
This value is left empty if the cast fails.
|
inline |
Return this
holding value type cast to type.
This value is left empty if the cast fails.
Return this
holding value type cast to same type that other
is holding.
This value is left empty if the cast fails.
|
inline |
|
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.
|
inline |
Return the number of elements in the held value if IsArrayValued(), return 0 otherwise.
VT_API std::type_info const & 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 GetHash | ( | ) | const |
Return a hash code for the held object by calling VtHashValue() on it.
|
inline |
VT_API std::type_info const & GetTypeid | ( | ) | const |
Returns the typeid of the type held by this value.
VT_API std::string GetTypeName | ( | ) | const |
Return the type name of the held typeid.
|
inline |
VT_API bool IsArrayValued | ( | ) | const |
Returns true iff this is holding an array type (see VtIsArray<>).
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
VtValue & operator= | ( | T const & | obj | ) |
Assignment operator from any type.
|
inline |
|
inlinestatic |
|
inlinestatic |
|
inline |
void Swap | ( | T & | rhs | ) |
Swap the held value with rhs. If this value is holding a T,.
|
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:
Rather than:
|
inline |
|
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.
|
inline |
|
inline |
void UncheckedSwap | ( | T & | rhs | ) |
|
inline |
|
friend |
|
friend |
|
friend |
Calls through to operator << on the held object.
|
friend |
|
friend |