Changeset 10413 for code/branches/core7/src/libraries/core/singleton
- Timestamp:
- May 2, 2015, 11:20:45 PM (10 years ago)
- Location:
- code/branches/core7/src/libraries/core/singleton
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core7/src/libraries/core/singleton/ScopedSingletonManager.cc
r10407 r10413 41 41 return managers; 42 42 } 43 /*static*/ ScopedSingletonManager::ManagerMultiMap& ScopedSingletonManager::getManagersByScope()44 {45 static ManagerMultiMap managers;46 return managers;47 }48 43 49 44 /*static*/ void ScopedSingletonManager::addManager(ScopedSingletonManager* manager) 50 45 { 51 46 getManagers()[manager->className_] = manager; 52 getManagersByScope().insert(std::make_pair(manager->scope_, manager));53 47 } 54 48 } -
code/branches/core7/src/libraries/core/singleton/ScopedSingletonManager.h
r10407 r10413 68 68 namespace orxonox 69 69 { 70 class Destroyable;71 72 70 /** 73 @brief Base class of ClassScopedSingletonManager, implements some static functions 74 used to dispatch calls to preUpdate and postUpdate to all instances of this class. 75 It also keeps track of all existing ScopedSingletonManagers and stores them in a 76 map, sorted by the scope they belong to. 71 @brief Base class of ClassScopedSingletonManager. Keeps track of all existing ScopedSingletonManagers 72 and stores them in a map, sorted by the scope they belong to. 77 73 */ 78 74 class _CoreExport ScopedSingletonManager … … 89 85 static void addManager(ScopedSingletonManager* manager); 90 86 91 /// Calls preUpdate in all instances of ScopedSingletonManager that are registered in the map.92 template<ScopeID::Value scope>93 static void preUpdate(const Clock& time)94 {95 assert(Scope<scope>::isActive());96 for (ManagerMultiMap::iterator it = getManagersByScope().lower_bound(scope); it != getManagersByScope().upper_bound(scope); ++it)97 it->second->preUpdate(time);98 }99 virtual void preUpdate(const Clock& time) = 0;100 101 /// Calls postUpdate in all instances of ScopedSingletonManager that are registered in the map.102 template<ScopeID::Value scope>103 static void postUpdate(const Clock& time)104 {105 assert(Scope<scope>::isActive());106 for (ManagerMultiMap::iterator it = getManagersByScope().lower_bound(scope); it != getManagersByScope().upper_bound(scope); ++it)107 it->second->postUpdate(time);108 }109 virtual void postUpdate(const Clock& time) = 0;110 111 87 static std::map<std::string, ScopedSingletonManager*>& getManagers(); 112 88 typedef std::multimap<ScopeID::Value, ScopedSingletonManager*> ManagerMultiMap; 113 static ManagerMultiMap& getManagersByScope();114 89 115 90 protected: … … 177 152 } 178 153 179 //! Called every frame by the ScopedSingletonManager180 void preUpdate(const Clock& time)181 {182 assert(Scope<scope>::isActive());183 // assuming T inherits Singleton<T>184 singletonPtr_->preUpdateSingleton(time);185 }186 187 //! Called every frame by the ScopedSingletonManager188 void postUpdate(const Clock& time)189 {190 assert(Scope<scope>::isActive());191 // assuming T inherits Singleton<T>192 singletonPtr_->postUpdateSingleton(time);193 }194 195 154 private: 196 155 T* singletonPtr_; ///< Unique instance of the singleton class @a T … … 257 216 } 258 217 259 //! Called every frame by the ScopedSingletonManager260 void preUpdate(const Clock& time)261 {262 assert(Scope<scope>::isActive());263 // assuming T inherits Singleton<T>264 if (singletonPtr_ != NULL)265 singletonPtr_->preUpdateSingleton(time);266 }267 268 //! Called every frame by the ScopedSingletonManager269 void postUpdate(const Clock& time)270 {271 assert(Scope<scope>::isActive());272 // assuming T inherits Singleton<T>273 if (singletonPtr_ != NULL)274 singletonPtr_->postUpdateSingleton(time);275 }276 277 218 private: 278 219 T* singletonPtr_; ///< Unique instance of the singleton class @a T
Note: See TracChangeset
for help on using the changeset viewer.