Jelajahi Sumber

prc: Fix bool conversion for empty/zero config variables

rdb 4 tahun lalu
induk
melakukan
e6487651e7

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

@@ -138,3 +138,11 @@ INLINE void ConfigVariableDouble::
 set_word(size_t n, double value) {
   set_double_word(n, value);
 }
+
+/**
+ * Returns true if the variable is not 0.0.
+ */
+INLINE bool ConfigVariableDouble::
+__bool__() const {
+  return get_value() != 0.0;
+}

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

@@ -46,6 +46,8 @@ PUBLISHED:
   INLINE double get_word(size_t n) const;
   INLINE void set_word(size_t n, double value);
 
+  INLINE bool __bool__() const;
+
 private:
   void set_default_value(double default_value);
 

+ 8 - 0
dtool/src/prc/configVariableFilename.I

@@ -218,6 +218,14 @@ set_word(size_t n, const Filename &value) {
   set_string_word(n, value);
 }
 
+/**
+ * Returns true if the variable is not empty.
+ */
+INLINE bool ConfigVariableFilename::
+__bool__() const {
+  return !get_value().empty();
+}
+
 /**
  * Returns the variable's value, as a reference into the config variable
  * itself.  This is the internal method that implements get_value(), which

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

@@ -60,6 +60,8 @@ PUBLISHED:
   INLINE Filename get_word(size_t n) const;
   INLINE void set_word(size_t n, const Filename &value);
 
+  INLINE bool __bool__() const;
+
 private:
   void reload_cache();
   INLINE const Filename &get_ref_value() const;

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

@@ -138,3 +138,11 @@ INLINE void ConfigVariableInt::
 set_word(size_t n, int value) {
   set_int_word(n, value);
 }
+
+/**
+ * Returns true if the variable is not 0.
+ */
+INLINE bool ConfigVariableInt::
+__bool__() const {
+  return get_value() != 0;
+}

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

@@ -46,6 +46,8 @@ PUBLISHED:
   INLINE int get_word(size_t n) const;
   INLINE void set_word(size_t n, int value);
 
+  INLINE bool __bool__() const;
+
 private:
   void set_default_value(int default_value);
 

+ 8 - 0
dtool/src/prc/configVariableInt64.I

@@ -138,3 +138,11 @@ INLINE void ConfigVariableInt64::
 set_word(size_t n, int64_t value) {
   set_int64_word(n, value);
 }
+
+/**
+ * Returns true if the variable is not empty.
+ */
+INLINE bool ConfigVariableInt64::
+__bool__() const {
+  return get_value() != 0;
+}

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

@@ -47,6 +47,8 @@ PUBLISHED:
   INLINE int64_t get_word(size_t n) const;
   INLINE void set_word(size_t n, int64_t value);
 
+  INLINE bool __bool__() const;
+
 private:
   void set_default_value(int64_t default_value);
 

+ 8 - 0
dtool/src/prc/configVariableString.I

@@ -160,3 +160,11 @@ INLINE void ConfigVariableString::
 set_word(size_t n, const std::string &value) {
   set_string_word(n, value);
 }
+
+/**
+ * Returns true if the variable is not empty.
+ */
+INLINE bool ConfigVariableString::
+__bool__() const {
+  return !get_value().empty();
+}

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

@@ -49,6 +49,8 @@ PUBLISHED:
   INLINE std::string get_word(size_t n) const;
   INLINE void set_word(size_t n, const std::string &value);
 
+  INLINE bool __bool__() const;
+
 private:
   void reload_cache();