[Orxonox-commit 5854] r10514 - code/branches/core7/src/libraries/core/singleton
landauf at orxonox.net
landauf at orxonox.net
Sun May 31 10:22:59 CEST 2015
Author: landauf
Date: 2015-05-31 10:22:59 +0200 (Sun, 31 May 2015)
New Revision: 10514
Modified:
code/branches/core7/src/libraries/core/singleton/Scope.h
code/branches/core7/src/libraries/core/singleton/ScopeManager.cc
code/branches/core7/src/libraries/core/singleton/ScopeManager.h
code/branches/core7/src/libraries/core/singleton/ScopedSingletonIncludes.cc
code/branches/core7/src/libraries/core/singleton/ScopedSingletonIncludes.h
code/branches/core7/src/libraries/core/singleton/ScopedSingletonWrapper.h
Log:
don't store scope in ScopeListener - instead register the listener in ScopeManager for a specific scope
Modified: code/branches/core7/src/libraries/core/singleton/Scope.h
===================================================================
--- code/branches/core7/src/libraries/core/singleton/Scope.h 2015-05-31 08:14:12 UTC (rev 10513)
+++ code/branches/core7/src/libraries/core/singleton/Scope.h 2015-05-31 08:22:59 UTC (rev 10514)
@@ -70,7 +70,7 @@
friend class ScopeManager;
protected:
- ScopeListener(ScopeID::Value scope) : scope_(scope), bActivated_(false) { }
+ ScopeListener() : bActivated_(false) { }
virtual ~ScopeListener() { }
//! Gets called if the scope is activated
@@ -78,12 +78,7 @@
//! Gets called if the scope is deactivated
virtual void deactivated() = 0;
- public:
- inline ScopeID::Value getScope() const
- { return this->scope_; }
-
private:
- ScopeID::Value scope_; //!< Store the scope to unregister on destruction
bool bActivated_;
};
Modified: code/branches/core7/src/libraries/core/singleton/ScopeManager.cc
===================================================================
--- code/branches/core7/src/libraries/core/singleton/ScopeManager.cc 2015-05-31 08:14:12 UTC (rev 10513)
+++ code/branches/core7/src/libraries/core/singleton/ScopeManager.cc 2015-05-31 08:22:59 UTC (rev 10514)
@@ -60,14 +60,14 @@
return this->activeScopes_.find(scope) != this->activeScopes_.end();
}
- void ScopeManager::addListener(ScopeListener* listener)
+ void ScopeManager::addListener(ScopeListener* listener, ScopeID::Value scope)
{
- this->listeners_[listener->getScope()].insert(listener);
+ this->listeners_[scope].insert(listener);
}
- void ScopeManager::removeListener(ScopeListener* listener)
+ void ScopeManager::removeListener(ScopeListener* listener, ScopeID::Value scope)
{
- this->listeners_[listener->getScope()].erase(listener);
+ this->listeners_[scope].erase(listener);
}
void ScopeManager::activateListenersForScope(ScopeID::Value scope)
Modified: code/branches/core7/src/libraries/core/singleton/ScopeManager.h
===================================================================
--- code/branches/core7/src/libraries/core/singleton/ScopeManager.h 2015-05-31 08:14:12 UTC (rev 10513)
+++ code/branches/core7/src/libraries/core/singleton/ScopeManager.h 2015-05-31 08:22:59 UTC (rev 10514)
@@ -64,9 +64,9 @@
bool isActive(ScopeID::Value scope);
/** Registers a listener for the given scope. */
- void addListener(ScopeListener* listener);
+ void addListener(ScopeListener* listener, ScopeID::Value scope);
/** Unregisters a listener for the given scope. */
- void removeListener(ScopeListener* listener);
+ void removeListener(ScopeListener* listener, ScopeID::Value scope);
private:
void activateListenersForScope(ScopeID::Value scope);
Modified: code/branches/core7/src/libraries/core/singleton/ScopedSingletonIncludes.cc
===================================================================
--- code/branches/core7/src/libraries/core/singleton/ScopedSingletonIncludes.cc 2015-05-31 08:14:12 UTC (rev 10513)
+++ code/branches/core7/src/libraries/core/singleton/ScopedSingletonIncludes.cc 2015-05-31 08:22:59 UTC (rev 10514)
@@ -32,11 +32,11 @@
{
void StaticallyInitializedScopedSingletonWrapper::load()
{
- ScopeManager::getInstance().addListener(this->wrapper_);
+ ScopeManager::getInstance().addListener(this->wrapper_, this->scope_);
}
void StaticallyInitializedScopedSingletonWrapper::unload()
{
- ScopeManager::getInstance().removeListener(this->wrapper_);
+ ScopeManager::getInstance().removeListener(this->wrapper_, this->scope_);
}
}
Modified: code/branches/core7/src/libraries/core/singleton/ScopedSingletonIncludes.h
===================================================================
--- code/branches/core7/src/libraries/core/singleton/ScopedSingletonIncludes.h 2015-05-31 08:14:12 UTC (rev 10513)
+++ code/branches/core7/src/libraries/core/singleton/ScopedSingletonIncludes.h 2015-05-31 08:22:59 UTC (rev 10514)
@@ -72,14 +72,17 @@
#define ManageScopedSingleton(className, scope, allowedToFail) \
className* className::singletonPtr_s = NULL; \
static ScopedSingletonWrapper& className##ScopedSingletonWrapper \
- = (new orxonox::SI_SSW(new ClassScopedSingletonWrapper<className, scope, allowedToFail>(#className)))->getWrapper()
+ = (new orxonox::SI_SSW(new ClassScopedSingletonWrapper<className, allowedToFail>(#className), scope))->getWrapper()
namespace orxonox
{
class _CoreExport StaticallyInitializedScopedSingletonWrapper : public StaticallyInitializedInstance
{
public:
- StaticallyInitializedScopedSingletonWrapper(ScopedSingletonWrapper* wrapper) : wrapper_(wrapper) {}
+ StaticallyInitializedScopedSingletonWrapper(ScopedSingletonWrapper* wrapper, ScopeID::Value scope)
+ : wrapper_(wrapper)
+ , scope_(scope)
+ {}
virtual void load();
virtual void unload();
@@ -89,6 +92,7 @@
private:
ScopedSingletonWrapper* wrapper_;
+ ScopeID::Value scope_;
};
typedef StaticallyInitializedScopedSingletonWrapper SI_SSW;
Modified: code/branches/core7/src/libraries/core/singleton/ScopedSingletonWrapper.h
===================================================================
--- code/branches/core7/src/libraries/core/singleton/ScopedSingletonWrapper.h 2015-05-31 08:14:12 UTC (rev 10513)
+++ code/branches/core7/src/libraries/core/singleton/ScopedSingletonWrapper.h 2015-05-31 08:22:59 UTC (rev 10514)
@@ -60,9 +60,8 @@
{
public:
/// Constructor: Initializes all the values
- ScopedSingletonWrapper(const std::string& className, ScopeID::Value scope)
- : ScopeListener(scope)
- , className_(className)
+ ScopedSingletonWrapper(const std::string& className)
+ : className_(className)
{ }
virtual ~ScopedSingletonWrapper() { }
@@ -73,12 +72,11 @@
/**
@anchor ClassScopedSingletonWrapper
- @brief Manages a scoped singleton for a given scope.
+ @brief Manages a scoped singleton
@param T The managed singleton class
- @param scope The scope in which the singleton @a T should be active
@param allowedToFail If true, a specialization of this template is used, that uses try-catch blocks to handle possible failures.
- This class inherits from ScopeListener for the given scope and thus its functions
+ This class inherits from ScopeListener and is registered for a scope in ScopeManager and thus its functions
activated() and deactivated() are called whenever the Scope changes its state.
If the Scope is activated, a new instance of @a T (which must be a singleton) is created.
@@ -86,13 +84,12 @@
@see Singleton
*/
- template <class T, ScopeID::Value scope, bool allowedToFail>
+ template <class T, bool allowedToFail>
class ClassScopedSingletonWrapper : public ScopedSingletonWrapper
{
public:
- //! Constructor: Initializes the singleton pointer and passes the scope to ScopedSingletonWrapper and ScopeListener
ClassScopedSingletonWrapper(const std::string& className)
- : ScopedSingletonWrapper(className, scope)
+ : ScopedSingletonWrapper(className)
, singletonPtr_(NULL)
{
}
@@ -134,20 +131,18 @@
/**
@brief This class partially spezializes ClassScopedSingletonWrapper for classes @a T that are allowed to fail.
@param T The managed singleton class
- @param scope The scope in which the singleton @a T should be active
Because @a T could fail when being created, this partial spezialization of ClassScopedSingletonWrapper
uses a try-catch block to handle exceptions.
See @ref ClassScopedSingletonWrapper for a full documentation of the basis template.
*/
- template <class T, ScopeID::Value scope>
- class ClassScopedSingletonWrapper<T, scope, true> : public ScopedSingletonWrapper
+ template <class T>
+ class ClassScopedSingletonWrapper<T, true> : public ScopedSingletonWrapper
{
public:
- //! Constructor: Initializes the singleton pointer and passes the scope to ScopedSingletonWrapper and ScopeListener
ClassScopedSingletonWrapper(const std::string& className)
- : ScopedSingletonWrapper(className, scope)
+ : ScopedSingletonWrapper(className)
, singletonPtr_(NULL)
{
}
More information about the Orxonox-commit
mailing list