aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/com/jogamp/common/nio/ElementBuffer.java
blob: 9bb75de4751d471d33ad610e5b53717b0357f17b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
/**
 * Copyright 2010-2023 JogAmp Community. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification, are
 * permitted provided that the following conditions are met:
 *
 *    1. Redistributions of source code must retain the above copyright notice, this list of
 *       conditions and the following disclaimer.
 *
 *    2. Redistributions in binary form must reproduce the above copyright notice, this list
 *       of conditions and the following disclaimer in the documentation and/or other materials
 *       provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * The views and conclusions contained in the software and documentation are those of the
 * authors and should not be interpreted as representing official policies, either expressed
 * or implied, of JogAmp Community.
 */

package com.jogamp.common.nio;

import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.DoubleBuffer;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import java.nio.LongBuffer;
import java.nio.ShortBuffer;

/**
 * Hardware independent container holding an array of linearly aligned elements,
 * while its {@link #getDirectBufferAddress()} is-a pointer-type value, i.e. the element-array address.
 * <p>
 * An instance maps an array of linearly aligned elements, represented as bytes.
 * </p>
 */
public class ElementBuffer extends AbstractBuffer<ElementBuffer> {
    /** supports backup array */
    ElementBuffer(final int elementSize, final ByteBuffer b) {
        super(b, elementSize, b.capacity()/elementSize);
    }

    /** Returns a non direct PointerBuffer in native order, having a backup array */
    public static ElementBuffer allocate(final int elementSize, final int elemCount) {
        return new ElementBuffer(elementSize, ByteBuffer.allocate(elemCount * elementSize));
    }

    /** Returns a direct PointerBuffer in native order, w/o backup array */
    public static ElementBuffer allocateDirect(final int elementSize, final int elemCount) {
        return new ElementBuffer(elementSize, Buffers.newDirectByteBuffer(elemCount * elementSize));
    }

    public static ElementBuffer wrap(final int elementSize, final ByteBuffer src) {
        return new ElementBuffer(elementSize, src);
    }
    public static ElementBuffer wrap(final int elementSize, final ByteBuffer src, final int srcByteOffset, final int elemCount) {
        final int oldPos = src.position();
        final int oldLimit = src.limit();
        src.position(srcByteOffset);
        src.limit(srcByteOffset + ( elementSize * elemCount ));
        final ElementBuffer r = new ElementBuffer(elementSize, src.slice().order(src.order())); // slice and duplicate may change byte order
        src.position(oldPos);
        src.limit(oldLimit);
        return r;
    }
    public static ElementBuffer derefPointer(final int elementSize, final long aptr, final int elemCount) {
        if( 0 == aptr ) {
            throw new NullPointerException("aptr is null");
        }
        final ByteBuffer bb = Buffers.getDirectByteBuffer(aptr, elemCount * elementSize);
        if( null == bb ) {
            throw new InternalError("Couldn't dereference aptr 0x"+Long.toHexString(aptr)+", size "+elemCount+" * "+elementSize);
        }
        return new ElementBuffer(elementSize, bb);
    }
    public static ElementBuffer derefPointer(final int elementSize, final ByteBuffer ptrSrc, final int ptrSrcByteOffset, final int elemCount) {
        return derefPointer(elementSize, PointerBuffer.wrap(ptrSrc, ptrSrcByteOffset, 1).get(0), elemCount);
    }

    @Override
    public final ElementBuffer put(final ElementBuffer src) {
        final int elemCount = src.remaining();
        if (remaining() < elemCount) {
            throw new IndexOutOfBoundsException("remaining[this "+remaining()+" < src "+elemCount+"], this "+this+", src "+src);
        }
        if( this.elementSize() != src.elementSize() ) {
            throw new IllegalArgumentException("Element-Size mismatch source "+src+", dest "+this);
        }
        final int srcPos = src.position();
        put(src.getByteBuffer(), srcPos, position, elemCount);
        src.position(srcPos + elemCount);
        position += elemCount;
        return this;
    }

    /** Returns the ByteBuffer, i.e. {@link #getBuffer()} w/o casting. */
    public final ByteBuffer getByteBuffer() {
        return (ByteBuffer) buffer;
    }

