Changeset 280:4ec36c3a04a3

Show
Ignore:
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
  • dwt/dwthelper/System.d

    r248 r280  
    148148        switch( key ){ 
    149149        case "os.name": return "linux"; 
     150        case "file.separator" : return "."; 
    150151        default: return null; 
    151152        } 
  • dwt/dwthelper/WeakHashMap.d

    r198 r280  
    11module dwt.dwthelper.WeakHashMap; 
     2 
     3 
     4private { 
     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} 
    29 
    310 
     
    1219            ptr = cast(size_t)cast(void*)k; 
    1320        } 
     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        } 
    1440    } 
    1541 
    1642    Object[ Ref ] data; 
     43    ClassInfo gcLock; 
     44    this(){ 
     45        unhookKey = new Ref(null); 
     46        gcLock = ClassInfo.find( "gcx.GCLock" ); 
     47    } 
    1748 
    18     public void add (Object key, Object element){ 
     49    public void put (Object key, Object element){ 
    1950        auto k = new Ref(key); 
     51        rt_attachDisposeEvent(key, &unhook); 
    2052        data[ k ] = element; 
    2153    } 
    22     public void removeKey (Object key){ 
     54    public void remove (Object key){ 
    2355        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        } 
    2560    } 
    2661    public Object get(Object key){ 
  • dwt/dwthelper/utils.d

    r277 r280  
    846846} 
    847847 
    848 interface Enumeration { 
    849     public bool hasMoreElements(); 
    850     public Object nextElement(); 
    851 } 
    852  
    853  
    854848template arraycast(T) { 
    855849    T[] arraycast(U) (U[] u) { 
     
    895889} 
    896890 
     891String[] 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 
     908T[] 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 
    897920 
    898921bool ArrayEquals(T)( T[] a, T[] b ){ 
     
    920943    } 
    921944    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     } 
    940945} 
    941946