Cafu Engine
ObserverPatternTools.hpp
Go to the documentation of this file.
1 /*
2 Cafu Engine, http://www.cafu.de/
3 Copyright (c) Carsten Fuchs and other contributors.
4 This project is licensed under the terms of the MIT license.
5 */
6 
7 /// @file
8 /// This file provides the classes for the Observer pattern as described in the book by the GoF.
9 /// These classes are specific to the tools. See the map document related observer classes for more details.
10 #ifndef CAFU_OBSERVER_PATTERN_TOOLS_HPP_INCLUDED
11 #define CAFU_OBSERVER_PATTERN_TOOLS_HPP_INCLUDED
12 
13 #include "Templates/Array.hpp"
14 
15 
16 class ToolT;
17 class ToolsSubjectT;
18 
19 
20 /// An enumeration that determines the urgency with which observers should update themselves when their subject has changed.
22 {
23  UPDATE_NOW, ///< Update immediately, in real-time, before the function returns.
24  UPDATE_SOON ///< Update as soon as convenient, at the next opportunity.
25 };
26 
27 
29 {
30  public:
31 
32  /// Notifies the observer that the current subject has been changed.
33  /// @param Subject The tools (tool manager) in which something has changed.
34  /// @param Tool The specific tool that has changed.
35  /// @param Priority The priority with which the update should be implemented.
36  virtual void NotifySubjectChanged(ToolsSubjectT* Subject, ToolT* Tool, ToolsUpdatePriorityT Priority) { }
37 
38  /// The virtual destructor.
39  virtual ~ToolsObserverT() { }
40 
41 
42  protected:
43 
44  /// The constructor. It is protected so that only derived classes can create instances of this class.
46 };
47 
48 
50 {
51  public:
52 
53  /// Registers the observer Obs for notification on changes in this class.
54  /// @param Obs The observer that is to be registered.
56 
57  /// Unregisters the observer Obs from further notification on changes in this class.
58  /// @param Obs The observer that is to be unregistered.
60 
61  /// Notifies all observers that something in the given tool changed so that they update themselves.
62  /// @param Tool The specific tool that has changed.
63  /// @param Priority The priority with which the update should be implemented.
64  void UpdateAllObservers(ToolT* Tool, ToolsUpdatePriorityT Priority);
65 
66  /// The virtual destructor.
67  virtual ~ToolsSubjectT();
68 
69 
70  protected:
71 
72  /// The constructor. It is protected so that only derived classes can create instances of this class.
73  ToolsSubjectT();
74 
75 
76  private:
77 
78  /// The list of the observers that have registered for notification on updates of this class.
79  ArrayT<ToolsObserverT*> m_Observers;
80 };
81 
82 #endif
void UpdateAllObservers(ToolT *Tool, ToolsUpdatePriorityT Priority)
Notifies all observers that something in the given tool changed so that they update themselves...
Definition: ObserverPatternTools.cpp:34
ToolsUpdatePriorityT
An enumeration that determines the urgency with which observers should update themselves when their s...
Definition: ObserverPatternTools.hpp:21
virtual void NotifySubjectChanged(ToolsSubjectT *Subject, ToolT *Tool, ToolsUpdatePriorityT Priority)
Notifies the observer that the current subject has been changed.
Definition: ObserverPatternTools.hpp:36
void UnregisterObserver(ToolsObserverT *Obs)
Unregisters the observer Obs from further notification on changes in this class.
Definition: ObserverPatternTools.cpp:26
Update as soon as convenient, at the next opportunity.
Definition: ObserverPatternTools.hpp:24
virtual ~ToolsSubjectT()
The virtual destructor.
Definition: ObserverPatternTools.cpp:41
Update immediately, in real-time, before the function returns.
Definition: ObserverPatternTools.hpp:23
ToolsSubjectT()
The constructor. It is protected so that only derived classes can create instances of this class...
Definition: ObserverPatternTools.cpp:10
void RegisterObserver(ToolsObserverT *Obs)
Registers the observer Obs for notification on changes in this class.
Definition: ObserverPatternTools.cpp:15
ToolsObserverT()
The constructor. It is protected so that only derived classes can create instances of this class...
Definition: ObserverPatternTools.hpp:45
Definition: ObserverPatternTools.hpp:28
This is the base class for all tools in the map editor.
Definition: Tool.hpp:34
virtual ~ToolsObserverT()
The virtual destructor.
Definition: ObserverPatternTools.hpp:39
Definition: ObserverPatternTools.hpp:49