    /**
     * Returns a slice of this instance's ByteBuffer `[offset..offset+length)`, i.e. referencing the underlying bytes.
     * @param offset starting element-index within this buffer
     * @param length element count
     * @return slice of this instance's ByteBuffer
     */
    public final ByteBuffer slice(final int offset, final int length) {
        if (0 > offset || offset + length > limit()) {
            throw new IndexOutOfBoundsException("idx "+offset+" + elemCount "+length+" not within [0.."+limit()+"), "+this);
        }
        final ByteBuffer src = getByteBuffer();
        final int oldPos = src.position();
        final int oldLimit = src.limit();
        src.position( elementSize * offset ).limit(elementSize * (offset + length));
        final ByteBuffer ref = src.slice().order(src.order()); // slice and duplicate may change byte order
        src.position( oldPos ).limit( oldLimit );
        return ref;
    }

    /** Absolute get method. Get element-bytes for `elemCount` elements from this buffer at `srcElemPos` into `destElemBytes` at the given element-index `destElemPos` */
    public final ByteBuffer get(final int srcElemPos, final ByteBuffer destElemBytes, final int destElemPos, final int elemCount) {
        if (0 > srcElemPos || srcElemPos + elemCount > limit() || 0 > elemCount ||
            0 > destElemPos || elementSize * ( destElemPos + elemCount ) > destElemBytes.limit() ) {
            throw new IndexOutOfBoundsException("destElemPos "+destElemPos+", srcElemPos "+srcElemPos+", elemCount "+elemCount+
                                                ", srcLimit "+limit()+", destLimit "+(destElemBytes.limit()/elementSize)+", "+this);
        }
        final ByteBuffer srcElemBytes = getByteBuffer();
        final int oldSrcLim = srcElemBytes.limit();
        srcElemBytes.position( srcElemPos * elementSize ).limit( ( srcElemPos + elemCount ) * elementSize ); // remaining = elemCount * elementSize
        final int oldDestPos = destElemBytes.position();
        destElemBytes.position( destElemPos * elementSize );
        destElemBytes.put(srcElemBytes).position(oldDestPos);
        srcElemBytes.limit(oldSrcLim).rewind();
        return destElemBytes;
    }
    /** Absolute get method. Copy the element-bytes from this buffer at the given element-index `srcElemPos`, storing them into `destElemBytes`. */
    public final ByteBuffer get(final int srcElemPos, final ByteBuffer destElemBytes) {
        return get(srcElemPos, destElemBytes, 0, 1);
    }
    /** Relative get method. Copy the element-bytes at the current position and increment the position by one, storing the element-bytes into `destElemBytes`. */
    public final ByteBuffer get(final ByteBuffer destElemBytes) {
        final ByteBuffer r = get(position, destElemBytes, 0, 1);
        position++;
        return r;
    }
    /**
     * Relative bulk get method. Copy the element-bytes <code> [ position .. position+elemCount [</code>
     * to the destination array <code> [ destElements[destElemPos] .. destElements[destElemPos+elemCount] [ </code>
     * and increment the position by <code>elemCount</code>. */
    public final ElementBuffer get(final ByteBuffer[] destElements, int destElemPos, int elemCount) {
        if (destElements.length<destElemPos+elemCount) {
            throw new IndexOutOfBoundsException("dest.length "+destElements.length+" < (offset "+destElemPos+" + length "+elemCount+")");
        }
        if (remaining() < elemCount) {
            throw new IndexOutOfBoundsException("remaining "+remaining()+" < length "+elemCount+", this "+this);
        }
        while(elemCount>0) {
            get(position++, destElements[destElemPos++]);
            elemCount--;
        }
        return this;
    }

    /** Absolute get method. Get byte-elements for `elemCount` elements from this buffer at `srcElemPos` into `dest` at the given element-index `destElemPos` */
    public final ElementBuffer get(final int srcElemPos, final byte[] dest, final int destElemPos, final int elemCount) {
        if( Buffers.SIZEOF_BYTE != elementSize ) { throw new UnsupportedOperationException("'byte' type byte-size "+Buffers.SIZEOF_BYTE+" != elementSize "+elementSize+", "+this); }
        if (0 > srcElemPos || srcElemPos + elemCount > limit() || 0 > elemCount ||
            0 > destElemPos || destElemPos + elemCount > dest.length ) {
            throw new IndexOutOfBoundsException("destElemPos "+destElemPos+", srcElemPos "+srcElemPos+", elemCount "+elemCount+
                                                ", srcLimit "+limit()+", destLimit "+dest.length+", "+this);
        }
        final ByteBuffer src = getByteBuffer();
        final int oldPos = src.position();
        final int oldLim = src.limit();
        src.position( srcElemPos ).limit( srcElemPos + elemCount ); // remaining = elemCount
        src.get(dest, destElemPos, elemCount);
        src.position( oldPos ).limit( oldLim );
        return this;
    }
    /** Absolute get method. Get short-elements for `elemCount` elements from this buffer at `srcElemPos` into `dest` at the given element-index `destElemPos` */
    public final ElementBuffer get(final int srcElemPos, final short[] dest, final int destElemPos, final int elemCount) {
        if( Buffers.SIZEOF_SHORT != elementSize ) { throw new UnsupportedOperationException("'short' type byte-size "+Buffers.SIZEOF_SHORT+" != elementSize "+elementSize+", "+this); }
        if (0 > srcElemPos || srcElemPos + elemCount > limit() || 0 > elemCount ||
            0 > destElemPos || destElemPos + elemCount > dest.length ) {
            throw new IndexOutOfBoundsException("destElemPos "+destElemPos+", srcElemPos "+srcElemPos+", elemCount "+elemCount+
                                                ", srcLimit "+limit()+", destLimit "+dest.length+", "+this);
        }
        final ShortBuffer src = getByteBuffer().asShortBuffer();
        src.position( srcElemPos ).limit( srcElemPos + elemCount ); // remaining = elemCount
        src.get(dest, destElemPos, elemCount);
        return this;
    }
    /** Absolute get method. Get char-elements for `elemCount` elements from this buffer at `srcElemPos` into `dest` at the given element-index `destElemPos` */
    public final ElementBuffer get(final int srcElemPos, final char[] dest, final int destElemPos, final int elemCount) {
        if( Buffers.SIZEOF_CHAR != elementSize ) { throw new UnsupportedOperationException("'char' type byte-size "+Buffers.SIZEOF_CHAR+" != elementSize "+elementSize+", "+this); }
        if (0 > srcElemPos || srcElemPos + elemCount > limit() || 0 > elemCount ||
            0 > destElemPos || destElemPos + elemCount > dest.length ) {
            throw new IndexOutOfBoundsException("destElemPos "+destElemPos+", srcElemPos "+srcElemPos+", elemCount "+elemCount+
                                                ", srcLimit "+limit()+", destLimit "+dest.length+", "+this);
        }
        final CharBuffer src = getByteBuffer().asCharBuffer();
        src.position( srcElemPos ).limit( srcElemPos + elemCount ); // remaining = elemCount
        src.get(dest, destElemPos, elemCount);
        return this;
    }
    /** Absolute get method. Get int-elements for `elemCount` elements from this buffer at `srcElemPos` into `dest` at the given element-index `destElemPos` */
    public final ElementBuffer get(final int srcElemPos, final int[] dest, final int destElemPos, final int elemCount) {
        if( Buffers.SIZEOF_INT != elementSize ) { throw new UnsupportedOperationException("'int' type byte-size "+Buffers.SIZEOF_INT+" != elementSize "+elementSize+", "+this); }
        if (0 > srcElemPos || srcElemPos + elemCount > limit() || 0 > elemCount ||
            0 > destElemPos || destElemPos + elemCount > dest.length ) {
            throw new IndexOutOfBoundsException("destElemPos "+destElemPos+", srcElemPos "+srcElemPos+", elemCount "+elemCount+
                                                ", srcLimit "+limit()+", destLimit "+dest.length+", "+this);
        }
        final IntBuffer src = getByteBuffer().asIntBuffer();
        src.position( srcElemPos ).limit( srcElemPos + elemCount ); // remaining = elemCount
        src.get(dest, destElemPos, elemCount);
        return this;
    }
    /** Absolute get method. Get float-elements for `elemCount` elements from this buffer at `srcElemPos` into `dest` at the given element-index `destElemPos` */
    public final ElementBuffer get(final int srcElemPos, final float[] dest, final int destElemPos, final int elemCount) {
        if( Buffers.SIZEOF_FLOAT != elementSize ) { throw new UnsupportedOperationException("'float' type byte-size "+Buffers.SIZEOF_FLOAT+" != elementSize "+elementSize+", "+this); }
        if (0 > srcElemPos || srcElemPos + elemCount > limit() || 0 > elemCount ||
            0 > destElemPos || destElemPos + elemCount > dest.length ) {
            throw new IndexOutOfBoundsException("destElemPos "+destElemPos+", srcElemPos "+srcElemPos+", elemCount "+elemCount+
                                                ", srcLimit "+limit()+", destLimit "+dest.length+", "+this);
        }
        final FloatBuffer src = getByteBuffer().asFloatBuffer();
        src.position( srcElemPos ).limit( srcElemPos + elemCount ); // remaining = elemCount
        src.get(dest, destElemPos, elemCount);
        return this;
    }
    /** Absolute get method. Get long-elements for `elemCount` elements from this buffer at `srcElemPos` into `dest` at the given element-index `destElemPos` */
    public final ElementBuffer get(final int srcElemPos, final long[] dest, final int destElemPos, final int elemCount) {
        if( Buffers.SIZEOF_LONG != elementSize ) { throw new UnsupportedOperationException("'long' type byte-size "+Buffers.SIZEOF_LONG+" != elementSize "+elementSize+", "+this); }
        if (0 > srcElemPos || srcElemPos + elemCount > limit() || 0 > elemCount ||
            0 > destElemPos || destElemPos + elemCount > dest.length ) {
            throw new IndexOutOfBoundsException("destElemPos "+destElemPos+", srcElemPos "+srcElemPos+", elemCount "+elemCount+
                                                ", srcLimit "+limit()+", destLimit "+dest.length+", "+this);
        }
        final LongBuffer src = getByteBuffer().asLongBuffer();
        src.position( srcElemPos ).limit( srcElemPos + elemCount ); // remaining = elemCount
        src.get(dest, destElemPos, elemCount);
        return this;
    }
    /** Absolute get method. Get double-elements for `elemCount` elements from this buffer at `srcElemPos` into `dest` at the given element-index `destElemPos` */
    public final ElementBuffer get(final int srcElemPos, final double[] dest, final int destElemPos, final int elemCount) {
        if( Buffers.SIZEOF_DOUBLE != elementSize ) { throw new UnsupportedOperationException("'double' type byte-size "+Buffers.SIZEOF_DOUBLE+" != elementSize "+elementSize+", "+this); }
        if (0 > srcElemPos || srcElemPos + elemCount > limit() || 0 > elemCount ||
            0 > destElemPos || destElemPos + elemCount > dest.length ) {
            throw new IndexOutOfBoundsException("destElemPos "+destElemPos+", srcElemPos "+srcElemPos+", elemCount "+elemCount+
                                                ", srcLimit "+limit()+", destLimit "+dest.length+", "+this);
        }
        final DoubleBuffer src = getByteBuffer().asDoubleBuffer();
        src.position( srcElemPos ).limit( srcElemPos + elemCount ); // remaining = elemCount
        src.get(dest, destElemPos, elemCount);
        return this;
    }


