diff --git a/src/config.cpp b/src/config.cpp index 821328d1dbc..613c3b0f914 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -31,6 +31,7 @@ #include #include +#include #include #include #include @@ -390,6 +391,16 @@ bool config::attribute_value::operator==(const config::attribute_value &other) c return boost::apply_visitor(equality_visitor(), value_, other.value_); } +/** + * Checks for equality of the attribute values when viewed as strings. + * Exception: Boolean synonyms can be equal ("yes" == "true"). + * Note: Blanks have no string representation, so do not equal "" (an empty string). + */ +bool config::attribute_value::equals(const std::string &str) const +{ + return boost::apply_visitor(boost::bind( equality_visitor(), _1, boost::cref(str) ), value_); +} + std::ostream &operator<<(std::ostream &os, const config::attribute_value &v) { // Simple implementation, but defined out-of-line because of the templating diff --git a/src/config.hpp b/src/config.hpp index fff9e2e093c..5bc0fc7d313 100644 --- a/src/config.hpp +++ b/src/config.hpp @@ -280,6 +280,16 @@ public: bool operator==(const attribute_value &other) const; bool operator!=(const attribute_value &other) const { return !operator==(other); } + // We don't want strange conversions to t_string when doing like (c["a"] == "b") + bool equals(const std::string& str) const; + friend bool operator==(const attribute_value &val, const std::string &str) + { return val.equals(str); } + friend bool operator==(const std::string &str, const attribute_value &val) + { return val.equals(str); } + friend bool operator==(const attribute_value &val, const char* str) + { return val.equals(std::string(str)); } + friend bool operator==(const char* str, const attribute_value &val) + { return val.equals(std::string(str)); } // Streaming: friend std::ostream& operator<<(std::ostream &os, const attribute_value &v);