Changeset 5877 for code/branches/core5/src/libraries/util
- Timestamp:
- Oct 5, 2009, 1:34:10 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core5/src/libraries/util/Scope.h
r5867 r5877 35 35 #include <map> 36 36 #include <set> 37 37 38 #include "Debug.h" 39 #include "ScopeGuard.h" 38 40 39 41 namespace orxonox … … 63 65 protected: 64 66 //! Constructor: Registers the instance. 65 ScopeListener(ScopeID::Value scope) : scope_(scope) 67 ScopeListener(ScopeID::Value scope) : scope_(scope), bActivated_(false) 66 68 { ScopeManager::listeners_s[this->scope_].insert(this); } 67 69 //! Destructor: Unregisters the instance. … … 76 78 private: 77 79 ScopeID::Value scope_; //!< Store the scope to unregister on destruction 80 bool bActivated_; 78 81 }; 79 82 … … 91 94 Scope() 92 95 { 93 ScopeManager::instanceCounts_s[scope]++; 94 assert(ScopeManager::instanceCounts_s[scope] > 0); 95 if (ScopeManager::instanceCounts_s[scope] == 1) 96 try 96 97 { 97 for (typename std::set<ScopeListener*>::iterator it = ScopeManager::listeners_s[scope].begin(); it != ScopeManager::listeners_s[scope].end(); ) 98 (*(it++))->activated(); 98 ScopeManager::instanceCounts_s[scope]++; 99 assert(ScopeManager::instanceCounts_s[scope] > 0); 100 if (ScopeManager::instanceCounts_s[scope] == 1) 101 { 102 Loki::ScopeGuard deactivator = Loki::MakeObjGuard(*this, &Scope::deactivateListeners); 103 for (typename std::set<ScopeListener*>::iterator it = ScopeManager::listeners_s[scope].begin(); it != ScopeManager::listeners_s[scope].end(); ) 104 { 105 (*it)->activated(); 106 (*(it++))->bActivated_ = true; 107 } 108 deactivator.Dismiss(); 109 } 110 } 111 catch (...) 112 { 113 ScopeManager::instanceCounts_s[scope]--; 114 throw; 99 115 } 100 116 } … … 111 127 112 128 if (ScopeManager::instanceCounts_s[scope] == 0) 129 this->deactivateListeners(); 130 } 131 132 void deactivateListeners() 133 { 134 for (typename std::set<ScopeListener*>::iterator it = ScopeManager::listeners_s[scope].begin(); it != ScopeManager::listeners_s[scope].end(); ) 113 135 { 114 for (typename std::set<ScopeListener*>::iterator it = ScopeManager::listeners_s[scope].begin(); it != ScopeManager::listeners_s[scope].end(); ) 115 (*(it++))->deactivated(); 136 if ((*it)->bActivated_) 137 { 138 try 139 { (*it)->deactivated(); } 140 catch (...) 141 { COUT(0) << "ScopeListener::deactivated() failed! This MUST NOT happen, fix it!" << std::endl; } 142 (*(it++))->bActivated_ = false; 143 } 144 else 145 ++it; 116 146 } 117 147 }
Note: See TracChangeset
for help on using the changeset viewer.