activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r1460470 - /activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/HashCode.h
Date Sun, 24 Mar 2013 21:35:00 GMT
Author: tabish
Date: Sun Mar 24 21:35:00 2013
New Revision: 1460470

URL: http://svn.apache.org/r1460470
Log:
Refined hash code templates.

Modified:
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/HashCode.h

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/HashCode.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/HashCode.h?rev=1460470&r1=1460469&r2=1460470&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/HashCode.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/HashCode.h Sun Mar 24 21:35:00
2013
@@ -47,23 +47,37 @@ namespace util {
      * @since 1.0
      */
     template<typename T>
-    struct HashCode : HashCodeUnaryBase<T> {
+    struct HashCode : HashCodeUnaryBase<const T&> {
     public:
+        int operator()(const T& arg) const {
+            return arg.getHashCode();
+        }
+    };
 
-        int operator()(T arg) const;
+    template<typename T>
+    struct HashCode<const T> : HashCodeUnaryBase<const T&> {
+        int operator()(const T& arg) const {
+            return arg.getHashCode();
+        }
     };
 
     template<typename T>
-    struct HashCode<T*> : public HashCodeUnaryBase<T*> {
-        int operator()(T* arg)  const {
-            return reinterpret_cast<int>(arg);
+    struct HashCode<T*> : public HashCodeUnaryBase<const T*> {
+        int operator()(const T* arg) const {
+            if (arg != NULL) {
+                return arg->getHashCode();
+            }
+            return 0;
         }
     };
 
     template<typename T>
-    struct HashCode<const T&> : HashCodeUnaryBase<const T&> {
-        int operator()(const T& arg) const {
-            return HashCode<const T*>(&arg);
+    struct HashCode<const T*> : public HashCodeUnaryBase<const T*> {
+        int operator()(const T* arg) const {
+            if (arg != NULL) {
+                return arg->getHashCode();
+            }
+            return 0;
         }
     };
 
@@ -168,11 +182,25 @@ namespace util {
         }
     };
 
+    template<>
+    struct HashCode<const std::string> : public HashCodeUnaryBase<const std::string&>
{
+        int operator()(const std::string& arg) const {
+            int h = 0;
+            if (h == 0 && arg.length() > 0) {
+                std::string::const_iterator iter = arg.begin();
+                for (; iter != arg.end(); ++iter) {
+                    h = 31 * h + (*iter);
+                }
+            }
+            return h;
+        }
+    };
+
     template<typename T>
     struct HashCode< decaf::lang::Pointer<T> > : public HashCodeUnaryBase<decaf::lang::Pointer<T>
> {
         int operator()(decaf::lang::Pointer<T> arg) const {
             if (arg != NULL) {
-                return HashCode<T>()(*arg);
+                return HashCode<const T>()(*arg);
             }
             return 0;
         }



Mime
View raw message