From d6b81dca0febebfcf5ead86ab40db23d90a6b9a9 Mon Sep 17 00:00:00 2001 From: Aleksandar Fabijanic Date: Tue, 12 Aug 2008 10:09:03 +0000 Subject: [PATCH] logical operators --- Foundation/include/Poco/DynamicAny.h | 68 ++++++++++++++++++++++------ Foundation/src/DynamicAny.cpp | 42 +++++++++++++++++ 2 files changed, 95 insertions(+), 15 deletions(-) diff --git a/Foundation/include/Poco/DynamicAny.h b/Foundation/include/Poco/DynamicAny.h index b297406c1..9ec7ec5dd 100644 --- a/Foundation/include/Poco/DynamicAny.h +++ b/Foundation/include/Poco/DynamicAny.h @@ -215,10 +215,8 @@ public: return *this; } - bool operator ! () - { - return !convert(); - } + const bool operator ! () const; + /// Logical NOT operator. DynamicAny& operator = (const DynamicAny& other); /// Assignment operator specialization for DynamicAny @@ -256,10 +254,10 @@ public: } DynamicAny& operator += (const DynamicAny& other); - /// Addition asignment operator specialization for DynamicAny + /// Addition asignment operator overload for DynamicAny DynamicAny& operator += (const char* other); - /// Addition asignment operator specialization for const char* + /// Addition asignment operator overload for const char* template const DynamicAny operator - (const T& other) const @@ -269,7 +267,7 @@ public: } const DynamicAny operator - (const DynamicAny& other) const; - /// Subtraction operator specialization for DynamicAny + /// Subtraction operator overload for DynamicAny template DynamicAny& operator -= (const T& other) @@ -279,7 +277,7 @@ public: } DynamicAny& operator -= (const DynamicAny& other); - /// Subtraction asignment operator specialization for DynamicAny + /// Subtraction asignment operator overload for DynamicAny template const DynamicAny operator * (const T& other) const @@ -289,7 +287,7 @@ public: } const DynamicAny operator * (const DynamicAny& other) const; - /// Multiplication operator specialization for DynamicAny + /// Multiplication operator overload for DynamicAny template DynamicAny& operator *= (const T& other) @@ -299,7 +297,7 @@ public: } DynamicAny& operator *= (const DynamicAny& other); - /// Multiplication asignment operator specialization for DynamicAny + /// Multiplication asignment operator overload for DynamicAny template const DynamicAny operator / (const T& other) const @@ -309,7 +307,7 @@ public: } const DynamicAny operator / (const DynamicAny& other) const; - /// Division operator specialization for DynamicAny + /// Division operator overload for DynamicAny template DynamicAny& operator /= (const T& other) @@ -330,10 +328,10 @@ public: } bool operator == (const char* other) const; - /// Equality operator specialization for const char* + /// Equality operator overload for const char* bool operator == (const DynamicAny& other) const; - /// Equality operator specialization for DynamicAny + /// Equality operator overload for DynamicAny template bool operator != (const T& other) const @@ -344,10 +342,10 @@ public: } bool operator != (const DynamicAny& other) const; - /// Inequality operator specialization for DynamicAny + /// Inequality operator overload for DynamicAny bool operator != (const char* other) const; - /// Inequality operator specialization for const char* + /// Inequality operator overload for const char* template bool operator < (const T& other) const @@ -357,6 +355,9 @@ public: return convert() < other; } + bool operator < (const DynamicAny& other) const; + /// Less than operator overload for DynamicAny + template bool operator <= (const T& other) const /// Less than or equal operator @@ -365,6 +366,9 @@ public: return convert() <= other; } + bool operator <= (const DynamicAny& other) const; + /// Less than or equal operator overload for DynamicAny + template bool operator > (const T& other) const /// Greater than operator @@ -373,6 +377,9 @@ public: return convert() > other; } + bool operator > (const DynamicAny& other) const; + /// Greater than operator overload for DynamicAny + template bool operator >= (const T& other) const /// Greater than or equal operator @@ -381,6 +388,31 @@ public: return convert() >= other; } + bool operator >= (const DynamicAny& other) const; + /// Greater than or equal operator overload for DynamicAny + + template + bool operator || (const T& other) const + /// Logical OR operator + { + if (isEmpty()) return false; + return convert() || other; + } + + bool operator || (const DynamicAny& other) const; + /// Logical OR operator operator overload for DynamicAny + + template + bool operator && (const T& other) const + /// Logical AND operator + { + if (isEmpty()) return false; + return convert() && other; + } + + bool operator && (const DynamicAny& other) const; + /// Logical AND operator operator overload for DynamicAny + bool isArray() const; /// Returns true if DynamicAny represents a vector @@ -543,6 +575,12 @@ inline DynamicAny& DynamicAny::operator += (const char*other) } +inline const bool DynamicAny::operator ! () const +{ + return !convert(); +} + + inline bool DynamicAny::isEmpty() const { return 0 == _pHolder; diff --git a/Foundation/src/DynamicAny.cpp b/Foundation/src/DynamicAny.cpp index 4a4860141..fb42d0243 100644 --- a/Foundation/src/DynamicAny.cpp +++ b/Foundation/src/DynamicAny.cpp @@ -275,6 +275,48 @@ bool DynamicAny::operator != (const char* other) const } +bool DynamicAny::operator < (const DynamicAny& other) const +{ + if (isEmpty() || other.isEmpty()) return false; + return convert() < other.convert(); +} + + +bool DynamicAny::operator <= (const DynamicAny& other) const +{ + if (isEmpty() || other.isEmpty()) return false; + return convert() <= other.convert(); +} + + +bool DynamicAny::operator > (const DynamicAny& other) const +{ + if (isEmpty() || other.isEmpty()) return false; + return convert() > other.convert(); +} + + +bool DynamicAny::operator >= (const DynamicAny& other) const +{ + if (isEmpty() || other.isEmpty()) return false; + return convert() >= other.convert(); +} + + +bool DynamicAny::operator || (const DynamicAny& other) const +{ + if (isEmpty() || other.isEmpty()) return false; + return convert() || other.convert(); +} + + +bool DynamicAny::operator && (const DynamicAny& other) const +{ + if (isEmpty() || other.isEmpty()) return false; + return convert() && other.convert(); +} + + void DynamicAny::empty() { delete _pHolder;