Changeset 10462 for code/branches/core7/src/libraries/core/singleton
- Timestamp:
- May 24, 2015, 11:42:16 PM (10 years ago)
- Location:
- code/branches/core7/src/libraries/core/singleton
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core7/src/libraries/core/singleton/Scope.h
r10461 r10462 111 111 try 112 112 { 113 ScopeManager::getInstance Counts()[scope]++;114 assert(ScopeManager::getInstance Counts()[scope]> 0);115 if (ScopeManager::getInstance Counts()[scope]== 1)113 ScopeManager::getInstance().getInstanceCount(scope)++; 114 assert(ScopeManager::getInstance().getInstanceCount(scope) > 0); 115 if (ScopeManager::getInstance().getInstanceCount(scope) == 1) 116 116 { 117 117 Loki::ScopeGuard deactivator = Loki::MakeObjGuard(*this, &Scope::deactivateListeners); 118 for (typename std::set<ScopeListener*>::iterator it = ScopeManager::get Listeners()[scope].begin(); it != ScopeManager::getListeners()[scope].end(); )118 for (typename std::set<ScopeListener*>::iterator it = ScopeManager::getInstance().getListeners(scope).begin(); it != ScopeManager::getInstance().getListeners(scope).end(); ) 119 119 { 120 120 (*it)->activated(); … … 126 126 catch (...) 127 127 { 128 ScopeManager::getInstance Counts()[scope]--;128 ScopeManager::getInstance().getInstanceCount(scope)--; 129 129 throw; 130 130 } … … 138 138 orxout(internal_status) << "destroying scope... (" << scope << ")" << endl; 139 139 140 ScopeManager::getInstance Counts()[scope]--;140 ScopeManager::getInstance().getInstanceCount(scope)--; 141 141 142 142 // This shouldn't happen but just to be sure: check if the count is positive 143 assert(ScopeManager::getInstance Counts()[scope]>= 0);144 if (ScopeManager::getInstance Counts()[scope]< 0)145 ScopeManager::getInstance Counts()[scope]= 0;143 assert(ScopeManager::getInstance().getInstanceCount(scope) >= 0); 144 if (ScopeManager::getInstance().getInstanceCount(scope) < 0) 145 ScopeManager::getInstance().getInstanceCount(scope) = 0; 146 146 147 if (ScopeManager::getInstance Counts()[scope]== 0)147 if (ScopeManager::getInstance().getInstanceCount(scope) == 0) 148 148 this->deactivateListeners(); 149 149 … … 154 154 void deactivateListeners() 155 155 { 156 for (typename std::set<ScopeListener*>::iterator it = ScopeManager::get Listeners()[scope].begin(); it != ScopeManager::getListeners()[scope].end(); )156 for (typename std::set<ScopeListener*>::iterator it = ScopeManager::getInstance().getListeners(scope).begin(); it != ScopeManager::getInstance().getListeners(scope).end(); ) 157 157 { 158 158 if ((*it)->bActivated_) … … 172 172 static bool isActive() 173 173 { 174 return (ScopeManager::getInstance Counts()[scope]> 0);174 return (ScopeManager::getInstance().getInstanceCount(scope) > 0); 175 175 } 176 176 }; -
code/branches/core7/src/libraries/core/singleton/ScopeManager.cc
r10461 r10462 32 32 */ 33 33 34 #include "ScopeManager.h" 35 34 36 #include "Scope.h" 35 37 36 38 namespace orxonox 37 39 { 38 /* static*/ std::map<ScopeID::Value, int>& ScopeManager::getInstanceCounts()40 /* static */ ScopeManager& ScopeManager::getInstance() 39 41 { 40 static std::map<ScopeID::Value, int> instanceCounts;41 return instance Counts;42 static ScopeManager instance; 43 return instance; 42 44 } 43 /*static*/ std::map<ScopeID::Value, std::set<ScopeListener*> >& ScopeManager::getListeners() 45 46 void ScopeManager::addListener(ScopeListener* listener) 44 47 { 45 static std::map<ScopeID::Value, std::set<ScopeListener*> > listeners; 46 return listeners; 48 this->listeners_[listener->getScope()].insert(listener); 49 } 50 51 void ScopeManager::removeListener(ScopeListener* listener) 52 { 53 this->listeners_[listener->getScope()].erase(listener); 47 54 } 48 55 } -
code/branches/core7/src/libraries/core/singleton/ScopeManager.h
r10461 r10462 54 54 class _CoreExport ScopeManager 55 55 { 56 template <ScopeID::Value scope> 57 friend class Scope; 58 friend class StaticallyInitializedScopedSingletonWrapper; 56 public: 57 static ScopeManager& getInstance(); 58 59 void addListener(ScopeListener* listener); 60 void removeListener(ScopeListener* listener); 61 62 inline int& getInstanceCount(ScopeID::Value scope) 63 { return this->instanceCounts_[scope]; } 64 inline std::set<ScopeListener*>& getListeners(ScopeID::Value scope) 65 { return this->listeners_[scope]; } 59 66 60 67 private: 61 st atic std::map<ScopeID::Value, int>& getInstanceCounts(); //!< Counts the number of active instances (>0 means active) for a scope62 st atic std::map<ScopeID::Value, std::set<ScopeListener*> >& getListeners(); //!< Stores all listeners for a scope68 std::map<ScopeID::Value, int> instanceCounts_; //!< Counts the number of active instances (>0 means active) for a scope 69 std::map<ScopeID::Value, std::set<ScopeListener*> > listeners_; //!< Stores all listeners for a scope 63 70 }; 64 71 } -
code/branches/core7/src/libraries/core/singleton/ScopedSingletonIncludes.cc
r10460 r10462 33 33 void StaticallyInitializedScopedSingletonWrapper::load() 34 34 { 35 ScopeManager::get Listeners()[this->wrapper_->getScope()].insert(this->wrapper_);35 ScopeManager::getInstance().addListener(this->wrapper_); 36 36 } 37 37 38 38 void StaticallyInitializedScopedSingletonWrapper::unload() 39 39 { 40 ScopeManager::get Listeners()[this->wrapper_->getScope()].erase(this->wrapper_);40 ScopeManager::getInstance().removeListener(this->wrapper_); 41 41 } 42 42 }
Note: See TracChangeset
for help on using the changeset viewer.