changeset 297:2f204a4aebc6

Fix: missing opEquals, toHash for ArrayWrapper. Fix: opEquals for ValueWrapper in case of T is Object
author Frank Benoit <benoit@tionex.de>
date Fri, 08 Aug 2008 15:25:08 +0200
parents e1dd8f5bc6ef
children eec6ddb07873 1e93ff891d85
files dwt/dwthelper/utils.d
diffstat 1 files changed, 37 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/dwt/dwthelper/utils.d	Thu Aug 07 21:34:21 2008 +0200
+++ b/dwt/dwthelper/utils.d	Fri Aug 08 15:25:08 2008 +0200
@@ -41,6 +41,15 @@
     public this( T[] data ){
         array = data;
     }
+    public override int opEquals( Object o ){
+        if( auto other = cast(ArrayWrapperT!(T))o){
+            return array == other.array;
+        }
+        return false;
+    }
+    public override hash_t toHash(){
+        return (typeid(T[])).getHash(&array);
+    }
 }
 
 class ValueWrapperT(T) : ValueWrapper {
@@ -48,14 +57,36 @@
     public this( T data ){
         value = data;
     }
-    public int opEquals( T other ){
-        return value == other;
+    static if( is(T==class) || is(T==interface)){
+        public int opEquals( Object other ){
+            if( auto o = cast(ValueWrapperT!(T))other ){
+                return value == o.value;
+            }
+            if( auto o = cast(T)other ){
+                if( value is o ){
+                    return true;
+                }
+                if( value is null || o is null ){
+                    return false;
+                }
+                return value == o;
+            }
+            return false;
+        }
     }
-    public int opEquals( Object other ){
-        if( auto o = cast(ValueWrapperT!(T))other ){
-            return value == o.value;
+    else{
+        public int opEquals( Object other ){
+            if( auto o = cast(ValueWrapperT!(T))other ){
+                return value == o.value;
+            }
+            return false;
         }
-        return false;
+        public int opEquals( T other ){
+            return value == other;
+        }
+    }
+    public override hash_t toHash(){
+        return (typeid(T)).getHash(&value);
     }
 }