ReferenceCountingCenter Class Reference

#include <ReferenceCounting.hpp>

Inheritance diagram for ReferenceCountingCenter:

Inheritance graph
[legend]
Collaboration diagram for ReferenceCountingCenter:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 ReferenceCountingCenter ()
 The only public part is the constructor and destructor!
 ~ReferenceCountingCenter ()
 Destructs a ReferenceCountingCenter.

Static Public Member Functions

static ReferenceCountingCenterinstance ()
static void create ()
static void destroy ()

Static Protected Attributes

static ReferenceCountingCenter__pInstance

Private Member Functions

template<typename ReferenceCounterType>
const size_t & numberOfReferences (const ReferenceCounterType &rc)
 The number of references for a given address.
template<typename ReferenceCounterType>
void addReference (ReferenceCounterType &rc)
 Adds a reference to a given address.
template<typename ReferenceCounterType>
size_t removeReference (ReferenceCounterType &rc)
 Removes a reference.

Private Attributes

std::map< const void *, size_t > __counter
 The counter of references.
std::map< const void
*, std::string > 
__typeName
 associates the name of the associate type.

Friends

class ReferenceCounting
class ConstReferenceCounting


Detailed Description

This class provides a repository to manage reference counting.

Author:
Stephane Del Pino

Definition at line 47 of file ReferenceCounting.hpp.


Constructor & Destructor Documentation

ReferenceCountingCenter::ReferenceCountingCenter (  )  [inline]

The only public part is the constructor and destructor!

Builts a ReferenceCountingCenter

Definition at line 103 of file ReferenceCounting.hpp.

00104   {
00105     ;
00106   }

ReferenceCountingCenter::~ReferenceCountingCenter (  )  [inline]

Destructs a ReferenceCountingCenter.

Definition at line 109 of file ReferenceCounting.hpp.

References __counter, __typeName, and fflog().

00110   {
00111 #ifndef NDEBUG
00112     fflog(0) << "\n###### REFERENCE COUNTING STATE ######\n";
00113     fflog(0) << "Number of referenced addresses:  "
00114              << std::setw(5) << __counter.size() << '\n';
00115     size_t n = 0;
00116     for (std::map<const void*,size_t>::iterator i= __counter.begin();
00117          i != __counter.end(); ++i) {
00118       n += (i->second != 0);
00119     }
00120     fflog(0) << "Number of unallocaded addresses: "
00121              << std::setw(5) << n << '\n';
00122     fflog(0) << "--------------------------------------\n";
00123     for (std::map<const void*,size_t>::iterator i= __counter.begin();
00124          i != __counter.end(); ++i) {
00125       if (i->second != 0) {
00126         fflog(0) << i->first << ": " << __typeName[i->first]
00127                  << ':' << std::setw(5) << i->second << '\n';
00128       }
00129     }
00130     fflog(0) << "######################################\n";
00131 #endif // NDEBUG
00132   }

Here is the call graph for this function:


Member Function Documentation

template<typename ReferenceCounterType>
const size_t& ReferenceCountingCenter::numberOfReferences ( const ReferenceCounterType &  rc  )  [inline, private]

The number of references for a given address.

Definition at line 67 of file ReferenceCounting.hpp.

References __counter.

Referenced by ReferenceCounting< Undefined >::numberOfReferences(), and ConstReferenceCounting< SpectralConformTransformation >::numberOfReferences().

00068   {
00069     return __counter[rc.__ref]; 
00070   }

template<typename ReferenceCounterType>
void ReferenceCountingCenter::addReference ( ReferenceCounterType &  rc  )  [inline, private]

Adds a reference to a given address.

Definition at line 74 of file ReferenceCounting.hpp.

References __counter, and __typeName.

Referenced by ConstReferenceCounting< SpectralConformTransformation >::ConstReferenceCounting(), ReferenceCounting< Undefined >::operator=(), ConstReferenceCounting< SpectralConformTransformation >::operator=(), and ReferenceCounting< Undefined >::ReferenceCounting().

00075   {
00076     __counter[rc.__ref]++;
00077 #ifndef  NDEBUG
00078     __typeName[rc.__ref] = rc.typeName();
00079 #endif //NDEBUG
00080   }

template<typename ReferenceCounterType>
size_t ReferenceCountingCenter::removeReference ( ReferenceCounterType &  rc  )  [inline, private]

Removes a reference.

Definition at line 84 of file ReferenceCounting.hpp.

References __counter, and __typeName.

Referenced by ReferenceCounting< Undefined >::operator=(), ConstReferenceCounting< SpectralConformTransformation >::operator=(), ConstReferenceCounting< SpectralConformTransformation >::~ConstReferenceCounting(), and ReferenceCounting< Undefined >::~ReferenceCounting().

00085   {
00086     const void* address = rc.__ref;
00087     std::map<const void*,size_t>::iterator i = __counter.find(address);
00088     if ((i->second == 1)&&(address != 0)) {
00089       rc.eraseData();
00090       __counter.erase(i);
00091 #ifndef NDEBUG
00092       __typeName.erase(address);
00093 #endif // NDEBUG
00094       return 0;
00095     }
00096     return (--(i->second));
00097   }

static ReferenceCountingCenter & StaticBase< ReferenceCountingCenter >::instance (  )  [inline, static, inherited]

Access to auto instanciated static;

Returns:
*__pInstance

Definition at line 46 of file StaticBase.hpp.

00047   {
00048     return *__pInstance;
00049   }

static void StaticBase< ReferenceCountingCenter >::create (  )  [inline, static, inherited]

Creates __pInstance in Embedding class.

Definition at line 55 of file StaticBase.hpp.

Referenced by ThreadStaticCenter::ThreadStaticCenter().

00056   {
00057     __pInstance = new EmbeddingClass();
00058   }

static void StaticBase< ReferenceCountingCenter >::destroy (  )  [inline, static, inherited]

Destroyes __autoInstanciated in Embedding class.

Definition at line 64 of file StaticBase.hpp.

Referenced by ThreadStaticCenter::~ThreadStaticCenter().

00065   {
00066     delete __pInstance;
00067   }


Friends And Related Function Documentation

friend class ReferenceCounting [friend]

Definition at line 52 of file ReferenceCounting.hpp.

friend class ConstReferenceCounting [friend]

Definition at line 55 of file ReferenceCounting.hpp.


Member Data Documentation

std::map<const void*,size_t> ReferenceCountingCenter::__counter [private]

The counter of references.

Definition at line 58 of file ReferenceCounting.hpp.

Referenced by addReference(), numberOfReferences(), removeReference(), and ~ReferenceCountingCenter().

std::map<const void*,std::string> ReferenceCountingCenter::__typeName [private]

associates the name of the associate type.

Definition at line 62 of file ReferenceCounting.hpp.

Referenced by addReference(), removeReference(), and ~ReferenceCountingCenter().

The static variable

Definition at line 37 of file StaticBase.hpp.


The documentation for this class was generated from the following file:

Generated on Wed Nov 19 00:12:43 2008 for FreeFEM3D (aka ff3d) by  doxygen 1.5.6