tDecoratableManagerBase Class Reference

base class for managers of decorated classes More...

#include <tDecorator.h>

Inheritance diagram for tDecoratableManagerBase:

Inheritance graph
[legend]
Collaboration diagram for tDecoratableManagerBase:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 tDecoratableManagerBase ()
size_t GetSize () const
 returns the total allocated size of decorations
size_t Reserve (size_t allocate, size_t alignment=4)
 allocates some byes of decorator space, returns the offset to it
void AddDecorator (tDecoratorBase &decorator)
void CalculateOffsets ()
void ConstructAll (void *decorated)
void DestructAll (void *decorated)
void * Allocate (size_t size, const char *classn, const char *file, int line)
 reserve space for an object of class Decorated, prepended with space for its decorators
void Free (void *ptr, const char *classn, const char *file, int line)
 frees space reserved by Reseve() again

Protected Attributes

tDecoratableManagerBasebase_
size_t refCount_
 manager of the base class

Private Member Functions

 tDecoratableManagerBase (tDecoratableManagerBase const &)
 number of objects of this
tDecoratableManagerBaseoperator= (tDecoratableManagerBase const &)

Private Attributes

tDecoratorBasedecorators_
bool updateRequired_
 anchor of the decorators managed by this managers
size_t offset_
 flag indicating whether the following information needs an update


Detailed Description

base class for managers of decorated classes

Definition at line 80 of file tDecorator.h.


Constructor & Destructor Documentation

tDecoratableManagerBase::tDecoratableManagerBase (  )  [inline]

Definition at line 83 of file tDecorator.h.

00084             : base_( 0 ), refCount_( 0 ), decorators_( 0 )
00085             , updateRequired_( true ), offset_( 0 )
00086     {
00087     }

tDecoratableManagerBase::tDecoratableManagerBase ( tDecoratableManagerBase const &   )  [private]

number of objects of this


Member Function Documentation

size_t tDecoratableManagerBase::GetSize (  )  const [inline]

returns the total allocated size of decorations

Definition at line 90 of file tDecorator.h.

References tASSERT.

Referenced by Allocate(), and Free().

00091     {
00092         tASSERT( !updateRequired_ );
00093 
00094         return offset_;
00095     }

Here is the caller graph for this function:

size_t tDecoratableManagerBase::Reserve ( size_t  allocate,
size_t  alignment = 4 
) [inline]

allocates some byes of decorator space, returns the offset to it

Definition at line 98 of file tDecorator.h.

00099     {
00100         offset_ += allocate;
00101         offset_ = (( offset_ + alignment - 1 ) / alignment ) * alignment;
00102         return offset_;
00103     }

void tDecoratableManagerBase::AddDecorator ( tDecoratorBase decorator  )  [inline]

Definition at line 105 of file tDecorator.h.

References tListItem< T >::Insert(), and tASSERT.

Referenced by tDecorator< DecoratedDerived, Decoration >::tDecorator().

00106     {
00107         tASSERT( refCount_ == 0 );
00108 
00109         // add decorator to list and request
00110         decorator.Insert( decorators_ );
00111         updateRequired_ = true;
00112     }

Here is the call graph for this function:

Here is the caller graph for this function:

void tDecoratableManagerBase::CalculateOffsets (  )  [inline]

Definition at line 114 of file tDecorator.h.

References tDecoratorBase::GetSize(), tListItem< T >::Next(), and tDecoratorBase::offset_.

Referenced by Allocate().

00115     {
00116         // early exit if there is nothing to od
00117         if ( !updateRequired_ )
00118             return;
00119 
00120         // get start offset from base class
00121         offset_ = 0;
00122         if ( base_ )
00123         {
00124             base_->CalculateOffsets();
00125             offset_ = base_->offset_;
00126         }
00127 
00128         // iterate over listed decorators
00129         tDecoratorBase * run = decorators_;
00130         while ( run )
00131         {
00132             run->offset_ = Reserve( run->GetSize() );
00133             run = run->Next();
00134         }
00135 
00136         updateRequired_ = false;
00137     }

Here is the call graph for this function:

Here is the caller graph for this function:

void tDecoratableManagerBase::ConstructAll ( void *  decorated  )  [inline]

Definition at line 139 of file tDecorator.h.

References tDecoratorBase::Construct(), tListItem< T >::Next(), and tDecoratorBase::offset_.

Referenced by Allocate().

