Changeset 10514
- Timestamp:
- May 31, 2015, 10:22:59 AM (9 years ago)
- Location:
- code/branches/core7/src/libraries/core/singleton
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core7/src/libraries/core/singleton/Scope.h
r10513 r10514 71 71 72 72 protected: 73 ScopeListener( ScopeID::Value scope) : scope_(scope),bActivated_(false) { }73 ScopeListener() : bActivated_(false) { } 74 74 virtual ~ScopeListener() { } 75 75 … … 79 79 virtual void deactivated() = 0; 80 80 81 public:82 inline ScopeID::Value getScope() const83 { return this->scope_; }84 85 81 private: 86 ScopeID::Value scope_; //!< Store the scope to unregister on destruction87 82 bool bActivated_; 88 83 }; -
code/branches/core7/src/libraries/core/singleton/ScopeManager.cc
r10513 r10514 61 61 } 62 62 63 void ScopeManager::addListener(ScopeListener* listener )63 void ScopeManager::addListener(ScopeListener* listener, ScopeID::Value scope) 64 64 { 65 this->listeners_[ listener->getScope()].insert(listener);65 this->listeners_[scope].insert(listener); 66 66 } 67 67 68 void ScopeManager::removeListener(ScopeListener* listener )68 void ScopeManager::removeListener(ScopeListener* listener, ScopeID::Value scope) 69 69 { 70 this->listeners_[ listener->getScope()].erase(listener);70 this->listeners_[scope].erase(listener); 71 71 } 72 72 -
code/branches/core7/src/libraries/core/singleton/ScopeManager.h
r10513 r10514 65 65 66 66 /** Registers a listener for the given scope. */ 67 void addListener(ScopeListener* listener );67 void addListener(ScopeListener* listener, ScopeID::Value scope); 68 68 /** Unregisters a listener for the given scope. */ 69 void removeListener(ScopeListener* listener );69 void removeListener(ScopeListener* listener, ScopeID::Value scope); 70 70 71 71 private: -
code/branches/core7/src/libraries/core/singleton/ScopedSingletonIncludes.cc
r10462 r10514 33 33 void StaticallyInitializedScopedSingletonWrapper::load() 34 34 { 35 ScopeManager::getInstance().addListener(this->wrapper_ );35 ScopeManager::getInstance().addListener(this->wrapper_, this->scope_); 36 36 } 37 37 38 38 void StaticallyInitializedScopedSingletonWrapper::unload() 39 39 { 40 ScopeManager::getInstance().removeListener(this->wrapper_ );40 ScopeManager::getInstance().removeListener(this->wrapper_, this->scope_); 41 41 } 42 42 } -
code/branches/core7/src/libraries/core/singleton/ScopedSingletonIncludes.h
r10481 r10514 73 73 className* className::singletonPtr_s = NULL; \ 74 74 static ScopedSingletonWrapper& className##ScopedSingletonWrapper \ 75 = (new orxonox::SI_SSW(new ClassScopedSingletonWrapper<className, scope, allowedToFail>(#className)))->getWrapper()75 = (new orxonox::SI_SSW(new ClassScopedSingletonWrapper<className, allowedToFail>(#className), scope))->getWrapper() 76 76 77 77 namespace orxonox … … 80 80 { 81 81 public: 82 StaticallyInitializedScopedSingletonWrapper(ScopedSingletonWrapper* wrapper) : wrapper_(wrapper) {} 82 StaticallyInitializedScopedSingletonWrapper(ScopedSingletonWrapper* wrapper, ScopeID::Value scope) 83 : wrapper_(wrapper) 84 , scope_(scope) 85 {} 83 86 84 87 virtual void load(); … … 90 93 private: 91 94 ScopedSingletonWrapper* wrapper_; 95 ScopeID::Value scope_; 92 96 }; 93 97 -
code/branches/core7/src/libraries/core/singleton/ScopedSingletonWrapper.h
r10460 r10514 61 61 public: 62 62 /// Constructor: Initializes all the values 63 ScopedSingletonWrapper(const std::string& className, ScopeID::Value scope) 64 : ScopeListener(scope) 65 , className_(className) 63 ScopedSingletonWrapper(const std::string& className) 64 : className_(className) 66 65 { } 67 66 virtual ~ScopedSingletonWrapper() { } … … 74 73 @anchor ClassScopedSingletonWrapper 75 74 76 @brief Manages a scoped singleton for a given scope.75 @brief Manages a scoped singleton 77 76 @param T The managed singleton class 78 @param scope The scope in which the singleton @a T should be active79 77 @param allowedToFail If true, a specialization of this template is used, that uses try-catch blocks to handle possible failures. 80 78 81 This class inherits from ScopeListener for the given scopeand thus its functions79 This class inherits from ScopeListener and is registered for a scope in ScopeManager and thus its functions 82 80 activated() and deactivated() are called whenever the Scope changes its state. 83 81 … … 87 85 @see Singleton 88 86 */ 89 template <class T, ScopeID::Value scope,bool allowedToFail>87 template <class T, bool allowedToFail> 90 88 class ClassScopedSingletonWrapper : public ScopedSingletonWrapper 91 89 { 92 90 public: 93 //! Constructor: Initializes the singleton pointer and passes the scope to ScopedSingletonWrapper and ScopeListener94 91 ClassScopedSingletonWrapper(const std::string& className) 95 : ScopedSingletonWrapper(className , scope)92 : ScopedSingletonWrapper(className) 96 93 , singletonPtr_(NULL) 97 94 { … … 135 132 @brief This class partially spezializes ClassScopedSingletonWrapper for classes @a T that are allowed to fail. 136 133 @param T The managed singleton class 137 @param scope The scope in which the singleton @a T should be active138 134 139 135 Because @a T could fail when being created, this partial spezialization of ClassScopedSingletonWrapper … … 142 138 See @ref ClassScopedSingletonWrapper for a full documentation of the basis template. 143 139 */ 144 template <class T , ScopeID::Value scope>145 class ClassScopedSingletonWrapper<T, scope,true> : public ScopedSingletonWrapper140 template <class T> 141 class ClassScopedSingletonWrapper<T, true> : public ScopedSingletonWrapper 146 142 { 147 143 public: 148 //! Constructor: Initializes the singleton pointer and passes the scope to ScopedSingletonWrapper and ScopeListener149 144 ClassScopedSingletonWrapper(const std::string& className) 150 : ScopedSingletonWrapper(className , scope)145 : ScopedSingletonWrapper(className) 151 146 , singletonPtr_(NULL) 152 147 {
Note: See TracChangeset
for help on using the changeset viewer.