15 #include "configVariableManager.h"
16 #include "configVariableCore.h"
17 #include "configDeclaration.h"
18 #include "configPage.h"
19 #include "config_prc.h"
32 ConfigVariableManager::
33 ConfigVariableManager() {
44 ConfigVariableManager::
45 ~ConfigVariableManager() {
47 <<
"Internal error--ConfigVariableManager destructor called!\n";
60 VariablesByName::iterator ni;
61 ni = _variables_by_name.find(name);
62 if (ni != _variables_by_name.end()) {
69 VariableTemplates::const_iterator ti;
70 for (ti = _variable_templates.begin();
84 _variables_by_name[name] = variable;
85 _variables.push_back(variable);
118 ConfigFlags::ValueType value_type,
119 const string &default_value,
120 const string &description,
int flags) {
124 VariableTemplates::const_iterator ti = _variable_templates.find(gp);
125 if (ti != _variable_templates.end()) {
130 _variable_templates[gp] = core;
133 if (value_type != ConfigFlags::VT_undefined) {
136 if (!default_value.empty() ||
140 if (!description.empty()) {
150 Variables::iterator vi;
151 for (vi = _variables.begin(); vi != _variables.end(); ++vi) {
154 if (value_type != ConfigFlags::VT_undefined) {
157 if (!default_value.empty() ||
161 if (!description.empty()) {
182 if (n >= 0 && n < (
int)_variables.size()) {
183 return _variables[n]->get_name();
196 if (n >= 0 && n < (
int)_variables.size()) {
197 return _variables[n]->is_used();
207 void ConfigVariableManager::
208 output(ostream &out)
const {
209 out <<
"ConfigVariableManager, " << _variables.size() <<
" variables.";
217 void ConfigVariableManager::
218 write(ostream &out)
const {
219 VariablesByName::const_iterator ni;
220 for (ni = _variables_by_name.begin();
221 ni != _variables_by_name.end();
226 list_variable(variable,
false);
245 VariablesByName::const_iterator ni;
246 for (ni = _variables_by_name.begin();
247 ni != _variables_by_name.end();
252 variable->
get_value_type() == ConfigVariableCore::VT_search_path) {
255 for (
int i = 0; i < num_references; i++) {
279 VariablesByName::const_iterator ni;
280 for (ni = _variables_by_name.begin();
281 ni != _variables_by_name.end();
285 nout << variable->
get_name() <<
"\n";
287 for (
int i = 0; i < num_references; i++) {
304 VariablesByName::const_iterator ni;
305 for (ni = _variables_by_name.begin();
306 ni != _variables_by_name.end();
310 list_variable(variable,
true);
326 VariablesByName::const_iterator ni;
327 for (ni = _variables_by_name.begin();
328 ni != _variables_by_name.end();
332 list_variable(variable,
false);
355 void ConfigVariableManager::
357 bool include_descriptions)
const {
360 nout << variable->
get_name() <<
" not used";
362 nout <<
" (referenced in "
379 variable->
get_value_type() == ConfigVariableCore::VT_search_path) {
382 nout <<
" current value:\n";
384 for (
int i = 0; i < num_references; i++) {
400 nout <<
" (defined locally)\n";
bool has_local_value() const
Returns true if this variable's value has been shadowed by a local assignment (as created via make_lo...
The internal definition of a ConfigVariable.
const ConfigDeclaration * get_default_value() const
Returns the default variable specified for this variable.
const string & get_name() const
Returns the name of the variable.
const string & get_string_value() const
Returns the value assigned to this variable.
ConfigVariableCore * make_variable_template(const string &pattern, ConfigFlags::ValueType type, const string &default_value, const string &description=string(), int flags=0)
Defines a variable "template" to match against dynamically-defined variables that may or may not be c...
bool is_special() const
Returns true if this is the special "default" or "local" page, or false if it is an ordinary page...
void list_dynamic_variables() const
Writes a list of all the "dynamic" variables that have been declared somewhere in code...
bool matches(const string &candidate) const
Returns true if the candidate string matches the pattern, false otherwise.
void set_default_value(const string &default_value)
Specifies the default value for this variable if it is not defined in any prc file.
A global object that maintains the set of ConfigVariables (actually, ConfigVariableCores) everywhere ...
const ConfigDeclaration * get_declaration(int n) const
Returns the nth declarations that contributes to this variable's value.
const ConfigDeclaration * get_reference(int n) const
Returns the nth declaration in a prc file that references this variable.
ConfigVariableCore * make_variable(const string &name)
Creates and returns a new, undefined ConfigVariableCore with the indicated name; or if a variable wit...
bool is_variable_used(int n) const
Returns true if the nth active ConfigVariable in the list has been used by code, false otherwise...
const ConfigDeclaration * get_trusted_reference(int n) const
Returns the nth declaration in a trusted prc file that references this variable.
void list_variables() const
Writes a list of all the variables that have been declared somewhere in code, along with a brief desc...
int get_num_trusted_references() const
Returns the number of trusted prc files that reference this variable.
void write_prc_variables(ostream &out) const
Writes all of the prc-set config variables, as they appear in a prc file somewhere, one per line, very concisely.
void set_value_type(ValueType value_type)
Specifies the type of this variable.
void set_used()
Marks that the variable has been "declared" by a ConfigVariable.
void set_description(const string &description)
Specifies the one-line description of this variable.
ConfigPage * get_page() const
Returns the page on which this declaration can be found.
const string & get_name() const
Returns the name of the page.
bool is_used() const
Returns true if the variable has been referenced by a ConfigVariable somewhere in code...
int get_num_references() const
Returns the number of prc files that reference this variable.
void set_flags(int flags)
Specifies the trust level of this variable.
string get_variable_name(int n) const
Returns the name of the nth active ConfigVariable in the list.
const string & get_description() const
Returns the brief description of this variable, if it has been defined.
A single declaration of a config variable, typically defined as one line in a .prc file...
ValueType get_value_type() const
Returns the stated type of this variable.
bool is_dynamic() const
Returns true if the variable was indicated as "dynamic" by its constructor, indicating that its name ...
This class can be used to test for string matches against standard Unix-shell filename globbing conve...
void list_unused_variables() const
Writes a list of all the variables that have been defined in a prc file without having been declared ...