#include <tDecorator.h>
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 | |
tDecoratableManagerBase * | base_ |
size_t | refCount_ |
manager of the base class | |
Private Member Functions | |
tDecoratableManagerBase (tDecoratableManagerBase const &) | |
number of objects of this | |
tDecoratableManagerBase & | operator= (tDecoratableManagerBase const &) |
Private Attributes | |
tDecoratorBase * | decorators_ |
bool | updateRequired_ |
anchor of the decorators managed by this managers | |
size_t | offset_ |
flag indicating whether the following information needs an update |
Definition at line 80 of file tDecorator.h.
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
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 }
size_t tDecoratableManagerBase::Reserve | ( | size_t | allocate, | |
size_t | alignment = 4 | |||
) | [inline] |
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 }
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 }
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 }
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 }
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
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 |
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;
void tDecoratableManagerBase::Free | ( | void * | ptr, | |
const char * | classn, | |||
const char * | file, | |||
int | line | |||
) |
frees space reserved by Reseve() again
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 );
tDecoratableManagerBase& tDecoratableManagerBase::operator= | ( | tDecoratableManagerBase const & | ) | [private] |
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().
Definition at line 185 of file tDecorator.h.
bool tDecoratableManagerBase::updateRequired_ [private] |
size_t tDecoratableManagerBase::offset_ [private] |
flag indicating whether the following information needs an update
Definition at line 189 of file tDecorator.h.