QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
Singleton< T, Global > Class Template Reference

Basic support for the singleton pattern. More...

#include <ql/patterns/singleton.hpp>

+ Inheritance diagram for Singleton< T, Global >:
+ Collaboration diagram for Singleton< T, Global >:

Public Member Functions

 Singleton (const Singleton &)=delete
 
 Singleton (Singleton &&)=delete
 
Singletonoperator= (const Singleton &)=delete
 
Singletonoperator= (Singleton &&)=delete
 
 ~Singleton ()=default
 

Static Public Member Functions

static T & instance ()
 access to the unique instance More...
 

Protected Member Functions

 Singleton ()=default
 

Detailed Description

template<class T, class Global = std::integral_constant<bool, false>>
class QuantLib::Singleton< T, Global >

Basic support for the singleton pattern.

The typical use of this class is:

class Foo : public Singleton<Foo> {
friend class Singleton<Foo>;
private:
Foo() {}
public:
...
};
Basic support for the singleton pattern.
Definition: singleton.hpp:58

which, albeit sub-optimal, frees one from the concerns of creating and managing the unique instance and can serve later as a single implemementation point should synchronization features be added.

Global can be used to distinguish Singletons that are local to a session (Global = false) or that are global across all sessions (B = true). This is only relevant if QL_ENABLE_SESSIONS is enabled.

Notice that the creation and retrieval of (local or global) singleton instances through instance() is thread safe, but obviously subsequent operations on the singleton have to be synchronized within the singleton implementation itself.

Definition at line 58 of file singleton.hpp.

Constructor & Destructor Documentation

◆ Singleton() [1/3]

Singleton ( const Singleton< T, Global > &  )
delete

◆ Singleton() [2/3]

Singleton ( Singleton< T, Global > &&  )
delete

◆ ~Singleton()

~Singleton ( )
default

◆ Singleton() [3/3]

Singleton ( )
protecteddefault

Member Function Documentation

◆ operator=() [1/2]

Singleton & operator= ( const Singleton< T, Global > &  )
delete

◆ operator=() [2/2]

Singleton & operator= ( Singleton< T, Global > &&  )
delete

◆ instance()

T & instance
static

access to the unique instance

Definition at line 104 of file singleton.hpp.