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