RixStorage Class Reference

RixStorage allows plugins to store and share arbitrary data by associating it with an arbitrary key. More...

#include <RixInterfaces.h>

Inheritance diagram for RixStorage:

RixInterface List of all members.

Public Member Functions

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

Protected Member Functions

 RixStorage ()
 Constructor is for internal use only.

Protected Attributes

int m_version
 Version number of this interface.

Detailed Description

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);
    void* mydata = storage->Get("mydata");
    if (mydata == NULL) {
        mydata = MakeData();
        storage->Set("mydata", mydata, CleanupData);
    }
This code operates as follows:

Per-thread storage is thread-safe, but per-frame storage must be locked:

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

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 fuction 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 data.


Constructor & Destructor Documentation

RixStorage::RixStorage  )  [inline, protected]
 

Constructor is for internal use only.


Member Function Documentation

virtual void RixStorage::Clear const char *  key  )  [pure virtual]
 

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

virtual void* RixStorage::Get const char *  key  )  [pure virtual]
 

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

virtual int RixInterface::GetVersion  )  const [inline, virtual, inherited]
 

Get the version number of this interface.

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

virtual void RixStorage::Lock  )  [pure virtual]
 

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

virtual void RixStorage::Set const char *  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.

virtual void RixStorage::Unlock  )  [pure virtual]
 

Unlock this object.


Member Data Documentation

int RixInterface::m_version [protected, inherited]
 

Version number of this interface.


The documentation for this class was generated from the following file:
Generated on Wed May 10 11:00:40 2006 for PRManHeaders by  doxygen 1.4.6