Panda3D
configVariableString.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 configVariableString.I
10  * @author drose
11  * @date 2004-10-20
12  */
13 
14 /**
15  *
16  */
17 INLINE ConfigVariableString::
18 ConfigVariableString(const std::string &name) :
19  ConfigVariable(name, VT_string),
20  _local_modified(initial_invalid_cache())
21 {
22  _core->set_used();
23 }
24 
25 /**
26  *
27  */
28 INLINE ConfigVariableString::
29 ConfigVariableString(const std::string &name, const std::string &default_value,
30  const std::string &description, int flags) :
31 #ifdef PRC_SAVE_DESCRIPTIONS
32  ConfigVariable(name, VT_string, description, flags),
33 #else
34  ConfigVariable(name, VT_string, std::string(), flags),
35 #endif
36  _local_modified(initial_invalid_cache())
37 {
38  _core->set_default_value(default_value);
39  _core->set_used();
40 }
41 
42 /**
43  * Reassigns the variable's local value.
44  */
45 INLINE void ConfigVariableString::
46 operator = (const std::string &value) {
47  set_value(value);
48 }
49 
50 /**
51  * Returns the variable's value.
52  */
53 INLINE ConfigVariableString::
54 operator const std::string & () const {
55  return get_value();
56 }
57 
58 /**
59  *
60  */
61 INLINE const char *ConfigVariableString::
62 c_str() const {
63  return get_value().c_str();
64 }
65 
66 /**
67  *
68  */
69 INLINE bool ConfigVariableString::
70 empty() const {
71  return get_value().empty();
72 }
73 
74 /**
75  *
76  */
77 INLINE size_t ConfigVariableString::
78 length() const {
79  return get_value().length();
80 }
81 
82 /**
83  *
84  */
85 INLINE char ConfigVariableString::
86 operator [] (size_t n) const {
87  assert(n < length());
88  return get_value()[n];
89 }
90 
91 /**
92  *
93  */
94 INLINE bool ConfigVariableString::
95 operator == (const std::string &other) const {
96  return get_value() == other;
97 }
98 
99 /**
100  *
101  */
102 INLINE bool ConfigVariableString::
103 operator != (const std::string &other) const {
104  return get_value() != other;
105 }
106 
107 /**
108  *
109  */
110 INLINE bool ConfigVariableString::
111 operator < (const std::string &other) const {
112  return get_value() < other;
113 }
114 
115 /**
116  * Reassigns the variable's local value.
117  */
118 INLINE void ConfigVariableString::
119 set_value(const std::string &value) {
120  set_string_value(value);
121 }
122 
123 /**
124  * Returns the variable's value.
125  */
126 INLINE const std::string &ConfigVariableString::
127 get_value() const {
128  TAU_PROFILE("const string &ConfigVariableString::get_value() const", " ", TAU_USER);
129  if (!is_cache_valid(_local_modified)) {
130  ((ConfigVariableString *)this)->reload_cache();
131  }
132  return _cache;
133 }
134 
135 /**
136  * Returns the variable's default value.
137  */
138 INLINE std::string ConfigVariableString::
139 get_default_value() const {
140  const ConfigDeclaration *decl = ConfigVariable::get_default_value();
141  if (decl != nullptr) {
142  return decl->get_string_value();
143  }
144  return std::string();
145 }
146 
147 /**
148  * Returns the variable's nth value.
149  */
150 INLINE std::string ConfigVariableString::
151 get_word(size_t n) const {
152  return get_string_word(n);
153 }
154 
155 /**
156  * Reassigns the variable's nth value. This makes a local copy of the
157  * variable's overall value.
158  */
159 INLINE void ConfigVariableString::
160 set_word(size_t n, const std::string &value) {
161  set_string_word(n, value);
162 }
const std::string & get_string_value() const
Returns the value assigned to this variable.
std::string get_word(size_t n) const
Returns the variable's nth value.
void set_string_value(const std::string &value)
Changes the value assigned to this variable.
void operator=(const std::string &value)
Reassigns the variable's local value.
This is a generic, untyped ConfigVariable.
This is a convenience class to specialize ConfigVariable as a string type.
set_value
Reassigns the variable's local value.
get_value
Returns the variable's value.
void set_word(size_t n, const std::string &value)
Reassigns the variable's nth value.
A single declaration of a config variable, typically defined as one line in a .prc file,...