15 #ifndef epicsSingleton_h 16 #define epicsSingleton_h 21 #include "libComAPI.h" 28 typedef void * ( * PBuild ) ();
29 void incrRefCount ( PBuild );
30 typedef void ( * PDestroy ) (
void * );
31 void decrRefCount ( PDestroy );
32 void * pInstance ()
const;
35 std :: size_t _refCount;
44 template <
class TYPE >
57 TYPE * operator -> ();
58 const TYPE * operator -> ()
const;
60 const TYPE & operator * ()
const;
64 friend class reference;
68 reference getReference ();
69 const reference getReference ()
const;
72 static void * _build ();
73 static void _destroy (
void * );
78 template <
class TYPE >
87 template <
class TYPE >
90 _pSingleton ( ref._pSingleton )
93 _pSingleton->_singletonUntyped.
97 template <
class TYPE >
102 _pSingleton->_singletonUntyped.
106 template <
class TYPE >
111 if ( _pSingleton != ref._pSingleton ) {
113 _pSingleton->_singletonUntyped.
115 _pSingleton = ref._pSingleton;
117 _pSingleton->_singletonUntyped.
123 template <
class TYPE >
129 return reinterpret_cast <
TYPE * >
130 ( _pSingleton->_singletonUntyped.
pInstance () );
133 template <
class TYPE >
139 return reinterpret_cast <
const TYPE * >
140 ( _pSingleton->_singletonUntyped.
pInstance () );
143 template <
class TYPE >
151 template <
class TYPE >
160 _pInstance ( 0 ), _refCount ( 0 )
179 assert ( _refCount == 0 );
180 assert ( _pInstance == 0 );
184 template <
class TYPE >
190 template <
class TYPE >
192 _destroy (
void * pDestroyTypeless )
195 reinterpret_cast <
TYPE * > ( pDestroyTypeless );
199 template <
class TYPE >
206 template <
class TYPE >
215 #endif // epicsSingleton_h
#define assert(exp)
Declare that a condition should be true.
An EPICS-specific replacement for ANSI C's assert.