LibreOffice LibreOffice 5.3 SDK C/C++ API Reference

Classes | Public Member Functions | List of all members
salhelper::SingletonRef< SingletonClass > Class Template Reference

template for implementing singleton classes. More...

`#include <singletonref.hxx>`

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

## Detailed Description

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

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 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, it's not allowed to start operations inside the ctor of the internal wrapped object - especially operations which needs a reference to the same singleton too.

The only chance to suppress 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 can't be exported - e.g. from windows libraries.

## Constructor & Destructor Documentation

## ◆ SingletonRef()

template<class SingletonClass >

salhelper::SingletonRef< SingletonClass >::SingletonRef | ( |  | ) |
| 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!

## ◆ ~SingletonRef()

template<class SingletonClass >

salhelper::SingletonRef< SingletonClass >::~SingletonRef | ( |  | ) |
| inline

standard dtor.

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

## Member Function Documentation

## ◆ operator*()

template<class SingletonClass >

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

Allows (*rSingle).someBodyOp().

## ◆ operator->()

template<class SingletonClass >

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

Allows rSingle->someBodyOp().

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

- salhelper/singletonref.hxx