You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2013/11/24 22:56:26 UTC

git commit: Overloaded operators

Updated Branches:
  refs/heads/trunk 0ccee9843 -> 792d16f4d


Overloaded operators 

Project: http://git-wip-us.apache.org/repos/asf/activemq-cpp/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-cpp/commit/792d16f4
Tree: http://git-wip-us.apache.org/repos/asf/activemq-cpp/tree/792d16f4
Diff: http://git-wip-us.apache.org/repos/asf/activemq-cpp/diff/792d16f4

Branch: refs/heads/trunk
Commit: 792d16f4d6f89d3cddca98d97b23716f6470b602
Parents: 0ccee98
Author: Timothy Bish <ta...@gmai.com>
Authored: Sun Nov 24 16:56:16 2013 -0500
Committer: Timothy Bish <ta...@gmai.com>
Committed: Sun Nov 24 16:56:16 2013 -0500

----------------------------------------------------------------------
 activemq-cpp/src/main/decaf/lang/String.cpp     | 93 +++++++++++++++++++
 activemq-cpp/src/main/decaf/lang/String.h       | 54 ++++++++++-
 activemq-cpp/src/test/decaf/lang/StringTest.cpp | 97 +++++++++++++++++++-
 activemq-cpp/src/test/decaf/lang/StringTest.h   | 15 +++
 4 files changed, 257 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-cpp/blob/792d16f4/activemq-cpp/src/main/decaf/lang/String.cpp
----------------------------------------------------------------------
diff --git a/activemq-cpp/src/main/decaf/lang/String.cpp b/activemq-cpp/src/main/decaf/lang/String.cpp
index d3fe4fb..f91a190 100644
--- a/activemq-cpp/src/main/decaf/lang/String.cpp
+++ b/activemq-cpp/src/main/decaf/lang/String.cpp
@@ -312,6 +312,51 @@ bool String::operator< (const char* other) const {
 }
 
 ////////////////////////////////////////////////////////////////////////////////
