EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Singleton< X > Class Template Reference

Template used for singleton classes. More...

#include "Singleton.h"

Inheritance diagram for Singleton< X >:

Public Member Functions

 Singleton ()
 Primary constructor. More...
 

Static Public Member Functions

static X & get ()
 

Static Protected Attributes

static std::shared_ptr< X > mInstance
 

Detailed Description

template<typename X>
class Singleton< X >

Template used for singleton classes.

This template shall be used as base for classes which are intended to be singleton (i.e. there should be only 1 instance of this class at all).

Uses lazy construction (i.e. object is constructed on first access request).

Author
Bloody.Rabbit

Definition at line 43 of file Singleton.h.

Constructor & Destructor Documentation

template<typename X>
Singleton< X >::Singleton ( )
inline

Primary constructor.

Checks if the instance being constructed is first, i.e. mInstance hasn't been filled yet. This only makes sense if the actual class is derived from Singleton.

Definition at line 53 of file Singleton.h.

54  {
55  assert(mInstance.get() == nullptr);
56  }
static std::shared_ptr< X > mInstance
Definition: Singleton.h:69

Member Function Documentation

template<typename X>
static X& Singleton< X >::get ( )
inlinestatic
Returns
Reference to the singleton instance.

Definition at line 59 of file Singleton.h.

60  {
61  if (mInstance.get() == nullptr)
62  mInstance.reset( new X );
63 
64  return *mInstance;
65  }
static std::shared_ptr< X > mInstance
Definition: Singleton.h:69

Member Data Documentation

template<typename X>
std::shared_ptr< X > Singleton< X >::mInstance
staticprotected

Pointer to the singleton instance.

Definition at line 69 of file Singleton.h.

Referenced by Singleton< ConsoleCommand >::get(), and Singleton< ConsoleCommand >::Singleton().


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