Panda3D
 All Classes Functions Variables Enumerations
configVariable.I
1 // Filename: configVariable.I
2 // Created by: drose (18Oct04)
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: ConfigVariable::Constructor
18 // Access: Protected
19 // Description: This constructor is only intended to be called from a
20 // specialized ConfigVariableFoo derived class.
21 ////////////////////////////////////////////////////////////////////
22 INLINE ConfigVariable::
23 ConfigVariable(const string &name, ConfigVariable::ValueType value_type) :
24  ConfigVariableBase(name, value_type)
25 {
26 }
27 
28 ////////////////////////////////////////////////////////////////////
29 // Function: ConfigVariable::Constructor
30 // Access: Protected
31 // Description: This constructor is only intended to be called from a
32 // specialized ConfigVariableFoo derived class.
33 ////////////////////////////////////////////////////////////////////
34 INLINE ConfigVariable::
35 ConfigVariable(const string &name, ConfigVariable::ValueType value_type,
36  const string &description, int flags) :
37  ConfigVariableBase(name, value_type, description, flags)
38 {
39 }
40 
41 ////////////////////////////////////////////////////////////////////
42 // Function: ConfigVariable::Constructor
43 // Access: Published
44 // Description: Use this constructor to make a ConfigVariable of an
45 // unspecified type. Usually you'd want to do this just
46 // to reference a previously-defined ConfigVariable of a
47 // specific type, without having to know what type it is.
48 ////////////////////////////////////////////////////////////////////
49 INLINE ConfigVariable::
50 ConfigVariable(const string &name) :
51  ConfigVariableBase(name, VT_undefined)
52 {
53  _core->set_used();
54 }
55 
56 ////////////////////////////////////////////////////////////////////
57 // Function: ConfigVariable::Destructor
58 // Access: Published
59 // Description:
60 ////////////////////////////////////////////////////////////////////
61 INLINE ConfigVariable::
62 ~ConfigVariable() {
63 }
64 
65 ////////////////////////////////////////////////////////////////////
66 // Function: ConfigVariable::get_default_value
67 // Access: Published
68 // Description: Returns the default variable specified for this
69 // variable. If the variable has not yet been defined,
70 // this will return NULL.
71 ////////////////////////////////////////////////////////////////////
74  nassertr(is_constructed(), (ConfigDeclaration *)NULL);
75  return _core->get_default_value();
76 }
77 
78 ////////////////////////////////////////////////////////////////////
79 // Function: ConfigVariable::get_string_value
80 // Access: Published
81 // Description: Returns the toplevel value of the variable, formatted
82 // as a string.
83 ////////////////////////////////////////////////////////////////////
84 INLINE const string &ConfigVariable::
86  nassertr(is_constructed(), *new string());
87  const ConfigDeclaration *decl = _core->get_declaration(0);
88  return decl->get_string_value();
89 }
90 
91 ////////////////////////////////////////////////////////////////////
92 // Function: ConfigVariable::set_string_value
93 // Access: Published
94 // Description: Changes the value assigned to this variable. This
95 // creates a local value that shadows any values defined
96 // in the .prc files, until clear_local_value() is
97 // called.
98 ////////////////////////////////////////////////////////////////////
99 INLINE void ConfigVariable::
100 set_string_value(const string &string_value) {
101  nassertv(is_constructed());
102  _core->make_local_value()->set_string_value(string_value);
103 }
104 
105 ////////////////////////////////////////////////////////////////////
106 // Function: ConfigVariable::clear_value
107 // Access: Published
108 // Description: Removes the value assigned to this variable, and lets
109 // its original value (as read from the prc files) show
110 // through.
111 ////////////////////////////////////////////////////////////////////
112 INLINE void ConfigVariable::
114  nassertv(is_constructed());
115  _core->clear_local_value();
116 }
117 
118 ////////////////////////////////////////////////////////////////////
119 // Function: ConfigVariable::get_num_words
120 // Access: Published
121 // Description: Returns the number of words in the variable's
122 // value. A word is defined as a sequence of
123 // non-whitespace characters delimited by whitespace.
124 ////////////////////////////////////////////////////////////////////
125 INLINE int ConfigVariable::
126 get_num_words() const {
127  nassertr(is_constructed(), 0);
128  const ConfigDeclaration *decl = _core->get_declaration(0);
129  return decl->get_num_words();
130 }
131 
132 ////////////////////////////////////////////////////////////////////
133 // Function: ConfigVariable::has_string_word
134 // Access: Published
135 // Description: Returns true if the variable's value has a valid
136 // string value for the nth word. This is really the
137 // same thing as asking if there are at least n words in
138 // the value.
139 ////////////////////////////////////////////////////////////////////
140 INLINE bool ConfigVariable::
141 has_string_word(int n) const {
142  nassertr(is_constructed(), false);
143  const ConfigDeclaration *decl = _core->get_declaration(0);
144  return decl->has_string_word(n);
145 }
146 
147 ////////////////////////////////////////////////////////////////////
148 // Function: ConfigVariable::has_bool_word
149 // Access: Published
150 // Description: Returns true if the variable's value has a valid
151 // boolean value for the nth word.
152 ////////////////////////////////////////////////////////////////////
153 INLINE bool ConfigVariable::
154 has_bool_word(int n) const {
155  nassertr(is_constructed(), false);
156  const ConfigDeclaration *decl = _core->get_declaration(0);
157  return decl->has_bool_word(n);
158 }
159 
160 ////////////////////////////////////////////////////////////////////
161 // Function: ConfigVariable::has_int_word
162 // Access: Published
163 // Description: Returns true if the variable's value has a valid
164 // integer value for the nth word.
165 ////////////////////////////////////////////////////////////////////
166 INLINE bool ConfigVariable::
167 has_int_word(int n) const {
168  nassertr(is_constructed(), false);
169  const ConfigDeclaration *decl = _core->get_declaration(0);
170  return decl->has_int_word(n);
171 }
172 
173 ////////////////////////////////////////////////////////////////////
174 // Function: ConfigVariable::has_int64_word
175 // Access: Published
176 // Description: Returns true if the variable's value has a valid
177 // 64-bit integer value for the nth word.
178 ////////////////////////////////////////////////////////////////////
179 INLINE bool ConfigVariable::
180 has_int64_word(int n) const {
181  nassertr(is_constructed(), false);
182  const ConfigDeclaration *decl = _core->get_declaration(0);
183  return decl->has_int64_word(n);
184 }
185 
186 ////////////////////////////////////////////////////////////////////
187 // Function: ConfigVariable::has_double_word
188 // Access: Published
189 // Description: Returns true if the variable's value has a valid
190 // integer value for the nth word.
191 ////////////////////////////////////////////////////////////////////
192 INLINE bool ConfigVariable::
193 has_double_word(int n) const {
194  nassertr(is_constructed(), false);
195  const ConfigDeclaration *decl = _core->get_declaration(0);
196  return decl->has_double_word(n);
197 }
198 
199 ////////////////////////////////////////////////////////////////////
200 // Function: ConfigVariable::get_string_word
201 // Access: Published
202 // Description: Returns the string value of the nth word of the
203 // variable's value, or empty string if there is no
204 // nth value. See also has_string_word().
205 ////////////////////////////////////////////////////////////////////
206 INLINE string ConfigVariable::
207 get_string_word(int n) const {
208  nassertr(is_constructed(), string());
209  const ConfigDeclaration *decl = _core->get_declaration(0);
210  return decl->get_string_word(n);
211 }
212 
213 ////////////////////////////////////////////////////////////////////
214 // Function: ConfigVariable::get_bool_word
215 // Access: Published
216 // Description: Returns the boolean value of the nth word of the
217 // variable's value, or false if there is no nth
218 // value. See also has_bool_word().
219 ////////////////////////////////////////////////////////////////////
220 INLINE bool ConfigVariable::
221 get_bool_word(int n) const {
222  nassertr(is_constructed(), false);
223  const ConfigDeclaration *decl = _core->get_declaration(0);
224  return decl->get_bool_word(n);
225 }
226 
227 ////////////////////////////////////////////////////////////////////
228 // Function: ConfigVariable::get_int_word
229 // Access: Published
230 // Description: Returns the integer value of the nth word of the
231 // variable's value, or 0 if there is no nth value.
232 // See also has_int_word().
233 ////////////////////////////////////////////////////////////////////
234 INLINE int ConfigVariable::
235 get_int_word(int n) const {
236  nassertr(is_constructed(), 0);
237  const ConfigDeclaration *decl = _core->get_declaration(0);
238  return decl->get_int_word(n);
239 }
240 
241 ////////////////////////////////////////////////////////////////////
242 // Function: ConfigVariable::get_int64_word
243 // Access: Published
244 // Description: Returns the int64 value of the nth word of the
245 // variable's value, or 0 if there is no nth value.
246 // See also has_int_word().
247 ////////////////////////////////////////////////////////////////////
248 INLINE PN_int64 ConfigVariable::
249 get_int64_word(int n) const {
250  nassertr(is_constructed(), 0);
251  const ConfigDeclaration *decl = _core->get_declaration(0);
252  return decl->get_int64_word(n);
253 }
254 
255 ////////////////////////////////////////////////////////////////////
256 // Function: ConfigVariable::get_double_word
257 // Access: Published
258 // Description: Returns the integer value of the nth word of the
259 // variable's value, or 0 if there is no nth value.
260 // See also has_double_word().
261 ////////////////////////////////////////////////////////////////////
262 INLINE double ConfigVariable::
263 get_double_word(int n) const {
264  nassertr(is_constructed(), 0.0);
265  const ConfigDeclaration *decl = _core->get_declaration(0);
266  return decl->get_double_word(n);
267 }
268 
269 ////////////////////////////////////////////////////////////////////
270 // Function: ConfigVariable::set_string_word
271 // Access: Published
272 // Description: Changes the nth word to the indicated value without
273 // affecting the other words.
274 ////////////////////////////////////////////////////////////////////
275 INLINE void ConfigVariable::
276 set_string_word(int n, const string &value) {
277  nassertv(is_constructed());
278  _core->make_local_value()->set_string_word(n, value);
279 }
280 
281 ////////////////////////////////////////////////////////////////////
282 // Function: ConfigVariable::set_bool_word
283 // Access: Published
284 // Description: Changes the nth word to the indicated value without
285 // affecting the other words.
286 ////////////////////////////////////////////////////////////////////
287 INLINE void ConfigVariable::
288 set_bool_word(int n, bool value) {
289  nassertv(is_constructed());
290  _core->make_local_value()->set_bool_word(n, value);
291 }
292 
293 ////////////////////////////////////////////////////////////////////
294 // Function: ConfigVariable::set_int_word
295 // Access: Published
296 // Description: Changes the nth word to the indicated value without
297 // affecting the other words.
298 ////////////////////////////////////////////////////////////////////
299 INLINE void ConfigVariable::
300 set_int_word(int n, int value) {
301  nassertv(is_constructed());
302  _core->make_local_value()->set_int_word(n, value);
303 }
304 
305 ////////////////////////////////////////////////////////////////////
306 // Function: ConfigVariable::set_int64_word
307 // Access: Published
308 // Description: Changes the nth word to the indicated value without
309 // affecting the other words.
310 ////////////////////////////////////////////////////////////////////
311 INLINE void ConfigVariable::
312 set_int64_word(int n, PN_int64 value) {
313  nassertv(is_constructed());
314  _core->make_local_value()->set_int64_word(n, value);
315 }
316 
317 ////////////////////////////////////////////////////////////////////
318 // Function: ConfigVariable::set_double_word
319 // Access: Published
320 // Description: Changes the nth word to the indicated value without
321 // affecting the other words.
322 ////////////////////////////////////////////////////////////////////
323 INLINE void ConfigVariable::
324 set_double_word(int n, double value) {
325  nassertv(is_constructed());
326  _core->make_local_value()->set_double_word(n, value);
327 }
328 
329 ////////////////////////////////////////////////////////////////////
330 // Function: ConfigVariable::is_constructed
331 // Access: Protected
332 // Description: Returns true if the constructor has been called and
333 // _core initialized, false if the constructor has not
334 // yet been called and _core is NULL. This is intended
335 // to be placed in an assertion check, to guard against
336 // static-init ordering issues.
337 ////////////////////////////////////////////////////////////////////
338 INLINE bool ConfigVariable::
339 is_constructed() const {
340 #ifndef NDEBUG
341  if (_core == (ConfigVariableCore *)NULL) {
342  report_unconstructed();
343  return false;
344  }
345 #endif
346  return true;
347 }
bool get_bool_word(int n) const
Returns the boolean value of the nth word of the variable's value, or false if there is no nth value...
void set_bool_word(int n, bool value)
Changes the nth word to the indicated value without affecting the other words.
The internal definition of a ConfigVariable.
int get_num_words() const
Returns the number of words in the variable's value.
bool has_string_word(int n) const
Returns true if the variable's value has a valid string value for the nth word.
bool has_bool_word(int n) const
Returns true if the declaration's value has a valid boolean value for the nth word.
const string & get_string_value() const
Returns the value assigned to this variable.
void set_double_word(int n, double value)
Changes the nth word to the indicated value without affecting the other words.
string get_string_word(int n) const
Returns the string value of the nth word of the variable's value, or empty string if there is no nth ...
bool has_string_word(int n) const
Returns true if the declaration's value has a valid string value for the nth word.
const string & get_string_value() const
Returns the toplevel value of the variable, formatted as a string.
int get_num_words() const
Returns the number of words in the declaration's value.
double get_double_word(int n) const
Returns the integer value of the nth word of the declaration's value, or 0 if there is no nth value...
const ConfigDeclaration * get_default_value() const
Returns the default variable specified for this variable.
double get_double_word(int n) const
Returns the integer value of the nth word of the variable's value, or 0 if there is no nth value...
bool has_int64_word(int n) const
Returns true if the variable's value has a valid 64-bit integer value for the nth word...
bool has_double_word(int n) const
Returns true if the declaration's value has a valid integer value for the nth word.
int get_int_word(int n) const
Returns the integer value of the nth word of the variable's value, or 0 if there is no nth value...
bool has_int_word(int n) const
Returns true if the declaration's value has a valid integer value for the nth word.
bool has_double_word(int n) const
Returns true if the variable's value has a valid integer value for the nth word.
void set_int64_word(int n, PN_int64 value)
Changes the nth word to the indicated value without affecting the other words.
void clear_value()
Removes the value assigned to this variable, and lets its original value (as read from the prc files)...
bool has_bool_word(int n) const
Returns true if the variable's value has a valid boolean value for the nth word.
PN_int64 get_int64_word(int n) const
Returns the int64 value of the nth word of the variable's value, or 0 if there is no nth value...
string get_string_word(int n) const
Returns the string value of the nth word of the declaration's value, or empty string if there is no n...
void set_string_value(const string &value)
Changes the value assigned to this variable.
This class is the base class for both ConfigVariableList and ConfigVariable (and hence for all of the...
PN_int64 get_int64_word(int n) const
Returns the int64 value of the nth word of the declaration's value, or 0 if there is no nth value...
bool has_int64_word(int n) const
Returns true if the declaration's value has a valid int64 value for the nth word. ...
bool has_int_word(int n) const
Returns true if the variable's value has a valid integer value for the nth word.
A single declaration of a config variable, typically defined as one line in a .prc file...
void set_int_word(int n, int value)
Changes the nth word to the indicated value without affecting the other words.
void set_string_word(int n, const string &value)
Changes the nth word to the indicated value without affecting the other words.
bool get_bool_word(int n) const
Returns the boolean value of the nth word of the declaration's value, or false if there is no nth val...
int get_int_word(int n) const
Returns the integer value of the nth word of the declaration's value, or 0 if there is no nth value...