From e6487651e79e98fba2872921025d564516ff1d63 Mon Sep 17 00:00:00 2001 From: rdb Date: Tue, 9 Mar 2021 19:35:42 +0100 Subject: [PATCH] prc: Fix bool conversion for empty/zero config variables --- dtool/src/prc/configVariableDouble.I | 8 ++++++++ dtool/src/prc/configVariableDouble.h | 2 ++ dtool/src/prc/configVariableFilename.I | 8 ++++++++ dtool/src/prc/configVariableFilename.h | 2 ++ dtool/src/prc/configVariableInt.I | 8 ++++++++ dtool/src/prc/configVariableInt.h | 2 ++ dtool/src/prc/configVariableInt64.I | 8 ++++++++ dtool/src/prc/configVariableInt64.h | 2 ++ dtool/src/prc/configVariableString.I | 8 ++++++++ dtool/src/prc/configVariableString.h | 2 ++ 10 files changed, 50 insertions(+) diff --git a/dtool/src/prc/configVariableDouble.I b/dtool/src/prc/configVariableDouble.I index 3075591c0f..53a4b847b0 100644 --- a/dtool/src/prc/configVariableDouble.I +++ b/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; +} diff --git a/dtool/src/prc/configVariableDouble.h b/dtool/src/prc/configVariableDouble.h index 12332016ec..816c4cbf35 100644 --- a/dtool/src/prc/configVariableDouble.h +++ b/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); diff --git a/dtool/src/prc/configVariableFilename.I b/dtool/src/prc/configVariableFilename.I index 51013ddfcf..174c04e65a 100644 --- a/dtool/src/prc/configVariableFilename.I +++ b/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 diff --git a/dtool/src/prc/configVariableFilename.h b/dtool/src/prc/configVariableFilename.h index 7537e22117..c6677a7ec9 100644 --- a/dtool/src/prc/configVariableFilename.h +++ b/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; diff --git a/dtool/src/prc/configVariableInt.I b/dtool/src/prc/configVariableInt.I index f341070b77..a2c7d64487 100644 --- a/dtool/src/prc/configVariableInt.I +++ b/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; +} diff --git a/dtool/src/prc/configVariableInt.h b/dtool/src/prc/configVariableInt.h index 9d87fe3344..cd116557ed 100644 --- a/dtool/src/prc/configVariableInt.h +++ b/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); diff --git a/dtool/src/prc/configVariableInt64.I b/dtool/src/prc/configVariableInt64.I index a86fcc296e..68695a29f6 100644 --- a/dtool/src/prc/configVariableInt64.I +++ b/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; +} diff --git a/dtool/src/prc/configVariableInt64.h b/dtool/src/prc/configVariableInt64.h index a88f2272d8..7241219085 100644 --- a/dtool/src/prc/configVariableInt64.h +++ b/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); diff --git a/dtool/src/prc/configVariableString.I b/dtool/src/prc/configVariableString.I index d72c48cb8c..062439553d 100644 --- a/dtool/src/prc/configVariableString.I +++ b/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(); +} diff --git a/dtool/src/prc/configVariableString.h b/dtool/src/prc/configVariableString.h index d2b5b38b78..cb5249e6cf 100644 --- a/dtool/src/prc/configVariableString.h +++ b/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();