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

GcPseudoNew Class Template Reference

#include <GcPseudoNew.h>

Inheritance diagram for GcPseudoNew:

Inheritance graph
[legend]
Collaboration diagram for GcPseudoNew:

Collaboration graph
[legend]
List of all members.

Public Methods

 GcPseudoNew (void *libFunPtr)
 Constructor. It takes a void funtion pointer as returned e.g. by dlsym(). More...

virtual ~GcPseudoNew ()
 Destructor. Removes all objects created by calling create() method. More...

virtual T * create ()

Private Methods

 GcPseudoNew (GcPseudoNew &oldG)
 GcPseudoNew (GcPseudoNew &oldG, void *libFunPtr)
 GcPseudoNew (const GcPseudoNew &oldG, void *libFunPtr)
void operator= (GcPseudoNew &oldG)

Private Attributes

AIDA_STD::vector< T * > instances

Detailed Description

template<class T>
class GcPseudoNew< T >

Class to hold a pseudo-new function implemented in a shared library. This class implements garbage collection of dynamic objects created by its ancestor the PseudoNew class. Dynamic objects created by the create() method are tracked in a vector. When the GcPseudoNew operator goes out of scope it is destroyed: its destructor will trigger the destruction of all dynamic objects created so far. Be aware that this garbage collection strategy is very simple: once the gcPseudoNew instance goes out of scope, all dynamic objects are lost:

      class aParticle;
      if (1) {
        int i,nParticles=1000;
        // Declare a GcPseudoNew class returning an instance of type aParticle
        // The GcPseudoNew object will garbage collect dynamic objects.
        GcPseudoNew <aParticle> myPseudoNew (testLibMaker.lookUp("makeNew"));
        // Check we really looked up the function
        if (myPseudoNew.isValid()) {
          for (i=0;i<nParticles;i++)
            // Create a new instance of the class (dynamic memory)
            aParticle *myParticle = myPseudoNew.create();
        }
      } // myPseudoNew goes of of scope. All particles are destroyed
  

Definition at line 46 of file GcPseudoNew.h.


Constructor & Destructor Documentation

GcPseudoNew void *    libFunPtr [inline]
 

Definition at line 49 of file GcPseudoNew.h.

virtual ~GcPseudoNew   [inline, virtual]
 

Definition at line 52 of file GcPseudoNew.h.

References instances.

GcPseudoNew GcPseudoNew< T > &    oldG [inline, private]
 

Copy constructor & assignment operators are private: the object can't be passed by value.

Definition at line 71 of file GcPseudoNew.h.

GcPseudoNew GcPseudoNew< T > &    oldG,
void *    libFunPtr
[inline, private]
 

Definition at line 72 of file GcPseudoNew.h.

GcPseudoNew const GcPseudoNew< T > &    oldG,
void *    libFunPtr
[inline, private]
 

Definition at line 74 of file GcPseudoNew.h.


Member Function Documentation

virtual T* create   [inline, virtual]
 

Create a new instance of the class by calling the pseudo constructor. The object is saved in a vector for later garbage collection.

Reimplemented from PseudoNew.

Definition at line 61 of file GcPseudoNew.h.

References instances, and PseudoNew::newMethodPtr.

void operator= GcPseudoNew< T > &    oldG [inline, private]
 

Definition at line 76 of file GcPseudoNew.h.


Member Data Documentation

AIDA_STD::vector<T*> instances [private]
 

Definition at line 67 of file GcPseudoNew.h.

Referenced by create, and ~GcPseudoNew.


The documentation for this class was generated from the following file:
Generated on Tue May 20 14:50:28 2003 for HepUtilities by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002