Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
Gray::cSingleton< TYPE > Class Template Reference

#include <cSingleton.h>

Inheritance diagram for Gray::cSingleton< TYPE >:
Gray::cSingletonStatic< TYPE > Gray::cSingletonRegister Gray::CObject Gray::cHeapObject Gray::IHeapObject Gray::cSingletonSmart< cSQLMgr > Gray::cSingletonSmart< cNetSystem > Gray::cSingletonSmart< cXObjMgr > Gray::cSingletonSmart< cLogAppendConsole > Gray::cSingletonSmart< cJSXEngine > Gray::cSingletonSmart< TYPE > GrayLib::cSQLMgr GrayLib::cNetSystem GrayLib::cXObjMgr Gray::cLogAppendConsole GrayJS::cJSXEngine GrayLib::cXObjMgrPack

Static Public Member Functions

static TYPE *__stdcall get_Single ()
 
template<class TYPE2 >
static TYPE2 *__stdcall get_SingleT ()
 
static TYPE &__stdcall I ()
 
- Static Public Member Functions inherited from Gray::cSingletonStatic< TYPE >
static bool isSingleCreated () noexcept
 
static TYPEget_SingleU () noexcept
 
static TYPEget_Single ()
 
template<class TYPE2 >
static TYPE2 *__stdcall get_SingleCast ()
 
static TYPEI () noexcept
 
- Static Public Member Functions inherited from Gray::cSingletonRegister
static void __stdcall ReleaseModule (HMODULE hMod)
 

Protected Member Functions

 cSingleton (TYPE *pObject, const TYPEINFO_t &rAddrCode=typeid(TYPE)) noexcept
 
virtual ~cSingleton ()
 
- Protected Member Functions inherited from Gray::cSingletonStatic< TYPE >
 cSingletonStatic (TYPE *pObject) noexcept
 
virtual ~cSingletonStatic () noexcept
 
- Protected Member Functions inherited from Gray::cSingletonRegister
 cSingletonRegister (const TYPEINFO_t &rAddrCode) noexcept
 
virtual ~cSingletonRegister ()
 
void RegisterSingleton ()
 
- Protected Member Functions inherited from Gray::cHeapObject
const void * get_HeapPtr () const noexcept override
 Get the top level (outermost, freeable) class pointer. I can delete get_HeapPtr(). More...
 

Additional Inherited Members

- Public Member Functions inherited from Gray::CObject
virtual ~CObject ()
 
virtual bool isValidCheck () const noexcept
 < memory allocation and structure definitions are valid. More...
 
virtual void AssertValid () const
 < memory allocation and structure definitions are valid. More...
 
virtual void Serialize (cArchive &a)
 
- Public Member Functions inherited from Gray::cHeapObject
 cHeapObject ()
 
virtual ~cHeapObject ()
 
bool IsValidInsideN (INT_PTR index) const
 
bool IsValidInsidePtr (void const *pTest) const
 
virtual size_t GetHeapStatsThis (OUT ITERATE_t &iAllocCount) const
 
virtual bool isValidCheck () const noexcept
 
- Static Public Attributes inherited from Gray::cSingletonRegister
static cThreadLockFast sm_LockSingle
 common lock for all cSingleton. More...
 
- Protected Attributes inherited from Gray::cSingletonRegister
HMODULE m_hModuleLoaded
 What modules loaded this ? So singletons can be destroyed if DLL/SO unloads. More...
 
- Static Protected Attributes inherited from Gray::cSingletonStatic< TYPE >
static TYPEsm_pThe = nullptr
 pointer to the one and only object of this TYPE. ASSUME automatically init to = nullptr. More...
 

Detailed Description

template<class TYPE>
class Gray::cSingleton< TYPE >

abstract base class for singleton created lazy/on demand if it does not yet exist or maybe static. see cSingletonSmart<> to destroy on non use. Thread safe. ASSUME cSingletonRegister will handle destruct order on app close or module unload. ASSUME TYPE is based on cSingleton and IHeapObject.

Note
If this is really static beware of the "first use" race condition. static init will ASSERT if dynamic is called first.
This can get created at C static init time if used inside some other static. But later is OK too of course. It's Safe being constructed INSIDE another C runtime init constructor. (order irrelevant) ASSUME m_pThe = nullptr at init. http://www.cs.wustl.edu/~schmidt/editorial-3.html

Constructor & Destructor Documentation

◆ cSingleton()

template<class TYPE >
Gray::cSingleton< TYPE >::cSingleton ( TYPE pObject,
const TYPEINFO_t rAddrCode = typeid(TYPE) 
)
inlineprotectednoexcept

typically this == pObject is type of cSingleton

  • rAddrCode = typeid(XXX) but GCC doesn't like it as part of template?

◆ ~cSingleton()

template<class TYPE >
virtual Gray::cSingleton< TYPE >::~cSingleton ( )
inlineprotectedvirtual

I am being destroyed. sm_pThe is set to nullptr in ~cSingletonStatic

Member Function Documentation

◆ get_Single()

template<class TYPE >
static TYPE* __stdcall Gray::cSingleton< TYPE >::get_Single ( )
inlinestatic

get (or create) a pointer to the singleton object.

Note
This ensures proper creation order for singletons (Statics) that ref each other!
Todo:
use CreateObject from cObjectFactory Like the MFC CreateObject() and "CRuntime?"

◆ get_SingleT()

template<class TYPE >
template<class TYPE2 >
static TYPE2* __stdcall Gray::cSingleton< TYPE >::get_SingleT ( )
inlinestatic

get (or create) a pointer to the derived singleton TYPE2 object. ASSUME TYPE2 derived from TYPE.

Note
This can create a race condition. This decides the true TYPE of the object.

◆ I()

template<class TYPE >
static TYPE& __stdcall Gray::cSingleton< TYPE >::I ( )
inlinestatic

The singleton by reference.


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