|PUBLIC MEMBERS:||CLASSES | STRUCTS | UNIONS | ENUMS | TYPEDEFS | METHODS | STATIC METHODS | DATA | STATIC DATA|
|PRIVATE MEMBERS:||CLASSES | STRUCTS | UNIONS | ENUMS | TYPEDEFS | METHODS | STATIC METHODS | DATA | STATIC DATA|
:: salhelper ::
template< typename SingletonClass >
- Base Classes
- Known Derived Classes
- template for implementing singleton classes.
- Such classes can be instanciated everytimes they are needed. But the internal wrapped object will be created one times only. Of course its 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.
- To prevent the code against race conditions, its not
allowed to start operations inside the ctor
of the internal wrapped object - especialy operations
which needs a reference to the same singleton too.
The only chance to supress such strange constellations
is a lazy-init mechanism.
- a) The singleton class can provide a special init() method, which must be called as first after creation.
- b) The singleton class can call a special impl_init() method implicit for every called interface method.
standard dtor. SingletonClass *
operator->( ) const;
Allows rSingle->someBodyOp(). SingletonClass &
operator*( ) const;
SingletonLockInit creates an own mutex for guarding static contents.
ownStaticLock( ) const;
SingletonClass * m_pInstance; pointer to the internal wrapped singleton. sal_Int32 m_nRef; ref count, which regulate creation and removing of m_pInstance.
Copyright © 2012, The Apache Software Foundation, Licensed under the Apache License, Version 2.0. Apache, the Apache feather logo, Apache OpenOffice and OpenOffice.org are trademarks of The Apache Software Foundation. Other names may be trademarks of their respective owners.