Panda3D
event.h
1 // Filename: event.h
2 // Created by: drose (08Feb99)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 // Apparently some OSX system header defines EVENT_H. Go figure.
16 #ifndef __EVENT_H__
17 #define __EVENT_H__
18 
19 #include "pandabase.h"
20 #include "eventParameter.h"
21 #include "typedReferenceCount.h"
22 
23 class EventReceiver;
24 
25 ////////////////////////////////////////////////////////////////////
26 // Class : Event
27 // Description : A named event, possibly with parameters. Anyone in
28 // any thread may throw an event at any time; there will
29 // be one process responsible for reading and dispacting
30 // on the events (but not necessarily immediately).
31 //
32 // This function use to inherit from Namable, but that
33 // makes it too expensive to get its name the Python
34 // code. Now it just copies the Namable interface in.
35 ////////////////////////////////////////////////////////////////////
36 class EXPCL_PANDA_EVENT Event : public TypedReferenceCount {
37 PUBLISHED:
38  Event(const string &event_name, EventReceiver *receiver = NULL);
39  Event(const Event &copy);
40  void operator = (const Event &copy);
41  ~Event();
42 
43  INLINE void set_name(const string &name);
44  INLINE void clear_name();
45  INLINE bool has_name() const;
46  INLINE const string &get_name() const;
47 
48  void add_parameter(const EventParameter &obj);
49 
50  int get_num_parameters() const;
51  EventParameter get_parameter(int n) const;
52  MAKE_SEQ(get_parameters, get_num_parameters, get_parameter);
53 
54  bool has_receiver() const;
55  EventReceiver *get_receiver() const;
56  void set_receiver(EventReceiver *receiver);
57  void clear_receiver();
58 
59  void output(ostream &out) const;
60 
61 protected:
63  ParameterList _parameters;
64  EventReceiver *_receiver;
65 
66 private:
67  string _name;
68 
69 public:
70  static TypeHandle get_class_type() {
71  return _type_handle;
72  }
73  static void init_type() {
74  TypedReferenceCount::init_type();
75  register_type(_type_handle, "Event",
76  TypedReferenceCount::get_class_type());
77  }
78  virtual TypeHandle get_type() const {
79  return get_class_type();
80  }
81  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
82 
83 private:
84  static TypeHandle _type_handle;
85 };
86 
87 INLINE ostream &operator << (ostream &out, const Event &n);
88 
89 #include "event.I"
90 
91 #endif
An optional parameter associated with an event.
An abstract base class for anything that might care about receiving events.
Definition: eventReceiver.h:28
A base class for things which need to inherit from both TypedObject and from ReferenceCount.
A named event, possibly with parameters.
Definition: event.h:36
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85