Changeset 10412 for code/branches/core7/src/libraries/core/singleton
- Timestamp:
- May 2, 2015, 10:41:10 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/Scope.cc
r10407 r10412 36 36 namespace orxonox 37 37 { 38 std::map<ScopeID::Value, int> ScopeManager::instanceCounts_s; 39 std::map<ScopeID::Value, std::set<ScopeListener*> > ScopeManager::listeners_s; 38 /*static*/ std::map<ScopeID::Value, int>& ScopeManager::getInstanceCounts() 39 { 40 static std::map<ScopeID::Value, int> instanceCounts; 41 return instanceCounts; 42 } 43 /*static*/ std::map<ScopeID::Value, std::set<ScopeListener*> >& ScopeManager::getListeners() 44 { 45 static std::map<ScopeID::Value, std::set<ScopeListener*> > listeners; 46 return listeners; 47 } 40 48 } -
code/branches/core7/src/libraries/core/singleton/Scope.h
r10407 r10412 80 80 81 81 private: 82 static std::map<ScopeID::Value, int> instanceCounts_s; //!< Counts the number of active instances (>0 means active) for a scope83 static std::map<ScopeID::Value, std::set<ScopeListener*> > listeners_s; //!< Stores all listeners for a scope82 static std::map<ScopeID::Value, int>& getInstanceCounts(); //!< Counts the number of active instances (>0 means active) for a scope 83 static std::map<ScopeID::Value, std::set<ScopeListener*> >& getListeners(); //!< Stores all listeners for a scope 84 84 }; 85 85 … … 98 98 //! Constructor: Registers the instance. 99 99 ScopeListener(ScopeID::Value scope) : scope_(scope), bActivated_(false) 100 { ScopeManager:: listeners_s[this->scope_].insert(this); }100 { ScopeManager::getListeners()[this->scope_].insert(this); } 101 101 //! Destructor: Unregisters the instance. 102 102 virtual ~ScopeListener() 103 { ScopeManager:: listeners_s[this->scope_].erase(this); }103 { ScopeManager::getListeners()[this->scope_].erase(this); } 104 104 105 105 //! Gets called if the scope is activated … … 132 132 try 133 133 { 134 ScopeManager:: instanceCounts_s[scope]++;135 assert(ScopeManager:: instanceCounts_s[scope] > 0);136 if (ScopeManager:: instanceCounts_s[scope] == 1)134 ScopeManager::getInstanceCounts()[scope]++; 135 assert(ScopeManager::getInstanceCounts()[scope] > 0); 136 if (ScopeManager::getInstanceCounts()[scope] == 1) 137 137 { 138 138 Loki::ScopeGuard deactivator = Loki::MakeObjGuard(*this, &Scope::deactivateListeners); 139 for (typename std::set<ScopeListener*>::iterator it = ScopeManager:: listeners_s[scope].begin(); it != ScopeManager::listeners_s[scope].end(); )139 for (typename std::set<ScopeListener*>::iterator it = ScopeManager::getListeners()[scope].begin(); it != ScopeManager::getListeners()[scope].end(); ) 140 140 { 141 141 (*it)->activated(); … … 147 147 catch (...) 148 148 { 149 ScopeManager:: instanceCounts_s[scope]--;149 ScopeManager::getInstanceCounts()[scope]--; 150 150 throw; 151 151 } … … 159 159 orxout(internal_status) << "destroying scope... (" << scope << ")" << endl; 160 160 161 ScopeManager:: instanceCounts_s[scope]--;161 ScopeManager::getInstanceCounts()[scope]--; 162 162 163 163 // This shouldn't happen but just to be sure: check if the count is positive 164 assert(ScopeManager:: instanceCounts_s[scope] >= 0);165 if (ScopeManager:: instanceCounts_s[scope] < 0)166 ScopeManager:: instanceCounts_s[scope] = 0;167 168 if (ScopeManager:: instanceCounts_s[scope] == 0)164 assert(ScopeManager::getInstanceCounts()[scope] >= 0); 165 if (ScopeManager::getInstanceCounts()[scope] < 0) 166 ScopeManager::getInstanceCounts()[scope] = 0; 167 168 if (ScopeManager::getInstanceCounts()[scope] == 0) 169 169 this->deactivateListeners(); 170 170 … … 175 175 void deactivateListeners() 176 176 { 177 for (typename std::set<ScopeListener*>::iterator it = ScopeManager:: listeners_s[scope].begin(); it != ScopeManager::listeners_s[scope].end(); )177 for (typename std::set<ScopeListener*>::iterator it = ScopeManager::getListeners()[scope].begin(); it != ScopeManager::getListeners()[scope].end(); ) 178 178 { 179 179 if ((*it)->bActivated_) … … 193 193 static bool isActive() 194 194 { 195 return (ScopeManager:: instanceCounts_s[scope] > 0);195 return (ScopeManager::getInstanceCounts()[scope] > 0); 196 196 } 197 197 };
Note: See TracChangeset
for help on using the changeset viewer.