Panda3D
configVariableBase.I
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file configVariableBase.I
10  * @author drose
11  * @date 2004-10-21
12  */
13 
14 /**
15  * This constructor is only intended to be called from a specialized
16  * ConfigVariableFoo derived class.
17  */
18 INLINE ConfigVariableBase::
19 ConfigVariableBase(const std::string &name,
20  ConfigVariableBase::ValueType value_type) :
21  _core(ConfigVariableManager::get_global_ptr()->make_variable(name))
22 {
23  if (value_type != VT_undefined) {
24  _core->set_value_type(value_type);
25  }
26 }
27 
28 /**
29  *
30  */
31 INLINE ConfigVariableBase::
32 ~ConfigVariableBase() {
33 }
34 
35 /**
36  * Returns the name of the variable.
37  */
38 INLINE const std::string &ConfigVariableBase::
39 get_name() const {
40  nassertr(_core != nullptr, *new std::string());
41  return _core->get_name();
42 }
43 
44 /**
45  * Returns the stated type of this variable. This should be VT_list, unless a
46  * later variable declaration has changed it.
47  */
48 INLINE ConfigVariableBase::ValueType ConfigVariableBase::
49 get_value_type() const {
50  nassertr(_core != nullptr, VT_undefined);
51  return _core->get_value_type();
52 }
53 
54 /**
55  * Returns the brief description of this variable, if it has been defined.
56  */
57 INLINE const std::string &ConfigVariableBase::
58 get_description() const {
59  nassertr(_core != nullptr, *new std::string());
60  return _core->get_description();
61 }
62 
63 /**
64  * Returns the flags value as set by set_flags(). This includes the trust
65  * level and some other settings. See the individual methods is_closed(),
66  * get_trust_level(), etc. to pull out the semantic meaning of these flags
67  * individually.
68  */
69 INLINE int ConfigVariableBase::
70 get_flags() const {
71  nassertr(_core != nullptr, 0);
72  return _core->get_flags();
73 }
74 
75 /**
76  * Returns true if the variable is not trusted by any prc file (and hence
77  * cannot be modified from its compiled-in default value), or false for the
78  * normal case, in which the variable can be modified by any prc file at or
79  * above its trust level (see get_trust_level()).
80  *
81  * This value only has effect in a release build (specifically, when
82  * PRC_RESPECT_TRUST_LEVEL is defined true in Config.pp).
83  */
84 INLINE bool ConfigVariableBase::
85 is_closed() const {
86  nassertr(_core != nullptr, false);
87  return _core->is_closed();
88 }
89 
90 /**
91  * Returns the minimum trust_level a prc file must demonstrate in order to
92  * redefine the value for this variable. Arguably, this should be called the
93  * "mistrust level", since the larger the value, the more suspicious we are of
94  * prc files. This value is not used if is_closed() returns true, which
95  * indicates no file may be trusted.
96  *
97  * This value only has effect in a release build (specifically, when
98  * PRC_RESPECT_TRUST_LEVEL is defined true in Config.pp).
99  */
100 INLINE int ConfigVariableBase::
101 get_trust_level() const {
102  nassertr(_core != nullptr, 0);
103  return _core->get_trust_level();
104 }
105 
106 /**
107  * Returns true if the variable was indicated as "dynamic" by its constructor,
108  * indicating that its name was dynamically generated, possibly from a large
109  * pool, and it should not be listed along with the other variables.
110  */
111 INLINE bool ConfigVariableBase::
112 is_dynamic() const {
113  nassertr(_core != nullptr, false);
114  return _core->is_dynamic();
115 }
116 
117 /**
118  * Removes the local value defined for this variable, and allows its value to
119  * be once again retrieved from the .prc files.
120  *
121  * Returns true if the value was successfully removed, false if it did not
122  * exist in the first place.
123  */
124 INLINE bool ConfigVariableBase::
126  nassertr(_core != nullptr, false);
127  return _core->clear_local_value();
128 }
129 
130 /**
131  * Returns true if this variable's value has been shadowed by a local
132  * assignment (as created via make_local_value()), or false otherwise.
133  */
134 INLINE bool ConfigVariableBase::
136  nassertr(_core != nullptr, false);
137  return _core->has_local_value();
138 }
139 
140 /**
141  * Returns true if this variable has an explicit value, either from a prc file
142  * or locally set, or false if variable has its default value.
143  */
144 INLINE bool ConfigVariableBase::
145 has_value() const {
146  nassertr(_core != nullptr, false);
147  return _core->has_value();
148 }
149 
150 /**
151  *
152  */
153 INLINE void ConfigVariableBase::
154 output(std::ostream &out) const {
155  nassertv(_core != nullptr);
156  _core->output(out);
157 }
158 
159 /**
160  *
161  */
162 INLINE void ConfigVariableBase::
163 write(std::ostream &out) const {
164  nassertv(_core != nullptr);
165  _core->write(out);
166 }
167 
168 INLINE std::ostream &
169 operator << (std::ostream &out, const ConfigVariableBase &variable) {
170  variable.output(out);
171  return out;
172 }
bool has_local_value() const
Returns true if this variable's value has been shadowed by a local assignment (as created via make_lo...
int get_flags() const
Returns the flags value as set by set_flags().
bool has_value() const
Returns true if this variable has an explicit value, either from a prc file or locally set,...
get_value_type
Returns the stated type of this variable.
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...
A global object that maintains the set of ConfigVariables (actually, ConfigVariableCores) everywhere ...
is_closed
Returns true if the variable is not trusted by any prc file (and hence cannot be modified from its co...
get_description
Returns the brief description of this variable, if it has been defined.
bool clear_local_value()
Removes the local value defined for this variable, and allows its value to be once again retrieved fr...
is_dynamic
Returns true if the variable was indicated as "dynamic" by its constructor, indicating that its name ...
bool clear_local_value()
Removes the local value defined for this variable, and allows its value to be once again retrieved fr...
bool has_value() const
Returns true if this variable has an explicit value, either from a prc file or locally set,...
int get_flags() const
Returns the flags value as set by set_flags().
get_name
Returns the name of the variable.
This class is the base class for both ConfigVariableList and ConfigVariable (and hence for all of the...
set_value_type
Specifies the type of this variable.