thepeg is hosted by Hepforge, IPPP Durham
ThePEG  2.2.1
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>

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. More...
 
 ~Current ()
 The destructor removing the object specified in the constructor from the stack.
 
T & operator* () const
 Return a reference to the currently chosen object.
 
T * operator-> () const
 Return a pointer to the currently chosen object.
 
 operator bool () const
 Test for existance.
 
bool operator! () const
 Test for existance.
 

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.
 
static T * ptr ()
 Pointer to the stack.
 

Private Member Functions

Current< T > & operator= (const Current< T > &)=delete
 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

◆ Current()

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: