An adapter to turn a class into a singleton. More...
#include <dune/common/singleton.hh>
Classes | |
class | InstancePointer |
A simple smart pointer responsible for creation and deletion of the instance. More... | |
Static Public Member Functions | |
static T & | instance () |
Get the instance of the singleton. | |
Protected Member Functions | |
Singleton () | |
Singleton (const Singleton &) | |
Private copy constructor. | |
Singleton & | operator= (const Singleton &) |
Private assignment operator. |
An adapter to turn a class into a singleton.
The class represented by the template parameter T must have a parameterless constructor.
Class T can be publically derived from Singleton<T>:
#include<dune/common/singleton.hh> class Foo : public Dune::Singleton<Foo> { public: Foo() { bytes = new char[1000]; } ~Foo() { delete[] bytes; } private: char* bytes; };
Or one can construct a Singleton of an existing class. Say Foo1 is a class with parameterless constructor then
typedef Dune::Singleton<Foo1> FooSingleton; Foo1 instance& = FooSingleton::instance();
Creates a singleton of that class and accesses its instance.
Dune::Singleton< T >::Singleton | ( | ) | [inline, protected] |
Dune::Singleton< T >::Singleton | ( | const Singleton< T > & | ) | [inline, protected] |
Private copy constructor.
static T& Dune::Singleton< T >::instance | ( | ) | [inline, static] |
Get the instance of the singleton.
References Dune::Singleton< T >::InstancePointer::get(), and Dune::Singleton< T >::InstancePointer::set().
Singleton& Dune::Singleton< T >::operator= | ( | const Singleton< T > & | ) | [inline, protected] |
Private assignment operator.