00001 // Filename: configVariableCore.I00002 // Created by: drose (15Oct04)00003 //00004 ////////////////////////////////////////////////////////////////////00005 //00006 // PANDA 3D SOFTWARE00007 // Copyright (c) Carnegie Mellon University. All rights reserved.00008 //00009 // All use of this software is subject to the terms of the revised BSD00010 // license. You should have received a copy of this license along00011 // with this source code in a file named "LICENSE."00012 //00013 ////////////////////////////////////////////////////////////////////00014
00015
00016 ////////////////////////////////////////////////////////////////////00017 // Function: ConfigVariableCore::get_name00018 // Access: Public00019 // Description: Returns the name of the variable.00020 ////////////////////////////////////////////////////////////////////00021 INLINE conststring &ConfigVariableCore::00022get_name() const {
00023 return _name;
00024 }
00025
00026 ////////////////////////////////////////////////////////////////////00027 // Function: ConfigVariableCore::is_used00028 // Access: Public00029 // Description: Returns true if the variable has been referenced by a00030 // ConfigVariable somewhere in code, false otherwise.00031 ////////////////////////////////////////////////////////////////////00032 INLINE boolConfigVariableCore::00033is_used() const {
00034 return _is_used;
00035 }
00036
00037 ////////////////////////////////////////////////////////////////////00038 // Function: ConfigVariableCore::get_value_type00039 // Access: Public00040 // Description: Returns the stated type of this variable. If the00041 // variable has not yet been defined, this will be00042 // VT_undefined.00043 ////////////////////////////////////////////////////////////////////00044 INLINE ConfigVariableCore::ValueType ConfigVariableCore::00045get_value_type() const {
00046 return _value_type;
00047 }
00048
00049 ////////////////////////////////////////////////////////////////////00050 // Function: ConfigVariableCore::get_description00051 // Access: Public00052 // Description: Returns the brief description of this variable, if00053 // it has been defined.00054 ////////////////////////////////////////////////////////////////////00055 INLINE conststring &ConfigVariableCore::00056get_description() const {
00057 return _description;
00058 }
00059
00060 ////////////////////////////////////////////////////////////////////00061 // Function: ConfigVariableCore::get_flags00062 // Access: Public00063 // Description: Returns the flags value as set by set_flags(). This00064 // includes the trust level and some other settings.00065 // See the individual methods is_closed(),00066 // get_trust_level(), etc. to pull out the semantic00067 // meaning of these flags individually.00068 ////////////////////////////////////////////////////////////////////00069 INLINE intConfigVariableCore::00070get_flags() const {
00071 return _flags;
00072 }
00073
00074 ////////////////////////////////////////////////////////////////////00075 // Function: ConfigVariableCore::is_closed00076 // Access: Public00077 // Description: Returns true if the variable is not trusted by any00078 // prc file (and hence cannot be modified from its00079 // compiled-in default value), or false for the normal00080 // case, in which the variable can be modified by any00081 // prc file at or above its trust level (see00082 // get_trust_level()).00083 //00084 // This value only has effect in a release build00085 // (specifically, when PRC_RESPECT_TRUST_LEVEL is00086 // defined true in Config.pp).00087 ////////////////////////////////////////////////////////////////////00088 INLINE boolConfigVariableCore::00089is_closed() const {
00090 return (_flags & F_closed) != 0;
00091 }
00092
00093 ////////////////////////////////////////////////////////////////////00094 // Function: ConfigVariableCore::get_trust_level00095 // Access: Public00096 // Description: Returns the minimum trust_level a prc file must00097 // demonstrate in order to redefine the value for this00098 // variable. Arguably, this should be called the00099 // "mistrust level", since the larger the value, the00100 // more suspicious we are of prc files. This value is00101 // not used if is_closed() returns true, which indicates00102 // no file may be trusted.00103 //00104 // This value only has effect in a release build00105 // (specifically, when PRC_RESPECT_TRUST_LEVEL is00106 // defined true in Config.pp).00107 ////////////////////////////////////////////////////////////////////00108 INLINE intConfigVariableCore::00109get_trust_level() const {
00110 return (_flags & F_trust_level_mask);
00111 }
00112
00113 ////////////////////////////////////////////////////////////////////00114 // Function: ConfigVariableCore::is_dynamic00115 // Access: Public00116 // Description: Returns true if the variable was indicated as00117 // "dynamic" by its constructor, indicating that its00118 // name was dynamically generated, possibly from a large00119 // pool, and it should not be listed along with the00120 // other variables.00121 ////////////////////////////////////////////////////////////////////00122 INLINE boolConfigVariableCore::00123is_dynamic() const {
00124 return (_flags & F_dynamic) != 0;
00125 }
00126
00127 ////////////////////////////////////////////////////////////////////00128 // Function: ConfigVariableCore::get_default_value00129 // Access: Public00130 // Description: Returns the default variable specified for this00131 // variable. If the variable has not yet been defined,00132 // this will return NULL.00133 ////////////////////////////////////////////////////////////////////00134 INLINE constConfigDeclaration *ConfigVariableCore::00135get_default_value() const {
00136 return _default_value;
00137 }
00138
00139 ////////////////////////////////////////////////////////////////////00140 // Function: ConfigVariableCore::set_used00141 // Access: Public00142 // Description: Marks that the variable has been "declared" by a00143 // ConfigVariable.00144 ////////////////////////////////////////////////////////////////////00145 INLINE voidConfigVariableCore::00146set_used() {
00147 _is_used = true;
00148 }
00149
00150 ////////////////////////////////////////////////////////////////////00151 // Function: ConfigVariableCore::has_local_value00152 // Access: Public00153 // Description: Returns true if this variable's value has been00154 // shadowed by a local assignment (as created via00155 // make_local_value()), or false otherwise.00156 ////////////////////////////////////////////////////////////////////00157 INLINE boolConfigVariableCore::00158has_local_value() const {
00159 return _local_value != (ConfigDeclaration *)NULL;
00160 }
00161
00162 ////////////////////////////////////////////////////////////////////00163 // Function: ConfigVariableCore::get_num_references00164 // Access: Public00165 // Description: Returns the number of prc files that reference this00166 // variable. This is not exactly the same as the number00167 // of declarations; see get_reference().00168 ////////////////////////////////////////////////////////////////////00169 INLINE intConfigVariableCore::00170get_num_references() const {
00171 check_sort_declarations();
00172 return _declarations.size();
00173 }
00174
00175 ////////////////////////////////////////////////////////////////////00176 // Function: ConfigVariableCore::get_reference00177 // Access: Public00178 // Description: Returns the nth declaration in a prc file that00179 // references this variable. This is similar, but not00180 // identical to, get_declaration(). The difference is00181 // that this will list *only* true references in a prc00182 // file, and will not list default values or00183 // locally-assigned values; it also will list even the00184 // untrusted files.00185 ////////////////////////////////////////////////////////////////////00186 INLINE constConfigDeclaration *ConfigVariableCore::00187get_reference(int n) const {
00188 check_sort_declarations();
00189 nassertr(n >= 0 && n < (int)_declarations.size(), (ConfigDeclaration *)NULL);
00190 return _declarations[n];
00191 }
00192
00193 ////////////////////////////////////////////////////////////////////00194 // Function: ConfigVariableCore::get_num_trusted_references00195 // Access: Public00196 // Description: Returns the number of trusted prc files that00197 // reference this variable. See also00198 // get_num_references().00199 ////////////////////////////////////////////////////////////////////00200 INLINE intConfigVariableCore::00201get_num_trusted_references() const {
00202 check_sort_declarations();
00203 return _trusted_declarations.size();
00204 }
00205
00206 ////////////////////////////////////////////////////////////////////00207 // Function: ConfigVariableCore::get_trusted_reference00208 // Access: Public00209 // Description: Returns the nth declaration in a trusted prc file00210 // that references this variable. This is similar, but00211 // not identical to, get_declaration(). The difference00212 // is that this will list *only* true references in a00213 // prc file, and will not list default values or00214 // locally-assigned values.00215 //00216 // This is also similar to get_reference(), except that00217 // it only lists the trusted declarations, omitting the00218 // untrusted ones.00219 ////////////////////////////////////////////////////////////////////00220 INLINE constConfigDeclaration *ConfigVariableCore::00221get_trusted_reference(int n) const {
00222 check_sort_declarations();
00223 nassertr(n >= 0 && n < (int)_trusted_declarations.size(), (ConfigDeclaration *)NULL);
00224 return _trusted_declarations[n];
00225 }
00226
00227 ////////////////////////////////////////////////////////////////////00228 // Function: ConfigVariableCore::get_num_unique_references00229 // Access: Public00230 // Description: Returns the number of trusted, unique (by string00231 // value) values there exist for this variable.00232 ////////////////////////////////////////////////////////////////////00233 INLINE intConfigVariableCore::00234get_num_unique_references() const {
00235 check_sort_declarations();
00236 return _unique_declarations.size();
00237 }
00238
00239 ////////////////////////////////////////////////////////////////////00240 // Function: ConfigVariableCore::get_unique_reference00241 // Access: Public00242 // Description: Returns the nth trusted, unique value for this00243 // variable. This is similar to00244 // get_trusted_reference(), except that duplicate values00245 // are removed.00246 ////////////////////////////////////////////////////////////////////00247 INLINE constConfigDeclaration *ConfigVariableCore::00248get_unique_reference(int n) const {
00249 check_sort_declarations();
00250 nassertr(n >= 0 && n < (int)_unique_declarations.size(), (ConfigDeclaration *)NULL);
00251 return _unique_declarations[n];
00252 }
00253
00254 ////////////////////////////////////////////////////////////////////00255 // Function: ConfigVariableCore::check_sort_declarations()00256 // Access: Private00257 // Description: Called internally to ensure that the list of00258 // declarations is properly sorted.00259 ////////////////////////////////////////////////////////////////////00260 INLINE void ConfigVariableCore::
00261 check_sort_declarations() const {
00262 // First, make sure that all of the implicit .prc files have been00263 // loaded. This may unsort the list by adding a bunch more00264 // declarations.00265 ConfigPageManager::get_global_ptr()->load_implicit_pages();
00266
00267 // Then sort the list if it needs it.00268 if (!_declarations_sorted) {
00269 ((ConfigVariableCore *)this)->sort_declarations();
00270 }
00271 }
00272
00273 INLINE ostream &
00274 operator << (ostream &out, constConfigVariableCore &variable) {
00275 variable.output(out);
00276 return out;
00277 }