Mercurial > projects > dwt-win
annotate dwt/dwthelper/System.d @ 84:00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Wed, 06 Feb 2008 18:46:23 +0100 |
parents | 39a9959ef14d |
children | 184ab53b7785 |
rev | line source |
---|---|
23 | 1 /** |
0 | 2 * Authors: Frank Benoit <keinfarbton@googlemail.com> |
3 */ | |
4 module dwt.dwthelper.System; | |
5 | |
6 import tango.core.Exception; | |
84
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
33
diff
changeset
|
7 import tango.time.Clock; |
33 | 8 import tango.stdc.stdlib : exit; |
0 | 9 |
10 template SimpleType(T) { | |
11 debug{ | |
12 static void validCheck(uint SrcLen, uint DestLen, uint copyLen){ | |
13 if(SrcLen < copyLen || DestLen < copyLen|| SrcLen < 0 || DestLen < 0){ | |
23 | 14 //Util.trace("Error : SimpleType.arraycopy(), out of bounds."); |
0 | 15 assert(0); |
16 } | |
17 } | |
18 } | |
19 | |
20 static void remove(inout T[] items, int index) { | |
21 if(items.length == 0) | |
22 return; | |
23 | |
24 if(index < 0 || index >= items.length){ | |
25 throw new ArrayBoundsException(__FILE__, __LINE__); | |
26 } | |
27 | |
28 T element = items[index]; | |
29 | |
30 int length = items.length; | |
31 if(length == 1){ | |
32 items.length = 0; | |
33 return;// element; | |
34 } | |
35 | |
36 if(index == 0) | |
37 items = items[1 .. $]; | |
38 else if(index == length - 1) | |
39 items = items[0 .. index]; | |
40 else | |
41 items = items[0 .. index] ~ items[index + 1 .. $]; | |
42 } | |
43 | |
44 static void insert(inout T[] items, T item, int index = -1) { | |
45 if(index == -1) | |
46 index = items.length; | |
47 | |
48 if(index < 0 || index > items.length ){ | |
49 throw new ArrayBoundsException(__FILE__, __LINE__); | |
50 } | |
51 | |
52 if(index == items.length){ | |
53 items ~= item; | |
54 }else if(index == 0){ | |
55 T[] newVect; | |
56 newVect ~= item; | |
57 items = newVect ~ items; | |
58 }else if(index < items.length ){ | |
59 T[] arr1 = items[0 .. index]; | |
60 T[] arr2 = items[index .. $]; | |
61 | |
62 // Important : if you write like the following commented, | |
63 // you get wrong data | |
64 // code: T[] arr1 = items[0..index]; | |
65 // T[] arr2 = items[index..$]; | |
66 // items = arr1 ~ item; // error, !!! | |
67 // items ~= arr2; // item replace the arrr2[0] here | |
68 items = arr1 ~ item ~ arr2; | |
69 } | |
70 } | |
71 | |
72 static void arraycopy(T[] src, uint srcPos, T[] dest, uint destPos, uint len) | |
73 { | |
74 if(len == 0) return; | |
75 | |
76 assert(src); | |
77 assert(dest); | |
78 debug{validCheck(src.length - srcPos, dest.length - destPos, len);} | |
79 | |
80 if(src is dest){ | |
81 for(int i=0; i<len; ++i){ | |
82 dest[destPos+i] = src[srcPos+i]; | |
83 } | |
84 }else{ | |
85 dest[destPos..(len+destPos)] = src[srcPos..(len+srcPos)]; | |
86 } | |
87 } | |
88 } | |
89 | |
90 | |
91 class System { | |
92 | |
93 alias SimpleType!(int).arraycopy arraycopy; | |
94 alias SimpleType!(byte).arraycopy arraycopy; | |
95 alias SimpleType!(double).arraycopy arraycopy; | |
96 alias SimpleType!(float).arraycopy arraycopy; | |
97 alias SimpleType!(short).arraycopy arraycopy; | |
98 alias SimpleType!(long).arraycopy arraycopy; | |
99 alias SimpleType!(uint).arraycopy arraycopy; | |
100 alias SimpleType!(ushort).arraycopy arraycopy; | |
101 alias SimpleType!(ubyte).arraycopy arraycopy; | |
102 alias SimpleType!(ulong).arraycopy arraycopy; | |
103 alias SimpleType!(char).arraycopy arraycopy; | |
104 alias SimpleType!(wchar).arraycopy arraycopy; | |
105 alias SimpleType!(Object).arraycopy arraycopy; | |
106 alias SimpleType!(void*).arraycopy arraycopy; | |
107 | |
108 alias SimpleType!(int[]).arraycopy arraycopy; | |
109 alias SimpleType!(byte[]).arraycopy arraycopy; | |
110 alias SimpleType!(double[]).arraycopy arraycopy; | |
111 alias SimpleType!(float[]).arraycopy arraycopy; | |
112 alias SimpleType!(short[]).arraycopy arraycopy; | |
113 alias SimpleType!(long[]).arraycopy arraycopy; | |
114 alias SimpleType!(uint[]).arraycopy arraycopy; | |
115 alias SimpleType!(ushort[]).arraycopy arraycopy; | |
116 alias SimpleType!(ubyte[]).arraycopy arraycopy; | |
117 alias SimpleType!(ulong[]).arraycopy arraycopy; | |
118 alias SimpleType!(char[]).arraycopy arraycopy; | |
119 alias SimpleType!(wchar[]).arraycopy arraycopy; | |
120 alias SimpleType!(Object[]).arraycopy arraycopy; | |
121 alias SimpleType!(void*[]).arraycopy arraycopy; | |
122 alias SimpleType!(void*[]).arraycopy arraycopy; | |
123 | |
124 static long currentTimeMillis(){ | |
84
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
33
diff
changeset
|
125 return Clock.now().ticks() / 10000; |
0 | 126 } |
127 | |
33 | 128 static void exit( int code ){ |
129 .exit(code); | |
130 } | |
131 | |
0 | 132 } |
133 |