22 #ifndef __Singleton_hh__
23 #define __Singleton_hh__
25 #include <bias_config.h>
27 #include <Base/Debug/Error.hh>
28 #include <Base/Debug/Exception.hh>
33 #ifdef BIAS_HAVE_PTHREADS
39 #if defined BIAS_DEBUG && ! defined WIN32
73 MyClassSingleton::GetInstance()->foo();
77 The code wraps a previous defined class MyClass as a singleton. The Singleton
78 class exposes a single function GetInstance() returning a pointer to MyClass.
79 This function creates the single instance of MyClass if it is not already
80 present and registers the DeleteInstance_() function with the atexit()
81 function from the stdlib resulting in automatic destruction of the
82 singleton when the application terminates.
84 @author woelk 10/2007 */
100 #ifdef BIAS_HAVE_PTHREADS
101 static pthread_mutex_t *
Mutex_();
136 { BIASABORT;
return *
this; }
139 #ifdef BIAS_HAVE_PTHREADS
145 static pthread_mutex_t my_mutex = PTHREAD_MUTEX_INITIALIZER;
148 #endif //BIAS_HAVE_PTHREAD
154 #ifdef BIAS_HAVE_PTHREADS
159 #if defined BIAS_DEBUG && ! defined WIN32
161 std::cout<<
"created Singleton<"<<
typeid(T).name() <<
">\n";
180 #ifdef BIAS_HAVE_PTHREADS
190 #ifdef BIAS_HAVE_PTHREADS
194 #if defined BIAS_DEBUG && ! defined WIN32
196 std::cout<<
"deleting Singleton<"<<
typeid(T).name() <<
"> ... "
202 #if defined BIAS_DEBUG && ! defined WIN32
208 #ifdef BIAS_HAVE_PTHREADS
217 #endif // __Singleton_hh__
static pthread_mutex_t * Mutex_()
static void DeleteInstance_()
Simple singleton implementation for multithreaded applications.
Singleton< T > & operator=(const Singleton &t)
static T * Instance_
static members
bool SingletonDebugOutput_
This variable is defined in Singleton.cpp and steers the debug output of all Singleton classes...