00001 // Filename: eventParameter.I 00002 // Created by: drose (08Feb99) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved 00008 // 00009 // All use of this software is subject to the terms of the Panda 3d 00010 // Software license. You should have received a copy of this license 00011 // along with this source code; you will also find a current copy of 00012 // the license at http://www.panda3d.org/license.txt . 00013 // 00014 // To contact the maintainers of this program write to 00015 // panda3d@yahoogroups.com . 00016 // 00017 //////////////////////////////////////////////////////////////////// 00018 00019 00020 00021 template<class Type> 00022 TypeHandle EventStoreValue<Type>::_type_handle; 00023 00024 //////////////////////////////////////////////////////////////////// 00025 // Function: EventParameter::Default constructor 00026 // Access: Public 00027 // Description: Defines an EventParameter that stores nothing: the 00028 // "empty" parameter. 00029 //////////////////////////////////////////////////////////////////// 00030 INLINE EventParameter:: 00031 EventParameter() { 00032 } 00033 00034 //////////////////////////////////////////////////////////////////// 00035 // Function: EventParameter::Pointer constructor 00036 // Access: Public 00037 // Description: Defines an EventParameter that stores a pointer to 00038 // any kind of TypedReferenceCount object. This is the 00039 // most general constructor. 00040 // 00041 // This accepts a const pointer, even though it stores 00042 // (and eventually returns) a non-const pointer. This 00043 // is just the simplest way to allow both const and 00044 // non-const pointers to be stored, but it does lose the 00045 // constness. Be careful. 00046 //////////////////////////////////////////////////////////////////// 00047 INLINE EventParameter:: 00048 EventParameter(const TypedReferenceCount *ptr) : _ptr((TypedReferenceCount *)ptr) { } 00049 00050 00051 //////////////////////////////////////////////////////////////////// 00052 // Function: EventParameter::Integer constructor 00053 // Access: Public 00054 // Description: Defines an EventParameter that stores an integer 00055 // value. 00056 //////////////////////////////////////////////////////////////////// 00057 INLINE EventParameter:: 00058 EventParameter(int value) : _ptr(new EventStoreInt(value)) { } 00059 00060 00061 //////////////////////////////////////////////////////////////////// 00062 // Function: EventParameter::Double constructor 00063 // Access: Public 00064 // Description: Defines an EventParameter that stores a 00065 // floating-point value. 00066 //////////////////////////////////////////////////////////////////// 00067 INLINE EventParameter:: 00068 EventParameter(double value) : _ptr(new EventStoreDouble(value)) { } 00069 00070 00071 //////////////////////////////////////////////////////////////////// 00072 // Function: EventParameter::String constructor 00073 // Access: Public 00074 // Description: Defines an EventParameter that stores a string value. 00075 //////////////////////////////////////////////////////////////////// 00076 INLINE EventParameter:: 00077 EventParameter(const string &value) : _ptr(new EventStoreString(value)) { } 00078 00079 00080 //////////////////////////////////////////////////////////////////// 00081 // Function: EventParameter::Copy constructor 00082 // Access: Public 00083 // Description: 00084 //////////////////////////////////////////////////////////////////// 00085 INLINE EventParameter:: 00086 EventParameter(const EventParameter &other) : _ptr(other._ptr) { } 00087 00088 00089 //////////////////////////////////////////////////////////////////// 00090 // Function: EventParameter::Copy assignment operator 00091 // Access: Public 00092 // Description: 00093 //////////////////////////////////////////////////////////////////// 00094 INLINE EventParameter &EventParameter:: 00095 operator = (const EventParameter &other) { 00096 _ptr = other._ptr; 00097 return *this; 00098 } 00099 00100 //////////////////////////////////////////////////////////////////// 00101 // Function: EventParameter::is_empty 00102 // Access: Public 00103 // Description: Returns true if the EventParameter is the empty 00104 // parameter, storing nothing, or false otherwise. 00105 //////////////////////////////////////////////////////////////////// 00106 INLINE bool EventParameter:: 00107 is_empty() const { 00108 return (_ptr == (TypedReferenceCount *)NULL); 00109 } 00110 00111 //////////////////////////////////////////////////////////////////// 00112 // Function: EventParameter::is_int 00113 // Access: Public 00114 // Description: Returns true if the EventParameter stores an integer 00115 // value, false otherwise. 00116 //////////////////////////////////////////////////////////////////// 00117 INLINE bool EventParameter:: 00118 is_int() const { 00119 if (is_empty()) { 00120 return false; 00121 } 00122 return _ptr->is_of_type(EventStoreInt::get_class_type()); 00123 } 00124 00125 //////////////////////////////////////////////////////////////////// 00126 // Function: EventParameter::get_int_value 00127 // Access: Public 00128 // Description: Retrieves the value stored in the EventParameter. It 00129 // is only valid to call this if is_int() has already 00130 // returned true. 00131 //////////////////////////////////////////////////////////////////// 00132 INLINE int EventParameter:: 00133 get_int_value() const { 00134 nassertr(is_int(), 0); 00135 // We can't use DCAST, because EventStoreValue::init_type() breaks 00136 // convention and takes a parameter. But the above assertion should 00137 // protect us. 00138 return ((const EventStoreInt *)_ptr.p())->get_value(); 00139 } 00140 00141 //////////////////////////////////////////////////////////////////// 00142 // Function: EventParameter::is_double 00143 // Access: Public 00144 // Description: Returns true if the EventParameter stores a double 00145 // floating-point value, false otherwise. 00146 //////////////////////////////////////////////////////////////////// 00147 INLINE bool EventParameter:: 00148 is_double() const { 00149 if (is_empty()) { 00150 return false; 00151 } 00152 return _ptr->is_of_type(EventStoreDouble::get_class_type()); 00153 } 00154 00155 //////////////////////////////////////////////////////////////////// 00156 // Function: EventParameter::get_double_value 00157 // Access: Public 00158 // Description: Retrieves the value stored in the EventParameter. It 00159 // is only valid to call this if is_double() has already 00160 // returned true. 00161 //////////////////////////////////////////////////////////////////// 00162 INLINE double EventParameter:: 00163 get_double_value() const { 00164 nassertr(is_double(), 0.0); 00165 return ((const EventStoreDouble *)_ptr.p())->get_value(); 00166 } 00167 00168 //////////////////////////////////////////////////////////////////// 00169 // Function: EventParameter::is_string 00170 // Access: Public 00171 // Description: Returns true if the EventParameter stores a string 00172 // value, false otherwise. 00173 //////////////////////////////////////////////////////////////////// 00174 INLINE bool EventParameter:: 00175 is_string() const { 00176 if (is_empty()) { 00177 return false; 00178 } 00179 return _ptr->is_of_type(EventStoreString::get_class_type()); 00180 } 00181 00182 //////////////////////////////////////////////////////////////////// 00183 // Function: EventParameter::get_string_value 00184 // Access: Public 00185 // Description: Retrieves the value stored in the EventParameter. It 00186 // is only valid to call this if is_string() has already 00187 // returned true. 00188 //////////////////////////////////////////////////////////////////// 00189 INLINE string EventParameter:: 00190 get_string_value() const { 00191 nassertr(is_string(), ""); 00192 return ((const EventStoreString *)_ptr.p())->get_value(); 00193 } 00194 00195 //////////////////////////////////////////////////////////////////// 00196 // Function: EventParameter::get_ptr 00197 // Access: Public 00198 // Description: Retrieves a pointer to the actual value stored in the 00199 // parameter. The TypeHandle of this pointer may be 00200 // examined to determine the actual type of parameter it 00201 // contains. This is the only way to retrieve the value 00202 // when it is not one of the above predefined types. 00203 //////////////////////////////////////////////////////////////////// 00204 INLINE TypedReferenceCount *EventParameter:: 00205 get_ptr() const { 00206 return _ptr; 00207 } 00208 00209 INLINE ostream & 00210 operator << (ostream &out, const EventParameter ¶m) { 00211 param.output(out); 00212 return out; 00213 } 00214 00215 00216 //////////////////////////////////////////////////////////////////// 00217 // Function: EventStoreValue::set_value 00218 // Access: Public 00219 // Description: Changes the value stored in the parameter. It is 00220 // dangerous to do this for a parameter already added to 00221 // an event, since the parameters may be shared. 00222 //////////////////////////////////////////////////////////////////// 00223 template<class Type> 00224 INLINE void EventStoreValue<Type>:: 00225 set_value(const Type &value) { 00226 _value = value; 00227 } 00228 00229 00230 //////////////////////////////////////////////////////////////////// 00231 // Function: EventStoreValue::get_value 00232 // Access: Public 00233 // Description: Retrieves the value stored in the parameter. 00234 //////////////////////////////////////////////////////////////////// 00235 template<class Type> 00236 INLINE const Type &EventStoreValue<Type>:: 00237 get_value() const { 00238 return _value; 00239 } 00240 00241 //////////////////////////////////////////////////////////////////// 00242 // Function: EventStoreValue::output 00243 // Access: Public, Virtual 00244 // Description: 00245 //////////////////////////////////////////////////////////////////// 00246 template<class Type> 00247 void EventStoreValue<Type>:: 00248 output(ostream &out) const { 00249 out << _value; 00250 }