Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

RefClass< T, Arg, TStar > Class Template Reference

this is a container class that will be used to hold your dear class, and will assure that two classes that were constructed with the same argument get the same memory.this class requires that you have a decent copy constructorYou cannot do inheritance unless you use this class Unless you use TSub instead of TRef. More...

#include <refclass.h>

Collaboration diagram for RefClass< T, Arg, TStar >:

Collaboration graph
[legend]
List of all members.

Public Methods

Arg GetKey () const
 Gets the key from this one's iterator. More...

int getRefCount () const
 Debugging check-- gets the Reference Count. More...

 RefClass (const Arg &a)
 The default constructor that calls the private function. More...

 RefClass ()
 This is the default constructor for this class since we do not allow for NULL. More...

 RefClass (const RefClass< T, Arg, TStar > &r)
 This is the refclass copy construcotr...First increments the reference, then assigns the pointers. More...

RefClass< T, Arg, TStar > & operator= (const RefClass< T, Arg, TStar > &r)
 This is the famous gets operator that must increase the reference count before it destroys this object. More...

 ~RefClass ()
 The destructor is simple, just calls the DestroyObject helper used in the gets operator. More...

T * Get ()
 This is the Get functon that returns the second. It asserts that things aren't null, but that is not necessary code. More...

const T * Get () const
 This is the Get functon that returns the second. It asserts that things aren't null, but that is not necessary code. More...

T * operator * ()
 This is the derefernece-- redirects call to assertion/get. More...

const T * operator * () const
 This is the derefernece--redirects call to assertion/get. More...

T * operator-> ()
 This is the derefernece-- redirects call to assertion/get. More...

const T * operator-> () const
 This is the derefernece-- redirects call to assertion/get. More...

bool operator< (const RefClass< T, Arg, TStar > &r) const
 This is the less than operator that just redirects the query to the TStar. More...

bool operator== (const RefClass< T, Arg, TStar > &r) const
 This is the equality operator that just redirects the query to the TStar. More...

void Debug () const
 This prints out address. More...


Protected Types

enum  SPECIALARG { NOTATHANG }
 So Subclasses can be set to this NULL. More...


Protected Methods

void DestroyObject ()
 Destroys the object by decrementing reference count and deleting it if necessary.If refcount goes to zero this is our only change to kill the actual class.Not to be used by the outside world because it assumes things are in place, etc. More...

void IncRef () const
 Simply increments the refcount. Does not check if it is an iterator to NiL. More...

void DecRef () const
 Simply decrements the recount. Uses a primitive assert to assure it's not zero. More...

 RefClass (SPECIALARG dummy, SPECIALARG d)
bool isNull () const
 Checks if this is null; only for use by the subclass. More...

void setNull ()
 Sets this to null; only for use by the subclass. More...


Protected Attributes

TMap::iterator t
 The iterator that will point to a given thing in a class. More...


Static Protected Attributes

TMap NiL
 The NiL function to be compared against when this class is used by the killable subtype. More...

TMap hmap
 This is the static TMap that holds all the arg/T pairs--is pointed to by up to dozens of iterators (based on the refcount)this class relies on the fact that modifying hmap DOES NOT invalidate iterator. W00t! More...


Private Types

typedef TStar Tstar
typedef std::map< Arg, TStar > TMap

Private Methods

void TConstruct (const Arg &a)
 Constructs T with an argument of A. Privately owned, not to be used ooutside of RefClass. More...


Private Attributes

T * t
int refcount

Detailed Description

template<class T, class Arg, class TStar = TRef<T,Arg>>
class RefClass< T, Arg, TStar >

this is a container class that will be used to hold your dear class, and will assure that two classes that were constructed with the same argument get the same memory.this class requires that you have a decent copy constructorYou cannot do inheritance unless you use this class Unless you use TSub instead of TRef.

This class is a simple way to keep track of many objects which share their arguments This is the default type that would reside within a RefClass. It actually inherits from the class involved, thus it may not have any subclassage The advantage is that it needs less dereferencing.


Member Typedef Documentation

template<class T, class Arg, class TStar = TRef<T,Arg>>
typedef std::map<Arg,TStar> RefClass< T, Arg, TStar >::TMap [private]
 

