#include <cstddef>
#include <new>
#include "bio/common/thread/ThreadSafe.h"
Go to the source code of this file.
◆ BIO_SINGLETON
| #define BIO_SINGLETON |
( |
|
className, |
|
|
|
baseClass |
|
) |
| |
Value:class className : \
public baseClass, \
{ \
public: \
static className& Instance() \
{ \
return *static_cast<className*>( \
::bio::GetOrCreateSingleton( \
#className, \
&className::CreateInstance)); \
} \
private: \
static void* CreateInstance() \
{ \
BIO_SINGLETON_CREATE_INSTANCE(className) \
} \
className() \
{ \
} \
className(className const &); \
};
Definition ThreadSafe.h:57
ThreadSafe & operator=(const ThreadSafe &toCopy)
Definition ThreadSafe.cpp:220
Singleton interface makes the constructor private so that there is only one instance ever created, which is by Instance()
we also override default copy constructor and assignment operator so that nobody can make a copy of the singleton (otherwise it wouldn't be a singleton). We don't define them, so these methods will give a link error if used.
- Parameters
-
| className | the name of the new singleton |
| baseClass | the name of the class the new singleton will inherit from (i.e. what to make into a singleton). |
◆ BIO_SINGLETON_CREATE_INSTANCE
| #define BIO_SINGLETON_CREATE_INSTANCE |
( |
|
className | ) |
return new className(); |