00140     {
00141         if ( base_ )
00142         {
00143             base_->ConstructAll( decorated );
00144         }
00145 
00146         // iterate over listed decorators
00147         tDecoratorBase * run = decorators_;
00148         while ( run )
00149         {
00150             void * decoration = static_cast< char * >( decorated ) - run->offset_;
00151             run->Construct( decoration );
00152             run = run->Next();
00153         }
00154     }

Here is the call graph for this function:

Here is the caller graph for this function:

void tDecoratableManagerBase::DestructAll ( void *  decorated  )  [inline]

Definition at line 156 of file tDecorator.h.

References tDecoratorBase::Destruct(), tListItem< T >::Next(), and tDecoratorBase::offset_.

Referenced by Free().

00157     {
00158         if ( base_ )
00159         {
00160             base_->DestructAll( decorated );
00161         }
00162 
00163         // iterate over listed decorators
00164         tDecoratorBase * run = decorators_;
00165         while ( run )
00166         {
00167             void * decoration = static_cast< char * >( decorated ) - run->offset_;
00168             run->Destruct( decoration );
00169             run = run->Next();
00170         }
00171     }

Here is the call graph for this function:

Here is the caller graph for this function:

void * tDecoratableManagerBase::Allocate ( size_t  size,
const char *  classn,
const char *  file,
int  line 
)

reserve space for an object of class Decorated, prepended with space for its decorators

Parameters:
size size of the memory block to allocate
classn name of the class that is allocated
file name of the file this call comes from
line line in the file the call ocmes from
Returns:
the newly allocated block of memory, with space for decorators

calculate offsets of decorators if required

Reimplemented in tDecoratableManager< Decorated >.

Definition at line 45 of file tDecorator.cpp.

References CalculateOffsets(), ConstructAll(), GetSize(), and refCount_.

Referenced by tDecoratableManager< Decorated >::Allocate().

00046 {
00047     // register object with manager
00048     if ( refCount_++ == 0 )
00049     {
00051         CalculateOffsets();
00052     }
00053 
00054     // allocate requested space plus overhead for decorators
00055     size_t overhead = GetSize();
00056 #ifndef DONTUSEMEMMANAGER
00057 
00058     char * base = static_cast< char * > ( ::operator new( size + overhead, classn, file, line ) ) + overhead;
00059 #else
00060     char * base = static_cast< char * > ( ::operator new( size + overhead ) ) + overhead;
00061 #endif
00062 
00063     // call decoration constructors
00064     ConstructAll( base);
00065 
00066     return base;

Here is the call graph for this function:

Here is the caller graph for this function:

void tDecoratableManagerBase::Free ( void *  ptr,
const char *  classn,
const char *  file,
int  line 
)

frees space reserved by Reseve() again

Parameters:
ptr pointer to the memory area to be freed
classn name of the class that is allocated
file name of the file this call comes from
line line in the file the call ocmes from

Reimplemented in tDecoratableManager< Decorated >.

Definition at line 81 of file tDecorator.cpp.

References DestructAll(), GetSize(), and refCount_.

Referenced by tDecoratableManager< Decorated >::Free().

00083 {
00084     // call decoration destructors
00085     DestructAll( ptr );
00086 
00087     // deregister with manager
00088     --refCount_;
00089 
00090     // deallocate space and overhead
00091     size_t overhead = GetSize();
00092     char * base = ( ( char * ) ptr ) - overhead;
00093 
00094 #ifndef DONTUSEMEMMANAGER
00095     ::operator delete( base, classn, file, line );
00096 #else
00097     ::operator delete( base );

Here is the call graph for this function:

Here is the caller graph for this function:

tDecoratableManagerBase& tDecoratableManagerBase::operator= ( tDecoratableManagerBase const &   )  [private]


Member Data Documentation

tDecoratableManagerBase* tDecoratableManagerBase::base_ [protected]

Definition at line 179 of file tDecorator.h.

size_t tDecoratableManagerBase::refCount_ [protected]

manager of the base class

Definition at line 180 of file tDecorator.h.

Referenced by Allocate(), and Free().

tDecoratorBase* tDecoratableManagerBase::decorators_ [private]

Definition at line 185 of file tDecorator.h.

bool tDecoratableManagerBase::updateRequired_ [private]

anchor of the decorators managed by this managers

Definition at line 188 of file tDecorator.h.

size_t tDecoratableManagerBase::offset_ [private]

flag indicating whether the following information needs an update

Definition at line 189 of file tDecorator.h.


The documentation for this class was generated from the following files:
Generated on Sat Mar 15 23:56:07 2008 for Armagetron Advanced by  doxygen 1.5.4