Panda3D
event.cxx
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.cxx
10  * @author drose
11  * @date 1999-02-08
12  */
13 
14 #include "event.h"
15 #include "config_event.h"
16 
17 TypeHandle Event::_type_handle;
18 
19 /**
20  *
21  */
22 Event::
23 Event(const std::string &event_name, EventReceiver *receiver) :
24  _name(event_name)
25 {
26  _receiver = receiver;
27 }
28 
29 /**
30  *
31  */
32 Event::
33 Event(const Event &copy) :
34  _parameters(copy._parameters),
35  _receiver(copy._receiver),
36  _name(copy._name)
37 {
38 }
39 
40 /**
41  *
42  */
43 void Event::
44 operator = (const Event &copy) {
45  _parameters = copy._parameters;
46  _receiver = copy._receiver;
47  _name = copy._name;
48 }
49 
50 /**
51  *
52  */
53 Event::
54 ~Event() {
55 }
56 
57 /**
58  *
59  */
60 void Event::
61 add_parameter(const EventParameter &obj) {
62  _parameters.push_back(obj);
63 }
64 
65 
66 /**
67  *
68  */
69 int Event::
70 get_num_parameters() const {
71  return _parameters.size();
72 }
73 
74 /**
75  *
76  */
77 EventParameter Event::
78 get_parameter(int n) const {
79  nassertr(n >= 0 && n < (int)_parameters.size(), EventParameter(0));
80  return _parameters[n];
81 }
82 
83 
84 /**
85  *
86  */
87 bool Event::
88 has_receiver() const {
89  return _receiver != nullptr;
90 }
91 
92 /**
93  *
94  */
95 EventReceiver *Event::
96 get_receiver() const {
97  return _receiver;
98 }
99 
100 /**
101  *
102  */
103 void Event::
104 set_receiver(EventReceiver *receiver) {
105  _receiver = receiver;
106 }
107 
108 /**
109  *
110  */
111 void Event::
112 clear_receiver() {
113  _receiver = nullptr;
114 }
115 
116 /**
117  *
118  */
119 void Event::
120 output(std::ostream &out) const {
121  out << get_name();
122 
123  out << "(";
124  for (ParameterList::const_iterator pi = _parameters.begin(); pi != _parameters.end(); ++pi) {
125  if (pi != _parameters.begin()) {
126  out << ", ";
127  }
128  out << (*pi);
129  }
130  out << ")";
131 }
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
An optional parameter associated with an event.
An abstract base class for anything that might care about receiving events.
Definition: eventReceiver.h:25
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A named event, possibly with parameters.
Definition: event.h:33
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81