12 #ifndef SINGLETON_H_6014714286
13 #define SINGLETON_H_6014714286
58 template<
typename InstanceType >
67 static InstanceType* instancePtr;
76 CARNA_ASSERT_EX( instancePtr ==
nullptr,
"Multiple singleton instances created." );
77 instancePtr =
static_cast< InstanceType*
>( this );
85 if( instancePtr !=
nullptr )
103 instancePtr =
nullptr;
111 return instancePtr ==
nullptr ? *
new InstanceType() : *instancePtr;
119 return instancePtr !=
nullptr;
125 template<
typename InstanceType >
126 InstanceType* Singleton< InstanceType >::instancePtr =
nullptr;
134 #endif // SINGLETON_H_6014714286
static void reset()
Deletes the only instance from class InstanceType.
#define CARNA_ASSERT_EX(expression, description)
If the given expression is false, a break point is raised in debug mode and an AssertionFailure throw...
virtual ~Singleton()
Denotes that the instance was deleted.
static InstanceType & instance()
Returns the only instance from class InstanceType.
InstanceType Instance
Denotes the class, that is derived from this class template.
Singleton()
Denotes that the instance was created. Default constructor is hidden.
Defines Carna::base::CarnaException, Carna::base::AssertionFailure.
#define NON_COPYABLE
Features class it is placed in as non-copyable.
static bool exists()
Tells whether the instance from class InstanceType currently exists.