15 #include "configVariableCore.h" 16 #include "configDeclaration.h" 17 #include "configPage.h" 20 #include "config_prc.h" 23 #include "prc_parameters.h" 35 ConfigVariableCore(
const string &name) :
38 _value_type(VT_undefined),
42 _declarations_sorted(true),
45 #if defined(PRC_INC_TRUST_LEVEL) && PRC_INC_TRUST_LEVEL != 0 46 _flags = (_flags & ~F_trust_level_mask) | ((_flags & F_trust_level_mask) + PRC_INC_TRUST_LEVEL);
47 #endif // PRC_INC_TRUST_LEVEL 60 _is_used(templ._is_used),
61 _value_type(templ._value_type),
62 _description(templ._description),
66 _declarations_sorted(false),
82 ~ConfigVariableCore() {
84 <<
"Internal error--ConfigVariableCore destructor called!\n";
97 if (_value_queried && _value_type != value_type) {
98 if ((_flags & F_dconfig) != 0) {
106 <<
"changing type for ConfigVariable " 107 << get_name() <<
" from " << _value_type <<
" to " 108 << value_type <<
".\n";
112 _value_type = value_type;
126 if ((flags & F_dconfig) != 0) {
127 flags = (flags & ~F_trust_level_mask) | PRC_DCONFIG_TRUST_LEVEL;
130 #if defined(PRC_INC_TRUST_LEVEL) && PRC_INC_TRUST_LEVEL != 0 131 flags = (flags & ~F_trust_level_mask) | ((flags & F_trust_level_mask) + PRC_INC_TRUST_LEVEL);
132 #endif // PRC_INC_TRUST_LEVEL 134 if (_value_queried) {
135 int bits_changed = (_flags ^ flags);
136 if ((bits_changed & F_trust_level_mask) != 0) {
138 <<
"changing trust level for ConfigVariable " 139 << get_name() <<
" from " << (_flags & F_trust_level_mask) <<
" to " 140 << (flags & F_trust_level_mask) <<
".\n";
142 if ((bits_changed & ~(F_trust_level_mask | F_dconfig)) != 0) {
144 <<
"changing flags for ConfigVariable " 145 << get_name() <<
" from " << hex
146 << (_flags & ~F_trust_level_mask) <<
" to " 147 << (flags & ~F_trust_level_mask) << dec <<
".\n";
155 _declarations_sorted =
false;
168 if (_value_queried && _description != description) {
169 if ((_flags & F_dconfig) != 0) {
175 if (description ==
"DConfig") {
179 if (_description.empty()) {
180 _description = description;
185 if (description.empty()) {
190 if (_description.empty()) {
192 _description = description;
197 <<
"changing description for ConfigVariable " 198 << get_name() <<
".\n";
201 _description = description;
225 _default_value->set_string_value(default_value);
227 if (orig_default_value != default_value) {
228 if ((_flags & F_dconfig) != 0) {
236 <<
"changing default value for ConfigVariable " 237 << get_name() <<
" from '" << orig_default_value
238 <<
"' to '" << default_value <<
"'.\n";
261 string string_value = get_declaration(0)->get_string_value();
266 <<
"Assigning a local value to a \"closed\" ConfigVariable. " 267 "This is legal in a development build, but illegal in a release " 268 "build and may result in a compilation error or exception.\n";
306 if (has_local_value()) {
309 check_sort_declarations();
310 return (!_trusted_declarations.empty());
323 if (has_local_value()) {
326 check_sort_declarations();
327 if (!_trusted_declarations.empty()) {
328 return _trusted_declarations.size();
350 <<
"value queried before default value set for " 351 << get_name() <<
".\n";
355 if (has_local_value()) {
358 check_sort_declarations();
359 if (n >= 0 && n < (
int)_trusted_declarations.size()) {
360 return _trusted_declarations[n];
362 return _default_value;
370 void ConfigVariableCore::
371 output(ostream &out)
const {
372 out << get_declaration(0)->get_string_value();
380 void ConfigVariableCore::
381 write(ostream &out)
const {
382 out <<
"ConfigVariable " << get_name() <<
":\n";
384 check_sort_declarations();
386 if (has_local_value()) {
387 out <<
" " << *_local_value <<
" (defined locally)\n";
390 Declarations::const_iterator di;
391 for (di = _trusted_declarations.begin();
392 di != _trusted_declarations.end();
395 <<
" (from " << (*di)->get_page()->get_name() <<
")\n";
399 out <<
" " << *_default_value <<
" (default value)\n";
402 for (di = _untrusted_declarations.begin();
403 di != _untrusted_declarations.end();
406 <<
" (from " << (*di)->get_page()->get_name() <<
", untrusted)\n";
409 if (!_description.empty()) {
410 out <<
"\n" << _description <<
"\n";
421 void ConfigVariableCore::
423 _declarations.push_back(decl);
425 _declarations_sorted =
false;
435 void ConfigVariableCore::
437 Declarations::iterator di;
438 for (di = _declarations.begin(); di != _declarations.end(); ++di) {
443 Declarations::iterator di2 = _declarations.end();
446 _declarations.erase(di2);
447 _declarations_sorted =
false;
470 void ConfigVariableCore::
471 sort_declarations() {
473 Declarations::iterator di;
477 #ifdef PRC_RESPECT_TRUST_LEVEL 481 _trusted_declarations.clear();
482 _untrusted_declarations.clear();
483 for (di = _declarations.begin(); di != _declarations.end(); ++di) {
487 _trusted_declarations.push_back(decl);
489 _untrusted_declarations.push_back(decl);
493 #else // PRC_RESPECT_TRUST_LEVEL 496 _trusted_declarations = _declarations;
497 _untrusted_declarations.clear();
499 #endif // PRC_RESPECT_TRUST_LEVEL 505 _unique_declarations.clear();
507 init_system_type_handles();
509 for (di = _trusted_declarations.begin();
510 di != _trusted_declarations.end();
514 _unique_declarations.push_back(decl);
518 _declarations_sorted =
true;
int get_num_declarations() const
Returns the number of declarations that contribute to this variable's value.
The internal definition of a ConfigVariable.
static ConfigPage * get_local_page()
Returns a pointer to the global "local page".
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".
void set_default_value(const string &default_value)
Specifies the default value for this variable if it is not defined in any prc file.
ConfigDeclaration * make_declaration(const string &variable, const string &value)
Adds the indicated variable/value pair as a new declaration on the page.
const ConfigDeclaration * get_declaration(int n) const
Returns the nth declarations that contributes to this variable's value.
void set_value_type(ValueType value_type)
Specifies the type 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...
ConfigPage * get_page() const
Returns the page on which this declaration can be found.
void set_description(const string &description)
Specifies the one-line description of this variable.
A page of ConfigDeclarations that may be loaded or unloaded.
void set_flags(int flags)
Specifies the trust level 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...
const string & get_string_value() const
Returns the value assigned to this variable.
bool delete_declaration(ConfigDeclaration *decl)
Removes the indicated declaration from the page and deletes it.
int get_trust_level() const
Returns the trust level associated with this page.