ApparatusFramework::SingletonHandle< T > Class Template Reference
[Pattern Services]

#include <PatternServices/current/include/SingletonHandle.h>

List of all members.

Public Types

typedef T *(* DefaultMethod )(void)

Public Member Functions

 SingletonHandle (const DefaultMethod defaultMethod)
 ~SingletonHandle ()
T * operator-> ()

Detailed Description

template<typename T>
class ApparatusFramework::SingletonHandle< T >

A small template that serves as handle for a singleton instance. This template can be instanciated with an incomplete type, i.e. the forward declaration of a class:

    class ExampleSingleton;

    class Client {
    public:
      // Any public methods...
    private:
      SingletonHandle<ExampleSingleton> m_pExample;
    };

The handle needs to be initialized with the Default method of the singleton and can be used like a normal pointer:

    Client::Client() : m_pExample(Singleton<ExampleSingleton>::Default) {
      m_pExample->AnyMethod();
    }

Although we used the Singleton template in above example, the SingletonHandle could also be used with any other singleton. You just need to specify the correct static method that returns an instance of your singleton.

Definition at line 79 of file SingletonHandle.h.


Member Typedef Documentation

template<typename T >
typedef T*(* ApparatusFramework::SingletonHandle< T >::DefaultMethod)(void)

Type of function pointer used to access an instance of the singleton.

Definition at line 83 of file SingletonHandle.h.


Constructor & Destructor Documentation

template<typename T >
ApparatusFramework::SingletonHandle< T >::SingletonHandle ( const DefaultMethod  defaultMethod  )  [inline, explicit]

Constructs a new SingletonHandle object. This does not yet access the referenced singleton.

Parameters:
defaultMethod Function used to access an instance of the singleton.

Definition at line 116 of file SingletonHandle.h.

template<typename T >
ApparatusFramework::SingletonHandle< T >::~SingletonHandle (  )  [inline]

Destroys the object.

Definition at line 122 of file SingletonHandle.h.


Member Function Documentation

template<typename T >
T * ApparatusFramework::SingletonHandle< T >::operator-> (  )  [inline]

Returns a pointer to the singleton instance. The internal pointer is set upon first access to this method.

Returns:
A pointer to the singleton instance.

Definition at line 126 of file SingletonHandle.h.

© 2004-2010 bbv Software Services AG / Apparatus Services