forked from panda3d/panda3d
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfigVariable.I
More file actions
282 lines (257 loc) · 7.66 KB
/
configVariable.I
File metadata and controls
282 lines (257 loc) · 7.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
/**
* PANDA 3D SOFTWARE
* Copyright (c) Carnegie Mellon University. All rights reserved.
*
* All use of this software is subject to the terms of the revised BSD
* license. You should have received a copy of this license along
* with this source code in a file named "LICENSE."
*
* @file configVariable.I
* @author drose
* @date 2004-10-18
*/
/**
* This constructor is only intended to be called from a specialized
* ConfigVariableFoo derived class.
*/
INLINE ConfigVariable::
ConfigVariable(const std::string &name, ConfigVariable::ValueType value_type) :
ConfigVariableBase(name, value_type)
{
}
/**
* This constructor is only intended to be called from a specialized
* ConfigVariableFoo derived class.
*/
INLINE ConfigVariable::
ConfigVariable(const std::string &name, ConfigVariable::ValueType value_type,
const std::string &description, int flags) :
ConfigVariableBase(name, value_type, description, flags)
{
}
/**
* Use this constructor to make a ConfigVariable of an unspecified type.
* Usually you'd want to do this just to reference a previously-defined
* ConfigVariable of a specific type, without having to know what type it is.
*/
INLINE ConfigVariable::
ConfigVariable(const std::string &name) :
ConfigVariableBase(name, VT_undefined)
{
_core->set_used();
}
/**
*
*/
INLINE ConfigVariable::
~ConfigVariable() {
}
/**
* Returns the default variable specified for this variable. If the variable
* has not yet been defined, this will return NULL.
*/
INLINE const ConfigDeclaration *ConfigVariable::
get_default_value() const {
nassertr(is_constructed(), nullptr);
return _core->get_default_value();
}
/**
* Returns the toplevel value of the variable, formatted as a string.
*/
INLINE const std::string &ConfigVariable::
get_string_value() const {
nassertr(is_constructed(), *new std::string());
const ConfigDeclaration *decl = _core->get_declaration(0);
return decl->get_string_value();
}
/**
* Changes the value assigned to this variable. This creates a local value
* that shadows any values defined in the .prc files, until
* clear_local_value() is called.
*/
INLINE void ConfigVariable::
set_string_value(const std::string &string_value) {
nassertv(is_constructed());
_core->make_local_value()->set_string_value(string_value);
}
/**
* Removes the value assigned to this variable, and lets its original value
* (as read from the prc files) show through.
*/
INLINE void ConfigVariable::
clear_value() {
nassertv(is_constructed());
_core->clear_local_value();
}
/**
* Returns the number of words in the variable's value. A word is defined as
* a sequence of non-whitespace characters delimited by whitespace.
*/
INLINE size_t ConfigVariable::
get_num_words() const {
nassertr(is_constructed(), 0);
const ConfigDeclaration *decl = _core->get_declaration(0);
return decl->get_num_words();
}
/**
* Returns true if the variable's value has a valid string value for the nth
* word. This is really the same thing as asking if there are at least n
* words in the value.
*/
INLINE bool ConfigVariable::
has_string_word(size_t n) const {
nassertr(is_constructed(), false);
const ConfigDeclaration *decl = _core->get_declaration(0);
return decl->has_string_word(n);
}
/**
* Returns true if the variable's value has a valid boolean value for the nth
* word.
*/
INLINE bool ConfigVariable::
has_bool_word(size_t n) const {
nassertr(is_constructed(), false);
const ConfigDeclaration *decl = _core->get_declaration(0);
return decl->has_bool_word(n);
}
/**
* Returns true if the variable's value has a valid integer value for the nth
* word.
*/
INLINE bool ConfigVariable::
has_int_word(size_t n) const {
nassertr(is_constructed(), false);
const ConfigDeclaration *decl = _core->get_declaration(0);
return decl->has_int_word(n);
}
/**
* Returns true if the variable's value has a valid 64-bit integer value for
* the nth word.
*/
INLINE bool ConfigVariable::
has_int64_word(size_t n) const {
nassertr(is_constructed(), false);
const ConfigDeclaration *decl = _core->get_declaration(0);
return decl->has_int64_word(n);
}
/**
* Returns true if the variable's value has a valid integer value for the nth
* word.
*/
INLINE bool ConfigVariable::
has_double_word(size_t n) const {
nassertr(is_constructed(), false);
const ConfigDeclaration *decl = _core->get_declaration(0);
return decl->has_double_word(n);
}
/**
* Returns the string value of the nth word of the variable's value, or empty
* string if there is no nth value. See also has_string_word().
*/
INLINE std::string ConfigVariable::
get_string_word(size_t n) const {
nassertr(is_constructed(), std::string());
const ConfigDeclaration *decl = _core->get_declaration(0);
return decl->get_string_word(n);
}
/**
* Returns the boolean value of the nth word of the variable's value, or false
* if there is no nth value. See also has_bool_word().
*/
INLINE bool ConfigVariable::
get_bool_word(size_t n) const {
nassertr(is_constructed(), false);
const ConfigDeclaration *decl = _core->get_declaration(0);
return decl->get_bool_word(n);
}
/**
* Returns the integer value of the nth word of the variable's value, or 0 if
* there is no nth value. See also has_int_word().
*/
INLINE int ConfigVariable::
get_int_word(size_t n) const {
nassertr(is_constructed(), 0);
const ConfigDeclaration *decl = _core->get_declaration(0);
return decl->get_int_word(n);
}
/**
* Returns the int64 value of the nth word of the variable's value, or 0 if
* there is no nth value. See also has_int_word().
*/
INLINE int64_t ConfigVariable::
get_int64_word(size_t n) const {
nassertr(is_constructed(), 0);
const ConfigDeclaration *decl = _core->get_declaration(0);
return decl->get_int64_word(n);
}
/**
* Returns the integer value of the nth word of the variable's value, or 0 if
* there is no nth value. See also has_double_word().
*/
INLINE double ConfigVariable::
get_double_word(size_t n) const {
nassertr(is_constructed(), 0.0);
const ConfigDeclaration *decl = _core->get_declaration(0);
return decl->get_double_word(n);
}
/**
* Changes the nth word to the indicated value without affecting the other
* words.
*/
INLINE void ConfigVariable::
set_string_word(size_t n, const std::string &value) {
nassertv(is_constructed());
_core->make_local_value()->set_string_word(n, value);
}
/**
* Changes the nth word to the indicated value without affecting the other
* words.
*/
INLINE void ConfigVariable::
set_bool_word(size_t n, bool value) {
nassertv(is_constructed());
_core->make_local_value()->set_bool_word(n, value);
}
/**
* Changes the nth word to the indicated value without affecting the other
* words.
*/
INLINE void ConfigVariable::
set_int_word(size_t n, int value) {
nassertv(is_constructed());
_core->make_local_value()->set_int_word(n, value);
}
/**
* Changes the nth word to the indicated value without affecting the other
* words.
*/
INLINE void ConfigVariable::
set_int64_word(size_t n, int64_t value) {
nassertv(is_constructed());
_core->make_local_value()->set_int64_word(n, value);
}
/**
* Changes the nth word to the indicated value without affecting the other
* words.
*/
INLINE void ConfigVariable::
set_double_word(size_t n, double value) {
nassertv(is_constructed());
_core->make_local_value()->set_double_word(n, value);
}
/**
* Returns true if the constructor has been called and _core initialized,
* false if the constructor has not yet been called and _core is NULL. This
* is intended to be placed in an assertion check, to guard against static-
* init ordering issues.
*/
INLINE bool ConfigVariable::
is_constructed() const {
#ifndef NDEBUG
if (_core == nullptr) {
report_unconstructed();
return false;
}
#endif
return true;
}