[Orxonox-commit 5798] r10458 - in code/branches/core7: src/libraries/core src/libraries/core/input src/libraries/core/object src/libraries/core/singleton src/libraries/network src/libraries/util src/modules/designtools src/modules/notifications src/modules/pickup src/modules/questsystem src/orxonox src/orxonox/chat src/orxonox/overlays src/orxonox/sound test/core/singleton
landauf at orxonox.net
landauf at orxonox.net
Sun May 24 11:51:06 CEST 2015
Author: landauf
Date: 2015-05-24 11:51:05 +0200 (Sun, 24 May 2015)
New Revision: 10458
Added:
code/branches/core7/src/libraries/core/singleton/ScopedSingletonWrapper.h
Removed:
code/branches/core7/src/libraries/core/singleton/ScopedSingletonManager.cc
code/branches/core7/src/libraries/core/singleton/ScopedSingletonManager.h
Modified:
code/branches/core7/src/libraries/core/Core.cc
code/branches/core7/src/libraries/core/CorePrereqs.h
code/branches/core7/src/libraries/core/input/KeyBinderManager.cc
code/branches/core7/src/libraries/core/input/KeyDetector.cc
code/branches/core7/src/libraries/core/object/DestroyLaterManager.cc
code/branches/core7/src/libraries/core/singleton/CMakeLists.txt
code/branches/core7/src/libraries/core/singleton/Scope.h
code/branches/core7/src/libraries/network/Client.cc
code/branches/core7/src/libraries/network/LANDiscovery.cc
code/branches/core7/src/libraries/network/MasterServer.cc
code/branches/core7/src/libraries/util/Singleton.h
code/branches/core7/src/modules/designtools/ScreenshotManager.cc
code/branches/core7/src/modules/designtools/SkyboxGenerator.cc
code/branches/core7/src/modules/notifications/NotificationManager.cc
code/branches/core7/src/modules/pickup/PickupManager.cc
code/branches/core7/src/modules/questsystem/QuestManager.cc
code/branches/core7/src/orxonox/CameraManager.cc
code/branches/core7/src/orxonox/LevelManager.cc
code/branches/core7/src/orxonox/MoodManager.cc
code/branches/core7/src/orxonox/PlayerManager.cc
code/branches/core7/src/orxonox/chat/ChatHistory.cc
code/branches/core7/src/orxonox/chat/ChatInputHandler.cc
code/branches/core7/src/orxonox/chat/ChatManager.cc
code/branches/core7/src/orxonox/overlays/InGameConsole.cc
code/branches/core7/src/orxonox/sound/SoundManager.cc
code/branches/core7/test/core/singleton/ScopeTest.cc
Log:
renamed ScopedSingletonManager to ScopedSingletonWrapper. removed static maps.
Modified: code/branches/core7/src/libraries/core/Core.cc
===================================================================
--- code/branches/core7/src/libraries/core/Core.cc 2015-05-23 19:50:13 UTC (rev 10457)
+++ code/branches/core7/src/libraries/core/Core.cc 2015-05-24 09:51:05 UTC (rev 10458)
@@ -56,7 +56,7 @@
#include "util/output/LogWriter.h"
#include "util/output/OutputManager.h"
#include "core/singleton/Scope.h"
-#include "core/singleton/ScopedSingletonManager.h"
+#include "core/singleton/ScopedSingletonWrapper.h"
#include "util/SignalHandler.h"
#include "PathConfig.h"
#include "commandline/CommandLineIncludes.h"
Modified: code/branches/core7/src/libraries/core/CorePrereqs.h
===================================================================
--- code/branches/core7/src/libraries/core/CorePrereqs.h 2015-05-23 19:50:13 UTC (rev 10457)
+++ code/branches/core7/src/libraries/core/CorePrereqs.h 2015-05-24 09:51:05 UTC (rev 10458)
@@ -198,8 +198,8 @@
struct ResourceInfo;
template <ScopeID::Value>
class Scope;
- template <class, ScopeID::Value>
- class ScopedSingleton;
+ class ScopeManager;
+ class ScopedSingletonWrapper;
class SettingsConfigFile;
template <class T>
class SmartPtr;
Modified: code/branches/core7/src/libraries/core/input/KeyBinderManager.cc
===================================================================
--- code/branches/core7/src/libraries/core/input/KeyBinderManager.cc 2015-05-23 19:50:13 UTC (rev 10457)
+++ code/branches/core7/src/libraries/core/input/KeyBinderManager.cc 2015-05-24 09:51:05 UTC (rev 10458)
@@ -30,7 +30,7 @@
#include "util/Output.h"
#include "util/Exception.h"
-#include "core/singleton/ScopedSingletonManager.h"
+#include "core/singleton/ScopedSingletonWrapper.h"
#include "core/config/ConfigValueIncludes.h"
#include "core/CoreIncludes.h"
#include "core/LuaState.h"
Modified: code/branches/core7/src/libraries/core/input/KeyDetector.cc
===================================================================
--- code/branches/core7/src/libraries/core/input/KeyDetector.cc 2015-05-23 19:50:13 UTC (rev 10457)
+++ code/branches/core7/src/libraries/core/input/KeyDetector.cc 2015-05-24 09:51:05 UTC (rev 10458)
@@ -29,7 +29,7 @@
#include "KeyDetector.h"
#include "core/CoreIncludes.h"
-#include "core/singleton/ScopedSingletonManager.h"
+#include "core/singleton/ScopedSingletonWrapper.h"
#include "core/command/ConsoleCommandIncludes.h"
#include "Button.h"
#include "InputManager.h"
Modified: code/branches/core7/src/libraries/core/object/DestroyLaterManager.cc
===================================================================
--- code/branches/core7/src/libraries/core/object/DestroyLaterManager.cc 2015-05-23 19:50:13 UTC (rev 10457)
+++ code/branches/core7/src/libraries/core/object/DestroyLaterManager.cc 2015-05-24 09:51:05 UTC (rev 10458)
@@ -29,7 +29,7 @@
#include "DestroyLaterManager.h"
#include "core/CoreIncludes.h"
-#include "core/singleton/ScopedSingletonManager.h"
+#include "core/singleton/ScopedSingletonWrapper.h"
namespace orxonox
{
Modified: code/branches/core7/src/libraries/core/singleton/CMakeLists.txt
===================================================================
--- code/branches/core7/src/libraries/core/singleton/CMakeLists.txt 2015-05-23 19:50:13 UTC (rev 10457)
+++ code/branches/core7/src/libraries/core/singleton/CMakeLists.txt 2015-05-24 09:51:05 UTC (rev 10458)
@@ -1,4 +1,3 @@
ADD_SOURCE_FILES(CORE_SRC_FILES
Scope.cc
- ScopedSingletonManager.cc
)
Modified: code/branches/core7/src/libraries/core/singleton/Scope.h
===================================================================
--- code/branches/core7/src/libraries/core/singleton/Scope.h 2015-05-23 19:50:13 UTC (rev 10457)
+++ code/branches/core7/src/libraries/core/singleton/Scope.h 2015-05-24 09:51:05 UTC (rev 10458)
@@ -45,7 +45,6 @@
Scopes are usually used to control the creation and destruction of Singletons.
- at see orxonox::ScopedSingletonManager
@see orxonox::Singleton
*/
Deleted: code/branches/core7/src/libraries/core/singleton/ScopedSingletonManager.cc
===================================================================
--- code/branches/core7/src/libraries/core/singleton/ScopedSingletonManager.cc 2015-05-23 19:50:13 UTC (rev 10457)
+++ code/branches/core7/src/libraries/core/singleton/ScopedSingletonManager.cc 2015-05-24 09:51:05 UTC (rev 10458)
@@ -1,48 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Reto Grieder
- * Co-authors:
- * ...
- *
- */
-
-/**
- @file
- @brief Static linkage of the ScopedSingletonManager maps.
-*/
-
-#include "ScopedSingletonManager.h"
-
-namespace orxonox
-{
- /*static*/ std::map<std::string, ScopedSingletonManager*>& ScopedSingletonManager::getManagers()
- {
- static std::map<std::string, ScopedSingletonManager*> managers;
- return managers;
- }
-
- /*static*/ void ScopedSingletonManager::addManager(ScopedSingletonManager* manager)
- {
- getManagers()[manager->className_] = manager;
- }
-}
Deleted: code/branches/core7/src/libraries/core/singleton/ScopedSingletonManager.h
===================================================================
--- code/branches/core7/src/libraries/core/singleton/ScopedSingletonManager.h 2015-05-23 19:50:13 UTC (rev 10457)
+++ code/branches/core7/src/libraries/core/singleton/ScopedSingletonManager.h 2015-05-24 09:51:05 UTC (rev 10458)
@@ -1,243 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Reto Grieder
- * Co-authors:
- * ...
- *
- */
-
-/**
- @file
- @ingroup SingletonScope
- @brief Definition of orxonox::ScopedSingletonManager, orxonox::ClassScopedSingletonManager, and the ManageScopedSingleton macro.
-
- ScopedSingletonManager is used to create and destroy Singletons that belong to
- a given Scope. For each one of these singletons, the macro ManageScopedSingleton()
- has to be called to register the singleton with orxonox::ScopedSingletonManager.
-
- See @ref SingletonExample "this code" for an example.
-
- @see orxonox::Singleton
- @see orxonox::Scope
-*/
-
-#ifndef __ScopedSingletonManager_H__
-#define __ScopedSingletonManager_H__
-
-#include "core/CorePrereqs.h"
-
-#include <cassert>
-#include <map>
-#include "util/Exception.h"
-#include "util/Singleton.h"
-#include "Scope.h"
-
-/**
- @brief Registers an orxonox::Singleton with orxonox::ScopedSingletonManager.
- @param className The name of the singleton class
- @param scope The scope in which the singleton should exist
- @param 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 registered with ScopedSingletonManager
- 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::ScopedSingletonManager. To
- do so, the ManageScopedSingleton() macro has to be called:
-
- @code
- ManageScopedSingleton(TestSingleton, ScopeID::Graphics, false); // muste be called in a source (*.cc) file
- @endcode
-
- @b 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.
-
-*/
-#define ManageScopedSingleton(className, scope, allowedToFail) \
- className* className::singletonPtr_s = NULL; \
- static ClassScopedSingletonManager<className, scope, allowedToFail> className##ScopedSingletonManager(#className)
-
-namespace orxonox
-{
- /**
- @brief Base class of ClassScopedSingletonManager. Keeps track of all existing ScopedSingletonManagers
- and stores them in a map, sorted by the scope they belong to.
- */
- class _CoreExport ScopedSingletonManager
- {
- public:
- /// Constructor: Initializes all the values
- ScopedSingletonManager(const std::string& className, ScopeID::Value scope)
- : className_(className)
- , scope_(scope)
- { }
- virtual ~ScopedSingletonManager() { }
-
- /// Adds a new instance of ScopedSingletonManager to the map.
- static void addManager(ScopedSingletonManager* manager);
-
- static std::map<std::string, ScopedSingletonManager*>& getManagers();
- typedef std::multimap<ScopeID::Value, ScopedSingletonManager*> ManagerMultiMap;
-
- protected:
- const std::string className_; ///< The name of the scoped singleton class that is managed by this object
- const ScopeID::Value scope_; ///< The scope of the singleton that is managed by this object
- };
-
- /**
- @anchor ClassScopedSingletonManager
-
- @brief Manages a scoped singleton for a given scope.
- @param T The managed singleton class
- @param scope The scope in which the singleton @a T should be active
- @param allowedToFail If true, a specialization of this template is used, that uses try-catch blocks to handle possible failures.
-
- This class inherits from ScopeListener for the given scope and thus its functions
- activated() and deactivated() are called whenever the Scope changes its state.
-
- If the Scope is activated, a new instance of @a T (which must be a singleton) is created.
- If the Scope is deactivated, the singleton is destroyed.
-
- @see Singleton
- */
- template <class T, ScopeID::Value scope, bool allowedToFail>
- class ClassScopedSingletonManager : public ScopedSingletonManager, public ScopeListener
- {
- public:
- //! Constructor: Initializes the singleton pointer and passes the scope to ScopedSingletonManager and ScopeListener
- ClassScopedSingletonManager(const std::string& className)
- : ScopedSingletonManager(className, scope)
- , ScopeListener(scope)
- , singletonPtr_(NULL)
- {
- ScopedSingletonManager::addManager(this);
- }
-
- ~ClassScopedSingletonManager()
- {
- }
-
- //! Called if the Scope of the Singleton gets active (creates the instance)
- void activated()
- {
- assert(singletonPtr_ == NULL);
- singletonPtr_ = new T();
- }
-
- //! Called if the Scope of this Singleton gets deactivated (destroys the instance)
- void deactivated()
- {
- assert(singletonPtr_ != NULL);
- this->destroy(singletonPtr_);
- singletonPtr_ = NULL;
- }
-
- //! Destroys the singleton instance - overloaded for Destroyable, calls Destroyable::destroy()
- void destroy(Destroyable*)
- {
- singletonPtr_->destroy();
- }
- //! Destroys the singleton instance - overloaded for all other pointers, calls delete
- void destroy(void*)
- {
- delete singletonPtr_;
- }
-
- private:
- T* singletonPtr_; ///< Unique instance of the singleton class @a T
- };
-
- /**
- @brief This class partially spezializes ClassScopedSingletonManager for classes @a T that are allowed to fail.
- @param T The managed singleton class
- @param scope The scope in which the singleton @a T should be active
-
- Because @a T could fail when being created, this partial spezialization of ClassScopedSingletonManager
- uses a try-catch block to handle exceptions.
-
- See @ref ClassScopedSingletonManager for a full documentation of the basis template.
- */
- template <class T, ScopeID::Value scope>
- class ClassScopedSingletonManager<T, scope, true> : public ScopedSingletonManager, public ScopeListener
- {
- public:
- //! Constructor: Initializes the singleton pointer and passes the scope to ScopedSingletonManager and ScopeListener
- ClassScopedSingletonManager(const std::string& className)
- : ScopedSingletonManager(className, scope)
- , ScopeListener(scope)
- , singletonPtr_(NULL)
- {
- ScopedSingletonManager::addManager(this);
- }
-
- ~ClassScopedSingletonManager()
- {
- }
-
- //! Called if the Scope of the Singleton gets active (creates the instance)
- void activated()
- {
- assert(singletonPtr_ == NULL);
- try
- { singletonPtr_ = new T(); }
- catch (const InitialisationAbortedException& ex)
- { orxout(internal_error) << ex.getDescription() << endl; }
- catch (...)
- { orxout(internal_error) << "Singleton creation failed: " << Exception::handleMessage() << endl; }
- }
-
- //! Called if the Scope of this Singleton gets deactivated (destroys the instance)
- void deactivated()
- {
- if (singletonPtr_ != NULL)
- {
- this->destroy(singletonPtr_);
- singletonPtr_ = NULL;
- }
- }
-
- //! Destroys the singleton instance - overloaded for Destroyable, calls Destroyable::destroy()
- void destroy(Destroyable*)
- {
- singletonPtr_->destroy();
- }
- //! Destroys the singleton instance - overloaded for void*, calls delete
- void destroy(void*)
- {
- delete singletonPtr_;
- }
-
- private:
- T* singletonPtr_; ///< Unique instance of the singleton class @a T
- };
-}
-
-#endif /* __ScopedSingletonManager_H__ */
Copied: code/branches/core7/src/libraries/core/singleton/ScopedSingletonWrapper.h (from rev 10457, code/branches/core7/src/libraries/core/singleton/ScopedSingletonManager.h)
===================================================================
--- code/branches/core7/src/libraries/core/singleton/ScopedSingletonWrapper.h (rev 0)
+++ code/branches/core7/src/libraries/core/singleton/ScopedSingletonWrapper.h 2015-05-24 09:51:05 UTC (rev 10458)
@@ -0,0 +1,233 @@
+/*
+ * ORXONOX - the hottest 3D action shooter ever to exist
+ * > www.orxonox.net <
+ *
+ *
+ * License notice:
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Author:
+ * Reto Grieder
+ * Co-authors:
+ * ...
+ *
+ */
+
+/**
+ @file
+ @ingroup SingletonScope
+ @brief Definition of orxonox::ScopedSingletonWrapper, orxonox::ClassScopedSingletonWrapper, and the ManageScopedSingleton macro.
+
+ ScopedSingletonWrapper is used to create and destroy Singletons that belong to
+ a given Scope. For each one of these singletons, the macro ManageScopedSingleton()
+ has to be called to register the wrapper with orxonox::ScopeManager.
+
+ See @ref SingletonExample "this code" for an example.
+
+ @see orxonox::Singleton
+ @see orxonox::Scope
+*/
+
+#ifndef __ScopedSingletonWrapper_H__
+#define __ScopedSingletonWrapper_H__
+
+#include "core/CorePrereqs.h"
+
+#include <cassert>
+#include "util/Exception.h"
+#include "util/Singleton.h"
+#include "Scope.h"
+
+/**
+ @brief Creates an orxonox::ScopedSingletonWrapper for an orxonox::Singleton and registers it with orxonox::ScopeManager.
+ @param className The name of the singleton class
+ @param scope The scope in which the singleton should exist
+ @param 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:
+
+ @code
+ ManageScopedSingleton(TestSingleton, ScopeID::Graphics, false); // muste be called in a source (*.cc) file
+ @endcode
+
+ @b 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.
+
+*/
+#define ManageScopedSingleton(className, scope, allowedToFail) \
+ className* className::singletonPtr_s = NULL; \
+ static ClassScopedSingletonWrapper<className, scope, allowedToFail> className##ScopedSingletonWrapper(#className)
+
+namespace orxonox
+{
+ /**
+ @brief Base class of ClassScopedSingletonWrapper.
+ */
+ class _CoreExport ScopedSingletonWrapper
+ {
+ public:
+ /// Constructor: Initializes all the values
+ ScopedSingletonWrapper(const std::string& className, ScopeID::Value scope)
+ : className_(className)
+ , scope_(scope)
+ { }
+ virtual ~ScopedSingletonWrapper() { }
+
+ protected:
+ const std::string className_; ///< The name of the scoped singleton class that is managed by this object
+ const ScopeID::Value scope_; ///< The scope of the singleton that is managed by this object
+ };
+
+ /**
+ @anchor ClassScopedSingletonWrapper
+
+ @brief Manages a scoped singleton for a given scope.
+ @param T The managed singleton class
+ @param scope The scope in which the singleton @a T should be active
+ @param allowedToFail If true, a specialization of this template is used, that uses try-catch blocks to handle possible failures.
+
+ This class inherits from ScopeListener for the given scope and thus its functions
+ activated() and deactivated() are called whenever the Scope changes its state.
+
+ If the Scope is activated, a new instance of @a T (which must be a singleton) is created.
+ If the Scope is deactivated, the singleton is destroyed.
+
+ @see Singleton
+ */
+ template <class T, ScopeID::Value scope, bool allowedToFail>
+ class ClassScopedSingletonWrapper : public ScopedSingletonWrapper, public ScopeListener
+ {
+ public:
+ //! Constructor: Initializes the singleton pointer and passes the scope to ScopedSingletonWrapper and ScopeListener
+ ClassScopedSingletonWrapper(const std::string& className)
+ : ScopedSingletonWrapper(className, scope)
+ , ScopeListener(scope)
+ , singletonPtr_(NULL)
+ {
+ }
+
+ ~ClassScopedSingletonWrapper()
+ {
+ }
+
+ //! Called if the Scope of the Singleton gets active (creates the instance)
+ void activated()
+ {
+ assert(singletonPtr_ == NULL);
+ singletonPtr_ = new T();
+ }
+
+ //! Called if the Scope of this Singleton gets deactivated (destroys the instance)
+ void deactivated()
+ {
+ assert(singletonPtr_ != NULL);
+ this->destroy(singletonPtr_);
+ singletonPtr_ = NULL;
+ }
+
+ //! Destroys the singleton instance - overloaded for Destroyable, calls Destroyable::destroy()
+ void destroy(Destroyable*)
+ {
+ singletonPtr_->destroy();
+ }
+ //! Destroys the singleton instance - overloaded for all other pointers, calls delete
+ void destroy(void*)
+ {
+ delete singletonPtr_;
+ }
+
+ private:
+ T* singletonPtr_; ///< Unique instance of the singleton class @a T
+ };
+
+ /**
+ @brief This class partially spezializes ClassScopedSingletonWrapper for classes @a T that are allowed to fail.
+ @param T The managed singleton class
+ @param scope The scope in which the singleton @a T should be active
+
+ Because @a T could fail when being created, this partial spezialization of ClassScopedSingletonWrapper
+ uses a try-catch block to handle exceptions.
+
+ See @ref ClassScopedSingletonWrapper for a full documentation of the basis template.
+ */
+ template <class T, ScopeID::Value scope>
+ class ClassScopedSingletonWrapper<T, scope, true> : public ScopedSingletonWrapper, public ScopeListener
+ {
+ public:
+ //! Constructor: Initializes the singleton pointer and passes the scope to ScopedSingletonWrapper and ScopeListener
+ ClassScopedSingletonWrapper(const std::string& className)
+ : ScopedSingletonWrapper(className, scope)
+ , ScopeListener(scope)
+ , singletonPtr_(NULL)
+ {
+ }
+
+ ~ClassScopedSingletonWrapper()
+ {
+ }
+
+ //! Called if the Scope of the Singleton gets active (creates the instance)
+ void activated()
+ {
+ assert(singletonPtr_ == NULL);
+ try
+ { singletonPtr_ = new T(); }
+ catch (const InitialisationAbortedException& ex)
+ { orxout(internal_error) << ex.getDescription() << endl; }
+ catch (...)
+ { orxout(internal_error) << "Singleton creation failed: " << Exception::handleMessage() << endl; }
+ }
+
+ //! Called if the Scope of this Singleton gets deactivated (destroys the instance)
+ void deactivated()
+ {
+ if (singletonPtr_ != NULL)
+ {
+ this->destroy(singletonPtr_);
+ singletonPtr_ = NULL;
+ }
+ }
+
+ //! Destroys the singleton instance - overloaded for Destroyable, calls Destroyable::destroy()
+ void destroy(Destroyable*)
+ {
+ singletonPtr_->destroy();
+ }
+ //! Destroys the singleton instance - overloaded for void*, calls delete
+ void destroy(void*)
+ {
+ delete singletonPtr_;
+ }
+
+ private:
+ T* singletonPtr_; ///< Unique instance of the singleton class @a T
+ };
+}
+
+#endif /* __ScopedSingletonWrapper_H__ */
Modified: code/branches/core7/src/libraries/network/Client.cc
===================================================================
--- code/branches/core7/src/libraries/network/Client.cc 2015-05-23 19:50:13 UTC (rev 10457)
+++ code/branches/core7/src/libraries/network/Client.cc 2015-05-24 09:51:05 UTC (rev 10458)
@@ -51,7 +51,7 @@
#include "core/CoreIncludes.h"
#include "core/Game.h"
#include "core/commandline/CommandLineParser.h"
-#include "core/singleton/ScopedSingletonManager.h"
+#include "core/singleton/ScopedSingletonWrapper.h"
namespace orxonox
{
Modified: code/branches/core7/src/libraries/network/LANDiscovery.cc
===================================================================
--- code/branches/core7/src/libraries/network/LANDiscovery.cc 2015-05-23 19:50:13 UTC (rev 10457)
+++ code/branches/core7/src/libraries/network/LANDiscovery.cc 2015-05-24 09:51:05 UTC (rev 10458)
@@ -32,7 +32,7 @@
#include <cstring>
#include "core/CoreIncludes.h"
-#include "core/singleton/ScopedSingletonManager.h"
+#include "core/singleton/ScopedSingletonWrapper.h"
namespace orxonox
Modified: code/branches/core7/src/libraries/network/MasterServer.cc
===================================================================
--- code/branches/core7/src/libraries/network/MasterServer.cc 2015-05-23 19:50:13 UTC (rev 10457)
+++ code/branches/core7/src/libraries/network/MasterServer.cc 2015-05-24 09:51:05 UTC (rev 10458)
@@ -30,7 +30,7 @@
#include "core/command/ConsoleCommandIncludes.h"
#include "core/CoreIncludes.h"
#include "core/CorePrereqs.h"
-#include "core/singleton/ScopedSingletonManager.h"
+#include "core/singleton/ScopedSingletonWrapper.h"
#include "util/Output.h"
namespace orxonox
Modified: code/branches/core7/src/libraries/util/Singleton.h
===================================================================
--- code/branches/core7/src/libraries/util/Singleton.h 2015-05-23 19:50:13 UTC (rev 10457)
+++ code/branches/core7/src/libraries/util/Singleton.h 2015-05-24 09:51:05 UTC (rev 10458)
@@ -51,7 +51,7 @@
public:
TestSingleton(); // public constructor because we may want to manage this singleton
- // with an orxonox::ScopedSingletonManager (see below)
+ // with an orxonox::ScopedSingletonWrapper
virtual ~TestSingleton(); // public destructor
void testFunction(); // put your functions here
Modified: code/branches/core7/src/modules/designtools/ScreenshotManager.cc
===================================================================
--- code/branches/core7/src/modules/designtools/ScreenshotManager.cc 2015-05-23 19:50:13 UTC (rev 10457)
+++ code/branches/core7/src/modules/designtools/ScreenshotManager.cc 2015-05-24 09:51:05 UTC (rev 10458)
@@ -47,7 +47,7 @@
#include "core/PathConfig.h"
#include "core/Resource.h"
#include "core/command/ConsoleCommandIncludes.h"
-#include "core/singleton/ScopedSingletonManager.h"
+#include "core/singleton/ScopedSingletonWrapper.h"
#include "util/StringUtils.h"
#include "CameraManager.h"
Modified: code/branches/core7/src/modules/designtools/SkyboxGenerator.cc
===================================================================
--- code/branches/core7/src/modules/designtools/SkyboxGenerator.cc 2015-05-23 19:50:13 UTC (rev 10457)
+++ code/branches/core7/src/modules/designtools/SkyboxGenerator.cc 2015-05-24 09:51:05 UTC (rev 10458)
@@ -44,7 +44,7 @@
#include "core/Resource.h"
#include "core/command/ConsoleCommandIncludes.h"
#include "core/command/CommandExecutor.h"
-#include "core/singleton/ScopedSingletonManager.h"
+#include "core/singleton/ScopedSingletonWrapper.h"
#include "controllers/HumanController.h"
#include "graphics/Camera.h"
Modified: code/branches/core7/src/modules/notifications/NotificationManager.cc
===================================================================
--- code/branches/core7/src/modules/notifications/NotificationManager.cc 2015-05-23 19:50:13 UTC (rev 10457)
+++ code/branches/core7/src/modules/notifications/NotificationManager.cc 2015-05-24 09:51:05 UTC (rev 10458)
@@ -36,7 +36,7 @@
#include "core/command/ConsoleCommand.h"
#include "core/CoreIncludes.h"
#include "core/LuaState.h"
-#include "core/singleton/ScopedSingletonManager.h"
+#include "core/singleton/ScopedSingletonWrapper.h"
#include "interfaces/NotificationListener.h"
Modified: code/branches/core7/src/modules/pickup/PickupManager.cc
===================================================================
--- code/branches/core7/src/modules/pickup/PickupManager.cc 2015-05-23 19:50:13 UTC (rev 10457)
+++ code/branches/core7/src/modules/pickup/PickupManager.cc 2015-05-24 09:51:05 UTC (rev 10458)
@@ -37,7 +37,7 @@
#include "core/LuaState.h"
#include "core/GUIManager.h"
#include "core/class/Identifier.h"
-#include "core/singleton/ScopedSingletonManager.h"
+#include "core/singleton/ScopedSingletonWrapper.h"
#include "network/Host.h"
#include "network/NetworkFunction.h"
Modified: code/branches/core7/src/modules/questsystem/QuestManager.cc
===================================================================
--- code/branches/core7/src/modules/questsystem/QuestManager.cc 2015-05-23 19:50:13 UTC (rev 10457)
+++ code/branches/core7/src/modules/questsystem/QuestManager.cc 2015-05-24 09:51:05 UTC (rev 10458)
@@ -35,7 +35,7 @@
#include "util/Exception.h"
#include "util/OrxAssert.h"
-#include "core/singleton/ScopedSingletonManager.h"
+#include "core/singleton/ScopedSingletonWrapper.h"
#include "core/command/ConsoleCommand.h"
#include "core/GUIManager.h"
#include "core/LuaState.h"
Modified: code/branches/core7/src/orxonox/CameraManager.cc
===================================================================
--- code/branches/core7/src/orxonox/CameraManager.cc 2015-05-23 19:50:13 UTC (rev 10457)
+++ code/branches/core7/src/orxonox/CameraManager.cc 2015-05-24 09:51:05 UTC (rev 10458)
@@ -37,7 +37,7 @@
#include "core/GameMode.h"
#include "core/GraphicsManager.h"
#include "core/object/ObjectList.h"
-#include "core/singleton/ScopedSingletonManager.h"
+#include "core/singleton/ScopedSingletonWrapper.h"
#include "tools/Shader.h"
#include "graphics/Camera.h"
Modified: code/branches/core7/src/orxonox/LevelManager.cc
===================================================================
--- code/branches/core7/src/orxonox/LevelManager.cc 2015-05-23 19:50:13 UTC (rev 10457)
+++ code/branches/core7/src/orxonox/LevelManager.cc 2015-05-24 09:51:05 UTC (rev 10458)
@@ -35,7 +35,7 @@
#include <map>
-#include "core/singleton/ScopedSingletonManager.h"
+#include "core/singleton/ScopedSingletonWrapper.h"
#include "core/commandline/CommandLineIncludes.h"
#include "core/config/ConfigValueIncludes.h"
#include "core/CoreIncludes.h"
Modified: code/branches/core7/src/orxonox/MoodManager.cc
===================================================================
--- code/branches/core7/src/orxonox/MoodManager.cc 2015-05-23 19:50:13 UTC (rev 10457)
+++ code/branches/core7/src/orxonox/MoodManager.cc 2015-05-24 09:51:05 UTC (rev 10458)
@@ -28,7 +28,7 @@
#include "MoodManager.h"
-#include "core/singleton/ScopedSingletonManager.h"
+#include "core/singleton/ScopedSingletonWrapper.h"
#include "core/config/ConfigValueIncludes.h"
#include "core/CoreIncludes.h"
#include "core/Resource.h"
Modified: code/branches/core7/src/orxonox/PlayerManager.cc
===================================================================
--- code/branches/core7/src/orxonox/PlayerManager.cc 2015-05-23 19:50:13 UTC (rev 10457)
+++ code/branches/core7/src/orxonox/PlayerManager.cc 2015-05-24 09:51:05 UTC (rev 10458)
@@ -30,7 +30,7 @@
#include "core/CoreIncludes.h"
#include "core/GameMode.h"
-#include "core/singleton/ScopedSingletonManager.h"
+#include "core/singleton/ScopedSingletonWrapper.h"
#include "Level.h"
#include "LevelManager.h"
Modified: code/branches/core7/src/orxonox/chat/ChatHistory.cc
===================================================================
--- code/branches/core7/src/orxonox/chat/ChatHistory.cc 2015-05-23 19:50:13 UTC (rev 10457)
+++ code/branches/core7/src/orxonox/chat/ChatHistory.cc 2015-05-24 09:51:05 UTC (rev 10458)
@@ -27,7 +27,7 @@
*/
#include "ChatHistory.h"
-#include "core/singleton/ScopedSingletonManager.h"
+#include "core/singleton/ScopedSingletonWrapper.h"
#ifndef CHATTEST
namespace orxonox
Modified: code/branches/core7/src/orxonox/chat/ChatInputHandler.cc
===================================================================
--- code/branches/core7/src/orxonox/chat/ChatInputHandler.cc 2015-05-23 19:50:13 UTC (rev 10457)
+++ code/branches/core7/src/orxonox/chat/ChatInputHandler.cc 2015-05-24 09:51:05 UTC (rev 10458)
@@ -46,7 +46,7 @@
# include <elements/CEGUIListboxTextItem.h>
#endif
-#include "core/singleton/ScopedSingletonManager.h"
+#include "core/singleton/ScopedSingletonWrapper.h"
#include "core/CoreIncludes.h"
#include "core/GUIManager.h"
#include "core/command/ConsoleCommandIncludes.h"
Modified: code/branches/core7/src/orxonox/chat/ChatManager.cc
===================================================================
--- code/branches/core7/src/orxonox/chat/ChatManager.cc 2015-05-23 19:50:13 UTC (rev 10457)
+++ code/branches/core7/src/orxonox/chat/ChatManager.cc 2015-05-24 09:51:05 UTC (rev 10458)
@@ -30,7 +30,7 @@
#include "ChatListener.h"
#include "core/CoreIncludes.h"
-#include "core/singleton/ScopedSingletonManager.h"
+#include "core/singleton/ScopedSingletonWrapper.h"
#include "core/command/ConsoleCommandIncludes.h"
#include "network/Host.h"
Modified: code/branches/core7/src/orxonox/overlays/InGameConsole.cc
===================================================================
--- code/branches/core7/src/orxonox/overlays/InGameConsole.cc 2015-05-23 19:50:13 UTC (rev 10457)
+++ code/branches/core7/src/orxonox/overlays/InGameConsole.cc 2015-05-24 09:51:05 UTC (rev 10458)
@@ -49,7 +49,7 @@
#include "core/CoreIncludes.h"
#include "core/config/ConfigValueIncludes.h"
#include "core/command/ConsoleCommandIncludes.h"
-#include "core/singleton/ScopedSingletonManager.h"
+#include "core/singleton/ScopedSingletonWrapper.h"
#include "core/GUIManager.h"
#include "core/input/InputManager.h"
#include "core/input/InputState.h"
Modified: code/branches/core7/src/orxonox/sound/SoundManager.cc
===================================================================
--- code/branches/core7/src/orxonox/sound/SoundManager.cc 2015-05-23 19:50:13 UTC (rev 10457)
+++ code/branches/core7/src/orxonox/sound/SoundManager.cc 2015-05-24 09:51:05 UTC (rev 10458)
@@ -37,7 +37,7 @@
#include "util/Exception.h"
#include "util/Math.h"
#include "util/Clock.h"
-#include "core/singleton/ScopedSingletonManager.h"
+#include "core/singleton/ScopedSingletonWrapper.h"
#include "core/config/ConfigValueIncludes.h"
#include "core/CoreIncludes.h"
#include "core/GameMode.h"
Modified: code/branches/core7/test/core/singleton/ScopeTest.cc
===================================================================
--- code/branches/core7/test/core/singleton/ScopeTest.cc 2015-05-23 19:50:13 UTC (rev 10457)
+++ code/branches/core7/test/core/singleton/ScopeTest.cc 2015-05-24 09:51:05 UTC (rev 10458)
@@ -1,5 +1,5 @@
#include <gtest/gtest.h>
-#include "core/singleton/ScopedSingletonManager.h"
+#include "core/singleton/ScopedSingletonWrapper.h"
namespace orxonox
{
More information about the Orxonox-commit
mailing list