Panda3D
|
00001 // Filename: configVariable.I 00002 // Created by: drose (18Oct04) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 00016 //////////////////////////////////////////////////////////////////// 00017 // Function: ConfigVariable::Constructor 00018 // Access: Protected 00019 // Description: This constructor is only intended to be called from a 00020 // specialized ConfigVariableFoo derived class. 00021 //////////////////////////////////////////////////////////////////// 00022 INLINE ConfigVariable:: 00023 ConfigVariable(const string &name, ConfigVariable::ValueType value_type) : 00024 ConfigVariableBase(name, value_type) 00025 { 00026 } 00027 00028 //////////////////////////////////////////////////////////////////// 00029 // Function: ConfigVariable::Constructor 00030 // Access: Protected 00031 // Description: This constructor is only intended to be called from a 00032 // specialized ConfigVariableFoo derived class. 00033 //////////////////////////////////////////////////////////////////// 00034 INLINE ConfigVariable:: 00035 ConfigVariable(const string &name, ConfigVariable::ValueType value_type, 00036 const string &description, int flags) : 00037 ConfigVariableBase(name, value_type, description, flags) 00038 { 00039 } 00040 00041 //////////////////////////////////////////////////////////////////// 00042 // Function: ConfigVariable::Constructor 00043 // Access: Published 00044 // Description: Use this constructor to make a ConfigVariable of an 00045 // unspecified type. Usually you'd want to do this just 00046 // to reference a previously-defined ConfigVariable of a 00047 // specific type, without having to know what type it is. 00048 //////////////////////////////////////////////////////////////////// 00049 INLINE ConfigVariable:: 00050 ConfigVariable(const string &name) : 00051 ConfigVariableBase(name, VT_undefined) 00052 { 00053 _core->set_used(); 00054 } 00055 00056 //////////////////////////////////////////////////////////////////// 00057 // Function: ConfigVariable::Destructor 00058 // Access: Published 00059 // Description: 00060 //////////////////////////////////////////////////////////////////// 00061 INLINE ConfigVariable:: 00062 ~ConfigVariable() { 00063 } 00064 00065 //////////////////////////////////////////////////////////////////// 00066 // Function: ConfigVariable::get_default_value 00067 // Access: Published 00068 // Description: Returns the default variable specified for this 00069 // variable. If the variable has not yet been defined, 00070 // this will return NULL. 00071 //////////////////////////////////////////////////////////////////// 00072 INLINE const ConfigDeclaration *ConfigVariable:: 00073 get_default_value() const { 00074 nassertr(is_constructed(), (ConfigDeclaration *)NULL); 00075 return _core->get_default_value(); 00076 } 00077 00078 //////////////////////////////////////////////////////////////////// 00079 // Function: ConfigVariable::get_string_value 00080 // Access: Published 00081 // Description: Returns the toplevel value of the variable, formatted 00082 // as a string. 00083 //////////////////////////////////////////////////////////////////// 00084 INLINE const string &ConfigVariable:: 00085 get_string_value() const { 00086 nassertr(is_constructed(), *new string()); 00087 const ConfigDeclaration *decl = _core->get_declaration(0); 00088 return decl->get_string_value(); 00089 } 00090 00091 //////////////////////////////////////////////////////////////////// 00092 // Function: ConfigVariable::set_string_value 00093 // Access: Published 00094 // Description: Changes the value assigned to this variable. This 00095 // creates a local value that shadows any values defined 00096 // in the .prc files, until clear_local_value() is 00097 // called. 00098 //////////////////////////////////////////////////////////////////// 00099 INLINE void ConfigVariable:: 00100 set_string_value(const string &string_value) { 00101 nassertv(is_constructed()); 00102 _core->make_local_value()->set_string_value(string_value); 00103 } 00104 00105 //////////////////////////////////////////////////////////////////// 00106 // Function: ConfigVariable::clear_value 00107 // Access: Published 00108 // Description: Removes the value assigned to this variable, and lets 00109 // its original value (as read from the prc files) show 00110 // through. 00111 //////////////////////////////////////////////////////////////////// 00112 INLINE void ConfigVariable:: 00113 clear_value() { 00114 nassertv(is_constructed()); 00115 _core->clear_local_value(); 00116 } 00117 00118 //////////////////////////////////////////////////////////////////// 00119 // Function: ConfigVariable::get_num_words 00120 // Access: Published 00121 // Description: Returns the number of words in the variable's 00122 // value. A word is defined as a sequence of 00123 // non-whitespace characters delimited by whitespace. 00124 //////////////////////////////////////////////////////////////////// 00125 INLINE int ConfigVariable:: 00126 get_num_words() const { 00127 nassertr(is_constructed(), 0); 00128 const ConfigDeclaration *decl = _core->get_declaration(0); 00129 return decl->get_num_words(); 00130 } 00131 00132 //////////////////////////////////////////////////////////////////// 00133 // Function: ConfigVariable::has_string_word 00134 // Access: Published 00135 // Description: Returns true if the variable's value has a valid 00136 // string value for the nth word. This is really the 00137 // same thing as asking if there are at least n words in 00138 // the value. 00139 //////////////////////////////////////////////////////////////////// 00140 INLINE bool ConfigVariable:: 00141 has_string_word(int n) const { 00142 nassertr(is_constructed(), false); 00143 const ConfigDeclaration *decl = _core->get_declaration(0); 00144 return decl->has_string_word(n); 00145 } 00146 00147 //////////////////////////////////////////////////////////////////// 00148 // Function: ConfigVariable::has_bool_word 00149 // Access: Published 00150 // Description: Returns true if the variable's value has a valid 00151 // boolean value for the nth word. 00152 //////////////////////////////////////////////////////////////////// 00153 INLINE bool ConfigVariable:: 00154 has_bool_word(int n) const { 00155 nassertr(is_constructed(), false); 00156 const ConfigDeclaration *decl = _core->get_declaration(0); 00157 return decl->has_bool_word(n); 00158 } 00159 00160 //////////////////////////////////////////////////////////////////// 00161 // Function: ConfigVariable::has_int_word 00162 // Access: Published 00163 // Description: Returns true if the variable's value has a valid 00164 // integer value for the nth word. 00165 //////////////////////////////////////////////////////////////////// 00166 INLINE bool ConfigVariable:: 00167 has_int_word(int n) const { 00168 nassertr(is_constructed(), false); 00169 const ConfigDeclaration *decl = _core->get_declaration(0); 00170 return decl->has_int_word(n); 00171 } 00172 00173 //////////////////////////////////////////////////////////////////// 00174 // Function: ConfigVariable::has_int64_word 00175 // Access: Published 00176 // Description: Returns true if the variable's value has a valid 00177 // 64-bit integer value for the nth word. 00178 //////////////////////////////////////////////////////////////////// 00179 INLINE bool ConfigVariable:: 00180 has_int64_word(int n) const { 00181 nassertr(is_constructed(), false); 00182 const ConfigDeclaration *decl = _core->get_declaration(0); 00183 return decl->has_int64_word(n); 00184 } 00185 00186 //////////////////////////////////////////////////////////////////// 00187 // Function: ConfigVariable::has_double_word 00188 // Access: Published 00189 // Description: Returns true if the variable's value has a valid 00190 // integer value for the nth word. 00191 //////////////////////////////////////////////////////////////////// 00192 INLINE bool ConfigVariable:: 00193 has_double_word(int n) const { 00194 nassertr(is_constructed(), false); 00195 const ConfigDeclaration *decl = _core->get_declaration(0); 00196 return decl->has_double_word(n); 00197 } 00198 00199 //////////////////////////////////////////////////////////////////// 00200 // Function: ConfigVariable::get_string_word 00201 // Access: Published 00202 // Description: Returns the string value of the nth word of the 00203 // variable's value, or empty string if there is no 00204 // nth value. See also has_string_word(). 00205 //////////////////////////////////////////////////////////////////// 00206 INLINE string ConfigVariable:: 00207 get_string_word(int n) const { 00208 nassertr(is_constructed(), string()); 00209 const ConfigDeclaration *decl = _core->get_declaration(0); 00210 return decl->get_string_word(n); 00211 } 00212 00213 //////////////////////////////////////////////////////////////////// 00214 // Function: ConfigVariable::get_bool_word 00215 // Access: Published 00216 // Description: Returns the boolean value of the nth word of the 00217 // variable's value, or false if there is no nth 00218 // value. See also has_bool_word(). 00219 //////////////////////////////////////////////////////////////////// 00220 INLINE bool ConfigVariable:: 00221 get_bool_word(int n) const { 00222 nassertr(is_constructed(), false); 00223 const ConfigDeclaration *decl = _core->get_declaration(0); 00224 return decl->get_bool_word(n); 00225 } 00226 00227 //////////////////////////////////////////////////////////////////// 00228 // Function: ConfigVariable::get_int_word 00229 // Access: Published 00230 // Description: Returns the integer value of the nth word of the 00231 // variable's value, or 0 if there is no nth value. 00232 // See also has_int_word(). 00233 //////////////////////////////////////////////////////////////////// 00234 INLINE int ConfigVariable:: 00235 get_int_word(int n) const { 00236 nassertr(is_constructed(), 0); 00237 const ConfigDeclaration *decl = _core->get_declaration(0); 00238 return decl->get_int_word(n); 00239 } 00240 00241 //////////////////////////////////////////////////////////////////// 00242 // Function: ConfigVariable::get_int64_word 00243 // Access: Published 00244 // Description: Returns the int64 value of the nth word of the 00245 // variable's value, or 0 if there is no nth value. 00246 // See also has_int_word(). 00247 //////////////////////////////////////////////////////////////////// 00248 INLINE PN_int64 ConfigVariable:: 00249 get_int64_word(int n) const { 00250 nassertr(is_constructed(), 0); 00251 const ConfigDeclaration *decl = _core->get_declaration(0); 00252 return decl->get_int64_word(n); 00253 } 00254 00255 //////////////////////////////////////////////////////////////////// 00256 // Function: ConfigVariable::get_double_word 00257 // Access: Published 00258 // Description: Returns the integer value of the nth word of the 00259 // variable's value, or 0 if there is no nth value. 00260 // See also has_double_word(). 00261 //////////////////////////////////////////////////////////////////// 00262 INLINE double ConfigVariable:: 00263 get_double_word(int n) const { 00264 nassertr(is_constructed(), 0.0); 00265 const ConfigDeclaration *decl = _core->get_declaration(0); 00266 return decl->get_double_word(n); 00267 } 00268 00269 //////////////////////////////////////////////////////////////////// 00270 // Function: ConfigVariable::set_string_word 00271 // Access: Published 00272 // Description: Changes the nth word to the indicated value without 00273 // affecting the other words. 00274 //////////////////////////////////////////////////////////////////// 00275 INLINE void ConfigVariable:: 00276 set_string_word(int n, const string &value) { 00277 nassertv(is_constructed()); 00278 _core->make_local_value()->set_string_word(n, value); 00279 } 00280 00281 //////////////////////////////////////////////////////////////////// 00282 // Function: ConfigVariable::set_bool_word 00283 // Access: Published 00284 // Description: Changes the nth word to the indicated value without 00285 // affecting the other words. 00286 //////////////////////////////////////////////////////////////////// 00287 INLINE void ConfigVariable:: 00288 set_bool_word(int n, bool value) { 00289 nassertv(is_constructed()); 00290 _core->make_local_value()->set_bool_word(n, value); 00291 } 00292 00293 //////////////////////////////////////////////////////////////////// 00294 // Function: ConfigVariable::set_int_word 00295 // Access: Published 00296 // Description: Changes the nth word to the indicated value without 00297 // affecting the other words. 00298 //////////////////////////////////////////////////////////////////// 00299 INLINE void ConfigVariable:: 00300 set_int_word(int n, int value) { 00301 nassertv(is_constructed()); 00302 _core->make_local_value()->set_int_word(n, value); 00303 } 00304 00305 //////////////////////////////////////////////////////////////////// 00306 // Function: ConfigVariable::set_int64_word 00307 // Access: Published 00308 // Description: Changes the nth word to the indicated value without 00309 // affecting the other words. 00310 //////////////////////////////////////////////////////////////////// 00311 INLINE void ConfigVariable:: 00312 set_int64_word(int n, PN_int64 value) { 00313 nassertv(is_constructed()); 00314 _core->make_local_value()->set_int_word(n, value); 00315 } 00316 00317 //////////////////////////////////////////////////////////////////// 00318 // Function: ConfigVariable::set_double_word 00319 // Access: Published 00320 // Description: Changes the nth word to the indicated value without 00321 // affecting the other words. 00322 //////////////////////////////////////////////////////////////////// 00323 INLINE void ConfigVariable:: 00324 set_double_word(int n, double value) { 00325 nassertv(is_constructed()); 00326 _core->make_local_value()->set_double_word(n, value); 00327 } 00328 00329 //////////////////////////////////////////////////////////////////// 00330 // Function: ConfigVariable::is_constructed 00331 // Access: Protected 00332 // Description: Returns true if the constructor has been called and 00333 // _core initialized, false if the constructor has not 00334 // yet been called and _core is NULL. This is intended 00335 // to be placed in an assertion check, to guard against 00336 // static-init ordering issues. 00337 //////////////////////////////////////////////////////////////////// 00338 INLINE bool ConfigVariable:: 00339 is_constructed() const { 00340 #ifndef NDEBUG 00341 if (_core == (ConfigVariableCore *)NULL) { 00342 report_unconstructed(); 00343 return false; 00344 } 00345 #endif 00346 return true; 00347 }