RenderMan API  23.0
RixStorage Class Referenceabstract

#include <RixInterfaces.h>

Inheritance diagram for RixStorage:
RixInterface

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
 
virtual void Clear (const RtUString key)=0
 
virtual void Lock ()=0
 Lock this object. (Unnecessary unless it's used for global storage.) More...
 
virtual void Unlock ()=0
 Unlock this object. More...
 
- Public Member Functions inherited from RixInterface
virtual int GetVersion () const
 

Protected Member Functions

 RixStorage ()
 Constructor is for internal use only. More...
 
- Protected Member Functions inherited from RixInterface
 RixInterface (int version)
 Interfaces should not be constructed by users. More...
 
virtual ~RixInterface ()
 Interfaces should not be deleted by users. More...
 

Additional Inherited Members

- Public Types inherited from RixInterface
enum  Type {
  k_Float, k_Integer, k_StringV, k_Color,
  k_Normal, k_Vector, k_Point, k_HPoint,
  k_MPoint, k_Matrix
}
 
- Protected Attributes inherited from RixInterface
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.

Definition at line 1363 of file RixInterfaces.h.

Constructor & Destructor Documentation

◆ RixStorage()

RixStorage::RixStorage ( )
inlineprotected

Constructor is for internal use only.

Definition at line 1389 of file RixInterfaces.h.

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.

◆ 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.


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