(incubating) | The Free and Open Productivity Suite

Developer's Guide

API

SDK

Tips 'n' Tricks

Miscellaneous

Content for OpenOffice.org version 3.3.

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

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.

Top of Page

Apache OpenOffice is an effort undergoing incubation at The Apache Software Foundation (ASF), sponsored by the Apache Incubator. Incubation is required of all newly accepted projects until a further review indicates that the infrastructure, communications, and decision making process have stabilized in a manner consistent with other successful ASF projects. While incubation status is not necessarily a reflection of the completeness or stability of the code, it does indicate that the project has yet to be fully endorsed by the ASF.

Copyright & License
Apache and the Apache feather logos are trademarks of The Apache Software Foundation. OpenOffice.org and the seagull logo are registered trademarks of The Apache Software Foundation. Other names appearing on the site may be trademarks of their respective owners.