annotate java/src/java/lang/util.d @ 25:f713da8bc051

Added SWT Linux GTK
author Frank Benoit <benoit@tionex.de>
date Fri, 20 Mar 2009 23:03:58 +0100
parents 9b96950f2c3c
children
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;
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
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
123
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
124 private struct GCStats {
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
125 size_t poolsize; // total size of pool
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
126 size_t usedsize; // bytes allocated
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
127 size_t freeblocks; // number of blocks marked FREE
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
128 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
129 size_t pageblocks; // number of blocks marked PAGE
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
130 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
131 private extern(C) GCStats gc_stats();
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
132
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
133 size_t RuntimeTotalMemory(){
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
134 GCStats s = gc_stats();
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
135 return s.poolsize;
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
136 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
137
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
138
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
139 template arraycast(T) {
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
140 T[] arraycast(U) (U[] u) {
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
141 static if (
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
142 (is (T == interface ) && is (U == interface )) ||
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
143 (is (T == class ) && is (U == class ))) {
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
144 return(cast(T[])u);
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
145 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
146 else {
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
147 int l = u.length;
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
148 T[] res;
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
149 res.length = l;
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
150 for (int i = 0; i < l; i++) {
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
151 res[i] = cast(T)u[i];
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 return(res);
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 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
156 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
157
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
158
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
159 bool ArrayEquals(T)( T[] a, T[] b ){
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
160 if( a.length !is b.length ){
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
161 return false;
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 for( int i = 0; i < a.length; i++ ){
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
164 static if( is( T==class) || is(T==interface)){
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
165 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
166 if( a[i] != b[i] ){
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
167 return false;
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 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
170 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
171 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
172 else{
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
173 return false;
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 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
176 else{
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
177 if( a[i] != b[i] ){
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
178 return false;
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 }
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 return true;
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
183 }
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 int arrayIndexOf(T)( T[] arr, T v ){
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
186 int res = -1;
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
187 int idx = 0;
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
188 foreach( p; arr ){
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
189 if( p == v){
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
190 res = idx;
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
191 break;
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
192 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
193 idx++;
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 return res;
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
25
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents: 21
diff changeset
198 T[] arrayIndexRemove(T)(T[] arr, uint n) {
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents: 21
diff changeset
199 if (n is 0)
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents: 21
diff changeset
200 return arr[1..$];
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents: 21
diff changeset
201 if (n > arr.length)
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents: 21
diff changeset
202 return arr;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents: 21
diff changeset
203 if (n is arr.length-1)
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents: 21
diff changeset
204 return arr[0..n-1];
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents: 21
diff changeset
205 // else
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents: 21
diff changeset
206 return arr[0..n] ~ arr[n+1..$];
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents: 21
diff changeset
207 }
0
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 struct ImportData{
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
210 void[] data;
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
211 String name;
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 public static ImportData opCall( void[] data, String name ){
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
214 ImportData res;
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
215 res.data = data;
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
216 res.name = name;
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
217 return res;
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 }
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
220
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
221 template getImportData(String name ){
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
222 const ImportData getImportData = ImportData( import(name), name );
6dd524f61e62 add dwt win and basic java stuff
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
223 }
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