Changeset 280:4ec36c3a04a3
- Timestamp:
- 08/07/08 09:06:52
(4 months ago)
- Author:
- Frank Benoit <benoit@tionex.de>
- branch:
- default
- Message:
sync with dwt-linux
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r248 |
r280 |
|
| 148 | 148 | switch( key ){ |
|---|
| 149 | 149 | case "os.name": return "linux"; |
|---|
| | 150 | case "file.separator" : return "."; |
|---|
| 150 | 151 | default: return null; |
|---|
| 151 | 152 | } |
|---|
| r198 |
r280 |
|
| 1 | 1 | module dwt.dwthelper.WeakHashMap; |
|---|
| | 2 | |
|---|
| | 3 | |
|---|
| | 4 | private { |
|---|
| | 5 | alias void delegate(Object) DisposeEvt; |
|---|
| | 6 | extern (C) void rt_attachDisposeEvent( Object obj, DisposeEvt evt ); |
|---|
| | 7 | extern (C) void rt_detachDisposeEvent( Object obj, DisposeEvt evt ); |
|---|
| | 8 | } |
|---|
| 2 | 9 | |
|---|
| 3 | 10 | |
|---|
| … | … | |
| 12 | 19 | ptr = cast(size_t)cast(void*)k; |
|---|
| 13 | 20 | } |
|---|
| | 21 | override hash_t toHash(){ |
|---|
| | 22 | return cast(hash_t)ptr; |
|---|
| | 23 | } |
|---|
| | 24 | override int opEquals( Object o ){ |
|---|
| | 25 | if( auto other = cast(Ref)o ){ |
|---|
| | 26 | return ptr is other.ptr; |
|---|
| | 27 | } |
|---|
| | 28 | return false; |
|---|
| | 29 | } |
|---|
| | 30 | } |
|---|
| | 31 | |
|---|
| | 32 | private Ref unhookKey; |
|---|
| | 33 | |
|---|
| | 34 | private void unhook(Object o) { |
|---|
| | 35 | unhookKey.ptr = cast(size_t)cast(void*)o; |
|---|
| | 36 | if( auto p = unhookKey in data ){ |
|---|
| | 37 | rt_detachDisposeEvent(o, &unhook); |
|---|
| | 38 | data.remove( unhookKey ); |
|---|
| | 39 | } |
|---|
| 14 | 40 | } |
|---|
| 15 | 41 | |
|---|
| 16 | 42 | Object[ Ref ] data; |
|---|
| | 43 | ClassInfo gcLock; |
|---|
| | 44 | this(){ |
|---|
| | 45 | unhookKey = new Ref(null); |
|---|
| | 46 | gcLock = ClassInfo.find( "gcx.GCLock" ); |
|---|
| | 47 | } |
|---|
| 17 | 48 | |
|---|
| 18 | | public void add (Object key, Object element){ |
|---|
| | 49 | public void put (Object key, Object element){ |
|---|
| 19 | 50 | auto k = new Ref(key); |
|---|
| | 51 | rt_attachDisposeEvent(key, &unhook); |
|---|
| 20 | 52 | data[ k ] = element; |
|---|
| 21 | 53 | } |
|---|
| 22 | | public void removeKey (Object key){ |
|---|
| | 54 | public void remove (Object key){ |
|---|
| 23 | 55 | scope k = new Ref(key); |
|---|
| 24 | | data.remove( k ); |
|---|
| | 56 | if( auto p = k in data ){ |
|---|
| | 57 | data.remove( k ); |
|---|
| | 58 | rt_detachDisposeEvent(key, &unhook); |
|---|
| | 59 | } |
|---|
| 25 | 60 | } |
|---|
| 26 | 61 | public Object get(Object key){ |
|---|
| r277 |
r280 |
|
| 846 | 846 | } |
|---|
| 847 | 847 | |
|---|
| 848 | | interface Enumeration { |
|---|
| 849 | | public bool hasMoreElements(); |
|---|
| 850 | | public Object nextElement(); |
|---|
| 851 | | } |
|---|
| 852 | | |
|---|
| 853 | | |
|---|
| 854 | 848 | template arraycast(T) { |
|---|
| 855 | 849 | T[] arraycast(U) (U[] u) { |
|---|
| … | … | |
| 895 | 889 | } |
|---|
| 896 | 890 | |
|---|
| | 891 | String[] stringArrayFromObject( Object obj ){ |
|---|
| | 892 | if( auto wrapper = cast(ArrayWrapperString2)obj ){ |
|---|
| | 893 | return wrapper.array; |
|---|
| | 894 | } |
|---|
| | 895 | if( auto wrapper = cast(ArrayWrapperObject)obj ){ |
|---|
| | 896 | String[] res = new String[ wrapper.array.length ]; |
|---|
| | 897 | foreach( idx, o; wrapper.array ){ |
|---|
| | 898 | if( auto swrapper = cast(ArrayWrapperString) o ){ |
|---|
| | 899 | res[idx] = swrapper.array; |
|---|
| | 900 | } |
|---|
| | 901 | } |
|---|
| | 902 | return res; |
|---|
| | 903 | } |
|---|
| | 904 | assert( obj is null ); // if not null, it was the wrong type |
|---|
| | 905 | return null; |
|---|
| | 906 | } |
|---|
| | 907 | |
|---|
| | 908 | T[] arrayFromObject(T)( Object obj ){ |
|---|
| | 909 | if( auto wrapper = cast(ArrayWrapperObject)obj ){ |
|---|
| | 910 | T[] res = new T[ wrapper.array.length ]; |
|---|
| | 911 | foreach( idx, o; wrapper.array ){ |
|---|
| | 912 | res[idx] = cast(T)o; |
|---|
| | 913 | } |
|---|
| | 914 | return res; |
|---|
| | 915 | } |
|---|
| | 916 | assert( obj is null ); // if not null, it was the wrong type |
|---|
| | 917 | return null; |
|---|
| | 918 | } |
|---|
| | 919 | |
|---|
| 897 | 920 | |
|---|
| 898 | 921 | bool ArrayEquals(T)( T[] a, T[] b ){ |
|---|
| … | … | |
| 920 | 943 | } |
|---|
| 921 | 944 | return true; |
|---|
| 922 | | } |
|---|
| 923 | | |
|---|
| 924 | | class Arrays{ |
|---|
| 925 | | public static bool equals(Object[] a, Object[] b){ |
|---|
| 926 | | if( a.length !is b.length ){ |
|---|
| 927 | | return false; |
|---|
| 928 | | } |
|---|
| 929 | | for( int i = 0; i < a.length; i++ ){ |
|---|
| 930 | | if( a[i] is null && b[i] is null ){ |
|---|
| 931 | | continue; |
|---|
| 932 | | } |
|---|
| 933 | | if( a[i] !is null && b[i] !is null && a[i] == b[i] ){ |
|---|
| 934 | | continue; |
|---|
| 935 | | } |
|---|
| 936 | | return false; |
|---|
| 937 | | } |
|---|
| 938 | | return true; |
|---|
| 939 | | } |
|---|
| 940 | 945 | } |
|---|
| 941 | 946 | |
|---|