Dragonfly  4.3
A text-based game engine
Manager.h
1 ///
2 /// The base manager
3 ///
4 
5 #ifndef __MANAGER_H__
6 #define __MANAGER_H__
7 
8 // System includes.
9 #include <string>
10 
11 // Engine includes.
12 #include "Event.h"
13 #include "Object.h"
14 #include "ObjectList.h"
15 
16 namespace df {
17 
18 const int MAX_EVENTS = 100; ///< Max number of different events.
19 
20 class Manager {
21 
22  private:
23  std::string m_type; ///< Manager type identifier.
24  int m_event_count; ///< Number of events.
25  std::string m_event_name[MAX_EVENTS]; ///< List of events.
26  ObjectList m_obj_list[MAX_EVENTS]; ///< Objects interested in event.
27  bool m_is_started; ///< True if startUp() succeeded
28 
29  /// Check if event is handled by this Manager.
30  /// If handled, return true else false.
31  /// (Base Manager always returns false.)
32  virtual bool isValid(std::string event_type) const;
33 
34  protected:
35  /// Set type identifier of Manager.
36  void setType(std::string new_type);
37 
38  public:
39  Manager();
40  virtual ~Manager();
41 
42  /// Get type identifier of Manager.
43  std::string getType() const;
44 
45  /// Startup Manager.
46  /// Return 0 if ok, else negative number.
47  virtual int startUp();
48 
49  /// Shutdown Manager.
50  virtual void shutDown();
51 
52  /// Return status of is_started (true when startUp() was successful).
53  bool isStarted() const;
54 
55  /// Send event to all interested Objects.
56  /// Return count of number of events sent.
57  int onEvent(const Event *p_event) const;
58 
59  /// Indicate interest in event.
60  /// Return 0 if ok, else -1.
61  /// (Note, doesn't check to see if Object is already registered.)
62  int registerInterest(Object *p_o, std::string event_type);
63 
64  /// Indicate no more interest in event.
65  /// Return 0 if ok, else -1.
66  int unregisterInterest(Object *p_o, std::string event_type);
67 
68 };
69 
70 } // end of namespace df
71 #endif // __MANAGER_H__
void setType(std::string new_type)
Set type identifier of Manager.
std::string m_type
Manager type identifier.
Definition: Manager.h:23
int registerInterest(Object *p_o, std::string event_type)
Indicate interest in event.
virtual int startUp()
Startup Manager.
const int MAX_EVENTS
Max number of different events.
Definition: Manager.h:18
Definition: ObjectList.h:15
bool isStarted() const
Return status of is_started (true when startUp() was successful).
int unregisterInterest(Object *p_o, std::string event_type)
Indicate no more interest in event.
Definition: Event.h:15
A 2-d bounding box.
Definition: Box.h:10
int m_event_count
Number of events.
Definition: Manager.h:24
std::string m_event_name[MAX_EVENTS]
List of events.
Definition: Manager.h:25
virtual void shutDown()
Shutdown Manager.
Definition: Object.h:59
bool m_is_started
True if startUp() succeeded.
Definition: Manager.h:27
std::string getType() const
Get type identifier of Manager.
virtual bool isValid(std::string event_type) const
Check if event is handled by this Manager.
int onEvent(const Event *p_event) const
Send event to all interested Objects.
Definition: Manager.h:20
ObjectList m_obj_list[MAX_EVENTS]
Objects interested in event.
Definition: Manager.h:26