30 const string &string_value,
int decl_seq) :
33 _string_value(string_value),
37 if (!_page->is_special()) {
38 _variable->add_declaration(
this);
48 _variable->remove_declaration(
this);
62 while (n >= _words.size()) {
68 _words[n]._str = value;
72 Words::const_iterator wi = _words.begin();
73 _string_value = (*wi)._str;
76 while (wi != _words.end()) {
78 _string_value += (*wi)._str;
92 _words[n]._flags |= (F_checked_bool | F_valid_bool);
93 _words[n]._bool = value;
105 _words[n]._flags |= (F_checked_int | F_valid_int);
106 _words[n]._int = value;
118 _words[n]._flags |= (F_checked_int64 | F_valid_int64);
119 _words[n]._int_64 = value;
131 _words[n]._flags |= (F_checked_double | F_valid_double);
132 _words[n]._double = value;
149 string str = _string_value;
152 if (str.find(
'$') != string::npos) {
165 fn = Filename::from_os_specific(str);
174void ConfigDeclaration::
175output(std::ostream &out)
const {
182void ConfigDeclaration::
183write(std::ostream &out)
const {
192void ConfigDeclaration::
198 _words.reserve(words.size());
200 for (vector_string::const_iterator wi = words.begin();
216void ConfigDeclaration::
217check_bool_word(
size_t n) {
222 if (n < _words.size()) {
223 Word &word = _words[n];
224 if ((word._flags & F_checked_bool) == 0) {
225 word._flags |= F_checked_bool;
231 }
else if (s ==
"#t" || s ==
"1" || s[0] ==
't') {
234 }
else if (s ==
"#f" || s ==
"0" || s[0] ==
'f') {
239 check_double_word(n);
240 if ((word._flags & F_checked_double) != 0) {
241 word._bool = (word._double != 0.0);
247 <<
"Invalid bool value for ConfigVariable "
248 <<
get_variable()->get_name() <<
": " << word._str <<
"\n";
252 word._flags |= F_valid_bool;
260void ConfigDeclaration::
261check_int_word(
size_t n) {
266 if (n < _words.size()) {
267 Word &word = _words[n];
268 if ((word._flags & F_checked_int) == 0) {
269 word._flags |= F_checked_int;
274 bool overflow =
false;
276 string::const_iterator pi = word._str.begin();
277 if (pi != word._str.end() && (*pi) ==
'-') {
280 while (pi != word._str.end() && isdigit(*pi)) {
281 int next = word._int * 10 - (int)((*pi) -
'0');
282 if ((
int)(next / 10) != word._int) {
292 while (pi != word._str.end() && isdigit(*pi)) {
293 int next = word._int * 10 + (int)((*pi) -
'0');
294 if ((
int)(next / 10) != word._int) {
303 if (pi == word._str.end() && !overflow) {
304 word._flags |= F_valid_int;
307 <<
"Invalid integer value for ConfigVariable "
308 <<
get_variable()->get_name() <<
": " << word._str <<
"\n";
317void ConfigDeclaration::
318check_int64_word(
size_t n) {
323 if (n < _words.size()) {
324 Word &word = _words[n];
325 if ((word._flags & F_checked_int64) == 0) {
326 word._flags |= F_checked_int64;
329 bool overflow =
false;
331 string::const_iterator pi = word._str.begin();
332 if (pi != word._str.end() && (*pi) ==
'-') {
335 while (pi != word._str.end() && isdigit(*pi)) {
336 int64_t next = word._int_64 * 10 - (int)((*pi) -
'0');
337 if ((int64_t)(next / 10) != word._int_64) {
347 while (pi != word._str.end() && isdigit(*pi)) {
348 int64_t next = word._int_64 * 10 + (int)((*pi) -
'0');
349 if ((int64_t)(next / 10) != word._int_64) {
358 if (pi == word._str.end() && !overflow) {
359 word._flags |= F_valid_int64;
362 <<
"Invalid int64 value for ConfigVariable "
363 <<
get_variable()->get_name() <<
": " << word._str <<
"\n";
372void ConfigDeclaration::
373check_double_word(
size_t n) {
378 if (n < _words.size()) {
379 Word &word = _words[n];
380 if ((word._flags & F_checked_double) == 0) {
381 word._flags |= F_checked_double;
383 const char *nptr = word._str.c_str();
385 word._double =
pstrtod(nptr, &endptr);
387 if (*endptr ==
'\0') {
388 word._flags |= F_valid_double;
391 <<
"Invalid floating-point value for ConfigVariable "
392 <<
get_variable()->get_name() <<
": " << word._str <<
"\n";
408 size_t num_words = 0;
411 while (pos < str.length() && isspace((
unsigned int)str[pos])) {
414 while (pos < str.length()) {
415 size_t word_start = pos;
416 while (pos < str.length() && !isspace((
unsigned int)str[pos])) {
419 words.push_back(str.substr(word_start, pos - word_start));
422 while (pos < str.length() && isspace((
unsigned int)str[pos])) {
436 result.reserve(s.size());
437 string::const_iterator p;
438 for (p = s.begin(); p != s.end(); ++p) {
439 result += (char)tolower(*p);
void set_double_word(size_t n, double value)
Changes the nth word to the indicated value without affecting the other words.
void set_int_word(size_t n, int value)
Changes the nth word to the indicated value without affecting the other words.
void set_int64_word(size_t n, int64_t value)
Changes the nth word to the indicated value without affecting the other words.
const std::string & get_string_value() const
Returns the value assigned to this variable.
void set_string_word(size_t n, const std::string &value)
Changes the nth word to the indicated value without affecting the other words.
Filename get_filename_value() const
Interprets the string value as a filename and returns it, with any variables expanded.
static std::string downcase(const std::string &s)
Returns the input string with all uppercase letters converted to lowercase.
void set_bool_word(size_t n, bool value)
Changes the nth word to the indicated value without affecting the other words.
static size_t extract_words(const std::string &str, vector_string &words)
Divides the string into a number of words according to whitespace.
get_variable
Returns the variable that this declaration names.
A page of ConfigDeclarations that may be loaded or unloaded.
is_special
Returns true if this is the special "default" or "local" page, or false if it is an ordinary page,...
get_name
Returns the name of the page.
The internal definition of a ConfigVariable.
static void clear_shadow(const std::string &var)
Removes a value set by a previous call to shadow_environment_variable(), and lets the actual value of...
static std::string expand_string(const std::string &str)
Reads the string, looking for environment variable names marked by a $.
static void shadow_environment_variable(const std::string &var, const std::string &value)
Changes the apparent definition of the indicated environment variable by masking it within this class...
The name of a file, such as a texture file or an Egg file.
std::string to_os_specific() const
Converts the filename from our generic Unix-like convention (forward slashes starting with the root a...
bool make_true_case()
On a case-insensitive operating system (e.g.
std::string get_dirname() const
Returns the directory part of the filename.
A fake mutex implementation for single-threaded applications that don't need any synchronization cont...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
double pstrtod(const char *nptr, char **endptr)
This function re-implements strtod, to avoid the problems that occur when the LC_NUMERIC locale gets ...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.