Panda3D
eventParameter.h
1 // Filename: eventParameter.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 #ifndef EVENTPARAMETER_H
16 #define EVENTPARAMETER_H
17 
18 #include "pandabase.h"
19 
20 #include "typedef.h"
21 #include "typedObject.h"
22 #include "typedWritableReferenceCount.h"
23 #include "pointerTo.h"
24 #include "bamReader.h"
25 #include "bamWriter.h"
26 #include "paramValue.h"
27 
28 ////////////////////////////////////////////////////////////////////
29 // Class : EventParameter
30 // Description : An optional parameter associated with an event. Each
31 // event may have zero or more of these. Each parameter
32 // stores a pointer to a TypedWritableReferenceCount
33 // object, which of course could be pretty much
34 // anything. To store a simple value like a double or a
35 // string, the EventParameter constructors transparently
36 // use the ParamValue template class from paramValue.h.
37 ////////////////////////////////////////////////////////////////////
38 class EXPCL_PANDA_EVENT EventParameter {
39 PUBLISHED:
40  INLINE EventParameter();
41  INLINE EventParameter(const TypedWritableReferenceCount *ptr);
42  INLINE EventParameter(const TypedReferenceCount *ptr);
43  INLINE EventParameter(int value);
44  INLINE EventParameter(double value);
45  INLINE EventParameter(const string &value);
46  INLINE EventParameter(const wstring &value);
47 
48  INLINE EventParameter(const EventParameter &copy);
49  INLINE EventParameter &operator = (const EventParameter &copy);
50  INLINE ~EventParameter();
51 
52  // These functions are conveniences to easily determine if the
53  // EventParameter is one of the predefined parameter types, and
54  // retrieve the corresponding value. Of course, it is possible that
55  // the EventParameter is some user-defined type, and is none of
56  // these.
57  INLINE bool is_empty() const;
58  INLINE bool is_int() const;
59  INLINE int get_int_value() const;
60  INLINE bool is_double() const;
61  INLINE double get_double_value() const;
62  INLINE bool is_string() const;
63  INLINE string get_string_value() const;
64  INLINE bool is_wstring() const;
65  INLINE wstring get_wstring_value() const;
66 
67  INLINE bool is_typed_ref_count() const;
68  INLINE TypedReferenceCount *get_typed_ref_count_value() const;
69 
70  INLINE TypedWritableReferenceCount *get_ptr() const;
71 
72  void output(ostream &out) const;
73 
74 private:
76 };
77 
78 INLINE ostream &operator << (ostream &out, const EventParameter &param);
79 
81 
82 EXPORT_TEMPLATE_CLASS(EXPCL_PANDA_EVENT, EXPTP_PANDA_EVENT, ParamValue<int>);
83 EXPORT_TEMPLATE_CLASS(EXPCL_PANDA_EVENT, EXPTP_PANDA_EVENT, ParamValue<double>);
84 
89 
90 #include "eventParameter.I"
91 
92 // Tell GCC that we'll take care of the instantiation explicitly here.
93 #ifdef __GNUC__
94 #pragma interface
95 #endif
96 
97 #endif
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
A base class for things which need to inherit from both TypedObject and from ReferenceCount.
A handy class object for storing simple values (like integers or strings) passed along with an Event ...
Definition: paramValue.h:109
A base class for things which need to inherit from both TypedWritable and from ReferenceCount.