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

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

List of all members.

Classes

struct  Aln

Static Public Member Functions

static T * Create (void *argument=0)
static T * Default ()
static bool IsCreated ()

Detailed Description

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

A template that helps define singletons for embedded applications. Probably the best way to declare a singleton is shown in the following example:

    class ExampleSingleton {
    public:
      void AnyMethod();
    private:
      friend class Singleton<ExampleSingleton>;       // friend for constructor
      explicit ExampleSingleton(void* argument);
      ExampleSingleton(const ExampleSingleton& src);  // prohibit copying
      ~ExampleSingleton();
    };

An instance of such a singleton would then be created by the Singleton<ExampleSingleton>::Create(); call.

A client of the example singleton could either call the default method Singleton<ExampleSingleton>::Default()->AnyMethod();, or use the SingletonHandle for more elegant access.

Two properties of the singleton template are aimed specifically at embedded applications:

Definition at line 87 of file Singleton.h.


Member Function Documentation

template<typename T >
T * ApparatusFramework::Singleton< T >::Create ( void *  argument = 0  )  [inline, static]

Creates an instance of the singleton if none exists yet. The object is created in static memory.

Parameters:
argument A general purpose parameter that is passed to the constructor of the singleton class.
Returns:
A pointer to the created singleton instance.

Definition at line 154 of file Singleton.h.

template<typename T >
T * ApparatusFramework::Singleton< T >::Default (  )  [inline, static]

References an instance that has been previously created.

Returns:
A pointer to the singleton instance.

Definition at line 163 of file Singleton.h.

template<typename T >
bool ApparatusFramework::Singleton< T >::IsCreated (  )  [inline, static]

States whether an instance of this singleton has been created.

Returns:
True if an instance has been created, false otherwise.

Definition at line 170 of file Singleton.h.

© 2004-2010 bbv Software Services AG / Apparatus Services