FreePOOMA
2.4.1
|
CompressibleBlock (CBlock) provides the storage for Pooma's compressible brick engine. More...
#include <CompressibleBlock.h>
Classes | |
class | CompressibleBlockController |
Public Types | |
enum | Notifier { notifyDestruct = 0, notifyUncompress = 1, notifyCompress = 2 } |
typedef CompressibleBlock< T > | This_t |
typedef T | Element_t |
typedef Pooma::DataObject_t | DataObject_t |
Public Member Functions | |
CompressibleBlock () | |
CompressibleBlock (int size) | |
CompressibleBlock (int size, int affinity) | |
CompressibleBlock (int size, int affinity, const T &model) | |
CompressibleBlock (const CompressibleBlock &block) | |
~CompressibleBlock () | |
int | size () const |
int | capacity () const |
bool | resize (int newsize, const typename DataBlockPtr< T >::NoInitTag &) |
void | setSize (int newsize) |
DataObject_t * | dataObject () const |
int | affinity () const |
bool | compressed () const |
T * | data () |
void | uncompress () const |
void | tryCompress () |
DataBlockPtr< T > | view () const |
DataBlockPtr< T > | dataBlock () const |
void | makeOwnCopy () |
void | invalidate () |
bool | isControllerPtrValid () const |
bool | isControllerValid () const |
bool | isControllerValidUnlocked () const |
bool | isShared () const |
bool | operator!= (const This_t &a) const |
bool | operator== (const This_t &a) const |
void | attach (Observer< T * > *o) |
void | detach (Observer< T * > *o) |
void | lock () const |
void | unlock () const |
Static Public Member Functions | |
static int | randomTries () |
CompressibleBlock (CBlock) provides the storage for Pooma's compressible brick engine.
Compressible brick engines need a data storage class that manages a block of data that has the following characteristics:
Since there can be multiple views (shallow copies) of the compressible block (both of the data and the data-object), it is important that the state be maintained by a separate object. Thus, CompressibleBlock is simply an envelope that holds a ref-counted pointer to a Compressible- BlockController (CBC). The CBC is a private nested class and thus does not appear directly in the user interface. However it is an important element of the design. CBlock itself is just an envelope that passes messages on to the CBC.
Given all that, here is how views of the data work: There can be compressible brick views (CompBrick and CompBrickViews) of the data. These all share the same CBlock, and they do not care whether the CBlock is compressed or not. There can also be plain BrickViews of the uncompressed data. When the last BrickView is destroyed, the CBlock should try to compress itself. Here is a diagram, then, of the possible views:
BrickView---->DataBlockPtr<-----CBlock<-----CompBrick BrickView------^ ^----CompBrickView
In order for CompBrick and CBlock to have consistent compressibility state, we must use the observer pattern and make it thread safe. Thus we have the following relationships amongst the classes:
CBC observes the DataBlockPtr (~DataBlockPtr calls notify)
CompBrick/CompBrickView observes the CBlock (the CBC really as attach/detach simply pass the request on) (CBC::trycompress and CBC::uncompress call notify)
typedef CompressibleBlock<T> CompressibleBlock< T >::This_t |
typedef T CompressibleBlock< T >::Element_t |
typedef Pooma::DataObject_t CompressibleBlock< T >::DataObject_t |
enum CompressibleBlock::Notifier |
CompressibleBlock< T >::CompressibleBlock | ( | ) | [inline] |
CompressibleBlock< T >::CompressibleBlock | ( | int | size | ) | [inline, explicit] |
CompressibleBlock< T >::CompressibleBlock | ( | int | size, |
int | affinity | ||
) | [inline] |
CompressibleBlock< T >::CompressibleBlock | ( | int | size, |
int | affinity, | ||
const T & | model | ||
) | [inline] |
CompressibleBlock< T >::CompressibleBlock | ( | const CompressibleBlock< T > & | block | ) | [inline] |
CompressibleBlock< T >::~CompressibleBlock | ( | ) | [inline] |
References RefCountedPtr< T >::isValid(), and PAssert.
int CompressibleBlock< T >::size | ( | ) | const [inline] |
int CompressibleBlock< T >::capacity | ( | ) | const [inline] |
bool CompressibleBlock< T >::resize | ( | int | newsize, |
const typename DataBlockPtr< T >::NoInitTag & | |||
) | [inline] |
void CompressibleBlock< T >::setSize | ( | int | newsize | ) | [inline] |
DataObject_t* CompressibleBlock< T >::dataObject | ( | ) | const [inline] |
References RefCountedPtr< T >::isValid(), and PAssert.
int CompressibleBlock< T >::affinity | ( | ) | const [inline] |
References RefCountedPtr< T >::isValid(), and PAssert.
bool CompressibleBlock< T >::compressed | ( | ) | const [inline] |
References RefCountedPtr< T >::isValid(), and PAssert.
T* CompressibleBlock< T >::data | ( | ) | [inline] |
References RefCountedPtr< T >::isValid(), and PAssert.
void CompressibleBlock< T >::uncompress | ( | ) | const [inline] |
References RefCountedPtr< T >::isValid(), and PAssert.
void CompressibleBlock< T >::tryCompress | ( | ) | [inline] |
References RefCountedPtr< T >::isValid(), and PAssert.
DataBlockPtr<T> CompressibleBlock< T >::view | ( | ) | const [inline] |
References RefCountedPtr< T >::isValid(), and PAssert.
DataBlockPtr<T> CompressibleBlock< T >::dataBlock | ( | ) | const [inline] |
References RefCountedPtr< T >::isValid(), and PAssert.
void CompressibleBlock< T >::makeOwnCopy | ( | ) | [inline] |
References RefCountedPtr< T >::makeOwnCopy().
void CompressibleBlock< T >::invalidate | ( | ) | [inline] |
References RefCountedPtr< T >::invalidate().
bool CompressibleBlock< T >::isControllerPtrValid | ( | ) | const [inline] |
References RefCountedPtr< T >::isValid().
bool CompressibleBlock< T >::isControllerValid | ( | ) | const [inline] |
References RefCountedPtr< T >::isValid().
bool CompressibleBlock< T >::isControllerValidUnlocked | ( | ) | const [inline] |
References RefCountedPtr< T >::isValid().
bool CompressibleBlock< T >::isShared | ( | ) | const [inline] |
References RefCountedPtr< T >::isShared().
bool CompressibleBlock< T >::operator!= | ( | const This_t & | a | ) | const [inline] |
bool CompressibleBlock< T >::operator== | ( | const This_t & | a | ) | const [inline] |
void CompressibleBlock< T >::attach | ( | Observer< T * > * | o | ) | [inline] |
References RefCountedPtr< T >::isValid(), and PAssert.
void CompressibleBlock< T >::detach | ( | Observer< T * > * | o | ) | [inline] |
References RefCountedPtr< T >::isValid(), and PAssert.
void CompressibleBlock< T >::lock | ( | ) | const [inline] |
void CompressibleBlock< T >::unlock | ( | ) | const [inline] |
static int CompressibleBlock< T >::randomTries | ( | ) | [inline, static] |