| 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.
Note further that this singleton pattern can work only, if
all user of such singleton are located inside the same library!
Because static values cant be exported - e.g. from windows libraries.
- File
- singletonref.hxx
Public Members
-
Private Members
-
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. |
Top of Page
Copyright © 2009 Sun Microsystems, Inc.