comparison dwt/dwthelper/WeakRef.d @ 7:e831403a80a9

Add 'cast' to casts
author Frank Benoit <benoit@tionex.de>
date Wed, 27 Aug 2008 14:30:35 +0200
parents 380af2bdd8e5
children 30a762abda2a
comparison
equal deleted inserted replaced
6:b903c16b6f48 7:e831403a80a9
18 * Usage example: 18 * Usage example:
19 --- 19 ---
20 class Something {} 20 class Something {}
21 21
22 auto a = new Something(); 22 auto a = new Something();
23 auto wa = new WeakRef!(Something)(a); 23 auto wa = new WeakRef!cast(Something)(a);
24 std.gc.fullCollect(); 24 std.gc.fullCollect();
25 25
26 // Reference 'a' prevents collection so wa.ptr is non-null 26 // Reference 'a' prevents collection so wa.ptr is non-null
27 assert(wa.ptr is a); 27 assert(wa.ptr is a);
28 28
34 * 34 *
35 * 35 *
36 * Author: William V. Baxter III 36 * Author: William V. Baxter III
37 * Contributors: 37 * Contributors:
38 * Date: 21 Jan 2008 38 * Date: 21 Jan 2008
39 * Copyright: (C) 2008 William Baxter 39 * Copyright: cast(C) 2008 William Baxter
40 * License: Public Domain where allowed by law, ZLIB/PNG otherwise. 40 * License: Public Domain where allowed by law, ZLIB/PNG otherwise.
41 */ 41 */
42 //=========================================================================== 42 //===========================================================================
43 43
44 module dwt.dwthelper.WeakRef; 44 module dwt.dwthelper.WeakRef;
45 45
46 private { 46 private {
47 alias void delegate(Object) DisposeEvt; 47 alias void delegate(Object) DisposeEvt;
48 extern (C) void rt_attachDisposeEvent( Object obj, DisposeEvt evt ); 48 extern cast(C) void rt_attachDisposeEvent( Object obj, DisposeEvt evt );
49 extern (C) void rt_detachDisposeEvent( Object obj, DisposeEvt evt ); 49 extern cast(C) void rt_detachDisposeEvent( Object obj, DisposeEvt evt );
50 } 50 }
51 51
52 class WeakRef(T : Object) { 52 class WeakRef(T : Object) {
53 private: 53 private:
54 size_t cast_ptr_; 54 size_t cast_ptr_;
75 } 75 }
76 WeakRef dup() { 76 WeakRef dup() {
77 return new WeakRef(ptr()); 77 return new WeakRef(ptr());
78 } 78 }
79 int opEquals( Object o ){ 79 int opEquals( Object o ){
80 if( auto other = cast( WeakRef!(T) )o ){ 80 if( auto other = cast( WeakRef!cast(T) )o ){
81 return other.cast_ptr_ is cast_ptr_; 81 return other.cast_ptr_ is cast_ptr_;
82 } 82 }
83 return false; 83 return false;
84 } 84 }
85 hash_t toHash(){ 85 hash_t toHash(){