GlueGen: src/java/com/jogamp/common/nio/NativeBuffer.java Source File

GlueGen v2.6.0-rc-20250822 GlueGen, Native Binding Generator for Java™ (public API).

NativeBuffer.java
Go to the documentation of this file.
1/**
2 * Copyright 2010-2023 JogAmp Community. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are
5 * permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
8 * conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * The views and conclusions contained in the software and documentation are those of the
25 * authors and should not be interpreted as representing official policies, either expressed
26 * or implied, of JogAmp Community.
27 */
28
29/*
30 * Created on Tuesday, March 30 2010 18:22
31 */
32package com.jogamp.common.nio;
33
34import java.nio.Buffer;
35import java.nio.ByteBuffer;
36
37/**
38 * Hardware independent container for various kinds of buffers.
39 * <p>
40 * Implementations follow {@link Buffer} semantics, e.g.
41 * <pre>
42 * 0 <= position <= limit <= capacity
43 * </pre>
44 * </p>
45 * @author Sven Gothel
46 * @author Michael Bien
47 */
48@SuppressWarnings("rawtypes")
49public interface NativeBuffer<B extends NativeBuffer> {
50
51 /** Returns byte size of one element */
52 public int elementSize();
53
54 /** Returns this buffer's element limit. */
55 public int limit();
56
57 /** Sets this buffer's element limit. */
58 public B limit(int newLim);
59
60 /** Returns this buffer's element capacity. */
61 public int capacity();
62
63 /** Returns this buffer's element position. */
64 public int position();
65
66 /** Sets this buffer's element position. */
67 public B position(int newPos);
68
69 /** Returns this buffer's remaining element, i.e. limit - position. */
70 public int remaining();
71
72 /** Returns {@link #remaining()} > 0 */
73 public boolean hasRemaining();
74
75 /** Sets the limit to the capacity and the position to zero. */
76 public B clear();
77
78 /** Sets the limit to the current position and the position to zero. */
79 public B flip();
80
81 /** Sets the position to zero. */
82 public B rewind();
83
84 /**
85 * @return true if this buffer has a primitive backup array, otherwise false
86 */
87 public boolean hasArray();
88
89 /**
90 * @return the array offset of the optional primitive backup array of the buffer if {@link #hasArray()} is true,
91 * otherwise 0.
92 */
93 public int arrayOffset();
94
95 /**
96 * @return the primitive backup array of the buffer if {@link #hasArray()} is true,
97 * otherwise it throws {@link java.lang.UnsupportedOperationException}.
98 * The returned primitive array maybe of type <code>int[]</code> or <code>long[]</code>, etc ..
99 * @throws UnsupportedOperationException if this object has no backup array
100 * @see #hasArray()
101 */
102 public Object array() throws UnsupportedOperationException ;
103
104 /** Returns the underlying buffer object. */
105 public Buffer getBuffer();
106 /** Return true if the underlying buffer is NIO direct, otherwise false. */
107 public boolean isDirect();
108 /** Returns the native address of the underlying buffer if {@link #isDirect()}, otherwise {@code 0}. */
109 public long getDirectBufferAddress();
110 /**
111 * Store the {@link #getDirectBufferAddress()} into the given {@link ByteBuffer} using relative put.
112 * <p>
113 * The native pointer value is stored either as a 32bit (int) or 64bit (long) wide value,
114 * depending of the CPU pointer width.
115 * </p>
116 */
117 public void storeDirectAddress(final ByteBuffer directDest);
118 /**
119 * Store the {@link #getDirectBufferAddress()} into the given {@link ByteBuffer} using absolute put.
120 * <p>
121 * The native pointer value is stored either as a 32bit (int) or 64bit (long) wide value,
122 * depending of the CPU pointer width.
123 * </p>
124 **/
125 public void storeDirectAddress(final ByteBuffer directDest, final int destOffset);
126
127 /**
128 * Relative bulk get method. Copy the source values <code> src[position .. capacity] [</code>
129 * to this buffer and increment the position by <code>capacity-position</code>.
130 */
131 public B put(B src);
132}
com.jogamp.common.nio.NativeBuffer
Hardware independent container for various kinds of buffers.
Definition: NativeBuffer.java:49
com.jogamp.common.nio.NativeBuffer.flip
B flip()
Sets the limit to the current position and the position to zero.
com.jogamp.common.nio.NativeBuffer.rewind
B rewind()
Sets the position to zero.
com.jogamp.common.nio.NativeBuffer.elementSize
int elementSize()
Returns byte size of one element.
com.jogamp.common.nio.NativeBuffer.arrayOffset
int arrayOffset()
com.jogamp.common.nio.NativeBuffer.capacity
int capacity()
Returns this buffer's element capacity.
com.jogamp.common.nio.NativeBuffer.position
B position(int newPos)
Sets this buffer's element position.
com.jogamp.common.nio.NativeBuffer.position
int position()
Returns this buffer's element position.
com.jogamp.common.nio.NativeBuffer.clear
B clear()
Sets the limit to the capacity and the position to zero.
com.jogamp.common.nio.NativeBuffer.limit
B limit(int newLim)
Sets this buffer's element limit.
com.jogamp.common.nio.NativeBuffer.remaining
int remaining()
Returns this buffer's remaining element, i.e.
com.jogamp.common.nio.NativeBuffer.hasArray
boolean hasArray()
com.jogamp.common.nio.NativeBuffer.hasRemaining
boolean hasRemaining()
Returns remaining() > 0.
com.jogamp.common.nio.NativeBuffer.limit
int limit()
Returns this buffer's element limit.
com.jogamp.common.nio.NativeBuffer.array
Object array()