+bool String::operator<=(const String& other) const {
+    return this->compareTo(other) <= 0;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool String::operator<=(const std::string& other) const {
+    return this->compareTo(other) <= 0;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool String::operator<=(const char* other) const {
+    return this->compareTo(other) <= 0;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool String::operator> (const String& other) const {
+    return this->compareTo(other) > 0;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool String::operator> (const std::string& other) const {
+    return this->compareTo(other) > 0;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool String::operator> (const char* other) const {
+    return this->compareTo(other) > 0;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool String::operator>=(const String& other) const {
+    return this->compareTo(other) >= 0;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool String::operator>=(const std::string& other) const {
+    return this->compareTo(other) >= 0;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool String::operator>=(const char* other) const {
+    return this->compareTo(other) >= 0;
+}
+
+////////////////////////////////////////////////////////////////////////////////
 String String::operator+ (const String& other) const {
     return this->concat(other);
 }
@@ -1477,4 +1522,52 @@ namespace lang {
         return out;
     }
 
+    bool operator==(const std::string& left, const String& right) {
+        return right.equals(left);
+    }
+
+    bool operator==(const char* left, const String& right) {
+        return right.equals(left);
+    }
+
+    bool operator!=(const std::string& left, const String& right) {
+        return !right.equals(left);
+    }
+
+    bool operator!=(const char* left, const String& right) {
+        return !right.equals(left);
+    }
+
+    bool operator< (const std::string& left, const String& right) {
+        return right.compareTo(left) > 0;
+    }
+
+    bool operator< (const char* left, const String& right) {
+        return right.compareTo(left) > 0;
+    }
+
+    bool operator<=(const std::string& left, const String& right) {
+        return right.compareTo(left) >= 0;
+    }
+
+    bool operator<=(const char* left, const String& right) {
+        return right.compareTo(left) >= 0;
+    }
+
+    bool operator> (const std::string& left, const String& right) {
+        return right.compareTo(left) < 0;
+    }
+
+    bool operator> (const char* left, const String& right) {
+        return right.compareTo(left) < 0;
+    }
+
+    bool operator>=(const std::string& left, const String& right) {
+        return right.compareTo(left) <= 0;
+    }
+
+    bool operator>=(const char* left, const String& right) {
+        return right.compareTo(left) <= 0;
+    }
+
 }}

http://git-wip-us.apache.org/repos/asf/activemq-cpp/blob/792d16f4/activemq-cpp/src/main/decaf/lang/String.h
----------------------------------------------------------------------
diff --git a/activemq-cpp/src/main/decaf/lang/String.h b/activemq-cpp/src/main/decaf/lang/String.h
index d2c3adf..121835c 100644
--- a/activemq-cpp/src/main/decaf/lang/String.h
+++ b/activemq-cpp/src/main/decaf/lang/String.h
@@ -232,7 +232,7 @@ namespace lang {
 
         /**
          * Comparison operators for the various string types that uses the compareTo method
-         * to determine the string are lexicographically equal or not.
+         * to determine if the string is lexicographically less than the other.
          *
          * @param other
          *      The string value to compare to this one.
@@ -244,6 +244,45 @@ namespace lang {
         bool operator< (const std::string& other) const;
 
         /**
+         * Comparison operators for the various string types that uses the compareTo method
+         * to determine if the string is lexicographically less than or equal to the other.
+         *
+         * @param other
+         *      The string value to compare to this one.
+         *
+         * @returns true if this string is lexicographically less than or equal to the other string.
+         */
+        bool operator<=(const char* other) const;
+        bool operator<=(const String& other) const;
+        bool operator<=(const std::string& other) const;
+
+        /**
+         * Comparison operators for the various string types that uses the compareTo method
+         * to determine if the string is lexicographically greater than the other.
+         *
+         * @param other
+         *      The string value to compare to this one.
+         *
+         * @returns true if this string is lexicographically greater than the other string.
+         */
+        bool operator> (const char* other) const;
+        bool operator> (const String& other) const;
+        bool operator> (const std::string& other) const;
+
+        /**
+         * Comparison operators for the various string types that uses the compareTo method
+         * to determine if the string is lexicographically greater than or equal to the other.
+         *
+         * @param other
+         *      The string value to compare to this one.
+         *
+         * @returns true if this string is lexicographically greater than the other string.
+         */
+        bool operator>=(const char* other) const;
+        bool operator>=(const String& other) const;
+        bool operator>=(const std::string& other) const;
+
+        /**
          * Concatenation operators for the various string types.  The value of this string
          * and the given string are concatenated and returned in a new String instance.
          *
@@ -1153,6 +1192,19 @@ namespace lang {
 
     std::ostream& operator<<(std::ostream &out, const String& target);
 
+    bool operator==(const std::string& left, const String& right);
+    bool operator==(const char* left, const String& right);
+    bool operator!=(const std::string& left, const String& right);
+    bool operator!=(const char* left, const String& right);
+    bool operator<=(const std::string& left, const String& right);
+    bool operator<=(const char* left, const String& right);
+    bool operator>=(const std::string& left, const String& right);
+    bool operator>=(const char* left, const String& right);
+    bool operator< (const std::string& left, const String& right);
+    bool operator< (const char* left, const String& right);
+    bool operator> (const std::string& left, const String& right);
+    bool operator> (const char* left, const String& right);
+
 }}
 
 #endif /* _DECAF_LANG_STRING_H_ */

http://git-wip-us.apache.org/repos/asf/activemq-cpp/blob/792d16f4/activemq-cpp/src/test/decaf/lang/StringTest.cpp
----------------------------------------------------------------------
diff --git a/activemq-cpp/src/test/decaf/lang/StringTest.cpp b/activemq-cpp/src/test/decaf/lang/StringTest.cpp
index c8e93fa..6a5734e 100644
--- a/activemq-cpp/src/test/decaf/lang/StringTest.cpp
+++ b/activemq-cpp/src/test/decaf/lang/StringTest.cpp
@@ -516,6 +516,40 @@ void StringTest::testEndsWith() {
 }
 
 ////////////////////////////////////////////////////////////////////////////////
+void StringTest::testEquals() {
+
+    String lower = "helloworld";
+    String lower2 = "helloworld";
+    String upper = "HELLOWORLD";
+
+    CPPUNIT_ASSERT_MESSAGE("lc version returned equal to uc", !lower.equals(upper));
+    CPPUNIT_ASSERT_MESSAGE("lc version returned unequal to lc", lower.equals(lower));
+    CPPUNIT_ASSERT_MESSAGE("lc version returned unequal to lc", lower.equals(lower2));
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void StringTest::testEqualsCString() {
+
+    String lower = "helloworld";
+    const char* lower2 = "helloworld";
+    const char* upper = "HELLOWORLD";
+
+    CPPUNIT_ASSERT_MESSAGE("lc version returned equal to uc", !lower.equals(upper));
+    CPPUNIT_ASSERT_MESSAGE("lc version returned unequal to lc", lower.equals(lower2));
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void StringTest::testEqualsStdString() {
+
+    String lower = "helloworld";
+    std::string lower2 = "helloworld";
+    std::string upper = "HELLOWORLD";
+
+    CPPUNIT_ASSERT_MESSAGE("lc version returned equal to uc", !lower.equals(upper));
+    CPPUNIT_ASSERT_MESSAGE("lc version returned unequal to lc", lower.equals(lower2));
+}
+
+////////////////////////////////////////////////////////////////////////////////
 void StringTest::testEqualsIgnoreCase() {
 
     String lower = "helloworld";
@@ -968,6 +1002,9 @@ void StringTest::testOperatorEqualsStdString() {
 
     CPPUNIT_ASSERT_MESSAGE("Failed comparison", input == std::string("HelloWorld"));
     CPPUNIT_ASSERT_MESSAGE("Failed comparison", !(input == std::string("HolloWorld")));
+
+    // Test comparison with lhs as std::string
+    CPPUNIT_ASSERT_MESSAGE("Failed comparison", std::string("HelloWorld") == input);
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -978,6 +1015,9 @@ void StringTest::testOperatorEqualsCString() {
     CPPUNIT_ASSERT_MESSAGE("Failed comparison", input == "HelloWorld");
     CPPUNIT_ASSERT_MESSAGE("Failed comparison", !(input == "HolloWorld"));
     CPPUNIT_ASSERT_MESSAGE("Failed comparison", !(input == NULL));
+
+    // Test comparison with lhs as C String
+    CPPUNIT_ASSERT_MESSAGE("Failed comparison", "HelloWorld" == input);
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -1026,6 +1066,10 @@ void StringTest::testOperatorLessStdString() {
 
     CPPUNIT_ASSERT_MESSAGE("Failed comparison", upper < lower);
     CPPUNIT_ASSERT_MESSAGE("Failed comparison", !(upper < std::string("HELLOWORLD")));
+
+    // test lhs as std::string
+    CPPUNIT_ASSERT_MESSAGE("Failed comparison", std::string("aaab") < String("aaac"));
+    CPPUNIT_ASSERT_MESSAGE("Failed comparison", std::string("aaab") <= String("aaab"));
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -1036,7 +1080,58 @@ void StringTest::testOperatorLessCString() {
 
     CPPUNIT_ASSERT_MESSAGE("Failed comparison", upper < lower);
     CPPUNIT_ASSERT_MESSAGE("Failed comparison", !(upper < "HELLOWORLD"));
-    CPPUNIT_ASSERT_MESSAGE("Failed comparison", !(upper < NULL));
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should have thrown a NullPointerException",
+        upper < NULL,
+        NullPointerException);
+
+    // test lhs as std::string
+    CPPUNIT_ASSERT_MESSAGE("Failed comparison", "aaab" < String("aaac"));
+    CPPUNIT_ASSERT_MESSAGE("Failed comparison", "aaab" <= String("aaab"));
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void StringTest::testOperatorGreaterString() {
+
+    String upper = "HELLOWORLD";
+    String lower = "helloworld";
+
+    CPPUNIT_ASSERT_MESSAGE("Failed comparison", lower > upper);
+    CPPUNIT_ASSERT_MESSAGE("Failed comparison", !(upper > upper));
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void StringTest::testOperatorGreaterStdString() {
+
+    std::string upper = "HELLOWORLD";
+    String lower = "helloworld";
+
+    CPPUNIT_ASSERT_MESSAGE("Failed comparison", lower > upper);
+    CPPUNIT_ASSERT_MESSAGE("Failed comparison", !(lower > std::string("helloworld")));
+
+    // test lhs as std::string
+    CPPUNIT_ASSERT_MESSAGE("Failed comparison", std::string("aaac") > String("aaab"));
+    CPPUNIT_ASSERT_MESSAGE("Failed comparison", std::string("aaac") >= String("aaac"));
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void StringTest::testOperatorGreaterCString() {
+
+    String lower = "helloworld";
+    const char* upper = "HELLOWORLD";
+
+    CPPUNIT_ASSERT_MESSAGE("Failed comparison", lower > upper);
+    CPPUNIT_ASSERT_MESSAGE("Failed comparison", !(lower > "helloworld"));
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should have thrown a NullPointerException",
+        lower < NULL,
+        NullPointerException);
+
+    // test lhs as C string
+    CPPUNIT_ASSERT_MESSAGE("Failed comparison", "aaac" > String("aaab"));
+    CPPUNIT_ASSERT_MESSAGE("Failed comparison", "aaac" >= String("aaac"));
 }
 
 ////////////////////////////////////////////////////////////////////////////////

http://git-wip-us.apache.org/repos/asf/activemq-cpp/blob/792d16f4/activemq-cpp/src/test/decaf/lang/StringTest.h
----------------------------------------------------------------------
diff --git a/activemq-cpp/src/test/decaf/lang/StringTest.h b/activemq-cpp/src/test/decaf/lang/StringTest.h
index 09d4c56..19c8ec9 100644
--- a/activemq-cpp/src/test/decaf/lang/StringTest.h
+++ b/activemq-cpp/src/test/decaf/lang/StringTest.h
@@ -53,6 +53,9 @@ namespace lang {
         CPPUNIT_TEST( testStartsWith );
         CPPUNIT_TEST( testStartsWithI );
         CPPUNIT_TEST( testEndsWith );
+        CPPUNIT_TEST( testEquals );
+        CPPUNIT_TEST( testEqualsCString );
+        CPPUNIT_TEST( testEqualsStdString );
         CPPUNIT_TEST( testEqualsIgnoreCase );
         CPPUNIT_TEST( testEqualsIgnoreCaseCString );
         CPPUNIT_TEST( testEqualsIgnoreCaseStdString );
@@ -91,6 +94,12 @@ namespace lang {
         CPPUNIT_TEST( testOperatorEqualsString );
         CPPUNIT_TEST( testOperatorEqualsStdString );
         CPPUNIT_TEST( testOperatorEqualsCString );
+        CPPUNIT_TEST( testOperatorLessString );
+        CPPUNIT_TEST( testOperatorLessStdString );
+        CPPUNIT_TEST( testOperatorLessCString );
+        CPPUNIT_TEST( testOperatorGreaterString );
+        CPPUNIT_TEST( testOperatorGreaterStdString );
+        CPPUNIT_TEST( testOperatorGreaterCString );
         CPPUNIT_TEST( testOperatorNotEqualsString );
         CPPUNIT_TEST( testOperatorNotEqualsStdString );
         CPPUNIT_TEST( testOperatorNotEqualsCString );
@@ -135,6 +144,9 @@ namespace lang {
         void testStartsWith();
         void testStartsWithI();
         void testEndsWith();
+        void testEquals();
+        void testEqualsCString();
+        void testEqualsStdString();
         void testEqualsIgnoreCase();
         void testEqualsIgnoreCaseCString();
         void testEqualsIgnoreCaseStdString();
@@ -183,6 +195,9 @@ namespace lang {
         void testOperatorLessString();
         void testOperatorLessStdString();
         void testOperatorLessCString();
+        void testOperatorGreaterString();
+        void testOperatorGreaterStdString();
+        void testOperatorGreaterCString();
         void testOperatorPlusString();
         void testOperatorPlusStdString();
         void testOperatorPlusCString();