Panda3D
configVariableCore.I
1 // Filename: configVariableCore.I
2 // Created by: drose (15Oct04)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 
16 ////////////////////////////////////////////////////////////////////
17 // Function: ConfigVariableCore::get_name
18 // Access: Public
19 // Description: Returns the name of the variable.
20 ////////////////////////////////////////////////////////////////////
21 INLINE const string &ConfigVariableCore::
22 get_name() const {
23  return _name;
24 }
25 
26 ////////////////////////////////////////////////////////////////////
27 // Function: ConfigVariableCore::is_used
28 // Access: Public
29 // Description: Returns true if the variable has been referenced by a
30 // ConfigVariable somewhere in code, false otherwise.
31 ////////////////////////////////////////////////////////////////////
32 INLINE bool ConfigVariableCore::
33 is_used() const {
34  return _is_used;
35 }
36 
37 ////////////////////////////////////////////////////////////////////
38 // Function: ConfigVariableCore::get_value_type
39 // Access: Public
40 // Description: Returns the stated type of this variable. If the
41 // variable has not yet been defined, this will be
42 // VT_undefined.
43 ////////////////////////////////////////////////////////////////////
44 INLINE ConfigVariableCore::ValueType ConfigVariableCore::
45 get_value_type() const {
46  return _value_type;
47 }
48 
49 ////////////////////////////////////////////////////////////////////
50 // Function: ConfigVariableCore::get_description
51 // Access: Public
52 // Description: Returns the brief description of this variable, if
53 // it has been defined.
54 ////////////////////////////////////////////////////////////////////
55 INLINE const string &ConfigVariableCore::
56 get_description() const {
57  return _description;
58 }
59 
60 ////////////////////////////////////////////////////////////////////
61 // Function: ConfigVariableCore::get_flags
62 // Access: Public
63 // Description: Returns the flags value as set by set_flags(). This
64 // includes the trust level and some other settings.
65 // See the individual methods is_closed(),
66 // get_trust_level(), etc. to pull out the semantic
67 // meaning of these flags individually.
68 ////////////////////////////////////////////////////////////////////
69 INLINE int ConfigVariableCore::
70 get_flags() const {
71  return _flags;
72 }
73 
74 ////////////////////////////////////////////////////////////////////
75 // Function: ConfigVariableCore::is_closed
76 // Access: Public
77 // Description: Returns true if the variable is not trusted by any
78 // prc file (and hence cannot be modified from its
79 // compiled-in default value), or false for the normal
80 // case, in which the variable can be modified by any
81 // prc file at or above its trust level (see
82 // get_trust_level()).
83 //
84 // This value only has effect in a release build
85 // (specifically, when PRC_RESPECT_TRUST_LEVEL is
86 // defined true in Config.pp).
87 ////////////////////////////////////////////////////////////////////
88 INLINE bool ConfigVariableCore::
89 is_closed() const {
90  return (_flags & F_closed) != 0;
91 }
92 
93 ////////////////////////////////////////////////////////////////////
94 // Function: ConfigVariableCore::get_trust_level
95 // Access: Public
96 // Description: Returns the minimum trust_level a prc file must
97 // demonstrate in order to redefine the value for this
98 // variable. Arguably, this should be called the
99 // "mistrust level", since the larger the value, the
100 // more suspicious we are of prc files. This value is
101 // not used if is_closed() returns true, which indicates
102 // no file may be trusted.
103 //
104 // This value only has effect in a release build
105 // (specifically, when PRC_RESPECT_TRUST_LEVEL is
106 // defined true in Config.pp).
107 ////////////////////////////////////////////////////////////////////
108 INLINE int ConfigVariableCore::
110  return (_flags & F_trust_level_mask);
111 }
112 
113 ////////////////////////////////////////////////////////////////////
114 // Function: ConfigVariableCore::is_dynamic
115 // Access: Public
116 // Description: Returns true if the variable was indicated as
117 // "dynamic" by its constructor, indicating that its
118 // name was dynamically generated, possibly from a large
119 // pool, and it should not be listed along with the
120 // other variables.
121 ////////////////////////////////////////////////////////////////////
122 INLINE bool ConfigVariableCore::
123 is_dynamic() const {
124  return (_flags & F_dynamic) != 0;
125 }
126 
127 ////////////////////////////////////////////////////////////////////
128 // Function: ConfigVariableCore::get_default_value
129 // Access: Public
130 // Description: Returns the default variable specified for this
131 // variable. If the variable has not yet been defined,
132 // this will return NULL.
133 ////////////////////////////////////////////////////////////////////
136  return _default_value;
137 }
138 
139 ////////////////////////////////////////////////////////////////////
140 // Function: ConfigVariableCore::set_used
141 // Access: Public
142 // Description: Marks that the variable has been "declared" by a
143 // ConfigVariable.
144 ////////////////////////////////////////////////////////////////////
145 INLINE void ConfigVariableCore::
147  _is_used = true;
148 }
149 
150 ////////////////////////////////////////////////////////////////////
151 // Function: ConfigVariableCore::has_local_value
152 // Access: Public
153 // Description: Returns true if this variable's value has been
154 // shadowed by a local assignment (as created via
155 // make_local_value()), or false otherwise.
156 ////////////////////////////////////////////////////////////////////
157 INLINE bool ConfigVariableCore::
159  return _local_value != (ConfigDeclaration *)NULL;
160 }
161 
162 ////////////////////////////////////////////////////////////////////
163 // Function: ConfigVariableCore::get_num_references
164 // Access: Public
165 // Description: Returns the number of prc files that reference this
166 // variable. This is not exactly the same as the number
167 // of declarations; see get_reference().
168 ////////////////////////////////////////////////////////////////////
169 INLINE int ConfigVariableCore::
171  check_sort_declarations();
172  return _declarations.size();
173 }
174 
175 ////////////////////////////////////////////////////////////////////
176 // Function: ConfigVariableCore::get_reference
177 // Access: Public
178 // Description: Returns the nth declaration in a prc file that
179 // references this variable. This is similar, but not
180 // identical to, get_declaration(). The difference is
181 // that this will list *only* true references in a prc
182 // file, and will not list default values or
183 // locally-assigned values; it also will list even the
184 // untrusted files.
185 ////////////////////////////////////////////////////////////////////
187 get_reference(int n) const {
188  check_sort_declarations();
189  nassertr(n >= 0 && n < (int)_declarations.size(), (ConfigDeclaration *)NULL);
190  return _declarations[n];
191 }
192 
193 ////////////////////////////////////////////////////////////////////
194 // Function: ConfigVariableCore::get_num_trusted_references
195 // Access: Public
196 // Description: Returns the number of trusted prc files that
197 // reference this variable. See also
198 // get_num_references().
199 ////////////////////////////////////////////////////////////////////
200 INLINE int ConfigVariableCore::
202  check_sort_declarations();
203  return _trusted_declarations.size();
204 }
205 
206 ////////////////////////////////////////////////////////////////////
207 // Function: ConfigVariableCore::get_trusted_reference
208 // Access: Public
209 // Description: Returns the nth declaration in a trusted prc file
210 // that references this variable. This is similar, but
211 // not identical to, get_declaration(). The difference
212 // is that this will list *only* true references in a
213 // prc file, and will not list default values or
214 // locally-assigned values.
215 //
216 // This is also similar to get_reference(), except that
217 // it only lists the trusted declarations, omitting the
218 // untrusted ones.
219 ////////////////////////////////////////////////////////////////////
221 get_trusted_reference(int n) const {
222  check_sort_declarations();
223  nassertr(n >= 0 && n < (int)_trusted_declarations.size(), (ConfigDeclaration *)NULL);
224  return _trusted_declarations[n];
225 }
226 
227 ////////////////////////////////////////////////////////////////////
228 // Function: ConfigVariableCore::get_num_unique_references
229 // Access: Public
230 // Description: Returns the number of trusted, unique (by string
231 // value) values there exist for this variable.
232 ////////////////////////////////////////////////////////////////////
233 INLINE int ConfigVariableCore::
235  check_sort_declarations();
236  return _unique_declarations.size();
237 }
238 
239 ////////////////////////////////////////////////////////////////////
240 // Function: ConfigVariableCore::get_unique_reference
241 // Access: Public
242 // Description: Returns the nth trusted, unique value for this
243 // variable. This is similar to
244 // get_trusted_reference(), except that duplicate values
245 // are removed.
246 ////////////////////////////////////////////////////////////////////
248 get_unique_reference(int n) const {
249  check_sort_declarations();
250  nassertr(n >= 0 && n < (int)_unique_declarations.size(), (ConfigDeclaration *)NULL);
251  return _unique_declarations[n];
252 }
253 
254 ////////////////////////////////////////////////////////////////////
255 // Function: ConfigVariableCore::check_sort_declarations()
256 // Access: Private
257 // Description: Called internally to ensure that the list of
258 // declarations is properly sorted.
259 ////////////////////////////////////////////////////////////////////
260 INLINE void ConfigVariableCore::
261 check_sort_declarations() const {
262  // First, make sure that all of the implicit .prc files have been
263  // loaded. This may unsort the list by adding a bunch more
264  // declarations.
265  ConfigPageManager::get_global_ptr()->load_implicit_pages();
266 
267  // Then sort the list if it needs it.
268  if (!_declarations_sorted) {
269  ((ConfigVariableCore *)this)->sort_declarations();
270  }
271 }
272 
273 INLINE ostream &
274 operator << (ostream &out, const ConfigVariableCore &variable) {
275  variable.output(out);
276  return out;
277 }
The internal definition of a ConfigVariable.
int get_flags() const
Returns the flags value as set by set_flags().
bool is_used() const
Returns true if the variable has been referenced by a ConfigVariable somewhere in code...
int get_num_unique_references() const
Returns the number of trusted, unique (by string value) values there exist for this variable...
void load_implicit_pages()
Searches the PRC_DIR and/or PRC_PATH directories for .prc files and loads them in as pages...
const string & get_name() const
Returns the name of the variable.
const ConfigDeclaration * get_reference(int n) const
Returns the nth declaration in a prc file that references this variable.
const ConfigDeclaration * get_default_value() const
Returns the default variable specified for this variable.
bool has_local_value() const
Returns true if this variable&#39;s value has been shadowed by a local assignment (as created via make_lo...
int get_trust_level() const
Returns the minimum trust_level a prc file must demonstrate in order to redefine the value for this v...
const ConfigDeclaration * get_trusted_reference(int n) const
Returns the nth declaration in a trusted prc file that references this variable.
void set_used()
Marks that the variable has been "declared" by a ConfigVariable.
const string & get_description() const
Returns the brief description of this variable, if it has been defined.
bool is_dynamic() const
Returns true if the variable was indicated as "dynamic" by its constructor, indicating that its name ...
int get_num_references() const
Returns the number of prc files that reference this variable.
bool is_closed() const
Returns true if the variable is not trusted by any prc file (and hence cannot be modified from its co...
int get_num_trusted_references() const
Returns the number of trusted prc files that reference this variable.
A single declaration of a config variable, typically defined as one line in a .prc file...
const ConfigDeclaration * get_unique_reference(int n) const
Returns the nth trusted, unique value for this variable.
ValueType get_value_type() const
Returns the stated type of this variable.