My Project
UDK 3.2.7 C/C++ API Reference
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Classes | Public Member Functions | List of all members
salhelper::SingletonRef< SingletonClass > Class Template Reference

template for implementing singleton classes. More...

#include <singletonref.hxx>

Classes

struct  SingletonLockInit
 creates an own mutex for guarding static contents.

Public Member Functions

 SingletonRef ()
 standard ctor.
 ~SingletonRef ()
 standard dtor.
SingletonClass * operator-> () const
 Allows rSingle->someBodyOp().
SingletonClass & operator* () const
 Allows (*rSingle).someBodyOp().

Detailed Description

template<class SingletonClass>
class salhelper::SingletonRef< SingletonClass >

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.
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.

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.

Constructor & Destructor Documentation

template<class SingletonClass >
salhelper::SingletonRef< SingletonClass >::SingletonRef ( )
inline

standard ctor.

The internal wrapped object is created only, if its ref count was 0. Otherwhise this method does nothing ... except increasing of the internal ref count!

template<class SingletonClass >
salhelper::SingletonRef< SingletonClass >::~SingletonRef ( )
inline

standard dtor.

The internal wrapped object is removed only, if its ref count wil be 0. Otherwhise this method does nothing ... except decreasing of the internal ref count!

Member Function Documentation

template<class SingletonClass >
SingletonClass& salhelper::SingletonRef< SingletonClass >::operator* ( ) const
inline

Allows (*rSingle).someBodyOp().

template<class SingletonClass >
SingletonClass* salhelper::SingletonRef< SingletonClass >::operator-> ( ) const
inline

Allows rSingle->someBodyOp().


The documentation for this class was generated from the following file: