operators <, <=, >, >=

This commit is contained in:
Aleksandar Fabijanic 2007-10-21 23:46:14 +00:00
parent 5d4080e7f4
commit 65587e39a3
2 changed files with 424 additions and 0 deletions

View File

@ -311,6 +311,34 @@ public:
bool operator != (const char* other) const; bool operator != (const char* other) const;
/// Inequality operator specialization for const char* /// Inequality operator specialization for const char*
template <typename T>
bool operator < (const T& other) const
/// Less than operator
{
return convert<T>() < other;
}
template <typename T>
bool operator <= (const T& other) const
/// Less than or equal operator
{
return convert<T>() <= other;
}
template <typename T>
bool operator > (const T& other) const
/// Greater than operator
{
return convert<T>() > other;
}
template <typename T>
bool operator >= (const T& other) const
/// Greater than or equal operator
{
return convert<T>() >= other;
}
bool isArray() const; bool isArray() const;
/// Returns true if DynamicAny represents a vector /// Returns true if DynamicAny represents a vector
@ -568,6 +596,34 @@ inline const bool operator != (const char& other, const DynamicAny& da)
} }
inline const bool operator < (const char& other, const DynamicAny& da)
/// Less than operator for comparing DynamicAny with char
{
return other < da.convert<char>();
}
inline const bool operator <= (const char& other, const DynamicAny& da)
/// Less than or equal operator for comparing DynamicAny with char
{
return other <= da.convert<char>();
}
inline const bool operator > (const char& other, const DynamicAny& da)
/// Greater than operator for comparing DynamicAny with char
{
return other > da.convert<char>();
}
inline const bool operator >= (const char& other, const DynamicAny& da)
/// Greater than or equal operator for comparing DynamicAny with char
{
return other >= da.convert<char>();
}
inline const Poco::Int8 operator + (const Poco::Int8& other, const DynamicAny& da) inline const Poco::Int8 operator + (const Poco::Int8& other, const DynamicAny& da)
/// Addition operator for adding DynamicAny to Poco::Int8 /// Addition operator for adding DynamicAny to Poco::Int8
{ {
@ -638,6 +694,34 @@ inline const bool operator != (const Poco::Int8& other, const DynamicAny& da)
} }
inline const bool operator < (const Poco::Int8& other, const DynamicAny& da)
/// Less than operator for comparing DynamicAny with Poco::Int8
{
return other < da.convert<Poco::Int8>();
}
inline const bool operator <= (const Poco::Int8& other, const DynamicAny& da)
/// Less than or equal operator for comparing DynamicAny with Poco::Int8
{
return other <= da.convert<Poco::Int8>();
}
inline const bool operator > (const Poco::Int8& other, const DynamicAny& da)
/// Greater than operator for comparing DynamicAny with Poco::Int8
{
return other > da.convert<Poco::Int8>();
}
inline const bool operator >= (const Poco::Int8& other, const DynamicAny& da)
/// Greater than or equal operator for comparing DynamicAny with Poco::Int8
{
return other >= da.convert<Poco::Int8>();
}
inline const Poco::UInt8 operator + (const Poco::UInt8& other, const DynamicAny& da) inline const Poco::UInt8 operator + (const Poco::UInt8& other, const DynamicAny& da)
/// Addition operator for adding DynamicAny to Poco::UInt8 /// Addition operator for adding DynamicAny to Poco::UInt8
{ {
@ -708,6 +792,34 @@ inline const bool operator != (const Poco::UInt8& other, const DynamicAny& da)
} }
inline const bool operator < (const Poco::UInt8& other, const DynamicAny& da)
/// Less than operator for comparing DynamicAny with Poco::UInt8
{
return other < da.convert<Poco::UInt8>();
}
inline const bool operator <= (const Poco::UInt8& other, const DynamicAny& da)
/// Less than or equal operator for comparing DynamicAny with Poco::UInt8
{
return other <= da.convert<Poco::UInt8>();
}
inline const bool operator > (const Poco::UInt8& other, const DynamicAny& da)
/// Greater than operator for comparing DynamicAny with Poco::UInt8
{
return other > da.convert<Poco::UInt8>();
}
inline const bool operator >= (const Poco::UInt8& other, const DynamicAny& da)
/// Greater than or equal operator for comparing DynamicAny with Poco::UInt8
{
return other >= da.convert<Poco::UInt8>();
}
inline const Poco::Int16 operator + (const Poco::Int16& other, const DynamicAny& da) inline const Poco::Int16 operator + (const Poco::Int16& other, const DynamicAny& da)
/// Addition operator for adding DynamicAny to Poco::Int16 /// Addition operator for adding DynamicAny to Poco::Int16
{ {
@ -778,6 +890,34 @@ inline const bool operator != (const Poco::Int16& other, const DynamicAny& da)
} }
inline const bool operator < (const Poco::Int16& other, const DynamicAny& da)
/// Less than operator for comparing DynamicAny with Poco::Int16
{
return other < da.convert<Poco::Int16>();
}
inline const bool operator <= (const Poco::Int16& other, const DynamicAny& da)
/// Less than or equal operator for comparing DynamicAny with Poco::Int16
{
return other <= da.convert<Poco::Int16>();
}
inline const bool operator > (const Poco::Int16& other, const DynamicAny& da)
/// Greater than operator for comparing DynamicAny with Poco::Int16
{
return other > da.convert<Poco::Int16>();
}
inline const bool operator >= (const Poco::Int16& other, const DynamicAny& da)
/// Greater than or equal operator for comparing DynamicAny with Poco::Int16
{
return other >= da.convert<Poco::Int16>();
}
inline const Poco::UInt16 operator + (const Poco::UInt16& other, const DynamicAny& da) inline const Poco::UInt16 operator + (const Poco::UInt16& other, const DynamicAny& da)
/// Addition operator for adding DynamicAny to Poco::UInt16 /// Addition operator for adding DynamicAny to Poco::UInt16
{ {
@ -848,6 +988,34 @@ inline const bool operator != (const Poco::UInt16& other, const DynamicAny& da)
} }
inline const bool operator < (const Poco::UInt16& other, const DynamicAny& da)
/// Less than operator for comparing DynamicAny with Poco::UInt16
{
return other < da.convert<Poco::UInt16>();
}
inline const bool operator <= (const Poco::UInt16& other, const DynamicAny& da)
/// Less than or equal operator for comparing DynamicAny with Poco::UInt16
{
return other <= da.convert<Poco::UInt16>();
}
inline const bool operator > (const Poco::UInt16& other, const DynamicAny& da)
/// Greater than operator for comparing DynamicAny with Poco::UInt16
{
return other > da.convert<Poco::UInt16>();
}
inline const bool operator >= (const Poco::UInt16& other, const DynamicAny& da)
/// Greater than or equal operator for comparing DynamicAny with Poco::UInt16
{
return other >= da.convert<Poco::UInt16>();
}
inline const Poco::Int32 operator + (const Poco::Int32& other, const DynamicAny& da) inline const Poco::Int32 operator + (const Poco::Int32& other, const DynamicAny& da)
/// Addition operator for adding DynamicAny to Poco::Int32 /// Addition operator for adding DynamicAny to Poco::Int32
{ {
@ -918,6 +1086,34 @@ inline const bool operator != (const Poco::Int32& other, const DynamicAny& da)
} }
inline const bool operator < (const Poco::Int32& other, const DynamicAny& da)
/// Less than operator for comparing DynamicAny with Poco::Int32
{
return other < da.convert<Poco::Int32>();
}
inline const bool operator <= (const Poco::Int32& other, const DynamicAny& da)
/// Less than or equal operator for comparing DynamicAny with Poco::Int32
{
return other <= da.convert<Poco::Int32>();
}
inline const bool operator > (const Poco::Int32& other, const DynamicAny& da)
/// Greater than operator for comparing DynamicAny with Poco::Int32
{
return other > da.convert<Poco::Int32>();
}
inline const bool operator >= (const Poco::Int32& other, const DynamicAny& da)
/// Greater than or equal operator for comparing DynamicAny with Poco::Int32
{
return other >= da.convert<Poco::Int32>();
}
inline const Poco::UInt32 operator + (const Poco::UInt32& other, const DynamicAny& da) inline const Poco::UInt32 operator + (const Poco::UInt32& other, const DynamicAny& da)
/// Addition operator for adding DynamicAny to Poco::UInt32 /// Addition operator for adding DynamicAny to Poco::UInt32
{ {
@ -988,6 +1184,34 @@ inline const bool operator != (const Poco::UInt32& other, const DynamicAny& da)
} }
inline const bool operator < (const Poco::UInt32& other, const DynamicAny& da)
/// Less than operator for comparing DynamicAny with Poco::UInt32
{
return other < da.convert<Poco::UInt32>();
}
inline const bool operator <= (const Poco::UInt32& other, const DynamicAny& da)
/// Less than or equal operator for comparing DynamicAny with Poco::UInt32
{
return other <= da.convert<Poco::UInt32>();
}
inline const bool operator > (const Poco::UInt32& other, const DynamicAny& da)
/// Greater than operator for comparing DynamicAny with Poco::UInt32
{
return other > da.convert<Poco::UInt32>();
}
inline const bool operator >= (const Poco::UInt32& other, const DynamicAny& da)
/// Greater than or equal operator for comparing DynamicAny with Poco::UInt32
{
return other >= da.convert<Poco::UInt32>();
}
inline const Poco::Int64 operator + (const Poco::Int64& other, const DynamicAny& da) inline const Poco::Int64 operator + (const Poco::Int64& other, const DynamicAny& da)
/// Addition operator for adding DynamicAny to Poco::Int64 /// Addition operator for adding DynamicAny to Poco::Int64
{ {
@ -1058,6 +1282,34 @@ inline const bool operator != (const Poco::Int64& other, const DynamicAny& da)
} }
inline const bool operator < (const Poco::Int64& other, const DynamicAny& da)
/// Less than operator for comparing DynamicAny with Poco::Int64
{
return other < da.convert<Poco::Int64>();
}
inline const bool operator <= (const Poco::Int64& other, const DynamicAny& da)
/// Less than or equal operator for comparing DynamicAny with Poco::Int64
{
return other <= da.convert<Poco::Int64>();
}
inline const bool operator > (const Poco::Int64& other, const DynamicAny& da)
/// Greater than operator for comparing DynamicAny with Poco::Int64
{
return other > da.convert<Poco::Int64>();
}
inline const bool operator >= (const Poco::Int64& other, const DynamicAny& da)
/// Greater than or equal operator for comparing DynamicAny with Poco::Int64
{
return other >= da.convert<Poco::Int64>();
}
inline const Poco::UInt64 operator + (const Poco::UInt64& other, const DynamicAny& da) inline const Poco::UInt64 operator + (const Poco::UInt64& other, const DynamicAny& da)
/// Addition operator for adding DynamicAny to Poco::UInt64 /// Addition operator for adding DynamicAny to Poco::UInt64
{ {
@ -1128,6 +1380,34 @@ inline const bool operator != (const Poco::UInt64& other, const DynamicAny& da)
} }
inline const bool operator < (const Poco::UInt64& other, const DynamicAny& da)
/// Less than operator for comparing DynamicAny with Poco::UInt64
{
return other < da.convert<Poco::UInt64>();
}
inline const bool operator <= (const Poco::UInt64& other, const DynamicAny& da)
/// Less than or equal operator for comparing DynamicAny with Poco::UInt64
{
return other <= da.convert<Poco::UInt64>();
}
inline const bool operator > (const Poco::UInt64& other, const DynamicAny& da)
/// Greater than operator for comparing DynamicAny with Poco::UInt64
{
return other > da.convert<Poco::UInt64>();
}
inline const bool operator >= (const Poco::UInt64& other, const DynamicAny& da)
/// Greater than or equal operator for comparing DynamicAny with Poco::UInt64
{
return other >= da.convert<Poco::UInt64>();
}
inline const float operator + (const float& other, const DynamicAny& da) inline const float operator + (const float& other, const DynamicAny& da)
/// Addition operator for adding DynamicAny to float /// Addition operator for adding DynamicAny to float
{ {
@ -1198,6 +1478,34 @@ inline const bool operator != (const float& other, const DynamicAny& da)
} }
inline const bool operator < (const float& other, const DynamicAny& da)
/// Less than operator for comparing DynamicAny with float
{
return other < da.convert<float>();
}
inline const bool operator <= (const float& other, const DynamicAny& da)
/// Less than or equal operator for comparing DynamicAny with float
{
return other <= da.convert<float>();
}
inline const bool operator > (const float& other, const DynamicAny& da)
/// Greater than operator for comparing DynamicAny with float
{
return other > da.convert<float>();
}
inline const bool operator >= (const float& other, const DynamicAny& da)
/// Greater than or equal operator for comparing DynamicAny with float
{
return other >= da.convert<float>();
}
inline const double operator + (const double& other, const DynamicAny& da) inline const double operator + (const double& other, const DynamicAny& da)
/// Addition operator for adding DynamicAny to double /// Addition operator for adding DynamicAny to double
{ {
@ -1268,6 +1576,34 @@ inline const bool operator != (const double& other, const DynamicAny& da)
} }
inline const bool operator < (const double& other, const DynamicAny& da)
/// Less than operator for comparing DynamicAny with double
{
return other < da.convert<double>();
}
inline const bool operator <= (const double& other, const DynamicAny& da)
/// Less than or equal operator for comparing DynamicAny with double
{
return other <= da.convert<double>();
}
inline const bool operator > (const double& other, const DynamicAny& da)
/// Greater than operator for comparing DynamicAny with double
{
return other > da.convert<double>();
}
inline const bool operator >= (const double& other, const DynamicAny& da)
/// Greater than or equal operator for comparing DynamicAny with double
{
return other >= da.convert<double>();
}
inline const bool operator == (const bool& other, const DynamicAny& da) inline const bool operator == (const bool& other, const DynamicAny& da)
/// Equality operator for comparing DynamicAny with bool /// Equality operator for comparing DynamicAny with bool
{ {
@ -1383,6 +1719,34 @@ inline const bool operator != (const long& other, const DynamicAny& da)
} }
inline const bool operator < (const long& other, const DynamicAny& da)
/// Less than operator for comparing DynamicAny with long
{
return other < da.convert<long>();
}
inline const bool operator <= (const long& other, const DynamicAny& da)
/// Less than or equal operator for comparing DynamicAny with long
{
return other <= da.convert<long>();
}
inline const bool operator > (const long& other, const DynamicAny& da)
/// Greater than operator for comparing DynamicAny with long
{
return other > da.convert<long>();
}
inline const bool operator >= (const long& other, const DynamicAny& da)
/// Greater than or equal operator for comparing DynamicAny with long
{
return other >= da.convert<long>();
}
#endif // POCO_LONG_IS_64_BIT #endif // POCO_LONG_IS_64_BIT

