annotate base/src/java/lang/util.d @ 44:ed96ea2a2764

First swt win snippets are buiding with d2+phobos
author Frank Benoit <benoit@tionex.de>
date Wed, 25 Mar 2009 18:31:01 +0100
parents 0ecb2b338560
children 8939451abc39
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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;
44
ed96ea2a2764 First swt win snippets are buiding with d2+phobos
Frank Benoit <benoit@tionex.de>
parents: 39
diff changeset
17 static import std.stdio;
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
18 alias std.c.stdlib.exit exit;
0
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
19 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
20
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
21 version(Tango){
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
22 } else { // Phobos
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
23 }
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
24 version(Tango){
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
25 } else { // Phobos
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
26 }
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
27 version(Tango){
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
28 } else { // Phobos
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
29 }
18
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
30
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
31 interface IDwtLogger {
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
32 void trace( String file, ulong line, String fmt, ... );
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
33 void info( String file, ulong line, String fmt, ... );
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
34 void warn( String file, ulong line, String fmt, ... );
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
35 void error( String file, ulong line, String fmt, ... );
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
36 void fatal( String file, ulong line, String fmt, ... );
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
37 }
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
38
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
39 version(Tango){
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
40 class DwtLogger : IDwtLogger {
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
41 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
42 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
43 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
44 }
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
45 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
46 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
47 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
48 return text;
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
49 }
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
50 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
51 if( logger.trace ){
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
52 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
53 }
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
54 }
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
55 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
56 if( logger.info ){
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
57 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
58 }
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
59 }
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
60 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
61 if( logger.warn ){
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
62 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
63 }
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
64 }
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
65 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
66 if( logger.error ){
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
67 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
68 }
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
69 }
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
70 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
71 if( logger.fatal ){
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
72 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
73 }
18
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
74 }
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
75 }
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
76 } else { // Phobos
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
77 class DwtLogger : IDwtLogger {
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
78 private this( String name ){
18
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
79 }
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
80 void trace( String file, ulong line, String fmt, ... ){
44
ed96ea2a2764 First swt win snippets are buiding with d2+phobos
Frank Benoit <benoit@tionex.de>
parents: 39
diff changeset
81 std.stdio.writefln( "TRC %s %d: %s", file, line, fmt );
18
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
82 }
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
83 void info( String file, ulong line, String fmt, ... ){
44
ed96ea2a2764 First swt win snippets are buiding with d2+phobos
Frank Benoit <benoit@tionex.de>
parents: 39
diff changeset
84 std.stdio.writefln( "INF %s %d: %s", file, line, fmt );
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
85 }
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
86 void warn( String file, ulong line, String fmt, ... ){
44
ed96ea2a2764 First swt win snippets are buiding with d2+phobos
Frank Benoit <benoit@tionex.de>
parents: 39
diff changeset
87 std.stdio.writefln( "WRN %s %d: %s", file, line, fmt );
18
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
88 }
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
89 void error( String file, ulong line, String fmt, ... ){
44
ed96ea2a2764 First swt win snippets are buiding with d2+phobos
Frank Benoit <benoit@tionex.de>
parents: 39
diff changeset
90 std.stdio.writefln( "ERR %s %d: %s", file, line, fmt );
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
91 }
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
92 void fatal( String file, ulong line, String fmt, ... ){
44
ed96ea2a2764 First swt win snippets are buiding with d2+phobos
Frank Benoit <benoit@tionex.de>
parents: 39
diff changeset
93 std.stdio.writefln( "FAT %s %d: %s", file, line, fmt );
18
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
94 }
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
95 }
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
96 }
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
97
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
98 private DwtLogger dwtLoggerInstance;
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 IDwtLogger getDwtLogger(){
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
101 if( dwtLoggerInstance is null ){
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
102 synchronized{
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
103 if( dwtLoggerInstance is null ){
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
104 dwtLoggerInstance = new DwtLogger( "dwt" );
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
105 }
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
106 }
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
107 }
735224fcc45f redirected all printings to DwtLogger
Frank Benoit <benoit@tionex.de>
parents: 9
diff changeset
108 return dwtLoggerInstance;
0
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
109 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
110
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
111 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
112 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
113 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
114 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
115 exit(1);
0
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
116 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
117
21
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
118 version(Tango){
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
119 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
120 } else { // Phobos
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
121 class Format{
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
122 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
123 implMissing(__FILE__,__LINE__);
9b96950f2c3c the 'java' tree compiles on both D1-Tango and D2-Phobos
Frank Benoit <benoit@tionex.de>
parents: 18
diff changeset
124 return null;
0
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
125 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
126 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
127 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
128
38
2e09b0e6857a work on phobosfication
Frank Benoit <benoit@tionex.de>
parents: 27
diff changeset
129 version( D_Version2 ){
39
0ecb2b338560 further work on phobosification
Frank Benoit <benoit@tionex.de>
parents: 38
diff changeset
130 mixin("invariant(T)[] _idup(T)( T[] str ){ return str.idup; }");
38
2e09b0e6857a work on phobosfication
Frank Benoit <benoit@tionex.de>
parents: 27
diff changeset
131 } else { // D1
39
0ecb2b338560 further work on phobosification
Frank Benoit <benoit@tionex.de>
parents: 38
diff changeset
132 String16 _idup( String16 str ){
38
2e09b0e6857a work on phobosfication
Frank Benoit <benoit@tionex.de>
parents: 27
diff changeset
133 return str.dup;
2e09b0e6857a work on phobosfication
Frank Benoit <benoit@tionex.de>
parents: 27
diff changeset
134 }
39
0ecb2b338560 further work on phobosification
Frank Benoit <benoit@tionex.de>
parents: 38
diff changeset
135 String _idup( String str ){
38
2e09b0e6857a work on phobosfication
Frank Benoit <benoit@tionex.de>
parents: 27
diff changeset
136 return str.dup;
2e09b0e6857a work on phobosfication
Frank Benoit <benoit@tionex.de>
parents: 27
diff changeset
137 }
2e09b0e6857a work on phobosfication
Frank Benoit <benoit@tionex.de>
parents: 27
diff changeset
138 }
0
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
139
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
140 private struct GCStats {
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
141 size_t poolsize; // total size of pool
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
142 size_t usedsize; // bytes allocated
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
143 size_t freeblocks; // number of blocks marked FREE
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
144 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
145 size_t pageblocks; // number of blocks marked PAGE
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 private extern(C) GCStats gc_stats();
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 size_t RuntimeTotalMemory(){
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
150 GCStats s = gc_stats();
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
151 return s.poolsize;
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
152 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
153
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
154
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
155 template arraycast(T) {
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
156 T[] arraycast(U) (U[] u) {
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
157 static if (
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
158 (is (T == interface ) && is (U == interface )) ||
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
159 (is (T == class ) && is (U == class ))) {
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
160 return(cast(T[])u);
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
161 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
162 else {
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
163 int l = u.length;
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
164 T[] res;
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
165 res.length = l;
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
166 for (int i = 0; i < l; i++) {
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
167 res[i] = cast(T)u[i];
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 return(res);
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
170 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
171 }
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
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
174
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
175 bool ArrayEquals(T)( T[] a, T[] b ){
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
176 if( a.length !is b.length ){
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 for( int i = 0; i < a.length; i++ ){
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
180 static if( is( T==class) || is(T==interface)){
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
181 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
182 if( a[i] != b[i] ){
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 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
187 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
188 else{
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
189 return false;
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 else{
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
193 if( a[i] != b[i] ){
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
194 return false;
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
195 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
196 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
197 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
198 return true;
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
199 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
200
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
201 int arrayIndexOf(T)( T[] arr, T v ){
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
202 int res = -1;
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
203 int idx = 0;
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
204 foreach( p; arr ){
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
205 if( p == v){
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
206 res = idx;
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
207 break;
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
208 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
209 idx++;
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
210 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
211 return res;
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
212 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
213
25
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents: 21
diff changeset
214 T[] arrayIndexRemove(T)(T[] arr, uint n) {
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents: 21
diff changeset
215 if (n is 0)
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents: 21
diff changeset
216 return arr[1..$];
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents: 21
diff changeset
217 if (n > arr.length)
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents: 21
diff changeset
218 return arr;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents: 21
diff changeset
219 if (n is arr.length-1)
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents: 21
diff changeset
220 return arr[0..n-1];
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents: 21
diff changeset
221 // else
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents: 21
diff changeset
222 return arr[0..n] ~ arr[n+1..$];
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents: 21
diff changeset
223 }
0
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
224
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
225 struct ImportData{
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
226 void[] data;
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
227 String name;
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 public static ImportData opCall( void[] data, String name ){
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
230 ImportData res;
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
231 res.data = data;
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
232 res.name = name;
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
233 return res;
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 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
236
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
237 template getImportData(String name ){
38
2e09b0e6857a work on phobosfication
Frank Benoit <benoit@tionex.de>
parents: 27
diff changeset
238 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
239 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
240
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
241