Panda3D
|
00001 // Filename: configVariableBase.I 00002 // Created by: drose (21Oct04) 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: ConfigVariableBase::Constructor 00018 // Access: Protected 00019 // Description: This constructor is only intended to be called from a 00020 // specialized ConfigVariableFoo derived class. 00021 //////////////////////////////////////////////////////////////////// 00022 INLINE ConfigVariableBase:: 00023 ConfigVariableBase(const string &name, 00024 ConfigVariableBase::ValueType value_type) : 00025 _core(ConfigVariableManager::get_global_ptr()->make_variable(name)) 00026 { 00027 if (value_type != VT_undefined) { 00028 _core->set_value_type(value_type); 00029 } 00030 } 00031 00032 //////////////////////////////////////////////////////////////////// 00033 // Function: ConfigVariableBase::Destructor 00034 // Access: Protected 00035 // Description: 00036 //////////////////////////////////////////////////////////////////// 00037 INLINE ConfigVariableBase:: 00038 ~ConfigVariableBase() { 00039 } 00040 00041 //////////////////////////////////////////////////////////////////// 00042 // Function: ConfigVariableBase::get_name 00043 // Access: Published 00044 // Description: Returns the name of the variable. 00045 //////////////////////////////////////////////////////////////////// 00046 INLINE const string &ConfigVariableBase:: 00047 get_name() const { 00048 nassertr(_core != (ConfigVariableCore *)NULL, *new string()); 00049 return _core->get_name(); 00050 } 00051 00052 //////////////////////////////////////////////////////////////////// 00053 // Function: ConfigVariableBase::get_value_type 00054 // Access: Published 00055 // Description: Returns the stated type of this variable. This 00056 // should be VT_list, unless a later variable 00057 // declaration has changed it. 00058 //////////////////////////////////////////////////////////////////// 00059 INLINE ConfigVariableBase::ValueType ConfigVariableBase:: 00060 get_value_type() const { 00061 nassertr(_core != (ConfigVariableCore *)NULL, VT_undefined); 00062 return _core->get_value_type(); 00063 } 00064 00065 //////////////////////////////////////////////////////////////////// 00066 // Function: ConfigVariableBase::get_description 00067 // Access: Published 00068 // Description: Returns the brief description of this variable, if 00069 // it has been defined. 00070 //////////////////////////////////////////////////////////////////// 00071 INLINE const string &ConfigVariableBase:: 00072 get_description() const { 00073 nassertr(_core != (ConfigVariableCore *)NULL, *new string()); 00074 return _core->get_description(); 00075 } 00076 00077 //////////////////////////////////////////////////////////////////// 00078 // Function: ConfigVariableBase::get_flags 00079 // Access: Public 00080 // Description: Returns the flags value as set by set_flags(). This 00081 // includes the trust level and some other settings. 00082 // See the individual methods is_closed(), 00083 // get_trust_level(), etc. to pull out the semantic 00084 // meaning of these flags individually. 00085 //////////////////////////////////////////////////////////////////// 00086 INLINE int ConfigVariableBase:: 00087 get_flags() const { 00088 nassertr(_core != (ConfigVariableCore *)NULL, 0); 00089 return _core->get_flags(); 00090 } 00091 00092 //////////////////////////////////////////////////////////////////// 00093 // Function: ConfigVariableBase::is_closed 00094 // Access: Public 00095 // Description: Returns true if the variable is not trusted by any 00096 // prc file (and hence cannot be modified from its 00097 // compiled-in default value), or false for the normal 00098 // case, in which the variable can be modified by any 00099 // prc file at or above its trust level (see 00100 // get_trust_level()). 00101 // 00102 // This value only has effect in a release build 00103 // (specifically, when PRC_RESPECT_TRUST_LEVEL is 00104 // defined true in Config.pp). 00105 //////////////////////////////////////////////////////////////////// 00106 INLINE bool ConfigVariableBase:: 00107 is_closed() const { 00108 nassertr(_core != (ConfigVariableCore *)NULL, false); 00109 return _core->is_closed(); 00110 } 00111 00112 //////////////////////////////////////////////////////////////////// 00113 // Function: ConfigVariableBase::get_trust_level 00114 // Access: Public 00115 // Description: Returns the minimum trust_level a prc file must 00116 // demonstrate in order to redefine the value for this 00117 // variable. Arguably, this should be called the 00118 // "mistrust level", since the larger the value, the 00119 // more suspicious we are of prc files. This value is 00120 // not used if is_closed() returns true, which indicates 00121 // no file may be trusted. 00122 // 00123 // This value only has effect in a release build 00124 // (specifically, when PRC_RESPECT_TRUST_LEVEL is 00125 // defined true in Config.pp). 00126 //////////////////////////////////////////////////////////////////// 00127 INLINE int ConfigVariableBase:: 00128 get_trust_level() const { 00129 nassertr(_core != (ConfigVariableCore *)NULL, 0); 00130 return _core->get_trust_level(); 00131 } 00132 00133 //////////////////////////////////////////////////////////////////// 00134 // Function: ConfigVariableBase::is_dynamic 00135 // Access: Public 00136 // Description: Returns true if the variable was indicated as 00137 // "dynamic" by its constructor, indicating that its 00138 // name was dynamically generated, possibly from a large 00139 // pool, and it should not be listed along with the 00140 // other variables. 00141 //////////////////////////////////////////////////////////////////// 00142 INLINE bool ConfigVariableBase:: 00143 is_dynamic() const { 00144 nassertr(_core != (ConfigVariableCore *)NULL, false); 00145 return _core->is_dynamic(); 00146 } 00147 00148 //////////////////////////////////////////////////////////////////// 00149 // Function: ConfigVariableBase::clear_local_value 00150 // Access: Published 00151 // Description: Removes the local value defined for this variable, 00152 // and allows its value to be once again retrieved from 00153 // the .prc files. 00154 // 00155 // Returns true if the value was successfully removed, 00156 // false if it did not exist in the first place. 00157 //////////////////////////////////////////////////////////////////// 00158 INLINE bool ConfigVariableBase:: 00159 clear_local_value() { 00160 nassertr(_core != (ConfigVariableCore *)NULL, false); 00161 return _core->clear_local_value(); 00162 } 00163 00164 //////////////////////////////////////////////////////////////////// 00165 // Function: ConfigVariableBase::has_local_value 00166 // Access: Published 00167 // Description: Returns true if this variable's value has been 00168 // shadowed by a local assignment (as created via 00169 // make_local_value()), or false otherwise. 00170 //////////////////////////////////////////////////////////////////// 00171 INLINE bool ConfigVariableBase:: 00172 has_local_value() const { 00173 nassertr(_core != (ConfigVariableCore *)NULL, false); 00174 return _core->has_local_value(); 00175 } 00176 00177 //////////////////////////////////////////////////////////////////// 00178 // Function: ConfigVariableBase::has_value 00179 // Access: Public 00180 // Description: Returns true if this variable has an explicit value, 00181 // either from a prc file or locally set, or false if 00182 // variable has its default value. 00183 //////////////////////////////////////////////////////////////////// 00184 INLINE bool ConfigVariableBase:: 00185 has_value() const { 00186 nassertr(_core != (ConfigVariableCore *)NULL, false); 00187 return _core->has_value(); 00188 } 00189 00190 //////////////////////////////////////////////////////////////////// 00191 // Function: ConfigVariableBase::output 00192 // Access: Published 00193 // Description: 00194 //////////////////////////////////////////////////////////////////// 00195 INLINE void ConfigVariableBase:: 00196 output(ostream &out) const { 00197 nassertv(_core != (ConfigVariableCore *)NULL); 00198 _core->output(out); 00199 } 00200 00201 //////////////////////////////////////////////////////////////////// 00202 // Function: ConfigVariableBase::write 00203 // Access: Published 00204 // Description: 00205 //////////////////////////////////////////////////////////////////// 00206 INLINE void ConfigVariableBase:: 00207 write(ostream &out) const { 00208 nassertv(_core != (ConfigVariableCore *)NULL); 00209 _core->write(out); 00210 } 00211 00212 INLINE ostream & 00213 operator << (ostream &out, const ConfigVariableBase &variable) { 00214 variable.output(out); 00215 return out; 00216 }