Webmaster  |  Imprint 
C++ Server Pages
Main  |  License  |  Documentation  |  Download 

Singleton Class Template Reference

Singleton class template. More...

#include <cxxtools/singleton.h>

List of all members.

Public Types

typedef A Allocator

Static Public Member Functions

static T & instance ()
 Returns the instance of the singleton type.

Protected Member Functions

 Singleton ()
 Contructor.
 ~Singleton ()
 Destructor.


Detailed Description

template<typename T, typename A = std::allocator<T>>
class cxxtools::Singleton< T, A >

Parameters:
T Type of the singleton
A Allocator for type T
The Singleton class template can be used to easily implement the Singleton design pattern. It can either be used directly or as a base class. An allocator can be used to control how the singleton instance will be allocated.

The follwing example shows how to use the singleton as a base class:

              class MySingleton : public Singleton<MySingleton>
              {
                   friend class Singleton<MySingleton>;

                   // ...
               };


Member Function Documentation

static T& instance (  )  [static]

When called for the first time, the singleton instance will be created with the specified alloctaor. All subsequent calls wikk return a reference to the previously created instance.

Returns:
The singleton instance

Copyright © 2008 The Tntnet Development Team
Tntnet 1.6