    /** Absolute put method. Put element-bytes for `elemCount` elements from `srcElemBytes` at `srcElemPos` into this buffer at the given element-index `destElemPos` */
    public final ElementBuffer put(final ByteBuffer srcElemBytes, final int srcElemPos, final int destElemPos, final int elemCount) {
        if (0 > destElemPos || destElemPos + elemCount > limit() || 0 > elemCount ||
            0 > srcElemPos || elementSize * ( srcElemPos + elemCount ) > srcElemBytes.limit() ) {
            throw new IndexOutOfBoundsException("srcElemPos "+srcElemPos+", destElemPos "+destElemPos+", elemCount "+elemCount+
                                                ", destLimit "+limit()+", srcLimit "+(srcElemBytes.limit()/elementSize)+", "+this);
        }
        final ByteBuffer destElemBytes = getByteBuffer();
        final int oldSrcPos = srcElemBytes.position();
        final int oldSrcLim = srcElemBytes.limit();
        srcElemBytes.position( srcElemPos * elementSize ).limit( ( srcElemPos + elemCount ) * elementSize ); // remaining = elemCount * elementSize
        destElemBytes.position( elementSize * destElemPos );
        destElemBytes.put(srcElemBytes).rewind();
        srcElemBytes.limit(oldSrcLim).position(oldSrcPos);
        return this;
    }
    /** Absolute put method. Put element-bytes from `srcElemBytes` into the given element-index `destElemPos` */
    public final ElementBuffer put(final int destElemPos, final ByteBuffer srcElemBytes) {
        return put(srcElemBytes, 0, destElemPos, 1);
    }
    /** Relative put method. Put the element-bytes at the current position and increment the position by one. */
    public final ElementBuffer put(final ByteBuffer srcElemBytes) {
        put(position, srcElemBytes);
        position++;
        return this;
    }
    /**
     * Relative bulk put method. Put the element-bytes <code> [ srcElements[offset] .. srcElements[offset+length] [</code>
     * at the current position and increment the position by <code>length</code>. */
    public final ElementBuffer put(final ByteBuffer[] srcElements, int offset, int length) {
        if (srcElements.length<offset+length) {
            throw new IndexOutOfBoundsException("src.length "+srcElements.length+" < (offset "+offset+" + length "+length+")");
        }
        if (remaining() < length) {
            throw new IndexOutOfBoundsException("remaining "+remaining()+" < length "+length+", this "+this);
        }
        while(length>0) {
            put(position++, srcElements[offset++]);
            length--;
        }
        return this;
    }

