Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core7/src/libraries/core/singleton/ScopeManager.cc @ 10538

Last change on this file since 10538 was 10538, checked in by landauf, 9 years ago

now that the order of initialization is well defined (first identifiers, then singletons) we can safely create singletons right after they are registered (and unload them again when they are unregistered). this reverts changes from r10517

  • Property svn:eol-style set to native
File size: 3.1 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Fabian 'x3n' Landau
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29/**
30    @file
31    @brief Implementation of orxonox::ScopeManager.
32*/
33
34#include "ScopeManager.h"
35
36#include "Scope.h"
37
38namespace orxonox
39{
40    /* static */ ScopeManager& ScopeManager::getInstance()
41    {
42        static ScopeManager instance;
43        return instance;
44    }
45
46    void ScopeManager::addScope(ScopeID::Value scope)
47    {
48        this->activeScopes_.insert(scope);
49        this->activateListenersForScope(scope);
50    }
51
52    void ScopeManager::removeScope(ScopeID::Value scope)
53    {
54        this->activeScopes_.erase(scope);
55        this->deactivateListenersForScope(scope);
56    }
57
58    bool ScopeManager::isActive(ScopeID::Value scope)
59    {
60        return this->activeScopes_.find(scope) != this->activeScopes_.end();
61    }
62
63    void ScopeManager::addListener(ScopeListener* listener, ScopeID::Value scope)
64    {
65        this->listeners_[scope].insert(listener);
66        if (this->isActive(scope))
67            this->activateListener(listener);
68    }
69
70    void ScopeManager::removeListener(ScopeListener* listener, ScopeID::Value scope)
71    {
72        if (this->isActive(scope))
73            this->deactivateListener(listener);
74        this->listeners_[scope].erase(listener);
75    }
76
77    void ScopeManager::activateListenersForScope(ScopeID::Value scope)
78    {
79        for (std::set<ScopeListener*>::iterator it = this->listeners_[scope].begin(); it != this->listeners_[scope].end(); ++it)
80            this->activateListener(*it);
81    }
82
83    void ScopeManager::deactivateListenersForScope(ScopeID::Value scope)
84    {
85        for (std::set<ScopeListener*>::iterator it = this->listeners_[scope].begin(); it != this->listeners_[scope].end(); ++it)
86            this->deactivateListener(*it);
87    }
88
89    void ScopeManager::activateListener(ScopeListener* listener)
90    {
91        listener->activated();
92        listener->bActivated_ = true;
93    }
94
95    void ScopeManager::deactivateListener(ScopeListener* listener)
96    {
97        if (listener->bActivated_)
98        {
99            try
100                { listener->deactivated(); }
101            catch (...)
102                { orxout(internal_warning) << "ScopeListener::deactivated() failed! This MUST NOT happen, fix it!" << endl; }
103            listener->bActivated_ = false;
104        }
105    }
106}
Note: See TracBrowser for help on using the repository browser.