root/cafu/trunk/CaWE/ObserverPatternTools.hpp

Revision 457, 3.6 KB (checked in by Carsten, 4 months ago)

Using UltraEdit's multi-line search-and-replace-in-files feature, replaced


^#ifndef _(CAFU|CF|CFS|CA)_(.*)_$
^#define _\1_\2_$

with

#ifndef CAFU_\2_INCLUDED
#define CAFU_\2_INCLUDED

and


^#ifndef _(.*)_HPP_$
^#define _\1_HPP_$

with

#ifndef CAFU_\1_HPP_INCLUDED
#define CAFU_\1_HPP_INCLUDED

Closes #91.

Line 
1/*
2=================================================================================
3This file is part of Cafu, the open-source game engine and graphics engine
4for multiplayer, cross-platform, real-time 3D action.
5Copyright (C) 2002-2012 Carsten Fuchs Software.
6
7Cafu is free software: you can redistribute it and/or modify it under the terms
8of the GNU General Public License as published by the Free Software Foundation,
9either version 3 of the License, or (at your option) any later version.
10
11Cafu is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
12without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13PURPOSE. See the GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with Cafu. If not, see <http://www.gnu.org/licenses/>.
17
18For support and more information about Cafu, visit us at <http://www.cafu.de>.
19=================================================================================
20*/
21
22/// @file
23/// This file provides the classes for the Observer pattern as described in the book by the GoF.
24/// These classes are specific to the tools. See the map document related observer classes for more details.
25#ifndef CAFU_OBSERVER_PATTERN_TOOLS_HPP_INCLUDED
26#define CAFU_OBSERVER_PATTERN_TOOLS_HPP_INCLUDED
27
28#include "Templates/Array.hpp"
29
30
31class ToolT;
32class ToolsSubjectT;
33
34
35/// An enumeration that determines the urgency with which observers should update themselves when their subject has changed.
36enum ToolsUpdatePriorityT
37{
38    UPDATE_NOW,     ///< Update immediately, in real-time, before the function returns.
39    UPDATE_SOON     ///< Update as soon as convenient, at the next opportunity.
40};
41
42
43class ToolsObserverT
44{
45    public:
46
47    /// Notifies the observer that the current subject has been changed.
48    /// @param Subject    The tools (tool manager) in which something has changed.
49    /// @param Tool       The specific tool that has changed.
50    /// @param Priority   The priority with which the update should be implemented.
51    virtual void NotifySubjectChanged(ToolsSubjectT* Subject, ToolT* Tool, ToolsUpdatePriorityT Priority) { }
52
53    /// The virtual destructor.
54    virtual ~ToolsObserverT() { }
55
56
57    protected:
58
59    /// The constructor. It is protected so that only derived classes can create instances of this class.
60    ToolsObserverT() { }
61};
62
63
64class ToolsSubjectT
65{
66    public:
67
68    /// Registers the observer Obs for notification on changes in this class.
69    /// @param Obs   The observer that is to be registered.
70    virtual void RegisterObserver(ToolsObserverT* Obs);
71
72    /// Unregisters the observer Obs from further notification on changes in this class.
73    /// @param Obs   The observer that is to be unregistered.
74    virtual void UnregisterObserver(ToolsObserverT* Obs);
75
76    /// Notifies all observers that something in the given tool changed so that they update themselves.
77    /// @param Tool       The specific tool that has changed.
78    /// @param Priority   The priority with which the update should be implemented.
79    virtual void UpdateAllObservers(ToolT* Tool, ToolsUpdatePriorityT Priority);
80
81    /// The virtual destructor.
82    virtual ~ToolsSubjectT();
83
84
85    protected:
86
87    /// The constructor. It is protected so that only derived classes can create instances of this class.
88    ToolsSubjectT();
89
90
91    private:
92
93    /// The list of the observers that have registered for notification on updates of this class.
94    ArrayT<ToolsObserverT*> m_Observers;
95};
96
97#endif
Note: See TracBrowser for help on using the browser.