Mercurial > projects > dwt2
annotate base/src/java/lang/util.d @ 39:0ecb2b338560
further work on phobosification
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Wed, 25 Mar 2009 13:20:43 +0100 |
parents | 2e09b0e6857a |
children | ed96ea2a2764 |
rev | line source |
---|---|
0
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
1 module java.lang.util; |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
2 |
21
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
3 public import java.lang.wrappers; |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
4 public import java.lang.String; |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
5 public import java.lang.interfaces; |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
6 |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
7 version(Tango){ |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
8 static import tango.text.convert.Format; |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
9 static import tango.core.Exception; |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
10 static import tango.util.log.Log; |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
11 static import tango.stdc.stdlib; |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
12 |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
13 alias tango.stdc.stdlib.exit exit; |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
14 } else { // Phobos |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
15 static import core.exception; |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
16 static import std.c.stdlib; |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
17 alias std.c.stdlib.exit exit; |
0
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
18 } |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
19 |
21
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
20 version(Tango){ |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
21 } else { // Phobos |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
22 } |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
23 version(Tango){ |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
24 } else { // Phobos |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
25 } |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
26 version(Tango){ |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
27 } else { // Phobos |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
28 } |
18
735224fcc45f
redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents:
9
diff
changeset
|
29 |
735224fcc45f
redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents:
9
diff
changeset
|
30 interface IDwtLogger { |
735224fcc45f
redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents:
9
diff
changeset
|
31 void trace( String file, ulong line, String fmt, ... ); |
735224fcc45f
redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents:
9
diff
changeset
|
32 void info( String file, ulong line, String fmt, ... ); |
735224fcc45f
redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents:
9
diff
changeset
|
33 void warn( String file, ulong line, String fmt, ... ); |
735224fcc45f
redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents:
9
diff
changeset
|
34 void error( String file, ulong line, String fmt, ... ); |
735224fcc45f
redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents:
9
diff
changeset
|
35 void fatal( String file, ulong line, String fmt, ... ); |
735224fcc45f
redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents:
9
diff
changeset
|
36 } |
735224fcc45f
redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents:
9
diff
changeset
|
37 |
21
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
38 version(Tango){ |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
39 class DwtLogger : IDwtLogger { |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
40 tango.util.log.Log.Logger logger; |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
41 private this( char[] name ){ |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
42 logger = tango.util.log.Log.Log.lookup( name ); |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
43 } |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
44 private char[] format( String file, ulong line, String fmt, TypeInfo[] types, void* argptr ){ |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
45 auto msg = Format.convert( types, argptr, fmt ); |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
46 auto text = Format( "{} {}: {}", file, line, msg ); |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
47 return text; |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
48 } |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
49 void trace( String file, ulong line, String fmt, ... ){ |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
50 if( logger.trace ){ |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
51 logger.trace( format( file, line, fmt, _arguments, _argptr )); |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
52 } |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
53 } |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
54 void info( String file, ulong line, String fmt, ... ){ |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
55 if( logger.info ){ |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
56 logger.info( format( file, line, fmt, _arguments, _argptr )); |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
57 } |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
58 } |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
59 void warn( String file, ulong line, String fmt, ... ){ |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
60 if( logger.warn ){ |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
61 logger.warn( format( file, line, fmt, _arguments, _argptr )); |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
62 } |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
63 } |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
64 void error( String file, ulong line, String fmt, ... ){ |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
65 if( logger.error ){ |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
66 logger.error( format( file, line, fmt, _arguments, _argptr )); |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
67 } |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
68 } |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
69 void fatal( String file, ulong line, String fmt, ... ){ |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
70 if( logger.fatal ){ |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
71 logger.fatal( format( file, line, fmt, _arguments, _argptr )); |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
72 } |
18
735224fcc45f
redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents:
9
diff
changeset
|
73 } |
735224fcc45f
redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents:
9
diff
changeset
|
74 } |
21
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
75 } else { // Phobos |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
76 class DwtLogger : IDwtLogger { |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
77 private this( String name ){ |
18
735224fcc45f
redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents:
9
diff
changeset
|
78 } |
21
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
79 void trace( String file, ulong line, String fmt, ... ){ |
18
735224fcc45f
redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents:
9
diff
changeset
|
80 } |
21
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
81 void info( String file, ulong line, String fmt, ... ){ |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
82 } |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
83 void warn( String file, ulong line, String fmt, ... ){ |
18
735224fcc45f
redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents:
9
diff
changeset
|
84 } |
21
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
85 void error( String file, ulong line, String fmt, ... ){ |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
86 } |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
87 void fatal( String file, ulong line, String fmt, ... ){ |
18
735224fcc45f
redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents:
9
diff
changeset
|
88 } |
735224fcc45f
redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents:
9
diff
changeset
|
89 } |
735224fcc45f
redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents:
9
diff
changeset
|
90 } |
735224fcc45f
redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents:
9
diff
changeset
|
91 |
735224fcc45f
redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents:
9
diff
changeset
|
92 private DwtLogger dwtLoggerInstance; |
735224fcc45f
redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents:
9
diff
changeset
|
93 |
735224fcc45f
redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents:
9
diff
changeset
|
94 IDwtLogger getDwtLogger(){ |
735224fcc45f
redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents:
9
diff
changeset
|
95 if( dwtLoggerInstance is null ){ |
735224fcc45f
redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents:
9
diff
changeset
|
96 synchronized{ |
735224fcc45f
redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents:
9
diff
changeset
|
97 if( dwtLoggerInstance is null ){ |
735224fcc45f
redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents:
9
diff
changeset
|
98 dwtLoggerInstance = new DwtLogger( "dwt" ); |
735224fcc45f
redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents:
9
diff
changeset
|
99 } |
735224fcc45f
redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents:
9
diff
changeset
|
100 } |
735224fcc45f
redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents:
9
diff
changeset
|
101 } |
735224fcc45f
redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents:
9
diff
changeset
|
102 return dwtLoggerInstance; |
0
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
103 } |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
104 |
21
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
105 void implMissing( String file, uint line ){ |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
106 getDwtLogger().fatal( file, line, "implementation missing in file {} line {}", file, line ); |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
107 getDwtLogger().fatal( file, line, "Please create a bug report at http://www.dsource.org/projects/dwt" ); |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
108 getDwtLogger().fatal( file, line, "exiting ..." ); |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
109 exit(1); |
0
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
110 } |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
111 |
21
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
112 version(Tango){ |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
113 public alias tango.text.convert.Format.Format Format; |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
114 } else { // Phobos |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
115 class Format{ |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
116 static String opCall( String fmt, ... ){ |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
117 implMissing(__FILE__,__LINE__); |
9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents:
18
diff
changeset
|
118 return null; |
0
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
119 } |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
120 } |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
121 } |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
122 |
38 | 123 version( D_Version2 ){ |
39
0ecb2b338560
further work on phobosification
Frank Benoit <benoit@tionex.de>
parents:
38
diff
changeset
|
124 mixin("invariant(T)[] _idup(T)( T[] str ){ return str.idup; }"); |
38 | 125 } else { // D1 |
39
0ecb2b338560
further work on phobosification
Frank Benoit <benoit@tionex.de>
parents:
38
diff
changeset
|
126 String16 _idup( String16 str ){ |
38 | 127 return str.dup; |
128 } | |
39
0ecb2b338560
further work on phobosification
Frank Benoit <benoit@tionex.de>
parents:
38
diff
changeset
|
129 String _idup( String str ){ |
38 | 130 return str.dup; |
131 } | |
132 } | |
0
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
133 |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
134 private struct GCStats { |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
135 size_t poolsize; // total size of pool |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
136 size_t usedsize; // bytes allocated |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
137 size_t freeblocks; // number of blocks marked FREE |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
138 size_t freelistsize; // total of memory on free lists |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
139 size_t pageblocks; // number of blocks marked PAGE |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
140 } |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
141 private extern(C) GCStats gc_stats(); |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
142 |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
143 size_t RuntimeTotalMemory(){ |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
144 GCStats s = gc_stats(); |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
145 return s.poolsize; |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
146 } |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
147 |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
148 |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
149 template arraycast(T) { |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
150 T[] arraycast(U) (U[] u) { |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
151 static if ( |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
152 (is (T == interface ) && is (U == interface )) || |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
153 (is (T == class ) && is (U == class ))) { |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
154 return(cast(T[])u); |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
155 } |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
156 else { |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
157 int l = u.length; |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
158 T[] res; |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
159 res.length = l; |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
160 for (int i = 0; i < l; i++) { |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
161 res[i] = cast(T)u[i]; |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
162 } |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
163 return(res); |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
164 } |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
165 } |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
166 } |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
167 |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
168 |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
169 bool ArrayEquals(T)( T[] a, T[] b ){ |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
170 if( a.length !is b.length ){ |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
171 return false; |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
172 } |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
173 for( int i = 0; i < a.length; i++ ){ |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
174 static if( is( T==class) || is(T==interface)){ |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
175 if( a[i] !is null && b[i] !is null ){ |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
176 if( a[i] != b[i] ){ |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
177 return false; |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
178 } |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
179 } |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
180 else if( a[i] is null && b[i] is null ){ |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
181 } |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
182 else{ |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
183 return false; |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
184 } |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
185 } |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
186 else{ |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
187 if( a[i] != b[i] ){ |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
188 return false; |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
189 } |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
190 } |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
191 } |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
192 return true; |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
193 } |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
194 |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
195 int arrayIndexOf(T)( T[] arr, T v ){ |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
196 int res = -1; |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
197 int idx = 0; |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
198 foreach( p; arr ){ |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
199 if( p == v){ |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
200 res = idx; |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
201 break; |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
202 } |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
203 idx++; |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
204 } |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
205 return res; |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
206 } |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
207 |
25 | 208 T[] arrayIndexRemove(T)(T[] arr, uint n) { |
209 if (n is 0) | |
210 return arr[1..$]; | |
211 if (n > arr.length) | |
212 return arr; | |
213 if (n is arr.length-1) | |
214 return arr[0..n-1]; | |
215 // else | |
216 return arr[0..n] ~ arr[n+1..$]; | |
217 } | |
0
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
218 |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
219 struct ImportData{ |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
220 void[] data; |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
221 String name; |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
222 |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
223 public static ImportData opCall( void[] data, String name ){ |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
224 ImportData res; |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
225 res.data = data; |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
226 res.name = name; |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
227 return res; |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
228 } |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
229 } |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
230 |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
231 template getImportData(String name ){ |
38 | 232 const ImportData getImportData = ImportData( cast(void[]) import(name), name ); |
0
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
233 } |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
234 |
6dd524f61e62
add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
235 |