Loading...
Searching...
No Matches
Dune::Singleton< T > Class Template Reference

An adapter to turn a class into a singleton. More...

`#include <dune/common/singleton.hh>`

## Public Member Functions

| Singleton (const Singleton &)=delete
void | operator= (const Singleton &)=delete

## Static Public Member Functions

static DUNE_EXPORT T & | instance ()
| Get the instance of the singleton.

## Protected Member Functions

| Singleton ()=default

## Detailed Description

template<class T>
class Dune::Singleton< T >

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 publicly 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;
};
singleton.hh
Useful wrapper for creating singletons.
Dune::Singleton
An adapter to turn a class into a singleton.
Definition singleton.hh:56

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();
Dune::Singleton::instance
static DUNE_EXPORT T & instance()
Get the instance of the singleton.
Definition singleton.hh:70

Creates a singleton of that class and accesses its instance.

## Constructor & Destructor Documentation

## Singleton() [1/2]

template<class T>

Dune::Singleton< T >::Singleton | ( |  | ) |

protected default

## Singleton() [2/2]

template<class T>

Dune::Singleton< T >::Singleton | ( | const Singleton< T > & |  | ) |

delete

## Member Function Documentation

## instance()

template<class T>

DUNE_EXPORT T & Dune::Singleton< T >::instance | ( |  | ) |

inline static

Get the instance of the singleton.

Returns
  The instance of the singleton.

## operator=()

template<class T>

void Dune::Singleton< T >::operator= | ( | const Singleton< T > & |  | ) |

delete

The documentation for this class was generated from the following file:

- singleton.hh