Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10514 for code/branches/core7


Ignore:
Timestamp:
May 31, 2015, 10:22:59 AM (9 years ago)
Author:
landauf
Message:

don't store scope in ScopeListener - instead register the listener in ScopeManager for a specific scope

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  
    7171
    7272        protected:
    73             ScopeListener(ScopeID::Value scope) : scope_(scope), bActivated_(false) { }
     73            ScopeListener() : bActivated_(false) { }
    7474            virtual ~ScopeListener() { }
    7575
     
    7979            virtual void deactivated() = 0;
    8080
    81         public:
    82             inline ScopeID::Value getScope() const
    83                 { return this->scope_; }
    84 
    8581        private:
    86             ScopeID::Value scope_; //!< Store the scope to unregister on destruction
    8782            bool bActivated_;
    8883    };
  • code/branches/core7/src/libraries/core/singleton/ScopeManager.cc

    r10513 r10514  
    6161    }
    6262
    63     void ScopeManager::addListener(ScopeListener* listener)
     63    void ScopeManager::addListener(ScopeListener* listener, ScopeID::Value scope)
    6464    {
    65         this->listeners_[listener->getScope()].insert(listener);
     65        this->listeners_[scope].insert(listener);
    6666    }
    6767
    68     void ScopeManager::removeListener(ScopeListener* listener)
     68    void ScopeManager::removeListener(ScopeListener* listener, ScopeID::Value scope)
    6969    {
    70         this->listeners_[listener->getScope()].erase(listener);
     70        this->listeners_[scope].erase(listener);
    7171    }
    7272
  • code/branches/core7/src/libraries/core/singleton/ScopeManager.h

    r10513 r10514  
    6565
    6666            /** Registers a listener for the given scope. */
    67             void addListener(ScopeListener* listener);
     67            void addListener(ScopeListener* listener, ScopeID::Value scope);
    6868            /** Unregisters a listener for the given scope. */
    69             void removeListener(ScopeListener* listener);
     69            void removeListener(ScopeListener* listener, ScopeID::Value scope);
    7070
    7171        private:
  • code/branches/core7/src/libraries/core/singleton/ScopedSingletonIncludes.cc

    r10462 r10514  
    3333    void StaticallyInitializedScopedSingletonWrapper::load()
    3434    {
    35         ScopeManager::getInstance().addListener(this->wrapper_);
     35        ScopeManager::getInstance().addListener(this->wrapper_, this->scope_);
    3636    }
    3737
    3838    void StaticallyInitializedScopedSingletonWrapper::unload()
    3939    {
    40         ScopeManager::getInstance().removeListener(this->wrapper_);
     40        ScopeManager::getInstance().removeListener(this->wrapper_, this->scope_);
    4141    }
    4242}
  • code/branches/core7/src/libraries/core/singleton/ScopedSingletonIncludes.h

    r10481 r10514  
    7373    className* className::singletonPtr_s = NULL; \
    7474    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()
    7676
    7777namespace orxonox
     
    8080    {
    8181        public:
    82             StaticallyInitializedScopedSingletonWrapper(ScopedSingletonWrapper* wrapper) : wrapper_(wrapper) {}
     82            StaticallyInitializedScopedSingletonWrapper(ScopedSingletonWrapper* wrapper, ScopeID::Value scope)
     83                : wrapper_(wrapper)
     84                , scope_(scope)
     85            {}
    8386
    8487            virtual void load();
     
    9093        private:
    9194            ScopedSingletonWrapper* wrapper_;
     95            ScopeID::Value scope_;
    9296    };
    9397
  • code/branches/core7/src/libraries/core/singleton/ScopedSingletonWrapper.h

    r10460 r10514  
    6161        public:
    6262            /// 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)
    6665            { }
    6766            virtual ~ScopedSingletonWrapper() { }
     
    7473        @anchor ClassScopedSingletonWrapper
    7574
    76         @brief Manages a scoped singleton for a given scope.
     75        @brief Manages a scoped singleton
    7776        @param T The managed singleton class
    78         @param scope The scope in which the singleton @a T should be active
    7977        @param allowedToFail If true, a specialization of this template is used, that uses try-catch blocks to handle possible failures.
    8078
    81         This class inherits from ScopeListener for the given scope and thus its functions
     79        This class inherits from ScopeListener and is registered for a scope in ScopeManager and thus its functions
    8280        activated() and deactivated() are called whenever the Scope changes its state.
    8381
     
    8785        @see Singleton
    8886    */
    89     template <class T, ScopeID::Value scope, bool allowedToFail>
     87    template <class T, bool allowedToFail>
    9088    class ClassScopedSingletonWrapper : public ScopedSingletonWrapper
    9189    {
    9290    public:
    93         //! Constructor: Initializes the singleton pointer and passes the scope to ScopedSingletonWrapper and ScopeListener
    9491        ClassScopedSingletonWrapper(const std::string& className)
    95             : ScopedSingletonWrapper(className, scope)
     92            : ScopedSingletonWrapper(className)
    9693            , singletonPtr_(NULL)
    9794        {
     
    135132        @brief This class partially spezializes ClassScopedSingletonWrapper for classes @a T that are allowed to fail.
    136133        @param T The managed singleton class
    137         @param scope The scope in which the singleton @a T should be active
    138134
    139135        Because @a T could fail when being created, this partial spezialization of ClassScopedSingletonWrapper
     
    142138        See @ref ClassScopedSingletonWrapper for a full documentation of the basis template.
    143139    */
    144     template <class T, ScopeID::Value scope>
    145     class ClassScopedSingletonWrapper<T, scope, true> : public ScopedSingletonWrapper
     140    template <class T>
     141    class ClassScopedSingletonWrapper<T, true> : public ScopedSingletonWrapper
    146142    {
    147143    public:
    148         //! Constructor: Initializes the singleton pointer and passes the scope to ScopedSingletonWrapper and ScopeListener
    149144        ClassScopedSingletonWrapper(const std::string& className)
    150             : ScopedSingletonWrapper(className, scope)
     145            : ScopedSingletonWrapper(className)
    151146            , singletonPtr_(NULL)
    152147        {
Note: See TracChangeset for help on using the changeset viewer.