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