All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HdInstance< VALUE > Class Template Reference

This class is used as an interface to a shared instance in HdInstanceRegistry. More...

Public Types

typedef uint64_t KeyType
 
typedef VALUE ValueType
 
typedef KeyType ID
 
typedef
tbb::concurrent_unordered_map
< KeyType, ValueHolder > 
Dictionary
 
typedef std::mutex RegistryMutex
 
typedef std::unique_lock
< RegistryMutex > 
RegistryLock
 

Public Member Functions

 HdInstance (KeyType const &key, ValueType const &value, RegistryLock registryLock, Dictionary *container)
 Construct an instance holding a registry lock, representing a value held in a registry container. More...
 
 HdInstance (KeyType const &key)
 Construct an instance with no lock or registry container. More...
 
KeyType const & GetKey () const
 Returns the key. More...
 
ValueType const & GetValue () const
 Returns the value. More...
 
void SetValue (ValueType const &value)
 Update the value in dictionary indexed by the key. More...
 
bool IsFirstInstance () const
 Returns true if the value has not been initialized. More...
 

Detailed Description

template<typename VALUE>
class HdInstance< VALUE >

This class is used as an interface to a shared instance in HdInstanceRegistry.

KeyType is a hashable index type and VALUE is shared_ptr. In most use cases, the client computes a hash key which represents large bulky data (like topology, primvars) and registers it into HdInstanceRegistry. If the key has already been registered, the registry returns HdInstance and the client can use GetValue() without setting/computing actual bulky data. If it doesn't exist, IsFirstInstance() returns true for the first instance and the client needs to populate an appropriate data VALUE into the instance by SetValue().

In order to support concurrent access to HdInstanceRegistry, this class holds a lock to a mutex in HdInstanceRegistry. This lock will be held until the instance of this interface class is destroyed.

Definition at line 60 of file instanceRegistry.h.

Constructor & Destructor Documentation

HdInstance ( KeyType const &  key,
ValueType const &  value,
RegistryLock  registryLock,
Dictionary *  container 
)
inlineexplicit

Construct an instance holding a registry lock, representing a value held in a registry container.

Definition at line 88 of file instanceRegistry.h.

HdInstance ( KeyType const &  key)
inlineexplicit

Construct an instance with no lock or registry container.

This is used to present a consistent interface to clients in cases where shared resource registration is disabled.

Definition at line 102 of file instanceRegistry.h.

Member Function Documentation

KeyType const& GetKey ( ) const
inline

Returns the key.

Definition at line 111 of file instanceRegistry.h.

ValueType const& GetValue ( ) const
inline

Returns the value.

Definition at line 114 of file instanceRegistry.h.

bool IsFirstInstance ( ) const
inline

Returns true if the value has not been initialized.

Definition at line 123 of file instanceRegistry.h.

void SetValue ( ValueType const &  value)
inline

Update the value in dictionary indexed by the key.

Definition at line 117 of file instanceRegistry.h.


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