29 ConfigVariableManager::
30 ConfigVariableManager() {
38 ConfigVariableManager::
39 ~ConfigVariableManager() {
41 <<
"Internal error--ConfigVariableManager destructor called!\n";
51 VariablesByName::iterator ni;
52 ni = _variables_by_name.find(name);
53 if (ni != _variables_by_name.end()) {
60 VariableTemplates::const_iterator ti;
61 for (ti = _variable_templates.begin();
62 ti != _variable_templates.end() && variable ==
nullptr;
71 if (variable ==
nullptr) {
75 _variables_by_name[name] = variable;
76 _variables.push_back(variable);
102 ConfigFlags::ValueType value_type,
103 const string &default_value,
104 const string &description,
int flags) {
108 VariableTemplates::const_iterator ti = _variable_templates.find(gp);
109 if (ti != _variable_templates.end()) {
114 _variable_templates[gp] = core;
117 if (value_type != ConfigFlags::VT_undefined) {
120 if (!default_value.empty() ||
124 if (!description.empty()) {
134 Variables::iterator vi;
135 for (vi = _variables.begin(); vi != _variables.end(); ++vi) {
138 if (value_type != ConfigFlags::VT_undefined) {
141 if (!default_value.empty() ||
145 if (!description.empty()) {
163 if (n < _variables.size()) {
164 return _variables[n]->get_name();
175 if (n < _variables.size()) {
176 return _variables[n]->is_used();
184 void ConfigVariableManager::
185 output(std::ostream &out)
const {
186 out <<
"ConfigVariableManager, " << _variables.size() <<
" variables.";
192 void ConfigVariableManager::
193 write(std::ostream &out)
const {
194 VariablesByName::const_iterator ni;
195 for (ni = _variables_by_name.begin();
196 ni != _variables_by_name.end();
201 list_variable(variable,
false);
217 VariablesByName::const_iterator ni;
218 for (ni = _variables_by_name.begin();
219 ni != _variables_by_name.end();
224 variable->
get_value_type() == ConfigVariableCore::VT_search_path) {
227 for (
size_t i = 0; i < num_references; ++i) {
248 VariablesByName::const_iterator ni;
249 for (ni = _variables_by_name.begin();
250 ni != _variables_by_name.end();
254 nout << variable->
get_name() <<
"\n";
256 for (
size_t i = 0; i < num_references; i++) {
257 nout <<
" " << variable->
get_reference(i)->get_page()->get_name()
270 VariablesByName::const_iterator ni;
271 for (ni = _variables_by_name.begin();
272 ni != _variables_by_name.end();
276 list_variable(variable,
true);
289 VariablesByName::const_iterator ni;
290 for (ni = _variables_by_name.begin();
291 ni != _variables_by_name.end();
295 list_variable(variable,
false);
305 if (_global_ptr ==
nullptr) {
314 void ConfigVariableManager::
316 bool include_descriptions)
const {
319 nout << variable->
get_name() <<
" not used";
321 nout <<
" (referenced in " 338 variable->
get_value_type() == ConfigVariableCore::VT_search_path) {
340 nout <<
" current value:\n";
342 for (
size_t i = 0; i < num_references; ++i) {
345 <<
" (from " << decl->
get_page()->get_name() <<
")\n";
354 if (!decl->
get_page()->is_special()) {
355 nout <<
" (from " << decl->
get_page()->get_name() <<
")\n";
357 nout <<
" (defined locally)\n";
362 if (decl !=
nullptr) {
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.
std::string get_variable_name(size_t n) const
Returns the name of the nth active ConfigVariable in the list.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
get_num_references
Returns the number of prc files that reference this variable.
void list_dynamic_variables() const
Writes a list of all the "dynamic" variables that have been declared somewhere in code,...
get_page
Returns the page on which this declaration can be found.
get_default_value
Returns the default variable specified for this variable.
get_reference
Returns the nth declaration in a prc file that references this variable.
get_value_type
Returns the stated type of this variable.
ConfigVariableCore * make_variable(const std::string &name)
Creates and returns a new, undefined ConfigVariableCore with the indicated name; or if a variable wit...
bool matches(const std::string &candidate) const
Returns true if the candidate string matches the pattern, false otherwise.
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.
A global object that maintains the set of ConfigVariables (actually, ConfigVariableCores) everywhere ...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
ConfigVariableCore * make_variable_template(const std::string &pattern, ConfigFlags::ValueType type, const std::string &default_value, const std::string &description=std::string(), int flags=0)
Defines a variable "template" to match against dynamically-defined variables that may or may not be c...
set_default_value
Specifies the default value for this variable if it is not defined in any prc file.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
get_description
Returns the brief description of this variable, if it has been defined.
is_used
Returns true if the variable has been referenced by a ConfigVariable somewhere in code,...
void set_used()
Marks that the variable has been "declared" by a ConfigVariable.
is_dynamic
Returns true if the variable was indicated as "dynamic" by its constructor, indicating that its name ...
get_num_trusted_references
Returns the number of trusted prc files that reference 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.
get_declaration
Returns the nth declarations that contributes to this variable's value.
bool is_variable_used(size_t n) const
Returns true if the nth active ConfigVariable in the list has been used by code, false otherwise.
void list_variables() const
Writes a list of all the variables that have been declared somewhere in code, along with a brief desc...
set_value_type
Specifies the type of this variable.
A single declaration of a config variable, typically defined as one line in a .prc file,...
void list_unused_variables() const
Writes a list of all the variables that have been defined in a prc file without having been declared ...
get_trusted_reference
Returns the nth declaration in a trusted prc file that references this variable.
This class can be used to test for string matches against standard Unix- shell filename globbing conv...
void write_prc_variables(std::ostream &out) const
Writes all of the prc-set config variables, as they appear in a prc file somewhere,...