changeset 282:92e785261f30

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:19:05 +0200
parents 617fdf42394b
children 98fd89730a00 bb89fd34ec82
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 15:07:17 2008 +0200
+++ b/dwt/dwthelper/utils.d	Fri Aug 08 15:19:05 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);
     }
 }