diff --git a/Foundation/include/Poco/DynamicAny.h b/Foundation/include/Poco/DynamicAny.h index 3bff46328..44815facc 100644 --- a/Foundation/include/Poco/DynamicAny.h +++ b/Foundation/include/Poco/DynamicAny.h @@ -564,6 +564,160 @@ inline T& operator /= (T& other, const DynamicAny& da) } +inline bool operator == (Poco::Int8 other, const DynamicAny& da) + /// Equality operator for Poco::Int8 comparison to DynamicAny +{ + return da.convert() == other; +} + + +inline bool operator != (Poco::Int8 other, const DynamicAny& da) + /// Inequality operator for Poco::Int8 comparison to DynamicAny +{ + return da.convert() != other; +} + + +inline bool operator == (Poco::UInt8 other, const DynamicAny& da) + /// Equality operator for Poco::UInt8 comparison to DynamicAny +{ + return da.convert() == other; +} + + +inline bool operator != (Poco::UInt8 other, const DynamicAny& da) + /// Inequality operator for Poco::UInt8 comparison to DynamicAny +{ + return da.convert() != other; +} + + +inline bool operator == (Poco::Int16 other, const DynamicAny& da) + /// Equality operator for Poco::Int8 comparison to DynamicAny +{ + return da.convert() == other; +} + + +inline bool operator != (Poco::Int16 other, const DynamicAny& da) + /// Inequality operator for Poco::Int8 comparison to DynamicAny +{ + return da.convert() != other; +} + + +inline bool operator == (Poco::UInt16 other, const DynamicAny& da) + /// Equality operator for Poco::UInt16 comparison to DynamicAny +{ + return da.convert() == other; +} + + +inline bool operator != (Poco::UInt16 other, const DynamicAny& da) + /// Inequality operator for Poco::UInt16 comparison to DynamicAny +{ + return da.convert() != other; +} + + +inline bool operator == (Poco::Int32 other, const DynamicAny& da) + /// Equality operator for Poco::Int32 comparison to DynamicAny +{ + return da.convert() == other; +} + + +inline bool operator != (Poco::Int32 other, const DynamicAny& da) + /// Inequality operator for Poco::Int32 comparison to DynamicAny +{ + return da.convert() != other; +} + + +inline bool operator == (Poco::UInt32 other, const DynamicAny& da) + /// Equality operator for Poco::UInt32 comparison to DynamicAny +{ + return da.convert() == other; +} + + +inline bool operator != (Poco::UInt32 other, const DynamicAny& da) + /// Inequality operator for Poco::UInt32 comparison to DynamicAny +{ + return da.convert() != other; +} + + +inline bool operator == (Poco::Int64 other, const DynamicAny& da) + /// Equality operator for Poco::Int64 comparison to DynamicAny +{ + return da.convert() == other; +} + + +inline bool operator != (Poco::Int64 other, const DynamicAny& da) + /// Inequality operator for Poco::Int64 comparison to DynamicAny +{ + return da.convert() != other; +} + + +inline bool operator == (Poco::UInt64 other, const DynamicAny& da) + /// Equality operator for Poco::UInt64 comparison to DynamicAny +{ + return da.convert() == other; +} + + +inline bool operator != (Poco::UInt64 other, const DynamicAny& da) + /// Inequality operator for Poco::UInt64 comparison to DynamicAny +{ + return da.convert() != other; +} + + +inline bool operator == (double other, const DynamicAny& da) + /// Equality operator for double comparison to DynamicAny +{ + return da.convert() == other; +} + + +inline bool operator != (double other, const DynamicAny& da) + /// Inequality operator for double comparison to DynamicAny +{ + return da.convert() != other; +} + + +inline bool operator == (float other, const DynamicAny& da) + /// Equality operator for float comparison to DynamicAny +{ + return da.convert() == other; +} + + +inline bool operator != (float other, const DynamicAny& da) + /// Inequality operator for float comparison to DynamicAny +{ + return da.convert() != other; +} + + +inline bool operator == (bool other, const DynamicAny& da) + /// Equality operator for bool comparison to DynamicAny +{ + return da.convert() == other; +} + + +inline bool operator != (bool other, const DynamicAny& da) + /// Inequality operator for bool comparison to DynamicAny +{ + return da.convert() != other; +} + + inline bool operator == (const std::string& other, const DynamicAny& da) /// Equality operator for DynamicAny comparison to std::string { @@ -572,12 +726,26 @@ inline bool operator == (const std::string& other, const DynamicAny& da) inline bool operator != (const std::string& other, const DynamicAny& da) - /// Equality operator for DynamicAny comparison to std::string + /// Inequality operator for DynamicAny comparison to std::string { return da.convert() != other; } +inline bool operator == (const char* other, const DynamicAny& da) + /// Equality operator for DynamicAny comparison to std::string +{ + return da.convert() == std::string(other); +} + + +inline bool operator != (const char* other, const DynamicAny& da) + /// Inequality operator for DynamicAny comparison to std::string +{ + return da.convert() != std::string(other); +} + + } // namespace Poco diff --git a/Foundation/testsuite/src/DynamicAnyTest.cpp b/Foundation/testsuite/src/DynamicAnyTest.cpp index 6e7397425..49c20c172 100644 --- a/Foundation/testsuite/src/DynamicAnyTest.cpp +++ b/Foundation/testsuite/src/DynamicAnyTest.cpp @@ -1363,14 +1363,51 @@ void DynamicAnyTest::testComparisonOperators() DynamicAny any2 = "1"; assert (any1 == any2); assert (any1 == 1); + assert (1 == any1); assert (any1 == "1"); assert ("1" == any1); + any1 = 1L; + assert (any1 == any2); + assert (any1 == 1L); + assert (1L == any1); + assert (any1 == "1"); + assert ("1" == any1); + assert (any1 != 2L); + assert (2L != any1); + assert (any1 != "2"); + assert ("2" != any1); + + any1 = 0x31; + assert (any1 == '1'); + assert ('1' == any1); + any1 = "2"; assert (any1 != any2); assert (any1 != 1); + assert (1 != any1); assert (any1 != "1"); assert ("1" != any1); + + any1 = 1.5; + assert (any1 == 1.5); + assert (1.5 == any1); + assert (any1 == "1.5"); + assert ("1.5" == any1); + assert (any1 != 2.5); + assert (2.5 != any1); + assert (any1 != "2.5"); + assert ("2.5" != any1); + + any1 = 1.5f; + assert (any1 == 1.5f); + assert (1.5f == any1); + assert (any1 == "1.5"); + assert ("1.5" == any1); + assert (any1 != 2.5f); + assert (2.5f != any1); + assert (any1 != "2.5"); + assert ("2.5" != any1); }