prc: Fix bool conversion for empty/zero config variables

This commit is contained in:
rdb 2021-03-09 19:35:42 +01:00
parent fd5cab1a3f
commit e6487651e7
10 changed files with 50 additions and 0 deletions

View File

@ -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;
}

View File

@ -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);

View File

@ -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

View File

@ -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;

View File

@ -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;
}

View File

@ -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);

View File

@ -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;
}

View File

@ -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);

View File

@ -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();
}

View File

@ -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();