Panda3D
configVariableInt.I
1 // Filename: configVariableInt.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: ConfigVariableInt::Constructor
18 // Access: Published
19 // Description:
20 ////////////////////////////////////////////////////////////////////
21 INLINE ConfigVariableInt::
22 ConfigVariableInt(const string &name) :
23  ConfigVariable(name, VT_int),
24  _local_modified(initial_invalid_cache())
25 {
26  _core->set_used();
27 }
28 
29 ////////////////////////////////////////////////////////////////////
30 // Function: ConfigVariableInt::Constructor
31 // Access: Published
32 // Description:
33 ////////////////////////////////////////////////////////////////////
34 INLINE ConfigVariableInt::
35 ConfigVariableInt(const string &name, int default_value,
36  const string &description, int flags) :
37 #ifdef PRC_SAVE_DESCRIPTIONS
38  ConfigVariable(name, ConfigVariableCore::VT_int, description, flags),
39 #else
40  ConfigVariable(name, ConfigVariableCore::VT_int, string(), flags),
41 #endif
42  _local_modified(initial_invalid_cache())
43 {
44  set_default_value(default_value);
45  _core->set_used();
46 }
47 
48 ////////////////////////////////////////////////////////////////////
49 // Function: ConfigVariableInt::Constructor
50 // Access: Published
51 // Description:
52 ////////////////////////////////////////////////////////////////////
53 INLINE ConfigVariableInt::
54 ConfigVariableInt(const string &name, const string &default_value,
55  const string &description, int flags) :
56 #ifdef PRC_SAVE_DESCRIPTIONS
57  ConfigVariable(name, ConfigVariableCore::VT_int, description, flags),
58 #else
59  ConfigVariable(name, ConfigVariableCore::VT_int, string(), flags),
60 #endif
61  _local_modified(initial_invalid_cache())
62 {
63  _core->set_default_value(default_value);
64  _core->set_used();
65 }
66 
67 ////////////////////////////////////////////////////////////////////
68 // Function: ConfigVariableInt::operator =
69 // Access: Published
70 // Description: Reassigns the variable's local value.
71 ////////////////////////////////////////////////////////////////////
72 INLINE void ConfigVariableInt::
73 operator = (int value) {
74  set_value(value);
75 }
76 
77 ////////////////////////////////////////////////////////////////////
78 // Function: ConfigVariableInt::typecast operator
79 // Access: Published
80 // Description: Returns the variable's value.
81 ////////////////////////////////////////////////////////////////////
82 INLINE ConfigVariableInt::
83 operator int () const {
84  return get_value();
85 }
86 
87 ////////////////////////////////////////////////////////////////////
88 // Function: ConfigVariableInt::size()
89 // Access: Published
90 // Description: Returns the number of unique words in the variable.
91 ////////////////////////////////////////////////////////////////////
92 INLINE int ConfigVariableInt::
93 size() const {
94  return get_num_words();
95 }
96 
97 ////////////////////////////////////////////////////////////////////
98 // Function: ConfigVariableInt::operator []
99 // Access: Published
100 // Description: Returns the value of the variable's nth word.
101 ////////////////////////////////////////////////////////////////////
102 INLINE int ConfigVariableInt::
103 operator [] (int n) const {
104  return get_word(n);
105 }
106 
107 ////////////////////////////////////////////////////////////////////
108 // Function: ConfigVariableInt::set_value
109 // Access: Published
110 // Description: Reassigns the variable's local value.
111 ////////////////////////////////////////////////////////////////////
112 INLINE void ConfigVariableInt::
113 set_value(int value) {
114  set_string_value("");
115  set_int_word(0, value);
116 }
117 
118 ////////////////////////////////////////////////////////////////////
119 // Function: ConfigVariableInt::get_value
120 // Access: Published
121 // Description: Returns the variable's value.
122 ////////////////////////////////////////////////////////////////////
123 INLINE int ConfigVariableInt::
124 get_value() const {
125  TAU_PROFILE("int ConfigVariableInt::get_value() const", " ", TAU_USER);
126  if (!is_cache_valid(_local_modified)) {
127  mark_cache_valid(((ConfigVariableInt *)this)->_local_modified);
128  ((ConfigVariableInt *)this)->_cache = get_int_word(0);
129  }
130  return _cache;
131 }
132 
133 ////////////////////////////////////////////////////////////////////
134 // Function: ConfigVariableInt::get_default_value
135 // Access: Published
136 // Description: Returns the variable's default value.
137 ////////////////////////////////////////////////////////////////////
138 INLINE int ConfigVariableInt::
141  if (decl != (ConfigDeclaration *)NULL) {
142  return decl->get_int_word(0);
143  }
144  return 0;
145 }
146 
147 ////////////////////////////////////////////////////////////////////
148 // Function: ConfigVariableInt::get_word
149 // Access: Published
150 // Description: Returns the variable's nth value.
151 ////////////////////////////////////////////////////////////////////
152 INLINE int ConfigVariableInt::
153 get_word(int n) const {
154  return get_int_word(n);
155 }
156 
157 ////////////////////////////////////////////////////////////////////
158 // Function: ConfigVariableInt::set_word
159 // Access: Published
160 // Description: Reassigns the variable's nth value. This makes a
161 // local copy of the variable's overall value.
162 ////////////////////////////////////////////////////////////////////
163 INLINE void ConfigVariableInt::
164 set_word(int n, int value) {
165  set_int_word(n, value);
166 }
167 
void set_word(int n, int value)
Reassigns the variable's nth value.
The internal definition of a ConfigVariable.
int operator[](int n) const
Returns the value of the variable's nth word.
const ConfigDeclaration * get_default_value() const
Returns the default variable specified for this variable.
void set_value(int value)
Reassigns the variable's local value.
int get_default_value() const
Returns the variable's default value.
This is a generic, untyped ConfigVariable.
int get_int_word(int n) const
Returns the integer value of the nth word of the declaration's value, or 0 if there is no nth value...
int size() const
Returns the number of unique words in the variable.
int get_word(int n) const
Returns the variable's nth value.
int get_num_words() const
Returns the number of words in the variable's value.
int get_int_word(int n) const
Returns the integer value of the nth word of the variable's value, or 0 if there is no nth value...
void set_string_value(const string &value)
Changes the value assigned to this variable.
This is a convenience class to specialize ConfigVariable as an integer type.
int get_value() const
Returns the variable's value.
A single declaration of a config variable, typically defined as one line in a .prc file...
void set_int_word(int n, int value)
Changes the nth word to the indicated value without affecting the other words.
void operator=(int value)
Reassigns the variable's local value.