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

PseudoNew Class Template Reference

#include <PseudoNew.h>

Inheritance diagram for PseudoNew:

Inheritance graph
[legend]
Collaboration diagram for PseudoNew:

Collaboration graph
[legend]
List of all members.

Public Methods

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

 PseudoNew (void)
 Default constructor. More...

virtual ~PseudoNew ()
void bind (void *libFunPtr)
virtual T * create ()
bool isValid ()
 Did we really find the pseudo constructor function in the library? More...


Protected Attributes

T *(* newMethodPtr )()

Detailed Description

template<class T>
class PseudoNew< T >

Class to hold a pseudo-new function implemented in a shared library. Each shared library should implement a function with C linkage that works as some kind of factory method. To get a new instance of the class implemented in the shared library the user code makes a call to such function. E.g.:
  // declaration
  extern "C" {
    aTest *makeNew();
  }

  // implementation
  aTest *makeNew() { return new shTest;  }

  
Unfortunately the code to look up the function pointer and use it is a bit cumbersome. This class hides the such complexity, e.g. it could be used like that:

     class aTest;
     // Declare a pseudo new class which will return an instance of type aTest
     // The pseudo constructor function in the shared library is named makeNew
      PseudoNew <aTest> myPseudoNew (testLibMaker.lookUp("makeNew"));
      // Check we really looked up the function
      if (myPseudoNew.isValid()) {
        // Create a new instance of the class (dynamic memory)
        aTest *myTest = myPseudoNew.create();
        // Call the method. Should return 1.
        cout << "Unit is: " << myTest->retUnit() << endl;
        // Don't forget to delete the object !!!
        delete myTest;
        }
  

Definition at line 44 of file PseudoNew.h.


Constructor & Destructor Documentation

PseudoNew void *    libFunPtr [inline]
 

Definition at line 47 of file PseudoNew.h.

References newMethodPtr.

PseudoNew void    [inline]
 

Definition at line 51 of file PseudoNew.h.

References newMethodPtr.

virtual ~PseudoNew   [inline, virtual]
 

Definition at line 54 of file PseudoNew.h.


Member Function Documentation

void bind void *    libFunPtr [inline]
 

Binding method (used to initialize an instance created with the default constructor. It takes a void function pointer as returned e.g. by dlsym().

Definition at line 58 of file PseudoNew.h.

References newMethodPtr.

virtual T* create   [inline, virtual]
 

Create a new instance of the class by calling the pseudo contructor. The object will (very likely) be created in dynamic memory, thus the user is responsible for deletion.

Reimplemented in GcPseudoNew.

Definition at line 65 of file PseudoNew.h.

bool isValid   [inline]
 

Definition at line 69 of file PseudoNew.h.

References newMethodPtr.


Member Data Documentation

T*(* newMethodPtr)() [protected]
 

Referenced by bind, GcPseudoNew::create, isValid, and PseudoNew.


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