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