15 #include "configDeclaration.h"
16 #include "configVariableCore.h"
17 #include "config_prc.h"
19 #include "string_utils.h"
29 const string &string_value,
int decl_seq) :
32 _string_value(string_value),
36 if (!_page->is_special()) {
37 _variable->add_declaration(
this);
48 ~ConfigDeclaration() {
50 _variable->remove_declaration(
this);
66 while (n >= (
int)_words.size()) {
72 _words[n]._str = value;
76 Words::const_iterator wi = _words.begin();
77 _string_value = (*wi)._str;
80 while (wi != _words.end()) {
82 _string_value += (*wi)._str;
98 _words[n]._flags |= (F_checked_bool | F_valid_bool);
99 _words[n]._bool = value;
113 _words[n]._flags |= (F_checked_int | F_valid_int);
114 _words[n]._int = value;
128 _words[n]._flags |= (F_checked_int64 | F_valid_int64);
129 _words[n]._int_64 = value;
143 _words[n]._flags |= (F_checked_double | F_valid_double);
144 _words[n]._double = value;
153 void ConfigDeclaration::
154 output(ostream &out)
const {
163 void ConfigDeclaration::
164 write(ostream &out)
const {
177 void ConfigDeclaration::
183 _words.reserve(words.size());
185 for (vector_string::const_iterator wi = words.begin();
204 void ConfigDeclaration::
205 check_bool_word(
int n) {
210 if (n >= 0 && n < (
int)_words.size()) {
211 Word &word = _words[n];
212 if ((word._flags & F_checked_bool) == 0) {
213 word._flags |= F_checked_bool;
219 }
else if (s ==
"#t" || s ==
"1" || s[0] ==
't') {
222 }
else if (s ==
"#f" || s ==
"0" || s[0] ==
'f') {
227 check_double_word(n);
228 if ((word._flags & F_checked_double) != 0) {
229 word._bool = (word._double != 0.0);
235 <<
"Invalid bool value for ConfigVariable "
240 word._flags |= F_valid_bool;
251 void ConfigDeclaration::
252 check_int_word(
int n) {
257 if (n >= 0 && n < (
int)_words.size()) {
258 Word &word = _words[n];
259 if ((word._flags & F_checked_int) == 0) {
260 word._flags |= F_checked_int;
265 bool overflow =
false;
267 string::const_iterator pi = word._str.begin();
268 if (pi != word._str.end() && (*pi) ==
'-') {
271 while (pi != word._str.end() && isdigit(*pi)) {
272 int next = word._int * 10 - (int)((*pi) -
'0');
273 if ((
int)(next / 10) != word._int) {
283 while (pi != word._str.end() && isdigit(*pi)) {
284 int next = word._int * 10 + (int)((*pi) -
'0');
285 if ((
int)(next / 10) != word._int) {
294 if (pi == word._str.end() && !overflow) {
295 word._flags |= F_valid_int;
298 <<
"Invalid integer value for ConfigVariable "
311 void ConfigDeclaration::
312 check_int64_word(
int n) {
317 if (n >= 0 && n < (
int)_words.size()) {
318 Word &word = _words[n];
319 if ((word._flags & F_checked_int64) == 0) {
320 word._flags |= F_checked_int64;
323 bool overflow =
false;
325 string::const_iterator pi = word._str.begin();
326 if (pi != word._str.end() && (*pi) ==
'-') {
329 while (pi != word._str.end() && isdigit(*pi)) {
330 PN_int64 next = word._int_64 * 10 - (int)((*pi) -
'0');
331 if ((PN_int64)(next / 10) != word._int_64) {
341 while (pi != word._str.end() && isdigit(*pi)) {
342 PN_int64 next = word._int_64 * 10 + (int)((*pi) -
'0');
343 if ((PN_int64)(next / 10) != word._int_64) {
352 if (pi == word._str.end() && !overflow) {
353 word._flags |= F_valid_int64;
356 <<
"Invalid int64 value for ConfigVariable "
369 void ConfigDeclaration::
370 check_double_word(
int n) {
375 if (n >= 0 && n < (
int)_words.size()) {
376 Word &word = _words[n];
377 if ((word._flags & F_checked_double) == 0) {
378 word._flags |= F_checked_double;
380 const char *nptr = word._str.c_str();
382 word._double = pstrtod(nptr, &endptr);
384 if (*endptr ==
'\0') {
385 word._flags |= F_valid_double;
388 <<
"Invalid floating-point value for ConfigVariable "
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])) {
439 result.reserve(s.size());
440 string::const_iterator p;
441 for (p = s.begin(); p != s.end(); ++p) {
442 result += tolower(*p);
The internal definition of a ConfigVariable.
const string & get_name() const
Returns the name of the variable.
const string & get_string_value() const
Returns the value assigned to this variable.
void set_int64_word(int n, PN_int64 value)
Changes the nth word to the indicated value without affecting the other words.
bool is_special() const
Returns true if this is the special "default" or "local" page, or false if it is an ordinary page...
static int extract_words(const string &str, vector_string &words)
Divides the string into a number of words according to whitespace.
void set_bool_word(int n, bool value)
Changes the nth word to the indicated value without affecting the other words.
void set_int_word(int n, int value)
Changes the nth word to the indicated value without affecting the other words.
A page of ConfigDeclarations that may be loaded or unloaded.
ConfigVariableCore * get_variable() const
Returns the variable that this declaration names.
static string downcase(const string &s)
Returns the input string with all uppercase letters converted to lowercase.
void set_string_word(int n, const string &value)
Changes the nth word to the indicated value without affecting the other words.
void set_double_word(int n, double value)
Changes the nth word to the indicated value without affecting the other words.