rwlogo
SourcePro 11.1

SourcePro® C++ API Reference Guide



   SourcePro C++
Documentation Home

RWTSingleton< T > Class Template Reference
[Smart Pointers]

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

#include <rw/pointer/RWTSingleton.h>

List of all members.

Static Public Member Functions

static RWTCountingPointer< T,
RWAtomicCounter > & 
instance ()

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.

Examples

 #include <rw/pointer/RWTSingleton.h>
 #include <iostream>
 
 class Foo
 {
 public:
     void function()
     {
         std::cout << "I'm a foo example" << std::endl;
     }
 };

 RWTCountingPointer<Foo> singleFooPtr = RWTSingleton<Foo>::instance();

 int main(void)
 {
     singleFooPtr->function();
     return 0;
 }

Member Function Documentation

template<class T>
static RWTCountingPointer<T, RWAtomicCounter>& RWTSingleton< T >::get ( void   )  [inline, static, protected]

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

template<class T>
static RWTCountingPointer<T, RWAtomicCounter>& RWTSingleton< T >::instance ( void   )  [inline, static]

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


© Copyright Rogue Wave Software, Inc. All Rights Reserved.
Rogue Wave and SourcePro are registered trademarks of Rogue Wave Software, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.