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