comparison dwt/dwthelper/utils.d @ 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 4ec36c3a04a3
children 98fd89730a00
comparison
equal deleted inserted replaced
281:617fdf42394b 282:92e785261f30
39 class ArrayWrapperT(T) : ArrayWrapper { 39 class ArrayWrapperT(T) : ArrayWrapper {
40 public T[] array; 40 public T[] array;
41 public this( T[] data ){ 41 public this( T[] data ){
42 array = data; 42 array = data;
43 } 43 }
44 public override int opEquals( Object o ){
45 if( auto other = cast(ArrayWrapperT!(T))o){
46 return array == other.array;
47 }
48 return false;
49 }
50 public override hash_t toHash(){
51 return (typeid(T[])).getHash(&array);
52 }
44 } 53 }
45 54
46 class ValueWrapperT(T) : ValueWrapper { 55 class ValueWrapperT(T) : ValueWrapper {
47 public T value; 56 public T value;
48 public this( T data ){ 57 public this( T data ){
49 value = data; 58 value = data;
50 } 59 }
51 public int opEquals( T other ){ 60 static if( is(T==class) || is(T==interface)){
52 return value == other; 61 public int opEquals( Object other ){
53 } 62 if( auto o = cast(ValueWrapperT!(T))other ){
54 public int opEquals( Object other ){ 63 return value == o.value;
55 if( auto o = cast(ValueWrapperT!(T))other ){ 64 }
56 return value == o.value; 65 if( auto o = cast(T)other ){
57 } 66 if( value is o ){
58 return false; 67 return true;
68 }
69 if( value is null || o is null ){
70 return false;
71 }
72 return value == o;
73 }
74 return false;
75 }
76 }
77 else{
78 public int opEquals( Object other ){
79 if( auto o = cast(ValueWrapperT!(T))other ){
80 return value == o.value;
81 }
82 return false;
83 }
84 public int opEquals( T other ){
85 return value == other;
86 }
87 }
88 public override hash_t toHash(){
89 return (typeid(T)).getHash(&value);
59 } 90 }
60 } 91 }
61 92
62 class Boolean : ValueWrapperT!(bool) { 93 class Boolean : ValueWrapperT!(bool) {
63 public static Boolean TRUE; 94 public static Boolean TRUE;