Overview | Namespace | Class | Index | Help |
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 >
class SingletonRef
- Base Classes
- None.
- Known Derived Classes
- None.
virtual | abstract | interface | template |
NO | NO | NO | YES |
- Summary
- template for implementing singleton classes.
- Description
- 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.
- ATTENTION!
- 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.
- File
- singletonref.hxx
Public Members
-
Methods
SingletonRef( );standard ctor.
~SingletonRef( );standard dtor. SingletonClass *
operator->( ) const;Allows rSingle->someBodyOp(). SingletonClass &
operator*( ) const;Allows (*rSingle).someBodyOp().
Private Members
-
Structs
SingletonLockInit creates an own mutex for guarding static contents.
Methods
::osl::Mutex &
ownStaticLock( ) const;
Static Data
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.