LibreOffice Module salhelper (master) 1
|
template for implementing singleton classes. More...
#include <singletonref.hxx>
Classes | |
struct | SingletonLockInit |
creates an own mutex for guarding static contents. More... | |
Public Member Functions | |
SingletonRef () | |
standard ctor. More... | |
~SingletonRef () | |
standard dtor. More... | |
SingletonClass * | operator-> () const |
Allows rSingle->someBodyOp(). More... | |
SingletonClass & | operator* () const |
Allows (*rSingle).someBodyOp(). More... | |
Private Member Functions | |
SingletonRef (SingletonRef &) SAL_DELETED_FUNCTION | |
::osl::Mutex & | ownStaticLock () const |
Static Private Attributes | |
static SingletonClass * | m_pInstance = NULL |
pointer to the internal wrapped singleton. More... | |
static sal_Int32 | m_nRef = 0 |
ref count, which regulate creation and removing of m_pInstance. More... | |
template for implementing singleton classes.
Such classes can be instantiated every time they are needed. But the internal wrapped object will be created one times only. Of course it's used resources are referenced one times only too. This template hold it alive till the last reference is gone. Further all operations on this reference are threadsafe. Only calls directly to the internal object (which modify its state) must be made threadsafe by the object itself or from outside.
The only chance to suppress such strange constellations is a lazy-init mechanism.
Note further that this singleton pattern can work only, if all user of such singleton are located inside the same library! Because static values can't be exported - e.g. from windows libraries.
Definition at line 73 of file singletonref.hxx.
|
inline |
standard ctor.
The internal wrapped object is created only, if its ref count was 0. Otherwise this method does nothing ... except increasing of the internal ref count!
Definition at line 99 of file singletonref.hxx.
References salhelper::SingletonRef< SingletonClass >::m_nRef, salhelper::SingletonRef< SingletonClass >::m_pInstance, and salhelper::SingletonRef< SingletonClass >::ownStaticLock().
|
inline |
standard dtor.
The internal wrapped object is removed only, if its ref count will be 0. Otherwise this method does nothing ... except decreasing of the internal ref count!
Definition at line 122 of file singletonref.hxx.
References salhelper::SingletonRef< SingletonClass >::m_nRef, salhelper::SingletonRef< SingletonClass >::m_pInstance, NULL, and salhelper::SingletonRef< SingletonClass >::ownStaticLock().
|
private |
|
inline |
Allows (*rSingle).someBodyOp().
Definition at line 155 of file singletonref.hxx.
References salhelper::SingletonRef< SingletonClass >::m_pInstance, and salhelper::SingletonRef< SingletonClass >::ownStaticLock().
|
inline |
Allows rSingle->someBodyOp().
Definition at line 144 of file singletonref.hxx.
References salhelper::SingletonRef< SingletonClass >::m_pInstance, and salhelper::SingletonRef< SingletonClass >::ownStaticLock().
|
inlineprivate |
|
staticprivate |
ref count, which regulate creation and removing of m_pInstance.
Definition at line 84 of file singletonref.hxx.
Referenced by salhelper::SingletonRef< SingletonClass >::SingletonRef(), and salhelper::SingletonRef< SingletonClass >::~SingletonRef().
|
staticprivate |
pointer to the internal wrapped singleton.
Definition at line 81 of file singletonref.hxx.
Referenced by salhelper::SingletonRef< SingletonClass >::operator*(), salhelper::SingletonRef< SingletonClass >::operator->(), salhelper::SingletonRef< SingletonClass >::SingletonRef(), and salhelper::SingletonRef< SingletonClass >::~SingletonRef().