    /** Absolute put method. Put byte-elements for `elemCount` elements from `src` at `srcElemPos` into this buffer at the given element-index `destElemPos` */
    public final ElementBuffer put(final byte[] src, final int srcElemPos, final int destElemPos, final int elemCount) {
        if( Buffers.SIZEOF_BYTE != elementSize ) { throw new UnsupportedOperationException("'byte' type byte-size "+Buffers.SIZEOF_BYTE+" != elementSize "+elementSize+", "+this); }
        if (0 > destElemPos || destElemPos + elemCount > limit() || 0 > elemCount ||
            0 > srcElemPos || srcElemPos + elemCount > src.length ) {
            throw new IndexOutOfBoundsException("srcElemPos "+srcElemPos+", destElemPos "+destElemPos+", elemCount "+elemCount+
                                                ", destLimit "+limit()+", srcLimit "+src.length+", "+this);
        }
        final ByteBuffer dest = getByteBuffer();
        final int oldPos = dest.position();
        final int oldLim = dest.limit();
        dest.position( destElemPos ).limit( destElemPos + elemCount ); // remaining = elemCount
        dest.put(src, srcElemPos, elemCount);
        dest.position( oldPos ).limit( oldLim );
        return this;
    }
    /** Absolute put method. Put short-elements for `elemCount` elements from `src` at `srcElemPos` into this buffer at the given element-index `destElemPos` */
    public final ElementBuffer put(final short[] src, final int srcElemPos, final int destElemPos, final int elemCount) {
        if( Buffers.SIZEOF_SHORT != elementSize ) { throw new UnsupportedOperationException("'short' type byte-size "+Buffers.SIZEOF_SHORT+" != elementSize "+elementSize+", "+this); }
        if (0 > destElemPos || destElemPos + elemCount > limit() || 0 > elemCount ||
            0 > srcElemPos || srcElemPos + elemCount > src.length ) {
            throw new IndexOutOfBoundsException("srcElemPos "+srcElemPos+", destElemPos "+destElemPos+", elemCount "+elemCount+
                                                ", destLimit "+limit()+", srcLimit "+src.length+", "+this);
        }
        final ShortBuffer dest = getByteBuffer().asShortBuffer();
        dest.position( destElemPos ).limit( destElemPos + elemCount ); // remaining = elemCount
        dest.put(src, srcElemPos, elemCount);
        return this;
    }
    /** Absolute put method. Put char-elements for `elemCount` elements from `src` at `srcElemPos` into this buffer at the given element-index `destElemPos` */
    public final ElementBuffer put(final char[] src, final int srcElemPos, final int destElemPos, final int elemCount) {
        if( Buffers.SIZEOF_CHAR != elementSize ) { throw new UnsupportedOperationException("'char' type byte-size "+Buffers.SIZEOF_CHAR+" != elementSize "+elementSize+", "+this); }
        if (0 > destElemPos || destElemPos + elemCount > limit() || 0 > elemCount ||
            0 > srcElemPos || srcElemPos + elemCount > src.length ) {
            throw new IndexOutOfBoundsException("srcElemPos "+srcElemPos+", destElemPos "+destElemPos+", elemCount "+elemCount+
                                                ", destLimit "+limit()+", srcLimit "+src.length+", "+this);
        }
        final CharBuffer dest = getByteBuffer().asCharBuffer();
        dest.position( destElemPos ).limit( destElemPos + elemCount ); // remaining = elemCount
        dest.put(src, srcElemPos, elemCount);
        return this;
    }
    /** Absolute put method. Put int-elements for `elemCount` elements from `src` at `srcElemPos` into this buffer at the given element-index `destElemPos` */
    public final ElementBuffer put(final int[] src, final int srcElemPos, final int destElemPos, final int elemCount) {
        if( Buffers.SIZEOF_INT != elementSize ) { throw new UnsupportedOperationException("'int' type byte-size "+Buffers.SIZEOF_INT+" != elementSize "+elementSize+", "+this); }
        if (0 > destElemPos || destElemPos + elemCount > limit() || 0 > elemCount ||
            0 > srcElemPos || srcElemPos + elemCount > src.length ) {
            throw new IndexOutOfBoundsException("srcElemPos "+srcElemPos+", destElemPos "+destElemPos+", elemCount "+elemCount+
                                                ", destLimit "+limit()+", srcLimit "+src.length+", "+this);
        }
        final IntBuffer dest = getByteBuffer().asIntBuffer();
        dest.position( destElemPos ).limit( destElemPos + elemCount ); // remaining = elemCount
        dest.put(src, srcElemPos, elemCount);
        return this;
    }
    /** Absolute put method. Put float-elements for `elemCount` elements from `src` at `srcElemPos` into this buffer at the given element-index `destElemPos` */
    public final ElementBuffer put(final float[] src, final int srcElemPos, final int destElemPos, final int elemCount) {
        if( Buffers.SIZEOF_FLOAT != elementSize ) { throw new UnsupportedOperationException("'float' type byte-size "+Buffers.SIZEOF_FLOAT+" != elementSize "+elementSize+", "+this); }
        if (0 > destElemPos || destElemPos + elemCount > limit() || 0 > elemCount ||
            0 > srcElemPos || srcElemPos + elemCount > src.length ) {
            throw new IndexOutOfBoundsException("srcElemPos "+srcElemPos+", destElemPos "+destElemPos+", elemCount "+elemCount+
                                                ", destLimit "+limit()+", srcLimit "+src.length+", "+this);
        }
        final FloatBuffer dest = getByteBuffer().asFloatBuffer();
        dest.position( destElemPos ).limit( destElemPos + elemCount ); // remaining = elemCount
        dest.put(src, srcElemPos, elemCount);
        return this;
    }
    /** Absolute put method. Put long-elements for `elemCount` elements from `src` at `srcElemPos` into this buffer at the given element-index `destElemPos` */
    public final ElementBuffer put(final long[] src, final int srcElemPos, final int destElemPos, final int elemCount) {
        if( Buffers.SIZEOF_LONG != elementSize ) { throw new UnsupportedOperationException("'long' type byte-size "+Buffers.SIZEOF_LONG+" != elementSize "+elementSize+", "+this); }
        if (0 > destElemPos || destElemPos + elemCount > limit() || 0 > elemCount ||
            0 > srcElemPos || srcElemPos + elemCount > src.length ) {
            throw new IndexOutOfBoundsException("srcElemPos "+srcElemPos+", destElemPos "+destElemPos+", elemCount "+elemCount+
                                                ", destLimit "+limit()+", srcLimit "+src.length+", "+this);
        }
        final LongBuffer dest = getByteBuffer().asLongBuffer();
        dest.position( destElemPos ).limit( destElemPos + elemCount ); // remaining = elemCount
        dest.put(src, srcElemPos, elemCount);
        return this;
    }
    /** Absolute put method. Put double-elements for `elemCount` elements from `src` at `srcElemPos` into this buffer at the given element-index `destElemPos` */
    public final ElementBuffer put(final double[] src, final int srcElemPos, final int destElemPos, final int elemCount) {
        if( Buffers.SIZEOF_DOUBLE != elementSize ) { throw new UnsupportedOperationException("'double' type byte-size "+Buffers.SIZEOF_DOUBLE+" != elementSize "+elementSize+", "+this); }
        if (0 > destElemPos || destElemPos + elemCount > limit() || 0 > elemCount ||
            0 > srcElemPos || srcElemPos + elemCount > src.length ) {
            throw new IndexOutOfBoundsException("srcElemPos "+srcElemPos+", destElemPos "+destElemPos+", elemCount "+elemCount+
                                                ", destLimit "+limit()+", srcLimit "+src.length+", "+this);
        }
        final DoubleBuffer dest = getByteBuffer().asDoubleBuffer();
        dest.position( destElemPos ).limit( destElemPos + elemCount ); // remaining = elemCount
        dest.put(src, srcElemPos, elemCount);
        return this;
    }

    @Override
    public String toString() {
        return "ElementBuffer"+toSubString();
    }
}