Orxonox  0.0.5 Codename: Arcturus
Scope.h
Go to the documentation of this file.
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 
47 #ifndef __Core_Scope_H__
48 #define __Core_Scope_H__
49 
50 #include "core/CorePrereqs.h"
51 
52 #include <cassert>
53 #include <map>
54 #include <set>
55 #include <loki/ScopeGuard.h>
56 
57 #include "util/Output.h"
58 #include "ScopeManager.h"
59 
60 namespace orxonox
61 {
69  {
70  friend class ScopeManager;
71 
72  protected:
73  ScopeListener() : bActivated_(false) { }
74  virtual ~ScopeListener() = default;
75 
77  virtual void activated() = 0;
79  virtual void deactivated() = 0;
80 
81  private:
83  };
84 
93  template <ScopeID::Value scope>
94  class Scope
95  {
96  public:
99  {
100  orxout(internal_status) << "creating scope... (" << scope << ")" << endl;
101 
104  deactivator.Dismiss();
105 
106  orxout(internal_status) << "created scope (" << scope << ")" << endl;
107  }
108 
111  {
112  orxout(internal_status) << "destroying scope... (" << scope << ")" << endl;
113 
114  this->deactivateScope();
115 
116  orxout(internal_status) << "destroyed scope (" << scope << ")" << endl;
117  }
118 
121  {
123  }
124 
126  static bool isActive()
127  {
128  return ScopeManager::getInstance().isActive(scope);
129  }
130  };
131 }
132 
133 #endif /* __Core_Scope_H__ */
ObjScopeGuardImpl0< Obj, MemFun > MakeObjGuard(Obj &obj, MemFun memFun)
Definition: ScopeGuard.h:441
~Scope()
Destructor: deactivate the listeners.
Definition: Scope.h:110
void removeScope(ScopeID::Value scope)
Removes a scope and deactivates all listeners which are registered for this scope.
Definition: ScopeManager.cc:48
ScopeListeners register themselves in the corresponding Scope and wait for notifications.
Definition: Scope.h:68
Shared library macros, enums, constants and forward declarations for the core library ...
void Dismiss() const
Definition: ScopeGuard.h:82
void addScope(ScopeID::Value scope)
Adds a scope and activates all listeners which are registered for this scope.
Definition: ScopeManager.cc:42
void deactivateScope()
Deactivates the listeners of this scope in case the scope is destroyed or the construction fails...
Definition: Scope.h:120
bool bActivated_
Definition: Scope.h:82
Output level, used to log the program&#39;s internal state in the log file.
Definition: OutputDefinitions.h:97
bool isActive(ScopeID::Value scope)
Returns true if this scope is active.
Definition: ScopeManager.cc:54
static bool isActive()
Returns true if the scope is active.
Definition: Scope.h:126
Declaration of orxonox::ScopeManager.
OutputStream & orxout(OutputLevel level=level::debug_output, const OutputContextContainer &context=context::undefined())
This helper function returns a reference to a commonly used instance of OutputStream.
Definition: Output.h:81
Die Wagnis Klasse hat die folgenden Aufgaben:
Definition: ApplicationPaths.cc:66
#define _CoreExport
Definition: CorePrereqs.h:61
ScopeListener()
Definition: Scope.h:73
Defines the helper function orxout() and includes all necessary headers to use the output system...
Scope()
Constructor: activate the listeners.
Definition: Scope.h:98
Base class used by all ScopeGuard implementations.
Definition: ScopeGuard.h:47
The ScopeManager stores the variables of the Scope templates in a statically linked context...
Definition: ScopeManager.h:56
A scope for a given template argument is either active or not.
Definition: CorePrereqs.h:219
static ScopeManager & getInstance()
Returns a reference to the singleton instance.
Definition: Singleton.h:118