Panda3D
Loading...
Searching...
No Matches
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 */
17INLINE ConfigVariableString::
18ConfigVariableString(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 */
28INLINE ConfigVariableString::
29ConfigVariableString(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 */
46operator = (const std::string &value) {
47 set_value(value);
48}
49
50/**
51 * Returns the variable's value.
52 */
53INLINE ConfigVariableString::
54operator const std::string & () const {
55 return get_value();
56}
57
58/**
59 *
60 */
61INLINE const char *ConfigVariableString::
62c_str() const {
63 return get_value().c_str();
64}
65
66/**
67 *
68 */
69INLINE bool ConfigVariableString::
70empty() const {
71 return get_value().empty();
72}
73
74/**
75 *
76 */
77INLINE size_t ConfigVariableString::
78length() const {
79 return get_value().length();
80}
81
82/**
83 *
84 */
85INLINE char ConfigVariableString::
86operator [] (size_t n) const {
87 assert(n < length());
88 return get_value()[n];
89}
90
91/**
92 *
93 */
94INLINE bool ConfigVariableString::
95operator == (const std::string &other) const {
96 return get_value() == other;
97}
98
99/**
100 *
101 */
102INLINE bool ConfigVariableString::
103operator != (const std::string &other) const {
104 return get_value() != other;
105}
106
107/**
108 *
109 */
110INLINE bool ConfigVariableString::
111operator < (const std::string &other) const {
112 return get_value() < other;
113}
114
115/**
116 * Reassigns the variable's local value.
117 */
118INLINE void ConfigVariableString::
119set_value(const std::string &value) {
120 set_string_value(value);
121}
122
123/**
124 * Returns the variable's value.
125 */
126INLINE const std::string &ConfigVariableString::
127get_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 */
138INLINE std::string ConfigVariableString::
139get_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 */
150INLINE std::string ConfigVariableString::
151get_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 */
160set_word(size_t n, const std::string &value) {
161 set_string_word(n, value);
162}
A single declaration of a config variable, typically defined as one line in a .prc file,...
const std::string & get_string_value() const
Returns the value assigned to this variable.
This is a convenience class to specialize ConfigVariable as a string type.
void operator=(const std::string &value)
Reassigns the variable's local value.
set_value
Reassigns the variable's local value.
get_value
Returns the variable's value.
std::string get_word(size_t n) const
Returns the variable's nth value.
void set_word(size_t n, const std::string &value)
Reassigns the variable's nth value.
get_default_value
Returns the variable's default value.
This is a generic, untyped ConfigVariable.
void set_string_value(const std::string &value)
Changes the value assigned to this variable.
STL namespace.