Orxonox
0.0.5 Codename: Arcturus
|
Definition of the ManageScopedSingleton macro. More...
#include "core/CorePrereqs.h"
#include "ScopedSingletonWrapper.h"
#include "core/module/StaticallyInitializedInstance.h"
Go to the source code of this file.
Classes | |
class | orxonox::StaticallyInitializedScopedSingletonWrapper |
Namespaces | |
orxonox | |
Die Wagnis Klasse hat die folgenden Aufgaben: | |
Macros | |
#define | ManageScopedSingleton(className, scope, allowedToFail) |
Creates an orxonox::ScopedSingletonWrapper for an orxonox::Singleton and registers it with orxonox::ScopeManager. More... | |
Typedefs | |
typedef StaticallyInitializedScopedSingletonWrapper | orxonox::SI_SSW |
Definition of the ManageScopedSingleton macro.
#define ManageScopedSingleton | ( | className, | |
scope, | |||
allowedToFail | |||
) |
Creates an orxonox::ScopedSingletonWrapper for an orxonox::Singleton and registers it with orxonox::ScopeManager.
className | The name of the singleton class |
scope | The scope in which the singleton should exist |
allowedToFail | If true, the singleton is allowed to fail and thus a try-catch block is used when creating the singleton. |
If this macro is called for a singleton, it is wrapped in a ScopedSingletonWrapper and registered with ScopeManager and will thus be created if its scope becomes active and destroyed if is deactivated.
Usually a singleton gets created automatically when it is first used, but it will never be destroyed (unless the singleton explicitly deletes itself). To allow controlled construction and destruction, the singleton can be put within a virtual scope. This is done by registering the singleton class with orxonox::ScopeManager. To do so, the ManageScopedSingleton() macro has to be called:
Important: If you call ManageScopedSingleton(), you don't have to initialize singletonPtr_s anymore, because that's already done by the macro.
Now the singleton TestSingleton gets automatically created if the scope Graphics becomes active and also gets destroyed if the scope is deactivated.
Note that not all singletons must register with a scope, but it's recommended.