Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10513


Ignore:
Timestamp:
May 31, 2015, 10:14:12 AM (10 years ago)
Author:
landauf
Message:

refactoring: moved code from Scope.h into ScopeManager

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  
    6868    class _CoreExport ScopeListener
    6969    {
    70         template <ScopeID::Value scope>
    71         friend class Scope;
     70        friend class ScopeManager;
    7271
    7372        protected:
     
    108107                Loki::ScopeGuard deactivator = Loki::MakeObjGuard(*this, &Scope::deactivateScope);
    109108                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                 }
    115109                deactivator.Dismiss();
    116110
     
    132126            {
    133127                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                         try
    139                             { (*it)->deactivated(); }
    140                         catch (...)
    141                             { orxout(internal_warning) << "ScopeListener::deactivated() failed! This MUST NOT happen, fix it!" << endl; }
    142                         (*(it++))->bActivated_ = false;
    143                     }
    144                     else
    145                         ++it;
    146                 }
    147128            }
    148129
  • code/branches/core7/src/libraries/core/singleton/ScopeManager.cc

    r10463 r10513  
    2929/**
    3030    @file
    31     @brief Static linkage of the two maps in orxonox::ScopeManager.
     31    @brief Implementation of orxonox::ScopeManager.
    3232*/
    3333
     
    4747    {
    4848        this->activeScopes_.insert(scope);
     49        this->activateListenersForScope(scope);
    4950    }
    5051
     
    5253    {
    5354        this->activeScopes_.erase(scope);
     55        this->deactivateListenersForScope(scope);
    5456    }
    5557
     
    6870        this->listeners_[listener->getScope()].erase(listener);
    6971    }
     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    }
    70100}
  • code/branches/core7/src/libraries/core/singleton/ScopeManager.h

    r10463 r10513  
    5757            static ScopeManager& getInstance();
    5858
     59            /** Adds a scope and activates all listeners which are registered for this scope */
    5960            void addScope(ScopeID::Value scope);
     61            /** Removes a scope and deactivates all listeners which are registered for this scope */
    6062            void removeScope(ScopeID::Value scope);
     63            /** Returns true if this scope is active */
    6164            bool isActive(ScopeID::Value scope);
    6265
     66            /** Registers a listener for the given scope. */
    6367            void addListener(ScopeListener* listener);
     68            /** Unregisters a listener for the given scope. */
    6469            void removeListener(ScopeListener* listener);
    6570
    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);
    6874
    69         private:
     75            void activateListener(ScopeListener* listener);
     76            void deactivateListener(ScopeListener* listener);
     77
    7078            std::set<ScopeID::Value> activeScopes_;
    7179            std::map<ScopeID::Value, std::set<ScopeListener*> > listeners_; //!< Stores all listeners for a scope
Note: See TracChangeset for help on using the changeset viewer.