22 #include "prc_parameters.h" 34 ConfigVariableCore(
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);
46 #endif // 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);
118 #endif // 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());
286 size_t ConfigVariableCore::
287 get_num_declarations()
const {
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;
329 void ConfigVariableCore::
330 output(std::ostream &out)
const {
337 void ConfigVariableCore::
338 write(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";
375 void ConfigVariableCore::
377 _declarations.push_back(decl);
379 _declarations_sorted =
false;
386 void 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;
407 class CompareConfigDeclarations {
419 void ConfigVariableCore::
420 sort_declarations() {
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);
442 #else // PRC_RESPECT_TRUST_LEVEL 445 _trusted_declarations = _declarations;
446 _untrusted_declarations.clear();
448 #endif // PRC_RESPECT_TRUST_LEVEL 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;
const std::string & get_string_value() const
Returns the value assigned to this variable.
The internal definition of a ConfigVariable.
set_description
Specifies the one-line description of this variable.
static ConfigPage * get_local_page()
Returns a pointer to the global "local page".
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
get_page
Returns the page on which this declaration can be found.
bool has_value() const
Returns true if this variable has an explicit value, either from a prc file or locally set,...
static ConfigPage * get_default_page()
Returns a pointer to the global "default page".
get_trust_level
Returns the minimum trust_level a prc file must demonstrate in order to redefine the value for this v...
bool has_local_value() const
Returns true if this variable's value has been shadowed by a local assignment (as created via make_lo...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
set_default_value
Specifies the default value for this variable if it is not defined in any prc file.
is_closed
Returns true if the variable is not trusted by any prc file (and hence cannot be modified from its co...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool clear_local_value()
Removes the local value defined for this variable, and allows its value to be once again retrieved fr...
A page of ConfigDeclarations that may be loaded or unloaded.
void set_string_value(const std::string &value)
Changes the value assigned to this variable.
void set_flags(int flags)
Specifies the trust level of this variable.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
get_name
Returns the name of the variable.
This is our own Panda specialization on the default STL set.
get_declaration
Returns the nth declarations that contributes to this variable's value.
set_value_type
Specifies the type of this variable.
ConfigDeclaration * make_local_value()
Creates a new local value for this variable, if there is not already one specified.
A single declaration of a config variable, typically defined as one line in a .prc file,...
ConfigDeclaration * make_declaration(const std::string &variable, const std::string &value)
Adds the indicated variable/value pair as a new declaration on the page.
bool delete_declaration(ConfigDeclaration *decl)
Removes the indicated declaration from the page and deletes it.