ThePEG::Current< T > Class Template Reference

The Current class keeps a static stack of objects of the templated class, which can be used anywhere by any class. More...

#include <Current.h>

List of all members.

Public Member Functions

 Current ()
 Default constructor does nothing.
 Current (const Current< T > &)
 Copy-constructor does nothing.
 Current (T *t)
 Construct a new object specifying a new object, o, to be used during this objects lifetime.
 ~Current ()
 The destructor removing the object specified in the constructor from the stack.
T * operator-> () const
 Return a pointer to the currently chosen object.

Static Public Member Functions

static bool isVoid ()
 Returns true if there is no currently chosen object.
static T & current ()
 Return a reference to the currently chosen object.

Private Member Functions

Current< T > & operator= (const Current< T > &)
 Private and non-existent assignment operator.

Private Attributes

bool pushed
 True if this object is responsible for pushing an object onto the stack.

Static Private Attributes

static vector< T * > theStack
 The stack of objects requested.


Detailed Description

template<typename T>
class ThePEG::Current< T >

The Current class keeps a static stack of objects of the templated class, which can be used anywhere by any class.

When an object is active it adds itself to the stack which can be used by any other object through the static functions of the Current class. If someone needs to use an alternative object a new Current object can be constructed with a pointer to the desired object as argument and that object will the be used by the static Current functions until the Current object is destructed.

Default-contructed objects of the Current class can be used as a pointer to the currently chosen object on the stack.

The typical use case for this class is a handler class which uses a number of objects which do not have a reference back to the handler, but still need to acces some member functions. In a member function the handler class will construct a Current object: Current<Handler> current(this); in any following function called in this member function, any object can then access the handlers methods as Current<Handler>()->memfun();.

Definition at line 39 of file Current.h.


Constructor & Destructor Documentation

template<typename T>
ThePEG::Current< T >::Current ( T *  t  )  [inline]

Construct a new object specifying a new object, o, to be used during this objects lifetime.

The object must not be deleted until the Current object us destroyed.

Definition at line 59 of file Current.h.

References ThePEG::Current< T >::pushed, and ThePEG::Current< T >::theStack.


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

Generated on Thu Apr 29 12:43:25 2010 for ThePEG by  doxygen 1.5.5