Panda3D
configVariableString.I
1 // Filename: configVariableString.I
2 // Created by: drose (20Oct04)
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: ConfigVariableString::Constructor
18 // Access: Published
19 // Description:
20 ////////////////////////////////////////////////////////////////////
21 INLINE ConfigVariableString::
22 ConfigVariableString(const string &name) :
23  ConfigVariable(name, VT_string),
24  _local_modified(initial_invalid_cache())
25 {
26  _core->set_used();
27 }
28 
29 ////////////////////////////////////////////////////////////////////
30 // Function: ConfigVariableString::Constructor
31 // Access: Published
32 // Description:
33 ////////////////////////////////////////////////////////////////////
34 INLINE ConfigVariableString::
35 ConfigVariableString(const string &name, const string &default_value,
36  const string &description, int flags) :
37 #ifdef PRC_SAVE_DESCRIPTIONS
38  ConfigVariable(name, VT_string, description, flags),
39 #else
40  ConfigVariable(name, VT_string, string(), flags),
41 #endif
42  _local_modified(initial_invalid_cache())
43 {
44  _core->set_default_value(default_value);
45  _core->set_used();
46 }
47 
48 ////////////////////////////////////////////////////////////////////
49 // Function: ConfigVariableString::operator =
50 // Access: Published
51 // Description: Reassigns the variable's local value.
52 ////////////////////////////////////////////////////////////////////
53 INLINE void ConfigVariableString::
54 operator = (const string &value) {
55  set_value(value);
56 }
57 
58 ////////////////////////////////////////////////////////////////////
59 // Function: ConfigVariableString::string typecast operator
60 // Access: Published
61 // Description: Returns the variable's value.
62 ////////////////////////////////////////////////////////////////////
63 INLINE ConfigVariableString::
64 operator const string & () const {
65  return get_value();
66 }
67 
68 ////////////////////////////////////////////////////////////////////
69 // Function: ConfigVariableString::c_str
70 // Access: Public
71 // Description:
72 ////////////////////////////////////////////////////////////////////
73 INLINE const char *ConfigVariableString::
74 c_str() const {
75  return get_value().c_str();
76 }
77 
78 ////////////////////////////////////////////////////////////////////
79 // Function: ConfigVariableString::empty
80 // Access: Public
81 // Description:
82 ////////////////////////////////////////////////////////////////////
83 INLINE bool ConfigVariableString::
84 empty() const {
85  return get_value().empty();
86 }
87 
88 ////////////////////////////////////////////////////////////////////
89 // Function: ConfigVariableString::length
90 // Access: Public
91 // Description:
92 ////////////////////////////////////////////////////////////////////
93 INLINE size_t ConfigVariableString::
94 length() const {
95  return get_value().length();
96 }
97 
98 ////////////////////////////////////////////////////////////////////
99 // Function: ConfigVariableString::Indexing operator
100 // Access: Public
101 // Description:
102 ////////////////////////////////////////////////////////////////////
103 INLINE char ConfigVariableString::
104 operator [] (int n) const {
105  assert(n >= 0 && n < (int)length());
106  return get_value()[n];
107 }
108 
109 ////////////////////////////////////////////////////////////////////
110 // Function: ConfigVariableString::Equality operator
111 // Access: Public
112 // Description:
113 ////////////////////////////////////////////////////////////////////
114 INLINE bool ConfigVariableString::
115 operator == (const string &other) const {
116  return get_value() == other;
117 }
118 
119 ////////////////////////////////////////////////////////////////////
120 // Function: ConfigVariableString::Inequality operator
121 // Access: Public
122 // Description:
123 ////////////////////////////////////////////////////////////////////
124 INLINE bool ConfigVariableString::
125 operator != (const string &other) const {
126  return get_value() != other;
127 }
128 
129 ////////////////////////////////////////////////////////////////////
130 // Function: ConfigVariableString::Ordering operator
131 // Access: Public
132 // Description:
133 ////////////////////////////////////////////////////////////////////
134 INLINE bool ConfigVariableString::
135 operator < (const string &other) const {
136  return get_value() < other;
137 }
138 
139 ////////////////////////////////////////////////////////////////////
140 // Function: ConfigVariableString::set_value
141 // Access: Published
142 // Description: Reassigns the variable's local value.
143 ////////////////////////////////////////////////////////////////////
144 INLINE void ConfigVariableString::
145 set_value(const string &value) {
146  set_string_value(value);
147 }
148 
149 ////////////////////////////////////////////////////////////////////
150 // Function: ConfigVariableString::get_value
151 // Access: Published
152 // Description: Returns the variable's value.
153 ////////////////////////////////////////////////////////////////////
154 INLINE const string &ConfigVariableString::
155 get_value() const {
156  TAU_PROFILE("const string &ConfigVariableString::get_value() const", " ", TAU_USER);
157  if (!is_cache_valid(_local_modified)) {
158  ((ConfigVariableString *)this)->reload_cache();
159  }
160  return _cache;
161 }
162 
163 ////////////////////////////////////////////////////////////////////
164 // Function: ConfigVariableString::get_default_value
165 // Access: Published
166 // Description: Returns the variable's default value.
167 ////////////////////////////////////////////////////////////////////
168 INLINE string ConfigVariableString::
171  if (decl != (ConfigDeclaration *)NULL) {
172  return decl->get_string_value();
173  }
174  return string();
175 }
176 
177 ////////////////////////////////////////////////////////////////////
178 // Function: ConfigVariableString::get_word
179 // Access: Published
180 // Description: Returns the variable's nth value.
181 ////////////////////////////////////////////////////////////////////
182 INLINE string ConfigVariableString::
183 get_word(int n) const {
184  return get_string_word(n);
185 }
186 
187 ////////////////////////////////////////////////////////////////////
188 // Function: ConfigVariableString::set_word
189 // Access: Published
190 // Description: Reassigns the variable's nth value. This makes a
191 // local copy of the variable's overall value.
192 ////////////////////////////////////////////////////////////////////
193 INLINE void ConfigVariableString::
194 set_word(int n, const string &value) {
195  set_string_word(n, value);
196 }
string get_string_word(int n) const
Returns the string value of the nth word of the variable&#39;s value, or empty string if there is no nth ...
void operator=(const string &value)
Reassigns the variable&#39;s local value.
const ConfigDeclaration * get_default_value() const
Returns the default variable specified for this variable.
string get_word(int n) const
Returns the variable&#39;s nth value.
string get_default_value() const
Returns the variable&#39;s default value.
const string & get_value() const
Returns the variable&#39;s value.
void set_word(int n, const string &value)
Reassigns the variable&#39;s nth value.
This is a generic, untyped ConfigVariable.
This is a convenience class to specialize ConfigVariable as a string type.
void set_string_value(const string &value)
Changes the value assigned to this variable.
void set_value(const string &value)
Reassigns the variable&#39;s local value.
A single declaration of a config variable, typically defined as one line in a .prc file...
void set_string_word(int n, const string &value)
Changes the nth word to the indicated value without affecting the other words.
const string & get_string_value() const
Returns the value assigned to this variable.