Browse Source

assertion failures, support string default values

David Rose 21 years ago
parent
commit
cf34707189

+ 16 - 0
dtool/src/prc/configVariable.I

@@ -75,6 +75,7 @@ INLINE ConfigVariable::
 ////////////////////////////////////////////////////////////////////
 INLINE const ConfigDeclaration *ConfigVariable::
 get_default_value() const {
+  nassertr(_core != (ConfigVariableCore *)NULL, NULL);
   return _core->get_default_value();
 }
 
@@ -86,6 +87,7 @@ get_default_value() const {
 ////////////////////////////////////////////////////////////////////
 INLINE const string &ConfigVariable::
 get_string_value() const {
+  nassertr(_core != (ConfigVariableCore *)NULL, *new string());
   const ConfigDeclaration *decl = _core->get_declaration(0);
   return decl->get_string_value();
 }
@@ -100,6 +102,7 @@ get_string_value() const {
 ////////////////////////////////////////////////////////////////////
 INLINE void ConfigVariable::
 set_string_value(const string &string_value) {
+  nassertv(_core != (ConfigVariableCore *)NULL);
   _core->make_local_value()->set_string_value(string_value);
 }
 
@@ -112,6 +115,7 @@ set_string_value(const string &string_value) {
 ////////////////////////////////////////////////////////////////////
 INLINE int ConfigVariable::
 get_num_words() const {
+  nassertr(_core != (ConfigVariableCore *)NULL, 0);
   const ConfigDeclaration *decl = _core->get_declaration(0);
   return decl->get_num_words();
 }
@@ -126,6 +130,7 @@ get_num_words() const {
 ////////////////////////////////////////////////////////////////////
 INLINE bool ConfigVariable::
 has_string_word(int n) const {
+  nassertr(_core != (ConfigVariableCore *)NULL, false);
   const ConfigDeclaration *decl = _core->get_declaration(0);
   return decl->has_string_word(n);
 }
@@ -138,6 +143,7 @@ has_string_word(int n) const {
 ////////////////////////////////////////////////////////////////////
 INLINE bool ConfigVariable::
 has_bool_word(int n) const {
+  nassertr(_core != (ConfigVariableCore *)NULL, false);
   const ConfigDeclaration *decl = _core->get_declaration(0);
   return decl->has_bool_word(n);
 }
@@ -150,6 +156,7 @@ has_bool_word(int n) const {
 ////////////////////////////////////////////////////////////////////
 INLINE bool ConfigVariable::
 has_int_word(int n) const {
+  nassertr(_core != (ConfigVariableCore *)NULL, false);
   const ConfigDeclaration *decl = _core->get_declaration(0);
   return decl->has_int_word(n);
 }
@@ -162,6 +169,7 @@ has_int_word(int n) const {
 ////////////////////////////////////////////////////////////////////
 INLINE bool ConfigVariable::
 has_double_word(int n) const {
+  nassertr(_core != (ConfigVariableCore *)NULL, false);
   const ConfigDeclaration *decl = _core->get_declaration(0);
   return decl->has_double_word(n);
 }
@@ -175,6 +183,7 @@ has_double_word(int n) const {
 ////////////////////////////////////////////////////////////////////
 INLINE string ConfigVariable::
 get_string_word(int n) const {
+  nassertr(_core != (ConfigVariableCore *)NULL, string());
   const ConfigDeclaration *decl = _core->get_declaration(0);
   return decl->get_string_word(n);
 }
@@ -188,6 +197,7 @@ get_string_word(int n) const {
 ////////////////////////////////////////////////////////////////////
 INLINE bool ConfigVariable::
 get_bool_word(int n) const {
+  nassertr(_core != (ConfigVariableCore *)NULL, false);
   const ConfigDeclaration *decl = _core->get_declaration(0);
   return decl->get_bool_word(n);
 }
@@ -201,6 +211,7 @@ get_bool_word(int n) const {
 ////////////////////////////////////////////////////////////////////
 INLINE int ConfigVariable::
 get_int_word(int n) const {
+  nassertr(_core != (ConfigVariableCore *)NULL, 0);
   const ConfigDeclaration *decl = _core->get_declaration(0);
   return decl->get_int_word(n);
 }
@@ -214,6 +225,7 @@ get_int_word(int n) const {
 ////////////////////////////////////////////////////////////////////
 INLINE double ConfigVariable::
 get_double_word(int n) const {
+  nassertr(_core != (ConfigVariableCore *)NULL, 0.0);
   const ConfigDeclaration *decl = _core->get_declaration(0);
   return decl->get_double_word(n);
 }
@@ -226,6 +238,7 @@ get_double_word(int n) const {
 ////////////////////////////////////////////////////////////////////
 INLINE void ConfigVariable::
 set_string_word(int n, const string &value) {
+  nassertv(_core != (ConfigVariableCore *)NULL);
   _core->make_local_value()->set_string_word(n, value);
 }
 
@@ -237,6 +250,7 @@ set_string_word(int n, const string &value) {
 ////////////////////////////////////////////////////////////////////
 INLINE void ConfigVariable::
 set_bool_word(int n, bool value) {
+  nassertv(_core != (ConfigVariableCore *)NULL);
   _core->make_local_value()->set_bool_word(n, value);
 }
 
@@ -248,6 +262,7 @@ set_bool_word(int n, bool value) {
 ////////////////////////////////////////////////////////////////////
 INLINE void ConfigVariable::
 set_int_word(int n, int value) {
+  nassertv(_core != (ConfigVariableCore *)NULL);
   _core->make_local_value()->set_int_word(n, value);
 }
 
@@ -259,5 +274,6 @@ set_int_word(int n, int value) {
 ////////////////////////////////////////////////////////////////////
 INLINE void ConfigVariable::
 set_double_word(int n, double value) {
+  nassertv(_core != (ConfigVariableCore *)NULL);
   _core->make_local_value()->set_double_word(n, value);
 }

+ 12 - 0
dtool/src/prc/configVariableBase.I

@@ -49,6 +49,7 @@ INLINE ConfigVariableBase::
 ////////////////////////////////////////////////////////////////////
 INLINE const string &ConfigVariableBase::
 get_name() const {
+  nassertr(_core != (ConfigVariableCore *)NULL, *new string());
   return _core->get_name();
 }
 
@@ -61,6 +62,7 @@ get_name() const {
 ////////////////////////////////////////////////////////////////////
 INLINE ConfigVariableBase::ValueType ConfigVariableBase::
 get_value_type() const {
+  nassertr(_core != (ConfigVariableCore *)NULL, VT_undefined);
   return _core->get_value_type();
 }
 
@@ -72,6 +74,7 @@ get_value_type() const {
 ////////////////////////////////////////////////////////////////////
 INLINE const string &ConfigVariableBase::
 get_description() const {
+  nassertr(_core != (ConfigVariableCore *)NULL, *new string());
   return _core->get_description();
 }
 
@@ -86,6 +89,7 @@ get_description() const {
 ////////////////////////////////////////////////////////////////////
 INLINE int ConfigVariableBase::
 get_flags() const {
+  nassertr(_core != (ConfigVariableCore *)NULL, 0);
   return _core->get_flags();
 }
 
@@ -105,6 +109,7 @@ get_flags() const {
 ////////////////////////////////////////////////////////////////////
 INLINE bool ConfigVariableBase::
 is_closed() const {
+  nassertr(_core != (ConfigVariableCore *)NULL, false);
   return _core->is_closed();
 }
 
@@ -125,6 +130,7 @@ is_closed() const {
 ////////////////////////////////////////////////////////////////////
 INLINE int ConfigVariableBase::
 get_trust_level() const {
+  nassertr(_core != (ConfigVariableCore *)NULL, 0);
   return _core->get_trust_level();
 }
 
@@ -139,6 +145,7 @@ get_trust_level() const {
 ////////////////////////////////////////////////////////////////////
 INLINE bool ConfigVariableBase::
 is_dynamic() const {
+  nassertr(_core != (ConfigVariableCore *)NULL, false);
   return _core->is_dynamic();
 }
 
@@ -154,6 +161,7 @@ is_dynamic() const {
 ////////////////////////////////////////////////////////////////////
 INLINE bool ConfigVariableBase::
 clear_local_value() {
+  nassertr(_core != (ConfigVariableCore *)NULL, false);
   return _core->clear_local_value();
 }
 
@@ -166,6 +174,7 @@ clear_local_value() {
 ////////////////////////////////////////////////////////////////////
 INLINE bool ConfigVariableBase::
 has_local_value() const {
+  nassertr(_core != (ConfigVariableCore *)NULL, false);
   return _core->has_local_value();
 }
 
@@ -178,6 +187,7 @@ has_local_value() const {
 ////////////////////////////////////////////////////////////////////
 INLINE bool ConfigVariableBase::
 has_value() const {
+  nassertr(_core != (ConfigVariableCore *)NULL, false);
   return _core->has_value();
 }
 
@@ -188,6 +198,7 @@ has_value() const {
 ////////////////////////////////////////////////////////////////////
 INLINE void ConfigVariableBase::
 output(ostream &out) const {
+  nassertv(_core != (ConfigVariableCore *)NULL);
   _core->output(out);
 }
 
@@ -198,6 +209,7 @@ output(ostream &out) const {
 ////////////////////////////////////////////////////////////////////
 INLINE void ConfigVariableBase::
 write(ostream &out) const {
+  nassertv(_core != (ConfigVariableCore *)NULL);
   _core->write(out);
 }
 

+ 14 - 0
dtool/src/prc/configVariableBool.I

@@ -43,6 +43,20 @@ ConfigVariableBool(const string &name, bool default_value,
   _core->set_used();
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: ConfigVariableBool::Constructor
+//       Access: Published
+//  Description: 
+////////////////////////////////////////////////////////////////////
+INLINE ConfigVariableBool::
+ConfigVariableBool(const string &name, const string &default_value, 
+                   const string &description, int flags) :
+  ConfigVariable(name, VT_bool, description, flags)
+{
+  _core->set_default_value(default_value);
+  _core->set_used();
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: ConfigVariableBool::operator =
 //       Access: Published

+ 2 - 0
dtool/src/prc/configVariableBool.h

@@ -32,6 +32,8 @@ PUBLISHED:
   INLINE ConfigVariableBool(const string &name);
   INLINE ConfigVariableBool(const string &name, bool default_value,
                             const string &description = string(), int flags = 0);
+  INLINE ConfigVariableBool(const string &name, const string &default_value,
+                            const string &description = string(), int flags = 0);
 
   INLINE void operator = (bool value);
   INLINE operator bool () const;

+ 18 - 0
dtool/src/prc/configVariableDouble.I

@@ -47,6 +47,24 @@ ConfigVariableDouble(const string &name, double default_value,
   _core->set_used();
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: ConfigVariableDouble::Constructor
+//       Access: Published
+//  Description: 
+////////////////////////////////////////////////////////////////////
+INLINE ConfigVariableDouble::
+ConfigVariableDouble(const string &name, const string &default_value, 
+                     const string &description, int flags) :
+#ifdef PRC_SAVE_DESCRIPTIONS
+  ConfigVariable(name, ConfigVariableCore::VT_double, description, flags)
+#else
+  ConfigVariable(name, ConfigVariableCore::VT_double, string(), flags)
+#endif
+{
+  _core->set_default_value(default_value);
+  _core->set_used();
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: ConfigVariableDouble::operator =
 //       Access: Published

+ 3 - 0
dtool/src/prc/configVariableDouble.h

@@ -33,6 +33,9 @@ PUBLISHED:
   INLINE ConfigVariableDouble(const string &name, double default_value,
                               const string &description = string(), 
                               int flags = 0);
+  INLINE ConfigVariableDouble(const string &name, const string &default_value,
+                              const string &description = string(), 
+                              int flags = 0);
 
   INLINE void operator = (double value);
   INLINE operator double () const;

+ 23 - 0
dtool/src/prc/configVariableEnum.I

@@ -40,6 +40,29 @@ ConfigVariableEnum(const string &name, EnumType default_value,
   _core->set_used();
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: ConfigVariableEnum::Constructor
+//       Access: Published
+//  Description: 
+////////////////////////////////////////////////////////////////////
+template<class EnumType>
+INLINE ConfigVariableEnum<EnumType>::
+ConfigVariableEnum(const string &name, const string &adefault_value, 
+                   const string &description, int flags) :
+#ifdef PRC_SAVE_DESCRIPTIONS
+  ConfigVariable(name, ConfigVariableCore::VT_enum, description, flags),
+#else
+  ConfigVariable(name, ConfigVariableCore::VT_enum, string(), flags),
+#endif
+  _value_seq(-1),
+  _value(default_value),
+  _got_default_value(true),
+  _default_value(parse_string(default_value))
+{
+  _core->set_default_value(default_value);
+  _core->set_used();
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: ConfigVariableEnum::Destructor
 //       Access: Public

+ 3 - 0
dtool/src/prc/configVariableEnum.h

@@ -41,6 +41,9 @@ public:
   INLINE ConfigVariableEnum(const string &name, EnumType default_value, 
                             const string &description = string(), 
                             int flags = 0);
+  INLINE ConfigVariableEnum(const string &name, const string &default_value, 
+                            const string &description = string(), 
+                            int flags = 0);
   INLINE ~ConfigVariableEnum();
 
   INLINE void operator = (EnumType value);

+ 18 - 0
dtool/src/prc/configVariableInt.I

@@ -47,6 +47,24 @@ ConfigVariableInt(const string &name, int default_value,
   _core->set_used();
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: ConfigVariableInt::Constructor
+//       Access: Published
+//  Description: 
+////////////////////////////////////////////////////////////////////
+INLINE ConfigVariableInt::
+ConfigVariableInt(const string &name, const string &default_value, 
+                  const string &description, int flags) :
+#ifdef PRC_SAVE_DESCRIPTIONS
+  ConfigVariable(name, ConfigVariableCore::VT_int, description, flags)
+#else
+  ConfigVariable(name, ConfigVariableCore::VT_int, string(), flags)
+#endif
+{
+  _core->set_default_value(default_value);
+  _core->set_used();
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: ConfigVariableInt::operator =
 //       Access: Published

+ 3 - 0
dtool/src/prc/configVariableInt.h

@@ -33,6 +33,9 @@ PUBLISHED:
   INLINE ConfigVariableInt(const string &name, int default_value,
                            const string &description = string(), 
                            int flags = 0);
+  INLINE ConfigVariableInt(const string &name, const string &default_value,
+                           const string &description = string(), 
+                           int flags = 0);
 
   INLINE void operator = (int value);
   INLINE operator int () const;

+ 4 - 0
dtool/src/prc/configVariableList.I

@@ -56,6 +56,7 @@ ConfigVariableList(const string &name,
 ////////////////////////////////////////////////////////////////////
 INLINE int ConfigVariableList::
 get_num_values() const {
+  nassertr(_core != (ConfigVariableCore *)NULL, 0);
   return _core->get_num_trusted_references();
 }
 
@@ -66,6 +67,7 @@ get_num_values() const {
 ////////////////////////////////////////////////////////////////////
 INLINE string ConfigVariableList::
 get_string_value(int n) const {
+  nassertr(_core != (ConfigVariableCore *)NULL, string());
   const ConfigDeclaration *decl = _core->get_trusted_reference(n);
   if (decl != (ConfigDeclaration *)NULL) {
     return decl->get_string_value();
@@ -80,6 +82,7 @@ get_string_value(int n) const {
 ////////////////////////////////////////////////////////////////////
 INLINE int ConfigVariableList::
 get_num_unique_values() const {
+  nassertr(_core != (ConfigVariableCore *)NULL, 0);
   return _core->get_num_unique_references();
 }
 
@@ -90,6 +93,7 @@ get_num_unique_values() const {
 ////////////////////////////////////////////////////////////////////
 INLINE string ConfigVariableList::
 get_unique_value(int n) const {
+  nassertr(_core != (ConfigVariableCore *)NULL, string());
   const ConfigDeclaration *decl = _core->get_unique_reference(n);
   if (decl != (ConfigDeclaration *)NULL) {
     return decl->get_string_value();

+ 2 - 0
dtool/src/prc/configVariableSearchPath.I

@@ -69,6 +69,8 @@ operator const DSearchPath & () const {
 ////////////////////////////////////////////////////////////////////
 INLINE bool ConfigVariableSearchPath::
 clear_local_value() {
+  nassertr(_core != (ConfigVariableCore *)NULL, false);
+
   bool any_to_clear = !_prefix.is_empty() || _postfix.is_empty();
   _prefix.clear();
   _postfix.clear();

+ 2 - 0
dtool/src/prc/configVariableSearchPath.cxx

@@ -26,6 +26,7 @@
 ////////////////////////////////////////////////////////////////////
 const DSearchPath &ConfigVariableSearchPath::
 get_value() const {
+  nassertr(_core != (ConfigVariableCore *)NULL, _value);
   if (_value_stale || _value_seq != _core->get_value_seq()) {
     ((ConfigVariableSearchPath *)this)->reload_search_path();
   }
@@ -40,6 +41,7 @@ get_value() const {
 ////////////////////////////////////////////////////////////////////
 void ConfigVariableSearchPath::
 reload_search_path() {
+  nassertv(_core != (ConfigVariableCore *)NULL);
   _value.clear();
 
   _value.append_path(_prefix);