| 1 | /* |
|---|
| 2 | ================================================================================= |
|---|
| 3 | This file is part of Cafu, the open-source game engine and graphics engine |
|---|
| 4 | for multiplayer, cross-platform, real-time 3D action. |
|---|
| 5 | Copyright (C) 2002-2012 Carsten Fuchs Software. |
|---|
| 6 | |
|---|
| 7 | Cafu is free software: you can redistribute it and/or modify it under the terms |
|---|
| 8 | of the GNU General Public License as published by the Free Software Foundation, |
|---|
| 9 | either version 3 of the License, or (at your option) any later version. |
|---|
| 10 | |
|---|
| 11 | Cafu is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
|---|
| 12 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
|---|
| 13 | PURPOSE. See the GNU General Public License for more details. |
|---|
| 14 | |
|---|
| 15 | You should have received a copy of the GNU General Public License |
|---|
| 16 | along with Cafu. If not, see <http://www.gnu.org/licenses/>. |
|---|
| 17 | |
|---|
| 18 | For 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 | |
|---|
| 31 | class ToolT; |
|---|
| 32 | class ToolsSubjectT; |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | /// An enumeration that determines the urgency with which observers should update themselves when their subject has changed. |
|---|
| 36 | enum 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 | |
|---|
| 43 | class 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 | |
|---|
| 64 | class 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 |
|---|