SourcePro® API Reference Guide

 
Loading...
Searching...
No Matches
RWTSingleton< T > Class Template Reference

Ensures that a class has only one instance and provides a global point of access to it. More...

#include <rw/pointer/RWTSingleton.h>

Static Public Member Functions

static RWTCountingPointer< T, RWAtomicCounter > & instance ()
 

Protected Member Functions

 RWTSingleton ()
 

Static Protected Member Functions

static RWTCountingPointer< T, RWAtomicCounter > & get ()
 

Detailed Description

template<class T>
class RWTSingleton< T >

RWTSingleton ensures that a class has only one instance, and provides a global point of access to it. This is an Object Creational pattern. For more information, see Design Patterns by Gamma, Helm, Johnson, and Vlissides.

Example
#include <rw/pointer/RWTSingleton.h>
#include <iostream>
class Foo {
public:
void function() { std::cout << "I'm a foo example" << std::endl; }
};
int main(void) {
singleFooPtr->function();
return 0;
}
Defines a reference-counted pointer that provides reference counting semantics for types that do not ...
Definition RWTCountingPointer.h:64
static RWTCountingPointer< T, RWAtomicCounter > & instance()
Definition RWTSingleton.h:65

Constructor & Destructor Documentation

◆ RWTSingleton()

template<class T >
RWTSingleton< T >::RWTSingleton ( )
inlineprotected

The constructor is protected to ensure that only one instance can ever get created.

Member Function Documentation

◆ get()

template<class T >
static RWTCountingPointer< T, RWAtomicCounter > & RWTSingleton< T >::get ( )
inlinestaticprotected

Protected accessor function that gives access to the class state. Inherited classes use this function.

◆ instance()

template<class T >
static RWTCountingPointer< T, RWAtomicCounter > & RWTSingleton< T >::instance ( )
inlinestatic

Creates and returns the instance of T, if it has not already been created.

Copyright © 2024 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved.