Changeset 10513
- Timestamp:
- May 31, 2015, 10:14:12 AM (9 years ago)
- Location:
- code/branches/core7/src/libraries/core/singleton
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core7/src/libraries/core/singleton/Scope.h
r10463 r10513 68 68 class _CoreExport ScopeListener 69 69 { 70 template <ScopeID::Value scope> 71 friend class Scope; 70 friend class ScopeManager; 72 71 73 72 protected: … … 108 107 Loki::ScopeGuard deactivator = Loki::MakeObjGuard(*this, &Scope::deactivateScope); 109 108 ScopeManager::getInstance().addScope(scope); 110 for (typename std::set<ScopeListener*>::iterator it = ScopeManager::getInstance().getListeners(scope).begin(); it != ScopeManager::getInstance().getListeners(scope).end(); )111 {112 (*it)->activated();113 (*(it++))->bActivated_ = true;114 }115 109 deactivator.Dismiss(); 116 110 … … 132 126 { 133 127 ScopeManager::getInstance().removeScope(scope); 134 for (typename std::set<ScopeListener*>::iterator it = ScopeManager::getInstance().getListeners(scope).begin(); it != ScopeManager::getInstance().getListeners(scope).end(); )135 {136 if ((*it)->bActivated_)137 {138 try139 { (*it)->deactivated(); }140 catch (...)141 { orxout(internal_warning) << "ScopeListener::deactivated() failed! This MUST NOT happen, fix it!" << endl; }142 (*(it++))->bActivated_ = false;143 }144 else145 ++it;146 }147 128 } 148 129 -
code/branches/core7/src/libraries/core/singleton/ScopeManager.cc
r10463 r10513 29 29 /** 30 30 @file 31 @brief Static linkage of the two maps inorxonox::ScopeManager.31 @brief Implementation of orxonox::ScopeManager. 32 32 */ 33 33 … … 47 47 { 48 48 this->activeScopes_.insert(scope); 49 this->activateListenersForScope(scope); 49 50 } 50 51 … … 52 53 { 53 54 this->activeScopes_.erase(scope); 55 this->deactivateListenersForScope(scope); 54 56 } 55 57 … … 68 70 this->listeners_[listener->getScope()].erase(listener); 69 71 } 72 73 void ScopeManager::activateListenersForScope(ScopeID::Value scope) 74 { 75 for (typename std::set<ScopeListener*>::iterator it = this->listeners_[scope].begin(); it != this->listeners_[scope].end(); ++it) 76 this->activateListener(*it); 77 } 78 79 void ScopeManager::deactivateListenersForScope(ScopeID::Value scope) 80 { 81 for (typename std::set<ScopeListener*>::iterator it = this->listeners_[scope].begin(); it != this->listeners_[scope].end(); ++it) 82 if ((*it)->bActivated_) 83 this->deactivateListener(*it); 84 } 85 86 void ScopeManager::activateListener(ScopeListener* listener) 87 { 88 listener->activated(); 89 listener->bActivated_ = true; 90 } 91 92 void ScopeManager::deactivateListener(ScopeListener* listener) 93 { 94 try 95 { listener->deactivated(); } 96 catch (...) 97 { orxout(internal_warning) << "ScopeListener::deactivated() failed! This MUST NOT happen, fix it!" << endl; } 98 listener->bActivated_ = false; 99 } 70 100 } -
code/branches/core7/src/libraries/core/singleton/ScopeManager.h
r10463 r10513 57 57 static ScopeManager& getInstance(); 58 58 59 /** Adds a scope and activates all listeners which are registered for this scope */ 59 60 void addScope(ScopeID::Value scope); 61 /** Removes a scope and deactivates all listeners which are registered for this scope */ 60 62 void removeScope(ScopeID::Value scope); 63 /** Returns true if this scope is active */ 61 64 bool isActive(ScopeID::Value scope); 62 65 66 /** Registers a listener for the given scope. */ 63 67 void addListener(ScopeListener* listener); 68 /** Unregisters a listener for the given scope. */ 64 69 void removeListener(ScopeListener* listener); 65 70 66 inline std::set<ScopeListener*>& getListeners(ScopeID::Value scope) 67 { return this->listeners_[scope]; } 71 private: 72 void activateListenersForScope(ScopeID::Value scope); 73 void deactivateListenersForScope(ScopeID::Value scope); 68 74 69 private: 75 void activateListener(ScopeListener* listener); 76 void deactivateListener(ScopeListener* listener); 77 70 78 std::set<ScopeID::Value> activeScopes_; 71 79 std::map<ScopeID::Value, std::set<ScopeListener*> > listeners_; //!< Stores all listeners for a scope
Note: See TracChangeset
for help on using the changeset viewer.