15 #ifndef epicsSingleton_h
16 #define epicsSingleton_h
21 #include "libComAPI.h"
37 assert ( _pInstance == 0 );
40 typedef void * ( * PBuild ) ();
41 LIBCOM_API
void incrRefCount ( PBuild );
42 typedef void ( * PDestroy ) (
void * );
43 LIBCOM_API
void decrRefCount ( PDestroy );
44 inline void * pInstance ()
const {
return _pInstance; }
47 std :: size_t _refCount;
56 template <
class TYPE >
68 :_pSingleton ( ref._pSingleton )
71 _pSingleton->_singletonUntyped.
76 _pSingleton->_singletonUntyped.
84 if ( _pSingleton != ref._pSingleton ) {
86 _pSingleton->_singletonUntyped.
88 _pSingleton = ref._pSingleton;
90 _pSingleton->_singletonUntyped.
95 TYPE * operator -> () {
97 return reinterpret_cast < TYPE * >
98 ( _pSingleton->_singletonUntyped.pInstance () );
100 const TYPE * operator -> ()
const {
102 return reinterpret_cast <
const TYPE * >
103 ( _pSingleton->_singletonUntyped.pInstance () );
105 TYPE & operator * () {
106 return * this->operator -> ();
108 const TYPE & operator * ()
const {
109 return * this->operator -> ();
118 reference getReference () {
119 return reference ( *
this );
121 const reference getReference ()
const {
124 return pConstCastAway->getReference ();
128 static void * _build () {
return new TYPE (); }
129 static void _destroy (
void * pDestroyTypeless) {
131 reinterpret_cast < TYPE * > ( pDestroyTypeless );
138 #endif // epicsSingleton_h
#define assert(exp)
Declare that a condition should be true.
An EPICS-specific replacement for ANSI C's assert.