Panda3D
 All Classes Functions Variables Enumerations
eventParameter.I
1 // Filename: eventParameter.I
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 
16 ////////////////////////////////////////////////////////////////////
17 // Function: EventParameter::Default constructor
18 // Access: Published
19 // Description: Defines an EventParameter that stores nothing: the
20 // "empty" parameter.
21 ////////////////////////////////////////////////////////////////////
22 INLINE EventParameter::
24 }
25 
26 ////////////////////////////////////////////////////////////////////
27 // Function: EventParameter::Pointer constructor
28 // Access: Published
29 // Description: Defines an EventParameter that stores a pointer to
30 // any kind of TypedWritableReferenceCount object. This
31 // is the most general constructor.
32 //
33 // This accepts a const pointer, even though it stores
34 // (and eventually returns) a non-const pointer. This
35 // is just the simplest way to allow both const and
36 // non-const pointers to be stored, but it does lose the
37 // constness. Be careful.
38 ////////////////////////////////////////////////////////////////////
39 INLINE EventParameter::
41 
42 ////////////////////////////////////////////////////////////////////
43 // Function: EventParameter::Pointer constructor
44 // Access: Published
45 // Description: Defines an EventParameter that stores a pointer to
46 // a TypedReferenceCount object. Note that a
47 // TypedReferenceCount is not the same kind of pointer
48 // as a TypedWritableReferenceCount, hence we require
49 // both constructors.
50 //
51 // This accepts a const pointer, even though it stores
52 // (and eventually returns) a non-const pointer. This
53 // is just the simplest way to allow both const and
54 // non-const pointers to be stored, but it does lose the
55 // constness. Be careful.
56 ////////////////////////////////////////////////////////////////////
57 INLINE EventParameter::
59 
60 
61 ////////////////////////////////////////////////////////////////////
62 // Function: EventParameter::Integer constructor
63 // Access: Published
64 // Description: Defines an EventParameter that stores an integer
65 // value.
66 ////////////////////////////////////////////////////////////////////
67 INLINE EventParameter::
68 EventParameter(int value) : _ptr(new EventStoreInt(value)) { }
69 
70 
71 ////////////////////////////////////////////////////////////////////
72 // Function: EventParameter::Double constructor
73 // Access: Published
74 // Description: Defines an EventParameter that stores a
75 // floating-point value.
76 ////////////////////////////////////////////////////////////////////
77 INLINE EventParameter::
78 EventParameter(double value) : _ptr(new EventStoreDouble(value)) { }
79 
80 
81 ////////////////////////////////////////////////////////////////////
82 // Function: EventParameter::String constructor
83 // Access: Published
84 // Description: Defines an EventParameter that stores a string value.
85 ////////////////////////////////////////////////////////////////////
86 INLINE EventParameter::
87 EventParameter(const string &value) : _ptr(new EventStoreString(value)) { }
88 
89 ////////////////////////////////////////////////////////////////////
90 // Function: EventParameter::Wstring constructor
91 // Access: Published
92 // Description: Defines an EventParameter that stores a wstring value.
93 ////////////////////////////////////////////////////////////////////
94 INLINE EventParameter::
95 EventParameter(const wstring &value) : _ptr(new EventStoreWstring(value)) { }
96 
97 
98 ////////////////////////////////////////////////////////////////////
99 // Function: EventParameter::Copy constructor
100 // Access: Published
101 // Description:
102 ////////////////////////////////////////////////////////////////////
103 INLINE EventParameter::
104 EventParameter(const EventParameter &other) : _ptr(other._ptr) { }
105 
106 
107 ////////////////////////////////////////////////////////////////////
108 // Function: EventParameter::Copy assignment operator
109 // Access: Published
110 // Description:
111 ////////////////////////////////////////////////////////////////////
112 INLINE EventParameter &EventParameter::
113 operator = (const EventParameter &other) {
114  _ptr = other._ptr;
115  return *this;
116 }
117 
118 ////////////////////////////////////////////////////////////////////
119 // Function: EventParameter::Destructor
120 // Access: Published
121 // Description:
122 ////////////////////////////////////////////////////////////////////
123 INLINE EventParameter::
124 ~EventParameter() {
125 }
126 
127 ////////////////////////////////////////////////////////////////////
128 // Function: EventParameter::is_empty
129 // Access: Published
130 // Description: Returns true if the EventParameter is the empty
131 // parameter, storing nothing, or false otherwise.
132 ////////////////////////////////////////////////////////////////////
133 INLINE bool EventParameter::
134 is_empty() const {
135  return (_ptr == (TypedWritableReferenceCount *)NULL);
136 }
137 
138 ////////////////////////////////////////////////////////////////////
139 // Function: EventParameter::is_int
140 // Access: Published
141 // Description: Returns true if the EventParameter stores an integer
142 // value, false otherwise.
143 ////////////////////////////////////////////////////////////////////
144 INLINE bool EventParameter::
145 is_int() const {
146  if (is_empty()) {
147  return false;
148  }
149  return _ptr->is_of_type(EventStoreInt::get_class_type());
150 }
151 
152 ////////////////////////////////////////////////////////////////////
153 // Function: EventParameter::get_int_value
154 // Access: Published
155 // Description: Retrieves the value stored in the EventParameter. It
156 // is only valid to call this if is_int() has already
157 // returned true.
158 ////////////////////////////////////////////////////////////////////
159 INLINE int EventParameter::
160 get_int_value() const {
161  nassertr(is_int(), 0);
162  // We can't use DCAST, because EventStoreValue::init_type() breaks
163  // convention and takes a parameter. But the above assertion should
164  // protect us.
165  return ((const EventStoreInt *)_ptr.p())->get_value();
166 }
167 
168 ////////////////////////////////////////////////////////////////////
169 // Function: EventParameter::is_double
170 // Access: Published
171 // Description: Returns true if the EventParameter stores a double
172 // floating-point value, false otherwise.
173 ////////////////////////////////////////////////////////////////////
174 INLINE bool EventParameter::
175 is_double() const {
176  if (is_empty()) {
177  return false;
178  }
179  return _ptr->is_of_type(EventStoreDouble::get_class_type());
180 }
181 
182 ////////////////////////////////////////////////////////////////////
183 // Function: EventParameter::get_double_value
184 // Access: Published
185 // Description: Retrieves the value stored in the EventParameter. It
186 // is only valid to call this if is_double() has already
187 // returned true.
188 ////////////////////////////////////////////////////////////////////
189 INLINE double EventParameter::
191  nassertr(is_double(), 0.0);
192  return ((const EventStoreDouble *)_ptr.p())->get_value();
193 }
194 
195 ////////////////////////////////////////////////////////////////////
196 // Function: EventParameter::is_string
197 // Access: Published
198 // Description: Returns true if the EventParameter stores a string
199 // value, false otherwise.
200 ////////////////////////////////////////////////////////////////////
201 INLINE bool EventParameter::
202 is_string() const {
203  if (is_empty()) {
204  return false;
205  }
206  return _ptr->is_of_type(EventStoreString::get_class_type());
207 }
208 
209 ////////////////////////////////////////////////////////////////////
210 // Function: EventParameter::get_string_value
211 // Access: Published
212 // Description: Retrieves the value stored in the EventParameter. It
213 // is only valid to call this if is_string() has already
214 // returned true.
215 ////////////////////////////////////////////////////////////////////
216 INLINE string EventParameter::
218  nassertr(is_string(), "");
219  return ((const EventStoreString *)_ptr.p())->get_value();
220 }
221 
222 ////////////////////////////////////////////////////////////////////
223 // Function: EventParameter::is_wstring
224 // Access: Published
225 // Description: Returns true if the EventParameter stores a wstring
226 // value, false otherwise.
227 ////////////////////////////////////////////////////////////////////
228 INLINE bool EventParameter::
229 is_wstring() const {
230  if (is_empty()) {
231  return false;
232  }
233  return _ptr->is_of_type(EventStoreWstring::get_class_type());
234 }
235 
236 ////////////////////////////////////////////////////////////////////
237 // Function: EventParameter::get_wstring_value
238 // Access: Published
239 // Description: Retrieves the value stored in the EventParameter. It
240 // is only valid to call this if is_wstring() has already
241 // returned true.
242 ////////////////////////////////////////////////////////////////////
243 INLINE wstring EventParameter::
245  nassertr(is_wstring(), wstring());
246  return ((const EventStoreWstring *)_ptr.p())->get_value();
247 }
248 
249 ////////////////////////////////////////////////////////////////////
250 // Function: EventParameter::is_typed_ref_count
251 // Access: Published
252 // Description: Returns true if the EventParameter stores a
253 // TypedReferenceCount pointer, false otherwise. Note
254 // that a TypedReferenceCount is not exactly the same
255 // kind of pointer as a TypedWritableReferenceCount,
256 // hence the need for this separate call.
257 ////////////////////////////////////////////////////////////////////
258 INLINE bool EventParameter::
260  if (is_empty()) {
261  return false;
262  }
263  return _ptr->is_of_type(EventStoreTypedRefCount::get_class_type());
264 }
265 
266 ////////////////////////////////////////////////////////////////////
267 // Function: EventParameter::get_typed_ref_count_value
268 // Access: Published
269 // Description: Retrieves the value stored in the EventParameter. It
270 // is only valid to call this if is_typed_ref_count()
271 // has already returned true.
272 ////////////////////////////////////////////////////////////////////
275  nassertr(is_typed_ref_count(), NULL);
276  return ((const EventStoreTypedRefCount *)_ptr.p())->get_value();
277 }
278 
279 ////////////////////////////////////////////////////////////////////
280 // Function: EventParameter::get_ptr
281 // Access: Published
282 // Description: Retrieves a pointer to the actual value stored in the
283 // parameter. The TypeHandle of this pointer may be
284 // examined to determine the actual type of parameter it
285 // contains. This is the only way to retrieve the value
286 // when it is not one of the above predefined types.
287 ////////////////////////////////////////////////////////////////////
289 get_ptr() const {
290  return _ptr;
291 }
292 
293 INLINE ostream &
294 operator << (ostream &out, const EventParameter &param) {
295  param.output(out);
296  return out;
297 }
bool is_string() const
Returns true if the EventParameter stores a string value, false otherwise.
An optional parameter associated with an event.
A class object for storing specifically objects of type TypedReferenceCount, which is different than ...
Definition: paramValue.h:67
string get_string_value() const
Retrieves the value stored in the EventParameter.
A base class for things which need to inherit from both TypedObject and from ReferenceCount.
bool is_double() const
Returns true if the EventParameter stores a double floating-point value, false otherwise.
A handy class object for storing simple values (like integers or strings) passed along with an Event ...
Definition: paramValue.h:109
bool is_int() const
Returns true if the EventParameter stores an integer value, false otherwise.
EventParameter()
Defines an EventParameter that stores nothing: the &quot;empty&quot; parameter.
wstring get_wstring_value() const
Retrieves the value stored in the EventParameter.
double get_double_value() const
Retrieves the value stored in the EventParameter.
bool is_typed_ref_count() const
Returns true if the EventParameter stores a TypedReferenceCount pointer, false otherwise.
int get_int_value() const
Retrieves the value stored in the EventParameter.
A base class for things which need to inherit from both TypedWritable and from ReferenceCount.
bool is_empty() const
Returns true if the EventParameter is the empty parameter, storing nothing, or false otherwise...
TypedWritableReferenceCount * get_ptr() const
Retrieves a pointer to the actual value stored in the parameter.
bool is_wstring() const
Returns true if the EventParameter stores a wstring value, false otherwise.
TypedReferenceCount * get_typed_ref_count_value() const
Retrieves the value stored in the EventParameter.