1 |
package manta.runtime; |
package gnu.java.nio; |
2 |
|
|
3 |
import java.nio.*; |
import java.nio.*; |
4 |
|
|
13 |
ELT [] backing_buffer; |
ELT [] backing_buffer; |
14 |
private boolean ro; |
private boolean ro; |
15 |
|
|
16 |
BUFFERImpl(int cap, int off, int lim) |
public BUFFERImpl(int cap, int off, int lim) |
17 |
{ |
{ |
18 |
this.backing_buffer = new ELT[cap]; |
this.backing_buffer = new ELT[cap]; |
19 |
this.cap = cap; |
this.capacity(cap); |
20 |
this.pos = off; |
this.position(off); |
21 |
this.limit = lim; |
this.limit(lim); |
22 |
} |
} |
23 |
|
|
24 |
BUFFERImpl(ELT[] array, int off, int lim) |
public BUFFERImpl(ELT[] array, int off, int lim) |
25 |
{ |
{ |
26 |
this.backing_buffer = array; |
this.backing_buffer = array; |
27 |
this.cap = array.length; |
this.capacity(array.length); |
28 |
this.pos = off; |
this.position(off); |
29 |
this.limit = lim; |
this.limit(lim); |
30 |
} |
} |
31 |
|
|
32 |
BUFFERImpl(BUFFERImpl copy) |
public BUFFERImpl(BUFFERImpl copy) |
33 |
{ |
{ |
34 |
backing_buffer = copy.backing_buffer; |
backing_buffer = copy.backing_buffer; |
35 |
ro = copy.ro; |
ro = copy.ro; |
36 |
pos = copy.pos; |
|
37 |
limit = copy.limit; |
position(copy.position()); |
38 |
|
limit(copy.limit()); |
39 |
} |
} |
40 |
|
|
41 |
void inc_pos(int a) |
void inc_pos(int a) |
42 |
{ |
{ |
43 |
pos += a; |
position(position() + a); |
44 |
} |
} |
45 |
|
|
46 |
private static MantaNative ELT[] nio_cast(byte[]copy); |
private static native ELT[] nio_cast(byte[]copy); |
47 |
private static MantaNative ELT[] nio_cast(char[]copy); |
private static native ELT[] nio_cast(char[]copy); |
48 |
private static MantaNative ELT[] nio_cast(short[]copy); |
private static native ELT[] nio_cast(short[]copy); |
49 |
private static MantaNative ELT[] nio_cast(long[]copy); |
private static native ELT[] nio_cast(long[]copy); |
50 |
private static MantaNative ELT[] nio_cast(int[]copy); |
private static native ELT[] nio_cast(int[]copy); |
51 |
private static MantaNative ELT[] nio_cast(float[]copy); |
private static native ELT[] nio_cast(float[]copy); |
52 |
private static MantaNative ELT[] nio_cast(double[]copy); |
private static native ELT[] nio_cast(double[]copy); |
53 |
|
|
54 |
#define CAST_CTOR(ELT,TO_TYPE) \ |
#define CAST_CTOR(ELT,TO_TYPE) \ |
55 |
BUFFERImpl(ELT[] copy) \ |
BUFFERImpl(ELT[] copy) \ |
59 |
\ |
\ |
60 |
\ |
\ |
61 |
\ |
\ |
62 |
private static MantaNative ELT nio_get_ ## TO_TYPE(BUFFERImpl b, int index); \ |
private static native ELT nio_get_ ## TO_TYPE(BUFFERImpl b, int index); \ |
63 |
\ |
\ |
64 |
\ |
\ |
65 |
private static MantaNative void nio_put_ ## TO_TYPE(BUFFERImpl b, int index, ELT value);\ |
private static native void nio_put_ ## TO_TYPE(BUFFERImpl b, int index, ELT value);\ |
66 |
\ |
\ |
67 |
\ |
\ |
68 |
public java.nio. TO_TYPE ## Buffer as ## TO_TYPE ## Buffer() \ |
public java.nio. TO_TYPE ## Buffer as ## TO_TYPE ## Buffer() \ |
69 |
{ \ |
{ \ |
70 |
return new manta.runtime. TO_TYPE ## BufferImpl(backing_buffer); \ |
return new gnu.java.nio. TO_TYPE ## BufferImpl(backing_buffer); \ |
71 |
} |
} |
72 |
|
|
73 |
|
|
88 |
public java.nio. BUFFER slice() |
public java.nio. BUFFER slice() |
89 |
{ |
{ |
90 |
BUFFERImpl A = new BUFFERImpl(this); |
BUFFERImpl A = new BUFFERImpl(this); |
91 |
A.array_offset = pos; |
A.array_offset = position(); |
92 |
return A; |
return A; |
93 |
} |
} |
94 |
|
|
114 |
return backing_buffer != null; |
return backing_buffer != null; |
115 |
} |
} |
116 |
|
|
117 |
public ELT get() |
final public ELT get() |
118 |
{ |
{ |
119 |
ELT e = backing_buffer[pos]; |
ELT e = backing_buffer[position()]; |
120 |
pos++; |
position(position()+1); |
121 |
return e; |
return e; |
122 |
} |
} |
123 |
|
|
124 |
public java.nio. BUFFER put(ELT b) |
final public java.nio. BUFFER put(ELT b) |
125 |
{ |
{ |
126 |
backing_buffer[pos] = b; |
backing_buffer[position()] = b; |
127 |
pos++; |
position(position()+1); |
128 |
return this; |
return this; |
129 |
} |
} |
130 |
public ELT get(int index) |
final public ELT get(int index) |
131 |
{ |
{ |
132 |
return backing_buffer[index]; |
return backing_buffer[index]; |
133 |
} |
} |
134 |
public java.nio. BUFFER put(int index, ELT b) |
|
135 |
|
final public java.nio. BUFFER put(int index, ELT b) |
136 |
{ |
{ |
137 |
backing_buffer[index] = b; |
backing_buffer[index] = b; |
138 |
return this; |
return this; |
140 |
|
|
141 |
|
|
142 |
#define NATIVE_GET_PUT(TYPE,SIZE,ELT) \ |
#define NATIVE_GET_PUT(TYPE,SIZE,ELT) \ |
143 |
public ELT get ## TYPE() \ |
final public ELT get ## TYPE() \ |
144 |
{ \ |
{ \ |
145 |
ELT a = nio_get_ ## TYPE(this, pos); \ |
ELT a = nio_get_ ## TYPE(this, position()); \ |
146 |
inc_pos(SIZE); \ |
inc_pos(SIZE); \ |
147 |
return a; \ |
return a; \ |
148 |
} \ |
} \ |
149 |
public java.nio. BUFFER put ## TYPE(ELT value) \ |
final public java.nio. BUFFER put ## TYPE(ELT value) \ |
150 |
{ \ |
{ \ |
151 |
nio_put_ ## TYPE(this, pos, value); \ |
nio_put_ ## TYPE(this, position(), value); \ |
152 |
inc_pos(SIZE); \ |
inc_pos(SIZE); \ |
153 |
return this; \ |
return this; \ |
154 |
} \ |
} \ |
155 |
public ELT get ## TYPE(int index) \ |
final public ELT get ## TYPE(int index) \ |
156 |
{ \ |
{ \ |
157 |
ELT a = nio_get_ ## TYPE(this, index); \ |
ELT a = nio_get_ ## TYPE(this, index); \ |
158 |
inc_pos(SIZE); \ |
/*inc_pos(SIZE);*/ \ |
159 |
return a; \ |
return a; \ |
160 |
} \ |
} \ |
161 |
public java.nio. BUFFER put ## TYPE(int index, ELT value) \ |
final public java.nio. BUFFER put ## TYPE(int index, ELT value) \ |
162 |
{ \ |
{ \ |
163 |
nio_put_ ## TYPE(this, index, value); \ |
nio_put_ ## TYPE(this, index, value); \ |
164 |
inc_pos(SIZE); \ |
/* inc_pos(SIZE);*/ \ |
165 |
return this; \ |
return this; \ |
166 |
} |
} |
167 |
|
|
168 |
#define INLINE_GET_PUT(TYPE,ELT) \ |
#define INLINE_GET_PUT(TYPE,ELT) \ |
169 |
public ELT get ## TYPE() \ |
final public ELT get ## TYPE() \ |
170 |
{ \ |
{ \ |
171 |
return get(); \ |
return get(); \ |
172 |
} \ |
} \ |
173 |
public java.nio. BUFFER put ## TYPE(ELT value) \ |
final public java.nio. BUFFER put ## TYPE(ELT value) \ |
174 |
{ \ |
{ \ |
175 |
return put(value); \ |
return put(value); \ |
176 |
} \ |
} \ |
177 |
public ELT get ## TYPE(int index) \ |
final public ELT get ## TYPE(int index) \ |
178 |
{ \ |
{ \ |
179 |
return get(index); \ |
return get(index); \ |
180 |
} \ |
} \ |
181 |
public java.nio. BUFFER put ## TYPE(int index, ELT value) \ |
final public java.nio. BUFFER put ## TYPE(int index, ELT value) \ |
182 |
{ \ |
{ \ |
183 |
return put(index, value); \ |
return put(index, value); \ |
184 |
} |
} |