Changeset 10458 for code/branches/core7/src/libraries/core/singleton
- Timestamp:
- May 24, 2015, 11:51:05 AM (10 years ago)
- Location:
- code/branches/core7/src/libraries/core/singleton
- Files:
-
- 1 deleted
- 2 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core7/src/libraries/core/singleton/CMakeLists.txt
r10407 r10458 1 1 ADD_SOURCE_FILES(CORE_SRC_FILES 2 2 Scope.cc 3 ScopedSingletonManager.cc4 3 ) -
code/branches/core7/src/libraries/core/singleton/Scope.h
r10412 r10458 46 46 Scopes are usually used to control the creation and destruction of Singletons. 47 47 48 @see orxonox::ScopedSingletonManager49 48 @see orxonox::Singleton 50 49 */ -
code/branches/core7/src/libraries/core/singleton/ScopedSingletonWrapper.h
r10457 r10458 30 30 @file 31 31 @ingroup SingletonScope 32 @brief Definition of orxonox::ScopedSingleton Manager, orxonox::ClassScopedSingletonManager, and the ManageScopedSingleton macro.33 34 ScopedSingleton Manager is used to create and destroy Singletons that belong to32 @brief Definition of orxonox::ScopedSingletonWrapper, orxonox::ClassScopedSingletonWrapper, and the ManageScopedSingleton macro. 33 34 ScopedSingletonWrapper is used to create and destroy Singletons that belong to 35 35 a given Scope. For each one of these singletons, the macro ManageScopedSingleton() 36 has to be called to register the singleton with orxonox::ScopedSingletonManager.36 has to be called to register the wrapper with orxonox::ScopeManager. 37 37 38 38 See @ref SingletonExample "this code" for an example. … … 42 42 */ 43 43 44 #ifndef __ScopedSingleton Manager_H__45 #define __ScopedSingleton Manager_H__44 #ifndef __ScopedSingletonWrapper_H__ 45 #define __ScopedSingletonWrapper_H__ 46 46 47 47 #include "core/CorePrereqs.h" 48 48 49 49 #include <cassert> 50 #include <map>51 50 #include "util/Exception.h" 52 51 #include "util/Singleton.h" … … 54 53 55 54 /** 56 @brief Registers an orxonox::Singleton with orxonox::ScopedSingletonManager.55 @brief Creates an orxonox::ScopedSingletonWrapper for an orxonox::Singleton and registers it with orxonox::ScopeManager. 57 56 @param className The name of the singleton class 58 57 @param scope The scope in which the singleton should exist 59 58 @param allowedToFail If true, the singleton is allowed to fail and thus a try-catch block is used when creating the singleton. 60 59 61 If this macro is called for a singleton, it is registered with ScopedSingletonManager60 If this macro is called for a singleton, it is wrapped in a ScopedSingletonWrapper and registered with ScopeManager 62 61 and will thus be created if its scope becomes active and destroyed if is deactivated. 63 62 … … 66 65 be destroyed (unless the singleton explicitly deletes itself). To allow controlled 67 66 construction and destruction, the singleton can be put within a virtual scope. This is 68 done by registering the singleton class with orxonox::Scope dSingletonManager. To67 done by registering the singleton class with orxonox::ScopeManager. To 69 68 do so, the ManageScopedSingleton() macro has to be called: 70 69 … … 84 83 #define ManageScopedSingleton(className, scope, allowedToFail) \ 85 84 className* className::singletonPtr_s = NULL; \ 86 static ClassScopedSingleton Manager<className, scope, allowedToFail> className##ScopedSingletonManager(#className)85 static ClassScopedSingletonWrapper<className, scope, allowedToFail> className##ScopedSingletonWrapper(#className) 87 86 88 87 namespace orxonox 89 88 { 90 89 /** 91 @brief Base class of ClassScopedSingletonManager. Keeps track of all existing ScopedSingletonManagers 92 and stores them in a map, sorted by the scope they belong to. 90 @brief Base class of ClassScopedSingletonWrapper. 93 91 */ 94 class _CoreExport ScopedSingleton Manager92 class _CoreExport ScopedSingletonWrapper 95 93 { 96 94 public: 97 95 /// Constructor: Initializes all the values 98 ScopedSingleton Manager(const std::string& className, ScopeID::Value scope)96 ScopedSingletonWrapper(const std::string& className, ScopeID::Value scope) 99 97 : className_(className) 100 98 , scope_(scope) 101 99 { } 102 virtual ~ScopedSingletonManager() { } 103 104 /// Adds a new instance of ScopedSingletonManager to the map. 105 static void addManager(ScopedSingletonManager* manager); 106 107 static std::map<std::string, ScopedSingletonManager*>& getManagers(); 108 typedef std::multimap<ScopeID::Value, ScopedSingletonManager*> ManagerMultiMap; 100 virtual ~ScopedSingletonWrapper() { } 109 101 110 102 protected: … … 114 106 115 107 /** 116 @anchor ClassScopedSingleton Manager108 @anchor ClassScopedSingletonWrapper 117 109 118 110 @brief Manages a scoped singleton for a given scope. … … 130 122 */ 131 123 template <class T, ScopeID::Value scope, bool allowedToFail> 132 class ClassScopedSingleton Manager : public ScopedSingletonManager, public ScopeListener124 class ClassScopedSingletonWrapper : public ScopedSingletonWrapper, public ScopeListener 133 125 { 134 126 public: 135 //! Constructor: Initializes the singleton pointer and passes the scope to ScopedSingleton Manager and ScopeListener136 ClassScopedSingleton Manager(const std::string& className)137 : ScopedSingleton Manager(className, scope)127 //! Constructor: Initializes the singleton pointer and passes the scope to ScopedSingletonWrapper and ScopeListener 128 ClassScopedSingletonWrapper(const std::string& className) 129 : ScopedSingletonWrapper(className, scope) 138 130 , ScopeListener(scope) 139 131 , singletonPtr_(NULL) 140 132 { 141 ScopedSingletonManager::addManager(this); 142 } 143 144 ~ClassScopedSingletonManager() 133 } 134 135 ~ClassScopedSingletonWrapper() 145 136 { 146 137 } … … 177 168 178 169 /** 179 @brief This class partially spezializes ClassScopedSingleton Manager for classes @a T that are allowed to fail.170 @brief This class partially spezializes ClassScopedSingletonWrapper for classes @a T that are allowed to fail. 180 171 @param T The managed singleton class 181 172 @param scope The scope in which the singleton @a T should be active 182 173 183 Because @a T could fail when being created, this partial spezialization of ClassScopedSingleton Manager174 Because @a T could fail when being created, this partial spezialization of ClassScopedSingletonWrapper 184 175 uses a try-catch block to handle exceptions. 185 176 186 See @ref ClassScopedSingleton Manager for a full documentation of the basis template.177 See @ref ClassScopedSingletonWrapper for a full documentation of the basis template. 187 178 */ 188 179 template <class T, ScopeID::Value scope> 189 class ClassScopedSingleton Manager<T, scope, true> : public ScopedSingletonManager, public ScopeListener180 class ClassScopedSingletonWrapper<T, scope, true> : public ScopedSingletonWrapper, public ScopeListener 190 181 { 191 182 public: 192 //! Constructor: Initializes the singleton pointer and passes the scope to ScopedSingleton Manager and ScopeListener193 ClassScopedSingleton Manager(const std::string& className)194 : ScopedSingleton Manager(className, scope)183 //! Constructor: Initializes the singleton pointer and passes the scope to ScopedSingletonWrapper and ScopeListener 184 ClassScopedSingletonWrapper(const std::string& className) 185 : ScopedSingletonWrapper(className, scope) 195 186 , ScopeListener(scope) 196 187 , singletonPtr_(NULL) 197 188 { 198 ScopedSingletonManager::addManager(this); 199 } 200 201 ~ClassScopedSingletonManager() 189 } 190 191 ~ClassScopedSingletonWrapper() 202 192 { 203 193 } … … 241 231 } 242 232 243 #endif /* __ScopedSingleton Manager_H__ */233 #endif /* __ScopedSingletonWrapper_H__ */
Note: See TracChangeset
for help on using the changeset viewer.