Panda3D
 All Classes Functions Variables Enumerations
event.cxx
1 // Filename: event.cxx
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 #include "event.h"
16 #include "config_event.h"
17 
18 TypeHandle Event::_type_handle;
19 
20 ////////////////////////////////////////////////////////////////////
21 // Function: Event::Constructor
22 // Access: Public
23 // Description:
24 ////////////////////////////////////////////////////////////////////
25 Event::
26 Event(const string &event_name, EventReceiver *receiver) :
27  _name(event_name)
28 {
29  _receiver = receiver;
30 }
31 
32 ////////////////////////////////////////////////////////////////////
33 // Function: Event::Copy constructor
34 // Access: Public
35 // Description:
36 ////////////////////////////////////////////////////////////////////
37 Event::
38 Event(const Event &copy) :
39  _parameters(copy._parameters),
40  _receiver(copy._receiver),
41  _name(copy._name)
42 {
43 }
44 
45 ////////////////////////////////////////////////////////////////////
46 // Function: Event::Copy Assignment Operator
47 // Access: Public
48 // Description:
49 ////////////////////////////////////////////////////////////////////
50 void Event::
51 operator = (const Event &copy) {
52  _parameters = copy._parameters;
53  _receiver = copy._receiver;
54  _name = copy._name;
55 }
56 
57 ////////////////////////////////////////////////////////////////////
58 // Function: Event::Destructor
59 // Access: Public
60 // Description:
61 ////////////////////////////////////////////////////////////////////
62 Event::
63 ~Event() {
64 }
65 
66 ////////////////////////////////////////////////////////////////////
67 // Function: Event::add_parameter
68 // Access: Public
69 // Description:
70 ////////////////////////////////////////////////////////////////////
71 void Event::
72 add_parameter(const EventParameter &obj) {
73  _parameters.push_back(obj);
74 }
75 
76 
77 ////////////////////////////////////////////////////////////////////
78 // Function: Event::get_num_parameters
79 // Access: Public
80 // Description:
81 ////////////////////////////////////////////////////////////////////
82 int Event::
83 get_num_parameters() const {
84  return _parameters.size();
85 }
86 
87 ////////////////////////////////////////////////////////////////////
88 // Function: Event::get_parameter
89 // Access: Public
90 // Description:
91 ////////////////////////////////////////////////////////////////////
92 EventParameter Event::
93 get_parameter(int n) const {
94  nassertr(n >= 0 && n < (int)_parameters.size(), EventParameter(0));
95  return _parameters[n];
96 }
97 
98 
99 ////////////////////////////////////////////////////////////////////
100 // Function: Event::has_receiver
101 // Access: Public
102 // Description:
103 ////////////////////////////////////////////////////////////////////
104 bool Event::
105 has_receiver() const {
106  return _receiver != (EventReceiver *)NULL;
107 }
108 
109 ////////////////////////////////////////////////////////////////////
110 // Function: Event::get_receiver
111 // Access: Public
112 // Description:
113 ////////////////////////////////////////////////////////////////////
114 EventReceiver *Event::
115 get_receiver() const {
116  return _receiver;
117 }
118 
119 ////////////////////////////////////////////////////////////////////
120 // Function: Event::set_receiver
121 // Access: Public
122 // Description:
123 ////////////////////////////////////////////////////////////////////
124 void Event::
125 set_receiver(EventReceiver *receiver) {
126  _receiver = receiver;
127 }
128 
129 ////////////////////////////////////////////////////////////////////
130 // Function: Event::clear_receiver
131 // Access: Public
132 // Description:
133 ////////////////////////////////////////////////////////////////////
134 void Event::
135 clear_receiver() {
136  _receiver = (EventReceiver *)NULL;
137 }
138 
139 ////////////////////////////////////////////////////////////////////
140 // Function: Event::output
141 // Access: Public
142 // Description:
143 ////////////////////////////////////////////////////////////////////
144 void Event::
145 output(ostream &out) const {
146  out << get_name();
147 
148  out << "(";
149  for (ParameterList::const_iterator pi = _parameters.begin(); pi != _parameters.end(); ++pi) {
150  if (pi != _parameters.begin()) {
151  out << ", ";
152  }
153  out << (*pi);
154  }
155  out << ")";
156 }
An optional parameter associated with an event.
An abstract base class for anything that might care about receiving events.
Definition: eventReceiver.h:28
A named event, possibly with parameters.
Definition: event.h:36
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85