== and != overloads for POD

This commit is contained in:
Aleksandar Fabijanic
2007-09-24 22:33:37 +00:00
parent 8506aad3ae
commit 8bb74a06a4
2 changed files with 206 additions and 1 deletions

View File

@@ -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<Poco::Int8>() == other;
}
inline bool operator != (Poco::Int8 other, const DynamicAny& da)
/// Inequality operator for Poco::Int8 comparison to DynamicAny
{
return da.convert<Poco::Int8>() != other;
}
inline bool operator == (Poco::UInt8 other, const DynamicAny& da)
/// Equality operator for Poco::UInt8 comparison to DynamicAny
{
return da.convert<Poco::UInt8>() == other;
}
inline bool operator != (Poco::UInt8 other, const DynamicAny& da)
/// Inequality operator for Poco::UInt8 comparison to DynamicAny
{
return da.convert<Poco::UInt8>() != other;
}
inline bool operator == (Poco::Int16 other, const DynamicAny& da)
/// Equality operator for Poco::Int8 comparison to DynamicAny
{
return da.convert<Poco::Int16>() == other;
}
inline bool operator != (Poco::Int16 other, const DynamicAny& da)
/// Inequality operator for Poco::Int8 comparison to DynamicAny
{
return da.convert<Poco::Int16>() != other;
}
inline bool operator == (Poco::UInt16 other, const DynamicAny& da)
/// Equality operator for Poco::UInt16 comparison to DynamicAny
{
return da.convert<Poco::UInt16>() == other;
}
inline bool operator != (Poco::UInt16 other, const DynamicAny& da)
/// Inequality operator for Poco::UInt16 comparison to DynamicAny
{
return da.convert<Poco::UInt16>() != other;
}
inline bool operator == (Poco::Int32 other, const DynamicAny& da)
/// Equality operator for Poco::Int32 comparison to DynamicAny
{
return da.convert<Poco::Int32>() == other;
}
inline bool operator != (Poco::Int32 other, const DynamicAny& da)
/// Inequality operator for Poco::Int32 comparison to DynamicAny
{
return da.convert<Poco::Int32>() != other;
}
inline bool operator == (Poco::UInt32 other, const DynamicAny& da)
/// Equality operator for Poco::UInt32 comparison to DynamicAny
{
return da.convert<Poco::UInt32>() == other;
}
inline bool operator != (Poco::UInt32 other, const DynamicAny& da)
/// Inequality operator for Poco::UInt32 comparison to DynamicAny
{
return da.convert<Poco::UInt32>() != other;
}
inline bool operator == (Poco::Int64 other, const DynamicAny& da)
/// Equality operator for Poco::Int64 comparison to DynamicAny
{
return da.convert<Poco::Int64>() == other;
}
inline bool operator != (Poco::Int64 other, const DynamicAny& da)
/// Inequality operator for Poco::Int64 comparison to DynamicAny
{
return da.convert<Poco::Int64>() != other;
}
inline bool operator == (Poco::UInt64 other, const DynamicAny& da)
/// Equality operator for Poco::UInt64 comparison to DynamicAny
{
return da.convert<Poco::UInt64>() == other;
}
inline bool operator != (Poco::UInt64 other, const DynamicAny& da)
/// Inequality operator for Poco::UInt64 comparison to DynamicAny
{
return da.convert<Poco::UInt64>() != other;
}
inline bool operator == (double other, const DynamicAny& da)
/// Equality operator for double comparison to DynamicAny
{
return da.convert<double>() == other;
}
inline bool operator != (double other, const DynamicAny& da)
/// Inequality operator for double comparison to DynamicAny
{
return da.convert<double>() != other;
}
inline bool operator == (float other, const DynamicAny& da)
/// Equality operator for float comparison to DynamicAny
{
return da.convert<float>() == other;
}
inline bool operator != (float other, const DynamicAny& da)
/// Inequality operator for float comparison to DynamicAny
{
return da.convert<float>() != other;
}
inline bool operator == (bool other, const DynamicAny& da)
/// Equality operator for bool comparison to DynamicAny
{
return da.convert<bool>() == other;
}
inline bool operator != (bool other, const DynamicAny& da)
/// Inequality operator for bool comparison to DynamicAny
{
return da.convert<bool>() != 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<std::string>() != other;
}
inline bool operator == (const char* other, const DynamicAny& da)
/// Equality operator for DynamicAny comparison to std::string
{
return da.convert<std::string>() == 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>() != std::string(other);
}
} // namespace Poco

View File

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