A Discrete-Event Network Simulator
ns3::Singleton< T > Class Template Reference

A template singleton. More...

#include "singleton.h"

+ Inheritance diagram for ns3::Singleton< T >:
+ Collaboration diagram for ns3::Singleton< T >:

Static Public Member Functions

static T * Get (void)
 Get a pointer to the singleton instance. More...

Additional Inherited Members

- Private Member Functions inherited from ns3::NonCopyable
 NonCopyable ()
 Constructor. More...
 ~NonCopyable ()
 Destructor. More...

Detailed Description

template<typename T>
class ns3::Singleton< T >

A template singleton.

This template class can be used to implement the singleton pattern. The underlying object will be destroyed automatically when the process exits.

For a singleton whose lifetime is bounded by the simulation run, not the process, see SimulationSingleton.

To force your class ExampleS to be a singleton, inherit from Singleton:

class ExampleS : public Singleton<ExampleS> { ... };

Then, to reach the singleton instance, just do

ExampleS::Get ()->...;
If you call Get() again after the object has been destroyed, the object will be re-created which will result in a memory leak as reported by most memory leak checkers. It is up to the user to ensure that Get() is never called from a static variable finalizer.

Definition at line 63 of file singleton.h.

Member Function Documentation

template<typename T >
T * ns3::Singleton< T >::Get ( void  )

Get a pointer to the singleton instance.

The instance will be automatically deleted when the process exits.

A pointer to the singleton instance.

Definition at line 89 of file singleton.h.

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