Skip to content

Commit cf34707

Browse files
committed
assertion failures, support string default values
1 parent 2de4051 commit cf34707

13 files changed

+120
-0
lines changed

dtool/src/prc/configVariable.I

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ INLINE ConfigVariable::
7575
////////////////////////////////////////////////////////////////////
7676
INLINE const ConfigDeclaration *ConfigVariable::
7777
get_default_value() const {
78+
nassertr(_core != (ConfigVariableCore *)NULL, NULL);
7879
return _core->get_default_value();
7980
}
8081

@@ -86,6 +87,7 @@ get_default_value() const {
8687
////////////////////////////////////////////////////////////////////
8788
INLINE const string &ConfigVariable::
8889
get_string_value() const {
90+
nassertr(_core != (ConfigVariableCore *)NULL, *new string());
8991
const ConfigDeclaration *decl = _core->get_declaration(0);
9092
return decl->get_string_value();
9193
}
@@ -100,6 +102,7 @@ get_string_value() const {
100102
////////////////////////////////////////////////////////////////////
101103
INLINE void ConfigVariable::
102104
set_string_value(const string &string_value) {
105+
nassertv(_core != (ConfigVariableCore *)NULL);
103106
_core->make_local_value()->set_string_value(string_value);
104107
}
105108

@@ -112,6 +115,7 @@ set_string_value(const string &string_value) {
112115
////////////////////////////////////////////////////////////////////
113116
INLINE int ConfigVariable::
114117
get_num_words() const {
118+
nassertr(_core != (ConfigVariableCore *)NULL, 0);
115119
const ConfigDeclaration *decl = _core->get_declaration(0);
116120
return decl->get_num_words();
117121
}
@@ -126,6 +130,7 @@ get_num_words() const {
126130
////////////////////////////////////////////////////////////////////
127131
INLINE bool ConfigVariable::
128132
has_string_word(int n) const {
133+
nassertr(_core != (ConfigVariableCore *)NULL, false);
129134
const ConfigDeclaration *decl = _core->get_declaration(0);
130135
return decl->has_string_word(n);
131136
}
@@ -138,6 +143,7 @@ has_string_word(int n) const {
138143
////////////////////////////////////////////////////////////////////
139144
INLINE bool ConfigVariable::
140145
has_bool_word(int n) const {
146+
nassertr(_core != (ConfigVariableCore *)NULL, false);
141147
const ConfigDeclaration *decl = _core->get_declaration(0);
142148
return decl->has_bool_word(n);
143149
}
@@ -150,6 +156,7 @@ has_bool_word(int n) const {
150156
////////////////////////////////////////////////////////////////////
151157
INLINE bool ConfigVariable::
152158
has_int_word(int n) const {
159+
nassertr(_core != (ConfigVariableCore *)NULL, false);
153160
const ConfigDeclaration *decl = _core->get_declaration(0);
154161
return decl->has_int_word(n);
155162
}
@@ -162,6 +169,7 @@ has_int_word(int n) const {
162169
////////////////////////////////////////////////////////////////////
163170
INLINE bool ConfigVariable::
164171
has_double_word(int n) const {
172+
nassertr(_core != (ConfigVariableCore *)NULL, false);
165173
const ConfigDeclaration *decl = _core->get_declaration(0);
166174
return decl->has_double_word(n);
167175
}
@@ -175,6 +183,7 @@ has_double_word(int n) const {
175183
////////////////////////////////////////////////////////////////////
176184
INLINE string ConfigVariable::
177185
get_string_word(int n) const {
186+
nassertr(_core != (ConfigVariableCore *)NULL, string());
178187
const ConfigDeclaration *decl = _core->get_declaration(0);
179188
return decl->get_string_word(n);
180189
}
@@ -188,6 +197,7 @@ get_string_word(int n) const {
188197
////////////////////////////////////////////////////////////////////
189198
INLINE bool ConfigVariable::
190199
get_bool_word(int n) const {
200+
nassertr(_core != (ConfigVariableCore *)NULL, false);
191201
const ConfigDeclaration *decl = _core->get_declaration(0);
192202
return decl->get_bool_word(n);
193203
}
@@ -201,6 +211,7 @@ get_bool_word(int n) const {
201211
////////////////////////////////////////////////////////////////////
202212
INLINE int ConfigVariable::
203213
get_int_word(int n) const {
214+
nassertr(_core != (ConfigVariableCore *)NULL, 0);
204215
const ConfigDeclaration *decl = _core->get_declaration(0);
205216
return decl->get_int_word(n);
206217
}
@@ -214,6 +225,7 @@ get_int_word(int n) const {
214225
////////////////////////////////////////////////////////////////////
215226
INLINE double ConfigVariable::
216227
get_double_word(int n) const {
228+
nassertr(_core != (ConfigVariableCore *)NULL, 0.0);
217229
const ConfigDeclaration *decl = _core->get_declaration(0);
218230
return decl->get_double_word(n);
219231
}
@@ -226,6 +238,7 @@ get_double_word(int n) const {
226238
////////////////////////////////////////////////////////////////////
227239
INLINE void ConfigVariable::
228240
set_string_word(int n, const string &value) {
241+
nassertv(_core != (ConfigVariableCore *)NULL);
229242
_core->make_local_value()->set_string_word(n, value);
230243
}
231244

@@ -237,6 +250,7 @@ set_string_word(int n, const string &value) {
237250
////////////////////////////////////////////////////////////////////
238251
INLINE void ConfigVariable::
239252
set_bool_word(int n, bool value) {
253+
nassertv(_core != (ConfigVariableCore *)NULL);
240254
_core->make_local_value()->set_bool_word(n, value);
241255
}
242256

@@ -248,6 +262,7 @@ set_bool_word(int n, bool value) {
248262
////////////////////////////////////////////////////////////////////
249263
INLINE void ConfigVariable::
250264
set_int_word(int n, int value) {
265+
nassertv(_core != (ConfigVariableCore *)NULL);
251266
_core->make_local_value()->set_int_word(n, value);
252267
}
253268

@@ -259,5 +274,6 @@ set_int_word(int n, int value) {
259274
////////////////////////////////////////////////////////////////////
260275
INLINE void ConfigVariable::
261276
set_double_word(int n, double value) {
277+
nassertv(_core != (ConfigVariableCore *)NULL);
262278
_core->make_local_value()->set_double_word(n, value);
263279
}

dtool/src/prc/configVariableBase.I

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ INLINE ConfigVariableBase::
4949
////////////////////////////////////////////////////////////////////
5050
INLINE const string &ConfigVariableBase::
5151
get_name() const {
52+
nassertr(_core != (ConfigVariableCore *)NULL, *new string());
5253
return _core->get_name();
5354
}
5455

@@ -61,6 +62,7 @@ get_name() const {
6162
////////////////////////////////////////////////////////////////////
6263
INLINE ConfigVariableBase::ValueType ConfigVariableBase::
6364
get_value_type() const {
65+
nassertr(_core != (ConfigVariableCore *)NULL, VT_undefined);
6466
return _core->get_value_type();
6567
}
6668

@@ -72,6 +74,7 @@ get_value_type() const {
7274
////////////////////////////////////////////////////////////////////
7375
INLINE const string &ConfigVariableBase::
7476
get_description() const {
77+
nassertr(_core != (ConfigVariableCore *)NULL, *new string());
7578
return _core->get_description();
7679
}
7780

@@ -86,6 +89,7 @@ get_description() const {
8689
////////////////////////////////////////////////////////////////////
8790
INLINE int ConfigVariableBase::
8891
get_flags() const {
92+
nassertr(_core != (ConfigVariableCore *)NULL, 0);
8993
return _core->get_flags();
9094
}
9195

@@ -105,6 +109,7 @@ get_flags() const {
105109
////////////////////////////////////////////////////////////////////
106110
INLINE bool ConfigVariableBase::
107111
is_closed() const {
112+
nassertr(_core != (ConfigVariableCore *)NULL, false);
108113
return _core->is_closed();
109114
}
110115

@@ -125,6 +130,7 @@ is_closed() const {
125130
////////////////////////////////////////////////////////////////////
126131
INLINE int ConfigVariableBase::
127132
get_trust_level() const {
133+
nassertr(_core != (ConfigVariableCore *)NULL, 0);
128134
return _core->get_trust_level();
129135
}
130136

@@ -139,6 +145,7 @@ get_trust_level() const {
139145
////////////////////////////////////////////////////////////////////
140146
INLINE bool ConfigVariableBase::
141147
is_dynamic() const {
148+
nassertr(_core != (ConfigVariableCore *)NULL, false);
142149
return _core->is_dynamic();
143150
}
144151

@@ -154,6 +161,7 @@ is_dynamic() const {
154161
////////////////////////////////////////////////////////////////////
155162
INLINE bool ConfigVariableBase::
156163
clear_local_value() {
164+
nassertr(_core != (ConfigVariableCore *)NULL, false);
157165
return _core->clear_local_value();
158166
}
159167

@@ -166,6 +174,7 @@ clear_local_value() {
166174
////////////////////////////////////////////////////////////////////
167175
INLINE bool ConfigVariableBase::
168176
has_local_value() const {
177+
nassertr(_core != (ConfigVariableCore *)NULL, false);
169178
return _core->has_local_value();
170179
}
171180

@@ -178,6 +187,7 @@ has_local_value() const {
178187
////////////////////////////////////////////////////////////////////
179188
INLINE bool ConfigVariableBase::
180189
has_value() const {
190+
nassertr(_core != (ConfigVariableCore *)NULL, false);
181191
return _core->has_value();
182192
}
183193

@@ -188,6 +198,7 @@ has_value() const {
188198
////////////////////////////////////////////////////////////////////
189199
INLINE void ConfigVariableBase::
190200
output(ostream &out) const {
201+
nassertv(_core != (ConfigVariableCore *)NULL);
191202
_core->output(out);
192203
}
193204

@@ -198,6 +209,7 @@ output(ostream &out) const {
198209
////////////////////////////////////////////////////////////////////
199210
INLINE void ConfigVariableBase::
200211
write(ostream &out) const {
212+
nassertv(_core != (ConfigVariableCore *)NULL);
201213
_core->write(out);
202214
}
203215

dtool/src/prc/configVariableBool.I

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,20 @@ ConfigVariableBool(const string &name, bool default_value,
4343
_core->set_used();
4444
}
4545

46+
////////////////////////////////////////////////////////////////////
47+
// Function: ConfigVariableBool::Constructor
48+
// Access: Published
49+
// Description:
50+
////////////////////////////////////////////////////////////////////
51+
INLINE ConfigVariableBool::
52+
ConfigVariableBool(const string &name, const string &default_value,
53+
const string &description, int flags) :
54+
ConfigVariable(name, VT_bool, description, flags)
55+
{
56+
_core->set_default_value(default_value);
57+
_core->set_used();
58+
}
59+
4660
////////////////////////////////////////////////////////////////////
4761
// Function: ConfigVariableBool::operator =
4862
// Access: Published

dtool/src/prc/configVariableBool.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ class EXPCL_DTOOLCONFIG ConfigVariableBool : public ConfigVariable {
3232
INLINE ConfigVariableBool(const string &name);
3333
INLINE ConfigVariableBool(const string &name, bool default_value,
3434
const string &description = string(), int flags = 0);
35+
INLINE ConfigVariableBool(const string &name, const string &default_value,
36+
const string &description = string(), int flags = 0);
3537

3638
INLINE void operator = (bool value);
3739
INLINE operator bool () const;

dtool/src/prc/configVariableDouble.I

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,24 @@ ConfigVariableDouble(const string &name, double default_value,
4747
_core->set_used();
4848
}
4949

50+
////////////////////////////////////////////////////////////////////
51+
// Function: ConfigVariableDouble::Constructor
52+
// Access: Published
53+
// Description:
54+
////////////////////////////////////////////////////////////////////
55+
INLINE ConfigVariableDouble::
56+
ConfigVariableDouble(const string &name, const string &default_value,
57+
const string &description, int flags) :
58+
#ifdef PRC_SAVE_DESCRIPTIONS
59+
ConfigVariable(name, ConfigVariableCore::VT_double, description, flags)
60+
#else
61+
ConfigVariable(name, ConfigVariableCore::VT_double, string(), flags)
62+
#endif
63+
{
64+
_core->set_default_value(default_value);
65+
_core->set_used();
66+
}
67+
5068
////////////////////////////////////////////////////////////////////
5169
// Function: ConfigVariableDouble::operator =
5270
// Access: Published

dtool/src/prc/configVariableDouble.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ class EXPCL_DTOOLCONFIG ConfigVariableDouble : public ConfigVariable {
3333
INLINE ConfigVariableDouble(const string &name, double default_value,
3434
const string &description = string(),
3535
int flags = 0);
36+
INLINE ConfigVariableDouble(const string &name, const string &default_value,
37+
const string &description = string(),
38+
int flags = 0);
3639

3740
INLINE void operator = (double value);
3841
INLINE operator double () const;

dtool/src/prc/configVariableEnum.I

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,29 @@ ConfigVariableEnum(const string &name, EnumType default_value,
4040
_core->set_used();
4141
}
4242

43+
////////////////////////////////////////////////////////////////////
44+
// Function: ConfigVariableEnum::Constructor
45+
// Access: Published
46+
// Description:
47+
////////////////////////////////////////////////////////////////////
48+
template<class EnumType>
49+
INLINE ConfigVariableEnum<EnumType>::
50+
ConfigVariableEnum(const string &name, const string &adefault_value,
51+
const string &description, int flags) :
52+
#ifdef PRC_SAVE_DESCRIPTIONS
53+
ConfigVariable(name, ConfigVariableCore::VT_enum, description, flags),
54+
#else
55+
ConfigVariable(name, ConfigVariableCore::VT_enum, string(), flags),
56+
#endif
57+
_value_seq(-1),
58+
_value(default_value),
59+
_got_default_value(true),
60+
_default_value(parse_string(default_value))
61+
{
62+
_core->set_default_value(default_value);
63+
_core->set_used();
64+
}
65+
4366
////////////////////////////////////////////////////////////////////
4467
// Function: ConfigVariableEnum::Destructor
4568
// Access: Public

dtool/src/prc/configVariableEnum.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ class ConfigVariableEnum : public ConfigVariable {
4141
INLINE ConfigVariableEnum(const string &name, EnumType default_value,
4242
const string &description = string(),
4343
int flags = 0);
44+
INLINE ConfigVariableEnum(const string &name, const string &default_value,
45+
const string &description = string(),
46+
int flags = 0);
4447
INLINE ~ConfigVariableEnum();
4548

4649
INLINE void operator = (EnumType value);

dtool/src/prc/configVariableInt.I

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,24 @@ ConfigVariableInt(const string &name, int default_value,
4747
_core->set_used();
4848
}
4949

50+
////////////////////////////////////////////////////////////////////
51+
// Function: ConfigVariableInt::Constructor
52+
// Access: Published
53+
// Description:
54+
////////////////////////////////////////////////////////////////////
55+
INLINE ConfigVariableInt::
56+
ConfigVariableInt(const string &name, const string &default_value,
57+
const string &description, int flags) :
58+
#ifdef PRC_SAVE_DESCRIPTIONS
59+
ConfigVariable(name, ConfigVariableCore::VT_int, description, flags)
60+
#else
61+
ConfigVariable(name, ConfigVariableCore::VT_int, string(), flags)
62+
#endif
63+
{
64+
_core->set_default_value(default_value);
65+
_core->set_used();
66+
}
67+
5068
////////////////////////////////////////////////////////////////////
5169
// Function: ConfigVariableInt::operator =
5270
// Access: Published

dtool/src/prc/configVariableInt.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ class EXPCL_DTOOLCONFIG ConfigVariableInt : public ConfigVariable {
3333
INLINE ConfigVariableInt(const string &name, int default_value,
3434
const string &description = string(),
3535
int flags = 0);
36+
INLINE ConfigVariableInt(const string &name, const string &default_value,
37+
const string &description = string(),
38+
int flags = 0);
3639

3740
INLINE void operator = (int value);
3841
INLINE operator int () const;

0 commit comments

Comments
 (0)