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