template<class T, class Arg, class TStar = TRef<T,Arg>>
typedef TStar RefClass< T, Arg, TStar >::Tstar [private]
 


Member Enumeration Documentation

template<class T, class Arg, class TStar = TRef<T,Arg>>
enum RefClass::SPECIALARG [protected]
 

So Subclasses can be set to this NULL.

Enumeration values:
NOTATHANG 

00123 {NOTATHANG};


Constructor & Destructor Documentation

template<class T, class Arg, class TStar = TRef<T,Arg>>
RefClass< T, Arg, TStar >::RefClass SPECIALARG    dummy,
SPECIALARG    d
[inline, protected]
 

sets things to null. Not for use except by subclasses Not for general consumption.

00127 {t=NiL.begin();}

template<class T, class Arg, class TStar = TRef<T,Arg>>
RefClass< T, Arg, TStar >::RefClass const Arg &    a [inline]
 

The default constructor that calls the private function.

00138                             {
00139         TConstruct(a);
00140     }

template<class T, class Arg, class TStar = TRef<T,Arg>>
RefClass< T, Arg, TStar >::RefClass   [inline]
 

This is the default constructor for this class since we do not allow for NULL.

00142                 {
00143         TConstruct (Arg());
00144     }

template<class T, class Arg, class TStar = TRef<T,Arg>>
RefClass< T, Arg, TStar >::RefClass const RefClass< T, Arg, TStar > &    r [inline]
 

This is the refclass copy construcotr...First increments the reference, then assigns the pointers.

00146 {r.IncRef(); t = r.t;}

template<class T, class Arg, class TStar = TRef<T,Arg>>
RefClass< T, Arg, TStar >::~RefClass   [inline]
 

The destructor is simple, just calls the DestroyObject helper used in the gets operator.

00150 {DestroyObject();}


Member Function Documentation

template<class T, class Arg, class TStar = TRef<T,Arg>>
void RefClass< T, Arg, TStar >::Debug   const [inline]
 

This prints out address.

00168 {printf ("0x%x refcount %d content: %s\n",&((*t).second),(*t).second.refcount,(*t).second->print().c_str());}

template<class T, class Arg, class TStar = TRef<T,Arg>>
void RefClass< T, Arg, TStar >::DecRef   const [inline, protected]
 

Simply decrements the recount. Uses a primitive assert to assure it's not zero.

00118                       {
00119         (*t).second.refcount--; 
00120         REFASSERT((*t).second.refcount>=0);
00121     }

template<class T, class Arg, class TStar = TRef<T,Arg>>
void RefClass< T, Arg, TStar >::DestroyObject   [inline, protected]
 

Destroys the object by decrementing reference count and deleting it if necessary.If refcount goes to zero this is our only change to kill the actual class.Not to be used by the outside world because it assumes things are in place, etc.

Reimplemented in RefContainer< T, Arg, TStar >.

00107                          {
00108         DecRef();
00109         if ((*t).second.refcount==0) {
00110             (*t).second.Deallocate();
00111             hmap.erase(t);
00112             setNull(); //we don't need to change the object this is pointing to unless no one refs it :-)
00113         }
00114     }

template<class T, class Arg, class TStar = TRef<T,Arg>>
const T* RefClass< T, Arg, TStar >::Get   const [inline]
 

This is the Get functon that returns the second. It asserts that things aren't null, but that is not necessary code.

Reimplemented in RefContainer< T, Arg, TStar >.

00154 {REFASSERT (!isNull());return *((*t).second);}

template<class T, class Arg, class TStar = TRef<T,Arg>>
T* RefClass< T, Arg, TStar >::Get   [inline]
 

This is the Get functon that returns the second. It asserts that things aren't null, but that is not necessary code.

Reimplemented in RefContainer< T, Arg, TStar >.

00152 {REFASSERT (!isNull());return *((*t).second);}

template<class T, class Arg, class TStar = TRef<T,Arg>>
Arg RefClass< T, Arg, TStar >::GetKey   const [inline]
 

Gets the key from this one's iterator.

00134 {return (*t).first;}

template<class T, class Arg, class TStar = TRef<T,Arg>>
int RefClass< T, Arg, TStar >::getRefCount   const [inline]
 

Debugging check-- gets the Reference Count.

00136 {return (*t).second.refcount;}

