Panda3D

Loading...
Searching...
No Matches
configDeclaration.h
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.h
10 * @author drose
11 * @date 2004-10-15
12 */
13
14#ifndef CONFIGDECLARATION_H
15#define CONFIGDECLARATION_H
16
17#include "dtoolbase.h"
18#include "configFlags.h"
19#include "configPage.h"
20#include "vector_string.h"
21#include "numeric_types.h"
22#include "filename.h"
23
24#include <vector>
25
26 class ConfigVariableCore;
27
28/**
29 * A single declaration of a config variable, typically defined as one line in
30 * a .prc file, e.g. "show-frame-rate-meter 1". This is really just a
31 * pairing of a string name (actually, a ConfigVariableCore pointer) to a
32 * string value.
33 */
34 class EXPCL_DTOOL_PRC ConfigDeclaration : public ConfigFlags {
35 private:
36 ConfigDeclaration(ConfigPage *page, ConfigVariableCore *variable,
37 const std::string &string_value, int decl_seq);
38 ~ConfigDeclaration();
39
40 public:
41 INLINE bool operator < (const ConfigDeclaration &other) const;
42
43PUBLISHED:
44 INLINE ConfigPage *get_page() const;
45 INLINE ConfigVariableCore *get_variable() const;
46 MAKE_PROPERTY(page, get_page);
47 MAKE_PROPERTY(variable, get_variable);
48
49 INLINE const std::string &get_string_value() const;
50 INLINE void set_string_value(const std::string &value);
51
52 INLINE size_t get_num_words() const;
53
54 INLINE bool has_string_word(size_t n) const;
55 INLINE bool has_bool_word(size_t n) const;
56 INLINE bool has_int_word(size_t n) const;
57 INLINE bool has_int64_word(size_t n) const;
58 INLINE bool has_double_word(size_t n) const;
59
60 INLINE std::string get_string_word(size_t n) const;
61 INLINE bool get_bool_word(size_t n) const;
62 INLINE int get_int_word(size_t n) const;
63 INLINE int64_t get_int64_word(size_t n) const;
64 INLINE double get_double_word(size_t n) const;
65
66 void set_string_word(size_t n, const std::string &value);
67 void set_bool_word(size_t n, bool value);
68 void set_int_word(size_t n, int value);
69 void set_int64_word(size_t n, int64_t value);
70 void set_double_word(size_t n, double value);
71
72 Filename get_filename_value() const;
73
74 INLINE int get_decl_seq() const;
75
76 void output(std::ostream &out) const;
77 void write(std::ostream &out) const;
78
79 public:
80 static size_t extract_words(const std::string &str, vector_string &words);
81 static std::string downcase(const std::string &s);
82
83 private:
84 void get_words();
85 void check_bool_word(size_t n);
86 void check_int_word(size_t n);
87 void check_int64_word(size_t n);
88 void check_double_word(size_t n);
89
90 private:
91 ConfigPage *_page;
92 ConfigVariableCore *_variable;
93 std::string _string_value;
94 int _decl_seq;
95
96 enum WordFlags {
97 F_checked_bool = 0x0001,
98 F_valid_bool = 0x0002,
99 F_checked_int = 0x0004,
100 F_valid_int = 0x0008,
101 F_checked_double = 0x0010,
102 F_valid_double = 0x0020,
103 F_checked_int64 = 0x0040,
104 F_valid_int64 = 0x0080,
105 };
106
107 class Word {
108 public:
109 std::string _str;
110 bool _bool;
111 int _int;
112 int64_t _int_64;
113 double _double;
114 short _flags;
115 };
116
117 typedef std::vector<Word> Words;
118 Words _words;
119 bool _got_words;
120
121 friend class ConfigPage;
122};
123
124INLINE std::ostream &operator << (std::ostream &out, const ConfigDeclaration &decl);
125
126#include "configDeclaration.I"
127
128#endif
ConfigDeclaration
A single declaration of a config variable, typically defined as one line in a .prc file,...
Definition configDeclaration.h:34
ConfigDeclaration::get_int64_word
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.
Definition configDeclaration.I:191
ConfigDeclaration::has_bool_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.
Definition configDeclaration.I:97
ConfigDeclaration::get_bool_word
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...
Definition configDeclaration.I:161
ConfigDeclaration::get_double_word
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.
Definition configDeclaration.I:206
ConfigDeclaration::has_int_word
bool has_int_word(size_t n) const
Returns true if the declaration's value has a valid integer value for the nth word.
Definition configDeclaration.I:110
ConfigDeclaration::set_double_word
void set_double_word(size_t n, double value)
Changes the nth word to the indicated value without affecting the other words.
Definition configDeclaration.cxx:128
ConfigDeclaration::get_num_words
size_t get_num_words() const
Returns the number of words in the declaration's value.
Definition configDeclaration.I:72
ConfigDeclaration::set_int_word
void set_int_word(size_t n, int value)
Changes the nth word to the indicated value without affecting the other words.
Definition configDeclaration.cxx:102
ConfigDeclaration::set_int64_word
void set_int64_word(size_t n, int64_t value)
Changes the nth word to the indicated value without affecting the other words.
Definition configDeclaration.cxx:115
ConfigDeclaration::get_int_word
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.
Definition configDeclaration.I:176
ConfigDeclaration::has_double_word
bool has_double_word(size_t n) const
Returns true if the declaration's value has a valid integer value for the nth word.
Definition configDeclaration.I:136
ConfigDeclaration::get_string_value
const std::string & get_string_value() const
Returns the value assigned to this variable.
Definition configDeclaration.I:53
ConfigDeclaration::set_string_word
void set_string_word(size_t n, const std::string &value)
Changes the nth word to the indicated value without affecting the other words.
Definition configDeclaration.cxx:57
ConfigDeclaration::get_filename_value
Filename get_filename_value() const
Interprets the string value as a filename and returns it, with any variables expanded.
Definition configDeclaration.cxx:141
ConfigDeclaration::get_string_word
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...
Definition configDeclaration.I:149
ConfigDeclaration::has_int64_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.
Definition configDeclaration.I:123
ConfigDeclaration::set_bool_word
void set_bool_word(size_t n, bool value)
Changes the nth word to the indicated value without affecting the other words.
Definition configDeclaration.cxx:89
ConfigDeclaration::get_page
get_page
Returns the page on which this declaration can be found.
Definition configDeclaration.h:46
ConfigDeclaration::get_decl_seq
int get_decl_seq() const
Returns the sequence number of the declaration within the page.
Definition configDeclaration.I:224
ConfigDeclaration::set_string_value
void set_string_value(const std::string &value)
Changes the value assigned to this variable.
Definition configDeclaration.I:61
ConfigDeclaration::get_variable
get_variable
Returns the variable that this declaration names.
Definition configDeclaration.h:47
ConfigDeclaration::has_string_word
bool has_string_word(size_t n) const
Returns true if the declaration's value has a valid string value for the nth word.
Definition configDeclaration.I:85
ConfigFlags
This class is the base class of both ConfigVariable and ConfigVariableCore.
Definition configFlags.h:26
ConfigVariableCore
The internal definition of a ConfigVariable.
Definition configVariableCore.h:34
Filename
The name of a file, such as a texture file or an Egg file.
Definition filename.h:44
configDeclaration.I
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
configFlags.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
configPage.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
dtoolbase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
filename.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
numeric_types.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
extract_words
int extract_words(const string &str, vector_string &words)
Divides the string into a number of words according to whitespace.
Definition string_utils.cxx:105
downcase
string downcase(const string &s)
Returns the input string with all uppercase letters converted to lowercase.
Definition string_utils.cxx:71
vector_string.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.