Panda3D
 All Classes Functions Variables Enumerations
configVariableCore.I
00001 // Filename: configVariableCore.I
00002 // Created by:  drose (15Oct04)
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: ConfigVariableCore::get_name
00018 //       Access: Public
00019 //  Description: Returns the name of the variable.
00020 ////////////////////////////////////////////////////////////////////
00021 INLINE const string &ConfigVariableCore::
00022 get_name() const {
00023   return _name;
00024 }
00025 
00026 ////////////////////////////////////////////////////////////////////
00027 //     Function: ConfigVariableCore::is_used
00028 //       Access: Public
00029 //  Description: Returns true if the variable has been referenced by a
00030 //               ConfigVariable somewhere in code, false otherwise.
00031 ////////////////////////////////////////////////////////////////////
00032 INLINE bool ConfigVariableCore::
00033 is_used() const {
00034   return _is_used;
00035 }
00036 
00037 ////////////////////////////////////////////////////////////////////
00038 //     Function: ConfigVariableCore::get_value_type
00039 //       Access: Public
00040 //  Description: Returns the stated type of this variable.  If the
00041 //               variable has not yet been defined, this will be
00042 //               VT_undefined.
00043 ////////////////////////////////////////////////////////////////////
00044 INLINE ConfigVariableCore::ValueType ConfigVariableCore::
00045 get_value_type() const {
00046   return _value_type;
00047 }
00048 
00049 ////////////////////////////////////////////////////////////////////
00050 //     Function: ConfigVariableCore::get_description
00051 //       Access: Public
00052 //  Description: Returns the brief description of this variable, if
00053 //               it has been defined.
00054 ////////////////////////////////////////////////////////////////////
00055 INLINE const string &ConfigVariableCore::
00056 get_description() const {
00057   return _description;
00058 }
00059 
00060 ////////////////////////////////////////////////////////////////////
00061 //     Function: ConfigVariableCore::get_flags
00062 //       Access: Public
00063 //  Description: Returns the flags value as set by set_flags().  This
00064 //               includes the trust level and some other settings.
00065 //               See the individual methods is_closed(),
00066 //               get_trust_level(), etc. to pull out the semantic
00067 //               meaning of these flags individually.
00068 ////////////////////////////////////////////////////////////////////
00069 INLINE int ConfigVariableCore::
00070 get_flags() const {
00071   return _flags;
00072 }
00073 
00074 ////////////////////////////////////////////////////////////////////
00075 //     Function: ConfigVariableCore::is_closed
00076 //       Access: Public
00077 //  Description: Returns true if the variable is not trusted by any
00078 //               prc file (and hence cannot be modified from its
00079 //               compiled-in default value), or false for the normal
00080 //               case, in which the variable can be modified by any
00081 //               prc file at or above its trust level (see
00082 //               get_trust_level()).
00083 //
00084 //               This value only has effect in a release build
00085 //               (specifically, when PRC_RESPECT_TRUST_LEVEL is
00086 //               defined true in Config.pp).
00087 ////////////////////////////////////////////////////////////////////
00088 INLINE bool ConfigVariableCore::
00089 is_closed() const {
00090   return (_flags & F_closed) != 0;
00091 }
00092 
00093 ////////////////////////////////////////////////////////////////////
00094 //     Function: ConfigVariableCore::get_trust_level
00095 //       Access: Public
00096 //  Description: Returns the minimum trust_level a prc file must
00097 //               demonstrate in order to redefine the value for this
00098 //               variable.  Arguably, this should be called the
00099 //               "mistrust level", since the larger the value, the
00100 //               more suspicious we are of prc files.  This value is
00101 //               not used if is_closed() returns true, which indicates
00102 //               no file may be trusted.
00103 //
00104 //               This value only has effect in a release build
00105 //               (specifically, when PRC_RESPECT_TRUST_LEVEL is
00106 //               defined true in Config.pp).
00107 ////////////////////////////////////////////////////////////////////
00108 INLINE int ConfigVariableCore::
00109 get_trust_level() const {
00110   return (_flags & F_trust_level_mask);
00111 }
00112 
00113 ////////////////////////////////////////////////////////////////////
00114 //     Function: ConfigVariableCore::is_dynamic
00115 //       Access: Public
00116 //  Description: Returns true if the variable was indicated as
00117 //               "dynamic" by its constructor, indicating that its
00118 //               name was dynamically generated, possibly from a large
00119 //               pool, and it should not be listed along with the
00120 //               other variables.
00121 ////////////////////////////////////////////////////////////////////
00122 INLINE bool ConfigVariableCore::
00123 is_dynamic() const {
00124   return (_flags & F_dynamic) != 0;
00125 }
00126 
00127 ////////////////////////////////////////////////////////////////////
00128 //     Function: ConfigVariableCore::get_default_value
00129 //       Access: Public
00130 //  Description: Returns the default variable specified for this
00131 //               variable.  If the variable has not yet been defined,
00132 //               this will return NULL.
00133 ////////////////////////////////////////////////////////////////////
00134 INLINE const ConfigDeclaration *ConfigVariableCore::
00135 get_default_value() const {
00136   return _default_value;
00137 }
00138 
00139 ////////////////////////////////////////////////////////////////////
00140 //     Function: ConfigVariableCore::set_used
00141 //       Access: Public
00142 //  Description: Marks that the variable has been "declared" by a
00143 //               ConfigVariable.
00144 ////////////////////////////////////////////////////////////////////
00145 INLINE void ConfigVariableCore::
00146 set_used() {
00147   _is_used = true;
00148 }
00149 
00150 ////////////////////////////////////////////////////////////////////
00151 //     Function: ConfigVariableCore::has_local_value
00152 //       Access: Public
00153 //  Description: Returns true if this variable's value has been
00154 //               shadowed by a local assignment (as created via
00155 //               make_local_value()), or false otherwise.
00156 ////////////////////////////////////////////////////////////////////
00157 INLINE bool ConfigVariableCore::
00158 has_local_value() const {
00159   return _local_value != (ConfigDeclaration *)NULL;
00160 }
00161 
00162 ////////////////////////////////////////////////////////////////////
00163 //     Function: ConfigVariableCore::get_num_references
00164 //       Access: Public
00165 //  Description: Returns the number of prc files that reference this
00166 //               variable.  This is not exactly the same as the number
00167 //               of declarations; see get_reference().
00168 ////////////////////////////////////////////////////////////////////
00169 INLINE int ConfigVariableCore::
00170 get_num_references() const {
00171   check_sort_declarations();
00172   return _declarations.size();
00173 }
00174 
00175 ////////////////////////////////////////////////////////////////////
00176 //     Function: ConfigVariableCore::get_reference
00177 //       Access: Public
00178 //  Description: Returns the nth declaration in a prc file that
00179 //               references this variable.  This is similar, but not
00180 //               identical to, get_declaration().  The difference is
00181 //               that this will list *only* true references in a prc
00182 //               file, and will not list default values or
00183 //               locally-assigned values; it also will list even the
00184 //               untrusted files.
00185 ////////////////////////////////////////////////////////////////////
00186 INLINE const ConfigDeclaration *ConfigVariableCore::
00187 get_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_references
00195 //       Access: Public
00196 //  Description: Returns the number of trusted prc files that
00197 //               reference this variable.  See also
00198 //               get_num_references().
00199 ////////////////////////////////////////////////////////////////////
00200 INLINE int ConfigVariableCore::
00201 get_num_trusted_references() const {
00202   check_sort_declarations();
00203   return _trusted_declarations.size();
00204 }
00205 
00206 ////////////////////////////////////////////////////////////////////
00207 //     Function: ConfigVariableCore::get_trusted_reference
00208 //       Access: Public
00209 //  Description: Returns the nth declaration in a trusted prc file
00210 //               that references this variable.  This is similar, but
00211 //               not identical to, get_declaration().  The difference
00212 //               is that this will list *only* true references in a
00213 //               prc file, and will not list default values or
00214 //               locally-assigned values.
00215 //
00216 //               This is also similar to get_reference(), except that
00217 //               it only lists the trusted declarations, omitting the
00218 //               untrusted ones.
00219 ////////////////////////////////////////////////////////////////////
00220 INLINE const ConfigDeclaration *ConfigVariableCore::
00221 get_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_references
00229 //       Access: Public
00230 //  Description: Returns the number of trusted, unique (by string
00231 //               value) values there exist for this variable.
00232 ////////////////////////////////////////////////////////////////////
00233 INLINE int ConfigVariableCore::
00234 get_num_unique_references() const {
00235   check_sort_declarations();
00236   return _unique_declarations.size();
00237 }
00238 
00239 ////////////////////////////////////////////////////////////////////
00240 //     Function: ConfigVariableCore::get_unique_reference
00241 //       Access: Public
00242 //  Description: Returns the nth trusted, unique value for this
00243 //               variable.  This is similar to
00244 //               get_trusted_reference(), except that duplicate values
00245 //               are removed.
00246 ////////////////////////////////////////////////////////////////////
00247 INLINE const ConfigDeclaration *ConfigVariableCore::
00248 get_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: Private
00257 //  Description: Called internally to ensure that the list of
00258 //               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 been
00263   // loaded.  This may unsort the list by adding a bunch more
00264   // 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, const ConfigVariableCore &variable) {
00275   variable.output(out);
00276   return out;
00277 }
 All Classes Functions Variables Enumerations