Panda3D

configVariableInt.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 configVariableInt.I
10 * @author drose
11 * @date 2004-10-20
12 */
13
14 /**
15 *
16 */
17 INLINE ConfigVariableInt::
18 ConfigVariableInt(const std::string &name) :
19 ConfigVariable(name, VT_int),
20 _local_modified(initial_invalid_cache())
21 {
22 _core->set_used();
23 }
24
25 /**
26 *
27 */
28 INLINE ConfigVariableInt::
29 ConfigVariableInt(const std::string &name, int default_value,
30 const std::string &description, int flags) :
31 #ifdef PRC_SAVE_DESCRIPTIONS
32 ConfigVariable(name, ConfigVariableCore::VT_int, description, flags),
33 #else
34 ConfigVariable(name, ConfigVariableCore::VT_int, std::string(), flags),
35 #endif
36 _local_modified(initial_invalid_cache())
37 {
38 set_default_value(default_value);
39 _core->set_used();
40 }
41
42 /**
43 *
44 */
45 INLINE ConfigVariableInt::
46 ConfigVariableInt(const std::string &name, const std::string &default_value,
47 const std::string &description, int flags) :
48 #ifdef PRC_SAVE_DESCRIPTIONS
49 ConfigVariable(name, ConfigVariableCore::VT_int, description, flags),
50 #else
51 ConfigVariable(name, ConfigVariableCore::VT_int, std::string(), flags),
52 #endif
53 _local_modified(initial_invalid_cache())
54 {
55 _core->set_default_value(default_value);
56 _core->set_used();
57 }
58
59 /**
60 * Reassigns the variable's local value.
61 */
62 INLINE void ConfigVariableInt::
63 operator = (int value) {
64 set_value(value);
65 }
66
67 /**
68 * Returns the variable's value.
69 */
70 INLINE ConfigVariableInt::
71 operator int () const {
72 return get_value();
73 }
74
75 /**
76 * Returns the number of unique words in the variable.
77 */
78 INLINE size_t ConfigVariableInt::
79 size() const {
80 return get_num_words();
81 }
82
83 /**
84 * Returns the value of the variable's nth word.
85 */
86 INLINE int ConfigVariableInt::
87 operator [] (size_t n) const {
88 return get_word(n);
89 }
90
91 /**
92 * Reassigns the variable's local value.
93 */
94 INLINE void ConfigVariableInt::
95 set_value(int value) {
96 set_string_value("");
97 set_int_word(0, value);
98 }
99
100 /**
101 * Returns the variable's value.
102 */
103 INLINE int ConfigVariableInt::
104 get_value() const {
105 TAU_PROFILE("int ConfigVariableInt::get_value() const", " ", TAU_USER);
106 if (!is_cache_valid(_local_modified)) {
107 mark_cache_valid(((ConfigVariableInt *)this)->_local_modified);
108 ((ConfigVariableInt *)this)->_cache = get_int_word(0);
109 }
110 return _cache;
111 }
112
113 /**
114 * Returns the variable's default value.
115 */
116 INLINE int ConfigVariableInt::
117 get_default_value() const {
118 const ConfigDeclaration *decl = ConfigVariable::get_default_value();
119 if (decl != nullptr) {
120 return decl->get_int_word(0);
121 }
122 return 0;
123 }
124
125 /**
126 * Returns the variable's nth value.
127 */
128 INLINE int ConfigVariableInt::
129 get_word(size_t n) const {
130 return get_int_word(n);
131 }
132
133 /**
134 * Reassigns the variable's nth value. This makes a local copy of the
135 * variable's overall value.
136 */
137 INLINE void ConfigVariableInt::
138 set_word(size_t n, int value) {
139 set_int_word(n, value);
140 }
ConfigDeclaration
A single declaration of a config variable, typically defined as one line in a .prc file,...
Definition: configDeclaration.h:34
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
ConfigVariableCore
The internal definition of a ConfigVariable.
Definition: configVariableCore.h:34
ConfigVariableInt
This is a convenience class to specialize ConfigVariable as an integer type.
Definition: configVariableInt.h:24
ConfigVariableInt::set_word
void set_word(size_t n, int value)
Reassigns the variable's nth value.
Definition: configVariableInt.I:138
ConfigVariableInt::operator[]
int operator[](size_t n) const
Returns the value of the variable's nth word.
Definition: configVariableInt.I:87
ConfigVariableInt::operator=
void operator=(int value)
Reassigns the variable's local value.
Definition: configVariableInt.I:63
ConfigVariableInt::get_default_value
get_default_value
Returns the variable's default value.
Definition: configVariableInt.h:44
ConfigVariableInt::size
size_t size() const
Returns the number of unique words in the variable.
Definition: configVariableInt.I:79
ConfigVariableInt::get_word
int get_word(size_t n) const
Returns the variable's nth value.
Definition: configVariableInt.I:129
ConfigVariableInt::get_value
get_value
Returns the variable's value.
Definition: configVariableInt.h:43
ConfigVariableInt::set_value
set_value
Reassigns the variable's local value.
Definition: configVariableInt.h:43
ConfigVariable
This is a generic, untyped ConfigVariable.
Definition: configVariable.h:31
ConfigVariable::get_num_words
size_t get_num_words() const
Returns the number of words in the variable's value.
Definition: configVariable.I:100
ConfigVariable::set_string_value
void set_string_value(const std::string &value)
Changes the value assigned to this variable.
Definition: configVariable.I:80