22#include "prc_parameters.h"
34ConfigVariableCore(
const string &name) :
37 _value_type(VT_undefined),
39 _default_value(nullptr),
40 _local_value(nullptr),
41 _declarations_sorted(true),
44#if defined(PRC_INC_TRUST_LEVEL) && PRC_INC_TRUST_LEVEL != 0
45 _flags = (_flags & ~F_trust_level_mask) | ((_flags & F_trust_level_mask) + PRC_INC_TRUST_LEVEL);
57 _is_used(templ._is_used),
58 _value_type(templ._value_type),
59 _description(templ._description),
61 _default_value(nullptr),
62 _local_value(nullptr),
63 _declarations_sorted(false),
66 if (templ._default_value !=
nullptr) {
76~ConfigVariableCore() {
78 <<
"Internal error--ConfigVariableCore destructor called!\n";
88 if (_value_queried && _value_type != value_type) {
89 if ((_flags & F_dconfig) != 0) {
96 <<
"changing type for ConfigVariable "
97 <<
get_name() <<
" from " << _value_type <<
" to "
98 << value_type <<
".\n";
102 _value_type = value_type;
112 if ((flags & F_dconfig) != 0) {
113 flags = (flags & ~F_trust_level_mask) | PRC_DCONFIG_TRUST_LEVEL;
116#if defined(PRC_INC_TRUST_LEVEL) && PRC_INC_TRUST_LEVEL != 0
117 flags = (flags & ~F_trust_level_mask) | ((flags & F_trust_level_mask) + PRC_INC_TRUST_LEVEL);
120 if (_value_queried) {
121 int bits_changed = (_flags ^ flags);
122 if ((bits_changed & F_trust_level_mask) != 0) {
124 <<
"changing trust level for ConfigVariable "
125 <<
get_name() <<
" from " << (_flags & F_trust_level_mask) <<
" to "
126 << (flags & F_trust_level_mask) <<
".\n";
128 if ((bits_changed & ~(F_trust_level_mask | F_dconfig)) != 0) {
130 <<
"changing flags for ConfigVariable "
131 <<
get_name() <<
" from " << std::hex
132 << (_flags & ~F_trust_level_mask) <<
" to "
133 << (flags & ~F_trust_level_mask) << std::dec <<
".\n";
140 _declarations_sorted =
false;
151 if (_value_queried && _description != description) {
152 if ((_flags & F_dconfig) != 0) {
158 if (description ==
"DConfig") {
161 if (_description.empty()) {
162 _description = description;
167 if (description.empty()) {
172 if (_description.empty()) {
174 _description = description;
179 <<
"changing description for ConfigVariable "
183 _description = description;
192 if (_default_value ==
nullptr) {
206 if (orig_default_value != default_value) {
207 if ((_flags & F_dconfig) != 0) {
214 <<
"changing default value for ConfigVariable "
215 <<
get_name() <<
" from '" << orig_default_value
216 <<
"' to '" << default_value <<
"'.\n";
233 if (_local_value ==
nullptr) {
240 <<
"Assigning a local value to a \"closed\" ConfigVariable. "
241 "This is legal in a development build, but illegal in a release "
242 "build and may result in a compilation error or exception.\n";
258 if (_local_value !=
nullptr) {
260 _local_value =
nullptr;
277 check_sort_declarations();
278 return (!_trusted_declarations.empty());
291 check_sort_declarations();
292 if (!_trusted_declarations.empty()) {
293 return _trusted_declarations.size();
309 if (_default_value ==
nullptr) {
311 <<
"value queried before default value set for "
319 check_sort_declarations();
320 if (n < _trusted_declarations.size()) {
321 return _trusted_declarations[n];
323 return _default_value;
329void ConfigVariableCore::
330output(std::ostream &out)
const {
337void ConfigVariableCore::
338write(std::ostream &out)
const {
339 out <<
"ConfigVariable " <<
get_name() <<
":\n";
341 check_sort_declarations();
344 out <<
" " << *_local_value <<
" (defined locally)\n";
347 Declarations::const_iterator di;
348 for (di = _trusted_declarations.begin();
349 di != _trusted_declarations.end();
352 <<
" (from " << (*di)->get_page()->get_name() <<
")\n";
355 if (_default_value !=
nullptr) {
356 out <<
" " << *_default_value <<
" (default value)\n";
359 for (di = _untrusted_declarations.begin();
360 di != _untrusted_declarations.end();
363 <<
" (from " << (*di)->get_page()->get_name() <<
", untrusted)\n";
366 if (!_description.empty()) {
367 out <<
"\n" << _description <<
"\n";
375void ConfigVariableCore::
377 _declarations.push_back(decl);
379 _declarations_sorted =
false;
386void ConfigVariableCore::
388 Declarations::iterator di;
389 for (di = _declarations.begin(); di != _declarations.end(); ++di) {
394 Declarations::iterator di2 = _declarations.end();
397 _declarations.erase(di2);
398 _declarations_sorted =
false;
407class CompareConfigDeclarations {
419void ConfigVariableCore::
421 sort(_declarations.begin(), _declarations.end(), CompareConfigDeclarations());
422 Declarations::iterator di;
426#ifdef PRC_RESPECT_TRUST_LEVEL
430 _trusted_declarations.clear();
431 _untrusted_declarations.clear();
432 for (di = _declarations.begin(); di != _declarations.end(); ++di) {
436 _trusted_declarations.push_back(decl);
438 _untrusted_declarations.push_back(decl);
445 _trusted_declarations = _declarations;
446 _untrusted_declarations.clear();
453 _unique_declarations.clear();
455 init_system_type_handles();
457 for (di = _trusted_declarations.begin();
458 di != _trusted_declarations.end();
462 _unique_declarations.push_back(decl);
466 _declarations_sorted =
true;
A single declaration of a config variable, typically defined as one line in a .prc file,...
const std::string & get_string_value() const
Returns the value assigned to this variable.
get_page
Returns the page on which this declaration can be found.
void set_string_value(const std::string &value)
Changes the value assigned to this variable.
A page of ConfigDeclarations that may be loaded or unloaded.
bool delete_declaration(ConfigDeclaration *decl)
Removes the indicated declaration from the page and deletes it.
ConfigDeclaration * make_declaration(const std::string &variable, const std::string &value)
Adds the indicated variable/value pair as a new declaration on the page.
static ConfigPage * get_default_page()
Returns a pointer to the global "default page".
static ConfigPage * get_local_page()
Returns a pointer to the global "local page".
The internal definition of a ConfigVariable.
void set_flags(int flags)
Specifies the trust level of this variable.
bool has_local_value() const
Returns true if this variable's value has been shadowed by a local assignment (as created via make_lo...
get_declaration
Returns the nth declarations that contributes to this variable's value.
set_default_value
Specifies the default value for this variable if it is not defined in any prc file.
bool has_value() const
Returns true if this variable has an explicit value, either from a prc file or locally set,...
set_description
Specifies the one-line description of this variable.
bool clear_local_value()
Removes the local value defined for this variable, and allows its value to be once again retrieved fr...
is_closed
Returns true if the variable is not trusted by any prc file (and hence cannot be modified from its co...
get_num_declarations
Returns the number of declarations that contribute to this variable's value.
get_name
Returns the name of the variable.
ConfigDeclaration * make_local_value()
Creates a new local value for this variable, if there is not already one specified.
get_trust_level
Returns the minimum trust_level a prc file must demonstrate in order to redefine the value for this v...
set_value_type
Specifies the type of this variable.
This is our own Panda specialization on the default STL set.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.