Scarab  v3.2.4
Project 8 C++ Utility Library
Static Public Member Functions | Protected Member Functions | Static Protected Attributes | Static Private Member Functions | Static Private Attributes | Friends | List of all members
singleton< x_type > Class Template Reference

Base class that turns a class into a singleton. More...

#include <singleton.hh>

Inheritance diagram for singleton< x_type >:
Inheritance graph

Static Public Member Functions

static x_type * get_instance ()
 
static void kill_instance ()
 
template<class... x_args>
static x_type * create_instance (x_args... args)
 

Protected Member Functions

 singleton ()
 
 ~singleton ()
 

Static Protected Attributes

static std::mutex f_mutex
 

Static Private Member Functions

static void construct_instance ()
 
static void delete_instance ()
 

Static Private Attributes

static x_type * f_instance = nullptr
 
static destroyer< x_type > f_destroyer
 

Friends

class destroyer< x_type >
 

Detailed Description

template<class x_type>
class scarab::singleton< x_type >

Base class that turns a class into a singleton.

Author
N.S. Oblath

To use:

  1. Inherit your class from singleton< your_class >
  2. Make your constructor and destructor protected (or private)
  3. Add the allow_singleton_access( your_class ) macro to your class definition to allow the base classes to access your class

The mutex f_mutex provides thread safety for creation and destruction of an instance of the singleton. It's available to the derived class for thread-safe access to the object in general.

Definition at line 43 of file singleton.hh.

Constructor & Destructor Documentation

◆ singleton()

singleton ( )
protected

Definition at line 137 of file singleton.hh.

◆ ~singleton()

~singleton ( )
protected

Definition at line 141 of file singleton.hh.

Member Function Documentation

◆ construct_instance()

void construct_instance ( )
staticprivate

Definition at line 116 of file singleton.hh.

◆ create_instance()

x_type * create_instance ( x_args...  args)
static

Definition at line 103 of file singleton.hh.

◆ delete_instance()

void delete_instance ( )
staticprivate

Definition at line 126 of file singleton.hh.

◆ get_instance()

x_type * get_instance ( )
static

Definition at line 80 of file singleton.hh.

◆ kill_instance()

void kill_instance ( )
static

Definition at line 91 of file singleton.hh.

Friends And Related Function Documentation

◆ destroyer< x_type >

friend class destroyer< x_type >
friend

Definition at line 66 of file singleton.hh.

Member Data Documentation

◆ f_destroyer

destroyer< x_type > f_destroyer
staticprivate

Definition at line 58 of file singleton.hh.

◆ f_instance

x_type * f_instance = nullptr
staticprivate

Definition at line 57 of file singleton.hh.

◆ f_mutex

std::mutex f_mutex
staticprotected

Definition at line 61 of file singleton.hh.


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