00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef SIMULATION_SINGLETON_H
00021 #define SIMULATION_SINGLETON_H
00022
00023 namespace ns3 {
00024
00025
00026
00027
00028
00029
00030
00031
00032 template <typename T>
00033 class SimulationSingleton
00034 {
00035 public:
00036
00037
00038
00039
00040
00041
00042 static T *Get (void);
00043 private:
00044 static T **GetObject (void);
00045 static void DeleteObject (void);
00046 };
00047
00048 }
00049
00050
00051 #include "simulator.h"
00052
00053 namespace ns3 {
00054
00055 template <typename T>
00056 T *
00057 SimulationSingleton<T>::Get (void)
00058 {
00059 T ** ppobject = GetObject ();
00060 return *ppobject;
00061 }
00062
00063 template <typename T>
00064 T **
00065 SimulationSingleton<T>::GetObject (void)
00066 {
00067 static T *pobject = 0;
00068 if (pobject == 0)
00069 {
00070 pobject = new T ();
00071 Simulator::ScheduleDestroy (&SimulationSingleton<T>::DeleteObject);
00072 }
00073 return &pobject;
00074 }
00075
00076 template <typename T>
00077 void
00078 SimulationSingleton<T>::DeleteObject (void)
00079 {
00080 T **ppobject = GetObject ();
00081 delete (*ppobject);
00082 *ppobject = 0;
00083 }
00084
00085 }
00086
00087
00088 #endif