Panda3D
 All Classes Functions Variables Enumerations
configDeclaration.I
1 // Filename: configDeclaration.I
2 // Created by: drose (15Oct04)
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: ConfigDeclaration::operator <
18 // Access: Public
19 // Description: Sorts two declarations in order based on the order in
20 // which their respective pages were loaded, and the
21 // order in which they appear within the same page.
22 ////////////////////////////////////////////////////////////////////
23 INLINE bool ConfigDeclaration::
24 operator < (const ConfigDeclaration &other) const {
25  if (get_page() == other.get_page()) {
26  // On the same page, we compare based on the decl_seq.
27  return get_decl_seq() < other.get_decl_seq();
28  }
29 
30  // On different pages, we compare based on the page importance.
31  return *get_page() < *other.get_page();
32 }
33 
34 ////////////////////////////////////////////////////////////////////
35 // Function: ConfigDeclaration::get_page
36 // Access: Public
37 // Description: Returns the page on which this declaration can be
38 // found.
39 ////////////////////////////////////////////////////////////////////
41 get_page() const {
42  return _page;
43 }
44 
45 ////////////////////////////////////////////////////////////////////
46 // Function: ConfigDeclaration::get_variable
47 // Access: Public
48 // Description: Returns the variable that this declaration names.
49 // This variable may or may not have been defined by the
50 // time the declaration is read.
51 ////////////////////////////////////////////////////////////////////
53 get_variable() const {
54  return _variable;
55 }
56 
57 ////////////////////////////////////////////////////////////////////
58 // Function: ConfigDeclaration::get_string_value
59 // Access: Public
60 // Description: Returns the value assigned to this variable. This is
61 // the original one-line text defined for the variable
62 // in the .prc file (or passed to
63 // ConfigPage::make_declaration()).
64 ////////////////////////////////////////////////////////////////////
65 INLINE const string &ConfigDeclaration::
67  return _string_value;
68 }
69 
70 ////////////////////////////////////////////////////////////////////
71 // Function: ConfigDeclaration::set_string_value
72 // Access: Public
73 // Description: Changes the value assigned to this variable.
74 ////////////////////////////////////////////////////////////////////
75 INLINE void ConfigDeclaration::
76 set_string_value(const string &string_value) {
77  _string_value = string_value;
78  _got_words = false;
79  invalidate_cache();
80 }
81 
82 ////////////////////////////////////////////////////////////////////
83 // Function: ConfigDeclaration::get_num_words
84 // Access: Public
85 // Description: Returns the number of words in the declaration's
86 // value. A word is defined as a sequence of
87 // non-whitespace characters delimited by whitespace.
88 ////////////////////////////////////////////////////////////////////
89 INLINE int ConfigDeclaration::
90 get_num_words() const {
91  if (!_got_words) {
92  ((ConfigDeclaration *)this)->get_words();
93  }
94  return _words.size();
95 }
96 
97 ////////////////////////////////////////////////////////////////////
98 // Function: ConfigDeclaration::has_string_word
99 // Access: Public
100 // Description: Returns true if the declaration's value has a valid
101 // string value for the nth word. This is really the
102 // same thing as asking if there are at least n words in
103 // the value.
104 ////////////////////////////////////////////////////////////////////
105 INLINE bool ConfigDeclaration::
106 has_string_word(int n) const {
107  if (!_got_words) {
108  ((ConfigDeclaration *)this)->get_words();
109  }
110  return (n >= 0 && n < (int)_words.size());
111 }
112 
113 ////////////////////////////////////////////////////////////////////
114 // Function: ConfigDeclaration::has_bool_word
115 // Access: Public
116 // Description: Returns true if the declaration's value has a valid
117 // boolean value for the nth word.
118 ////////////////////////////////////////////////////////////////////
119 INLINE bool ConfigDeclaration::
120 has_bool_word(int n) const {
121  if (has_string_word(n)) {
122  ((ConfigDeclaration *)this)->check_bool_word(n);
123  return (_words[n]._flags & F_valid_bool) != 0;
124  }
125  return false;
126 }
127 
128 ////////////////////////////////////////////////////////////////////
129 // Function: ConfigDeclaration::has_int_word
130 // Access: Public
131 // Description: Returns true if the declaration's value has a valid
132 // integer value for the nth word.
133 ////////////////////////////////////////////////////////////////////
134 INLINE bool ConfigDeclaration::
135 has_int_word(int n) const {
136  if (has_string_word(n)) {
137  ((ConfigDeclaration *)this)->check_int_word(n);
138  return (_words[n]._flags & F_valid_int) != 0;
139  }
140  return false;
141 }
142 
143 ////////////////////////////////////////////////////////////////////
144 // Function: ConfigDeclaration::has_int64_word
145 // Access: Public
146 // Description: Returns true if the declaration's value has a valid
147 // int64 value for the nth word.
148 ////////////////////////////////////////////////////////////////////
149 INLINE bool ConfigDeclaration::
150 has_int64_word(int n) const {
151  if (has_string_word(n)) {
152  ((ConfigDeclaration *)this)->check_int64_word(n);
153  return (_words[n]._flags & F_valid_int64) != 0;
154  }
155  return false;
156 }
157 
158 ////////////////////////////////////////////////////////////////////
159 // Function: ConfigDeclaration::has_double_word
160 // Access: Public
161 // Description: Returns true if the declaration's value has a valid
162 // integer value for the nth word.
163 ////////////////////////////////////////////////////////////////////
164 INLINE bool ConfigDeclaration::
165 has_double_word(int n) const {
166  if (has_string_word(n)) {
167  ((ConfigDeclaration *)this)->check_double_word(n);
168  return (_words[n]._flags & F_valid_double) != 0;
169  }
170  return false;
171 }
172 
173 ////////////////////////////////////////////////////////////////////
174 // Function: ConfigDeclaration::get_string_word
175 // Access: Public
176 // Description: Returns the string value of the nth word of the
177 // declaration's value, or empty string if there is no
178 // nth value. See also has_string_word().
179 ////////////////////////////////////////////////////////////////////
180 INLINE string ConfigDeclaration::
181 get_string_word(int n) const {
182  if (has_string_word(n)) {
183  return _words[n]._str;
184  }
185  return string();
186 }
187 
188 ////////////////////////////////////////////////////////////////////
189 // Function: ConfigDeclaration::get_bool_word
190 // Access: Public
191 // Description: Returns the boolean value of the nth word of the
192 // declaration's value, or false if there is no nth
193 // value. See also has_bool_word().
194 ////////////////////////////////////////////////////////////////////
195 INLINE bool ConfigDeclaration::
196 get_bool_word(int n) const {
197  // We use has_string_word() instead of has_bool_word(), so we can
198  // return a partial answer if there was one.
199  if (has_string_word(n)) {
200  ((ConfigDeclaration *)this)->check_bool_word(n);
201  return _words[n]._bool;
202  }
203  return false;
204 }
205 
206 ////////////////////////////////////////////////////////////////////
207 // Function: ConfigDeclaration::get_int_word
208 // Access: Public
209 // Description: Returns the integer value of the nth word of the
210 // declaration's value, or 0 if there is no nth value.
211 // See also has_int_word().
212 ////////////////////////////////////////////////////////////////////
213 INLINE int ConfigDeclaration::
214 get_int_word(int n) const {
215  // We use has_string_word() instead of has_int_word(), so we can
216  // return a partial answer if there was one.
217  if (has_string_word(n)) {
218  ((ConfigDeclaration *)this)->check_int_word(n);
219  return _words[n]._int;
220  }
221  return 0;
222 }
223 
224 ////////////////////////////////////////////////////////////////////
225 // Function: ConfigDeclaration::get_int64_word
226 // Access: Public
227 // Description: Returns the int64 value of the nth word of the
228 // declaration's value, or 0 if there is no nth value.
229 // See also has_int64_word().
230 ////////////////////////////////////////////////////////////////////
231 INLINE PN_int64 ConfigDeclaration::
232 get_int64_word(int n) const {
233  // We use has_string_word() instead of has_int64_word(), so we can
234  // return a partial answer if there was one.
235  if (has_string_word(n)) {
236  ((ConfigDeclaration *)this)->check_int64_word(n);
237  return _words[n]._int_64;
238  }
239  return 0;
240 }
241 
242 ////////////////////////////////////////////////////////////////////
243 // Function: ConfigDeclaration::get_double_word
244 // Access: Public
245 // Description: Returns the integer value of the nth word of the
246 // declaration's value, or 0 if there is no nth value.
247 // See also has_double_word().
248 ////////////////////////////////////////////////////////////////////
249 INLINE double ConfigDeclaration::
250 get_double_word(int n) const {
251  // We use has_string_word() instead of has_double_word(), so we can
252  // return a partial answer if there was one.
253  if (has_string_word(n)) {
254  ((ConfigDeclaration *)this)->check_double_word(n);
255  return _words[n]._double;
256  }
257  return 0.0;
258 }
259 
260 
261 ////////////////////////////////////////////////////////////////////
262 // Function: ConfigDeclaration::get_decl_seq
263 // Access: Public
264 // Description: Returns the sequence number of the declaration within
265 // the page. Sequence numbers are assigned as each
266 // declaration is created; each declaration is given a
267 // higher sequence number than all the declarations
268 // created in the page before it.
269 ////////////////////////////////////////////////////////////////////
270 INLINE int ConfigDeclaration::
271 get_decl_seq() const {
272  return _decl_seq;
273 }
274 
275 INLINE ostream &
276 operator << (ostream &out, const ConfigDeclaration &decl) {
277  decl.output(out);
278  return out;
279 }
The internal definition of a ConfigVariable.
bool has_bool_word(int n) const
Returns true if the declaration&#39;s value has a valid boolean value for the nth word.
const string & get_string_value() const
Returns the value assigned to this variable.
bool has_string_word(int n) const
Returns true if the declaration&#39;s value has a valid string value for the nth word.
bool operator<(const ConfigDeclaration &other) const
Sorts two declarations in order based on the order in which their respective pages were loaded...
int get_num_words() const
Returns the number of words in the declaration&#39;s value.
double get_double_word(int n) const
Returns the integer value of the nth word of the declaration&#39;s value, or 0 if there is no nth value...
int get_decl_seq() const
Returns the sequence number of the declaration within the page.
bool has_double_word(int n) const
Returns true if the declaration&#39;s value has a valid integer value for the nth word.
void set_string_value(const string &value)
Changes the value assigned to this variable.
bool has_int_word(int n) const
Returns true if the declaration&#39;s value has a valid integer value for the nth word.
A page of ConfigDeclarations that may be loaded or unloaded.
Definition: configPage.h:33
ConfigPage * get_page() const
Returns the page on which this declaration can be found.
string get_string_word(int n) const
Returns the string value of the nth word of the declaration&#39;s value, or empty string if there is no n...
ConfigVariableCore * get_variable() const
Returns the variable that this declaration names.
PN_int64 get_int64_word(int n) const
Returns the int64 value of the nth word of the declaration&#39;s value, or 0 if there is no nth value...
bool has_int64_word(int n) const
Returns true if the declaration&#39;s value has a valid int64 value for the nth word. ...
A single declaration of a config variable, typically defined as one line in a .prc file...
bool get_bool_word(int n) const
Returns the boolean value of the nth word of the declaration&#39;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&#39;s value, or 0 if there is no nth value...