15 #ifndef epicsSingleton_h
16 #define epicsSingleton_h
21 #include "libComAPI.h"
26 #if __cplusplus>=201103L
31 ~SingletonUntyped () {
40 assert ( _pInstance == 0 );
43 typedef void * ( * PBuild ) ();
44 LIBCOM_API
void incrRefCount ( PBuild );
45 typedef void ( * PDestroy ) (
void * );
46 LIBCOM_API
void decrRefCount ( PDestroy );
47 inline void * pInstance ()
const {
return _pInstance; }
50 std :: size_t _refCount;
51 SingletonUntyped (
const SingletonUntyped & );
52 SingletonUntyped & operator = (
const SingletonUntyped & );
59 template <
class TYPE >
71 :_pSingleton ( ref._pSingleton )
74 _pSingleton->_singletonUntyped.
79 _pSingleton->_singletonUntyped.
87 if ( _pSingleton != ref._pSingleton ) {
89 _pSingleton->_singletonUntyped.
91 _pSingleton = ref._pSingleton;
93 _pSingleton->_singletonUntyped.
98 TYPE * operator -> () {
100 return reinterpret_cast < TYPE * >
101 ( _pSingleton->_singletonUntyped.pInstance () );
103 const TYPE * operator -> ()
const {
105 return reinterpret_cast <
const TYPE * >
106 ( _pSingleton->_singletonUntyped.pInstance () );
108 TYPE & operator * () {
109 return * this->operator -> ();
111 const TYPE & operator * ()
const {
112 return * this->operator -> ();
118 #if __cplusplus>=201103L
124 reference getReference () {
125 return reference ( *
this );
127 const reference getReference ()
const {
130 return pConstCastAway->getReference ();
134 static void * _build () {
return new TYPE (); }
135 static void _destroy (
void * pDestroyTypeless) {
137 reinterpret_cast < TYPE * > ( pDestroyTypeless );
144 #endif // epicsSingleton_h
#define assert(exp)
Declare that a condition should be true.
An EPICS-specific replacement for ANSI C's assert.