template<class T, class Arg, class TStar = TRef<T,Arg>>
void RefClass< T, Arg, TStar >::IncRef   const [inline, protected]
 

Simply increments the refcount. Does not check if it is an iterator to NiL.

00116 {(*t).second.refcount++;}

template<class T, class Arg, class TStar = TRef<T,Arg>>
bool RefClass< T, Arg, TStar >::isNull   const [inline, protected]
 

Checks if this is null; only for use by the subclass.

00129 {return t==NiL.begin();}

template<class T, class Arg, class TStar = TRef<T,Arg>>
const T* RefClass< T, Arg, TStar >::operator *   const [inline]
 

This is the derefernece--redirects call to assertion/get.

Reimplemented in RefContainer< T, Arg, TStar >.

00158 {return Get();}

template<class T, class Arg, class TStar = TRef<T,Arg>>
T* RefClass< T, Arg, TStar >::operator *   [inline]
 

This is the derefernece-- redirects call to assertion/get.

Reimplemented in RefContainer< T, Arg, TStar >.

00156 {return Get();}

template<class T, class Arg, class TStar = TRef<T,Arg>>
const T* RefClass< T, Arg, TStar >::operator->   const [inline]
 

This is the derefernece-- redirects call to assertion/get.

00162 {return Get();}

template<class T, class Arg, class TStar = TRef<T,Arg>>
T* RefClass< T, Arg, TStar >::operator->   [inline]
 

This is the derefernece-- redirects call to assertion/get.

00160 {return Get();}

template<class T, class Arg, class TStar = TRef<T,Arg>>
bool RefClass< T, Arg, TStar >::operator< const RefClass< T, Arg, TStar > &    r const [inline]
 

This is the less than operator that just redirects the query to the TStar.

00164 {return (*t).second<(*r.t).second;}

template<class T, class Arg, class TStar = TRef<T,Arg>>
RefClass<T,Arg,TStar>& RefClass< T, Arg, TStar >::operator= const RefClass< T, Arg, TStar > &    r [inline]
 

This is the famous gets operator that must increase the reference count before it destroys this object.

00148 {r.IncRef();DestroyObject();t=r.t;return *this;}

template<class T, class Arg, class TStar = TRef<T,Arg>>
bool RefClass< T, Arg, TStar >::operator== const RefClass< T, Arg, TStar > &    r const [inline]
 

This is the equality operator that just redirects the query to the TStar.

00166 {return (*t).second==(*r.t).second;}

template<class T, class Arg, class TStar = TRef<T,Arg>>
void RefClass< T, Arg, TStar >::setNull   [inline, protected]
 

Sets this to null; only for use by the subclass.

00131 {t = NiL.begin();}

template<class T, class Arg, class TStar = TRef<T,Arg>>
void RefClass< T, Arg, TStar >::TConstruct const Arg &    a [inline, private]
 

Constructs T with an argument of A. Privately owned, not to be used ooutside of RefClass.

00088                                     {
00089         t = hmap.find (a);
00090         if (t==hmap.end()) {
00091             t=hmap.insert(TMap::value_type(a,TStar (a))).first;
00092         }
00093         IncRef();
00094     }


Member Data Documentation

template<class T, class Arg, class TStar = TRef<T,Arg>>
TMap RefClass< T, Arg, TStar >::hmap [static, protected]
 

This is the static TMap that holds all the arg/T pairs--is pointed to by up to dozens of iterators (based on the refcount)this class relies on the fact that modifying hmap DOES NOT invalidate iterator. W00t!

template<class T, class Arg, class TStar = TRef<T,Arg>>
TMap RefClass< T, Arg, TStar >::NiL [static, protected]
 

The NiL function to be compared against when this class is used by the killable subtype.

template<class T, class Arg, class TStar = TRef<T,Arg>>
int RefClass< T, Arg, TStar >::refcount [private]
 

template<class T, class Arg, class TStar = TRef<T,Arg>>
T* RefClass< T, Arg, TStar >::t [private]
 

template<class T, class Arg, class TStar = TRef<T,Arg>>
TMap::iterator RefClass< T, Arg, TStar >::t [protected]
 

The iterator that will point to a given thing in a class.


The documentation for this class was generated from the following files:
Generated on Mon Jul 7 21:13:55 2003 for Ethereal by doxygen1.2.15