RenderManAPI  24.0
RixStorage Class Referenceabstract

NOTE: This interface is deprecated and will be removed in a future release. More...

#include <RixInterfaces.h>

Inherits RixInterface.

Public Types

enum  Type {
  k_Float, k_Integer, k_StringV, k_Color,
  k_Normal, k_Vector, k_Point, k_HPoint,
  k_MPoint, k_Matrix
}
 

Public Member Functions

virtual void * Get (const RtUString key)=0
 Get the data associated with the given key, or NULL if there is none. More...
 
virtual void Set (const RtUString key, void *data, RixCleanupFunc cleanup=NULL)=0
 Set the data associated with the given key, along with an optional cleanup function. More...
 
virtual void Clear (const RtUString key)=0
 Clear any data associated with the given key, calling its cleanup function (if any). More...
 
virtual void Lock ()=0
 Lock this object. (Unnecessary unless it's used for global storage.) More...
 
virtual void Unlock ()=0
 Unlock this object. More...
 
virtual int GetVersion () const
 Get the version number of this interface. More...
 

Protected Member Functions

 RixStorage ()
 Constructor is for internal use only. More...
 

Protected Attributes

int m_version
 Version number of this interface. More...
 

Detailed Description

NOTE: This interface is deprecated and will be removed in a future release.

RixStorage allows plugins to store and share arbitrary data by associating it with an arbitrary key. For example, a shader plugin might share per-thread data as follows:

RixStorage* storage = (RixStorage*)
rslContext->GetRixInterface(k_RixThreadData);
const static RtUString MYDATA("mydata");
void* mydata = storage->Get(MYDATA);
if (mydata == NULL) {
mydata = MakeData();
storage->Set(MYDATA, mydata, CleanupData);
}

This code operates as follows:

  • Get the per-thread data storage interface from the RslContext.
  • Look up the key to see if the data already exists.
  • If not, allocate the data and save it in per-thread storage.
  • The specified cleanup function is called when the thread exits (typically at the end of a frame).

Per-thread storage is thread-safe, but all other storage must be locked, for example the per-grid storage below is locked:

RixStorage* storage = (RixStorage*) rslCtx->GetRixInterface(k_RixLocalData);
const static RtUString MYGLOBAL("myglobal");
storage->Lock();
void* myglobal = storage->Get(MYGLOBAL);
if (myglobal == NULL) {
myglobal = MakeData();
storage->Set(MYGLOBAL, myglobal, CleanupData);
}
storage->Unlock();

Per-thread storage can also be used from the global RixContext, as in the example below:

RixContext *rixContext = RixGetContext();
RixStorage* storage = (RixStorage*)
const static RtUString MYDATA("mydata");
void* mydata = storage->Get(MYDATA);
if (mydata == NULL) {
mydata = MakeData();
storage->Set(MYDATA, mydata, CleanupData);
}

A cleanup function has a prototype like the following:

void myCleanup(RixContext* context, void* data);

The RixContext argument allows the cleanup function to obtain interfaces for reporting errors, etc. Note that a cleanup function for per-thread data can access the per-thread RixStorage interface (e.g. for maintaining memory usage statistics). But per-thread storage is not accessible in a cleanup function for per-frame or per-session data.

Member Enumeration Documentation

◆ Type

enum RixInterface::Type
inherited
Enumerator
k_Float 
k_Integer 
k_StringV 
k_Color 
k_Normal 
k_Vector 
k_Point 
k_HPoint 
k_MPoint 
k_Matrix 

Constructor & Destructor Documentation

◆ RixStorage()

RixStorage::RixStorage ( )
inlineprotected

Constructor is for internal use only.

Member Function Documentation

◆ Clear()

virtual void RixStorage::Clear ( const RtUString  key)
pure virtual

Clear any data associated with the given key, calling its cleanup function (if any).

◆ Get()

virtual void* RixStorage::Get ( const RtUString  key)
pure virtual

Get the data associated with the given key, or NULL if there is none.

◆ GetVersion()

virtual int RixInterface::GetVersion ( ) const
inlinevirtualinherited

Get the version number of this interface.

Different interfaces might have different version numbers in a given release.

References RixInterface::m_version.

◆ Lock()

virtual void RixStorage::Lock ( )
pure virtual

Lock this object. (Unnecessary unless it's used for global storage.)

◆ Set()

virtual void RixStorage::Set ( const RtUString  key,
void *  data,
RixCleanupFunc  cleanup = NULL 
)
pure virtual

Set the data associated with the given key, along with an optional cleanup function.

Any previously associated data is discarded (calling its cleanup function, if any). The key is copied.

◆ Unlock()

virtual void RixStorage::Unlock ( )
pure virtual

Unlock this object.

Member Data Documentation

◆ m_version

int RixInterface::m_version
protectedinherited

Version number of this interface.

Referenced by RixInterface::GetVersion().


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