Loading...
Searching...
No Matches
Singleton.h File Reference

Singleton template class allows to turn any new or existing class T into Singleton Pattern. More...

`#include "Destroyer.h"`

Go to the source code of this file.

## Classes

class | ASSA::Singleton< T >

## Namespaces

namespace | ASSA

## Macros

#define | ASSA_DECL_SINGLETON(K)
| ASSA_DECL_SINGLETON macro inserts static member declarations mandated by the Singleton class.

## Detailed Description

Singleton template class allows to turn any new or existing class T into Singleton Pattern.

It is accomplished by deriving class T from class Singleton.

It is assumed that Singleton objects are long-lived. Often they exist for the life of the program. You delete them not so much to reclaim space but to shut down in the orderly manner (such as return whatever resources derived class holds in its ownership back to the system). C++ deletes static objects automatically. Although, it doesn't guarantee the calling order. In other words, destructors of Singleton class are not order-dependent.

To force destruction order, Singleton class transfers ownership of object T to Destroyer class. When the program exits, the Destroyer will be destroyed, and the object T along with it. Singleton destructor is now implicit.

Definition in file Singleton.h.

## Macro Definition Documentation

## ASSA_DECL_SINGLETON

#define ASSA_DECL_SINGLETON | ( |  | K | ) |

Value:
template <> K* ASSA::Singleton<K>::m_instance = NULL; \
template <class T> ASSA::Destroyer<T> ASSA::Singleton<T>::m_destroyer; \
template ASSA::Destroyer<K> ASSA::Singleton<K>::m_destroyer;
ASSA::Destroyer
Definition Destroyer.h:25
ASSA::Singleton::m_destroyer
static Destroyer< T > m_destroyer
Destroyer that owns object T.
Definition Singleton.h:69
ASSA::Singleton::m_instance
static T * m_instance
Pointer to the object T instance.
Definition Singleton.h:66

ASSA_DECL_SINGLETON macro inserts static member declarations mandated by the Singleton class.

'assa-genesis' utility generates appropriate file templated by default.

Definition at line 82 of file Singleton.h.

#define ASSA_DECL_SINGLETON(K) \
template <> K* ASSA::Singleton<K>::m_instance = NULL; \
template <class T> ASSA::Destroyer<T> ASSA::Singleton<T>::m_destroyer; \
template ASSA::Destroyer<K> ASSA::Singleton<K>::m_destroyer;