Clarisse 5.0 SP8 SDK  5.0.5.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Public Member Functions | List of all members
CoreMetadata Class Reference

Public Member Functions

 ~CoreMetadata (void)
 
template<class T >
bool set (CoreStringView key, const T &value)
 
template<class T >
get (CoreStringView key, const T &default_value=T{}) const
 
bool set_custom (CoreStringView key, CoreBaseObject *value)
 
template<class T >
T * get_custom (CoreStringView key) const
 
void clear (void)
 
size_t size (void) const
 

Detailed Description

Helper class for metadata handling. This is basically a hash table of string keys and values stored in CoreVariant's. As such it supports the basic integers, floating point, string and pointer values.

But you can also attach custom user data, as long as that data is a heap allocated instance of a class inheriting from CoreBaseObject. In such case, the CoreMetadata class takes ownership of the instance and will delete it for you.

You can set/update data like this: ```{.cpp} CoreMetadata data;

// the simple data (types natively handled by CoreVariant) data.set("SomeLong"_sv, 10); data.set("SomeDouble"_sv, 10.0); data.set("String"_sv, "Hello");

// you can still be explicit about the types: in this case the data will be statically cast // to a void * before being set. This way you can set values of types not handled by CoreVariant // without having to cast yourself. data.set<void *>("Ptr", this);

// some more complex metadata struct CustomData : public CoreBaseObject { float f; CoreString s; }

// you need to allocate the custom data, and it will automatically be deleted whenever data is deleted. data.set_custom("CustomData"_sv, new CustomData{ 1.0f, "World" }); ```

And you access data like that: ```{.cpp} // when providing a default value, no need for an explicit template typename USD_LOG_INFO("SomeLong ", data.get("SomeLong"_sv, 0));

// otherwise you need it: USD_LOG_INFO("SomeLong ", data.get<long>("SomeLong"_sv));

// access a custom data CustomData custom_data = data.get_custom<CustomData>("CustomData"_sv); if (custom_data != nullptr) { / ...

Constructor & Destructor Documentation

CoreMetadata::~CoreMetadata ( void  )
inline

Destructor. We need to manually delete the custom user data since CoreVariant doesn't take ownership of the CoreBaseObject pointers it can hold.

Member Function Documentation

void CoreMetadata::clear ( void  )
inline

Clear all metadata.

template<class T >
T CoreMetadata::get ( CoreStringView  key,
const T &  default_value = T{} 
) const
inline

Get a metadata by key.

Template Parameters
TThe type of the metadata. Automatically deduced from default_value when provided, otherwise need to be explicitely set.
Parameters
keyThe key of the metadata
default_valueThe default value to return if there is no such key. T{} by default (T{} is the zero initializer, it will initialize the type with zeros)
Returns
The value of the metadata or the default value if there was no such metadata
template<class T >
T * CoreMetadata::get_custom ( CoreStringView  key) const
inline

Helper used to get a custom metadata.

Template Parameters
TThe class of the custom data. In the example, it was CustomData.
Parameters
keyThe key of the metadata
Returns
The custom data, or nullptr if not found.
template<class T >
bool CoreMetadata::set ( CoreStringView  key,
const T &  value 
)
inline

Set or add a data.

Template Parameters
TThe type of the metadata. Automatically deduced from value
Parameters
keyThe key of the metadata.
valueThe value to set/update.
returntrue if the value was created, false otherwise (in this case the value was just updated)
Note
The key must be a CoreStringView (you can use string literals with the _sv suffix, see example in the class doc)
bool CoreMetadata::set_custom ( CoreStringView  key,
CoreBaseObject value 
)
inline

Set or add a custom data. The CoreMetadata will assume ownership of the data.

Parameters
keyThe key of the metadata.
valueThe custom data to set/update.
returntrue if the value was created, false otherwise (in this case the value was just updated)
Note
The key must be a CoreStringView (you can use string literals with the _sv suffix, see example in the class doc)
size_t CoreMetadata::size ( void  ) const
inline

Get the number of data.