View File

@ -1366,6 +1366,18 @@ void DynamicAnyTest::testComparisonOperators()
assert (1 == any1); assert (1 == any1);
assert (any1 == "1"); assert (any1 == "1");
assert ("1" == any1); assert ("1" == any1);
assert (any1 <= 1);
assert (1 >= any1);
assert (any1 <= 2);
assert (2 >= any1);
assert (any1 < 2);
assert (2 > any1);
assert (any1 > 0);
assert (0 < any1);
assert (any1 >= 1);
assert (1 <= any1);
assert (any1 >= 0);
assert (0 <= any1);
any1 = 1L; any1 = 1L;
assert (any1 == any2); assert (any1 == any2);
@ -1377,10 +1389,34 @@ void DynamicAnyTest::testComparisonOperators()
assert (2L != any1); assert (2L != any1);
assert (any1 != "2"); assert (any1 != "2");
assert ("2" != any1); assert ("2" != any1);
assert (any1 <= 1L);
assert (1L >= any1);
assert (any1 <= 2L);
assert (2L >= any1);
assert (any1 < 2L);
assert (2L > any1);
assert (any1 > 0);
assert (0 < any1);
assert (any1 >= 1L);
assert (1L <= any1);
assert (any1 >= 0);
assert (0 <= any1);
any1 = 0x31; any1 = 0x31;
assert (any1 == '1'); assert (any1 == '1');
assert ('1' == any1); assert ('1' == any1);
assert (any1 <= '1');
assert ('1' >= any1);
assert (any1 <= '2');
assert ('2' >= any1);
assert (any1 < '2');
assert ('2' > any1);
assert (any1 > 0);
assert (0 < any1);
assert (any1 >= '1');
assert ('1' <= any1);
assert (any1 >= 0);
assert (0 <= any1);
any1 = "2"; any1 = "2";
assert (any1 != any2); assert (any1 != any2);
@ -1398,6 +1434,18 @@ void DynamicAnyTest::testComparisonOperators()
assert (2.5 != any1); assert (2.5 != any1);
assert (any1 != "2.5"); assert (any1 != "2.5");
assert ("2.5" != any1); assert ("2.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);
assert (any1 > 0);
assert (0 < any1);
assert (any1 >= 1.5);
assert (1.5 <= any1);
assert (any1 >= 0);
assert (0 <= any1);
any1 = 1.5f; any1 = 1.5f;
assert (any1 == 1.5f); assert (any1 == 1.5f);
@ -1408,6 +1456,18 @@ void DynamicAnyTest::testComparisonOperators()
assert (2.5f != any1); assert (2.5f != any1);
assert (any1 != "2.5"); assert (any1 != "2.5");
assert ("2.5" != any1); assert ("2.5" != any1);
assert (any1 <= 1.5f);
assert (1.5f >= any1);
assert (any1 <= 2.5f);
assert (2.5f >= any1);
assert (any1 < 2.5f);
assert (2.5f > any1);
assert (any1 > 0);
assert (0 < any1);
assert (any1 >= 1.5f);
assert (1.5f <= any1);
assert (any1 >= 0);
assert (0 <= any1);
} }