PTLib  Version 2.18.8
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PSingleton< Type, GuardType, Creator > Class Template Reference

Template class for a simple singleton object. More...

#include <object.h>

Inheritance diagram for PSingleton< Type, GuardType, Creator >:

Public Member Functions

 PSingleton ()
 
Type * operator-> () const
 
Type & operator* () const
 

Protected Attributes

Type * m_instance
 

Detailed Description

template<class Type, typename GuardType = unsigned, Type *(*)() Creator = PSingletonCreatorDefault<Type>>
class PSingleton< Type, GuardType, Creator >

Template class for a simple singleton object.

 Usage is typically like:

        typedef PSingleton<MyClass> MySingleton;
        MySingleton()->DoSomething();

Default is not thread safe, however the following is:


        typedef PSingleton<MyClass, atomic<uint32_t> > MySafeSingleton;
        MySafeSingleton()->DoSomething();

If the singleton class requires parameters on construction, then a creator function may be included in the template parameters:


        MyClass * CreateMyClass() { return new MyClass("fred"); }
        typedef PSingleton<MyClass, atomic<uint32_t>, CreateMyClass> MySafeSingleton;
        MySafeSingleton()->DoSomething();

Constructor & Destructor Documentation

template<class Type, typename GuardType = unsigned, Type *(*)() Creator = PSingletonCreatorDefault<Type>>
PSingleton< Type, GuardType, Creator >::PSingleton ( )
inline

Member Function Documentation

template<class Type, typename GuardType = unsigned, Type *(*)() Creator = PSingletonCreatorDefault<Type>>
Type& PSingleton< Type, GuardType, Creator >::operator* ( ) const
inline
template<class Type, typename GuardType = unsigned, Type *(*)() Creator = PSingletonCreatorDefault<Type>>
Type* PSingleton< Type, GuardType, Creator >::operator-> ( ) const
inline

Member Data Documentation

template<class Type, typename GuardType = unsigned, Type *(*)() Creator = PSingletonCreatorDefault<Type>>
Type* PSingleton< Type, GuardType, Creator >::m_instance
protected

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