diff options
Diffstat (limited to 'src/java/com/jogamp/common/nio')
-rw-r--r-- | src/java/com/jogamp/common/nio/AbstractBuffer.java | 20 | ||||
-rw-r--r-- | src/java/com/jogamp/common/nio/Buffers.java | 156 | ||||
-rw-r--r-- | src/java/com/jogamp/common/nio/CachedBufferFactory.java | 54 | ||||
-rw-r--r-- | src/java/com/jogamp/common/nio/NativeBuffer.java | 16 | ||||
-rw-r--r-- | src/java/com/jogamp/common/nio/PointerBuffer.java | 44 | ||||
-rw-r--r-- | src/java/com/jogamp/common/nio/StructAccessor.java | 50 |
6 files changed, 170 insertions, 170 deletions
diff --git a/src/java/com/jogamp/common/nio/AbstractBuffer.java b/src/java/com/jogamp/common/nio/AbstractBuffer.java index 4afff2a..4213a4d 100644 --- a/src/java/com/jogamp/common/nio/AbstractBuffer.java +++ b/src/java/com/jogamp/common/nio/AbstractBuffer.java @@ -3,14 +3,14 @@ * * 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 @@ -20,12 +20,12 @@ * 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. */ - + /* * Created on Saturday, March 27 2010 11:55 */ @@ -51,7 +51,7 @@ public abstract class AbstractBuffer<B extends AbstractBuffer> implements Native Platform.initSingleton(); // loads native gluegen-rt library } - /** + /** * capacity and elementSize should be match the equation w/ target buffer type * <pre> * capacity = elementSizeInBytes(buffer) * buffer.capacity() ) / elementSize @@ -64,14 +64,14 @@ public abstract class AbstractBuffer<B extends AbstractBuffer> implements Native this.buffer = buffer; this.elementSize = elementSize; this.capacity = capacity; - + this.position = 0; } public final int elementSize() { return elementSize; } - + public final int limit() { return capacity; } @@ -113,7 +113,7 @@ public abstract class AbstractBuffer<B extends AbstractBuffer> implements Native public final boolean isDirect() { return buffer.isDirect(); } - + public final boolean hasArray() { return buffer.hasArray(); } @@ -129,7 +129,7 @@ public abstract class AbstractBuffer<B extends AbstractBuffer> implements Native public Object array() throws UnsupportedOperationException { return buffer.array(); } - + @Override public String toString() { return "AbstractBuffer[direct "+isDirect()+", hasArray "+hasArray()+", capacity "+capacity+", position "+position+", elementSize "+elementSize+", buffer[capacity "+buffer.capacity()+", lim "+buffer.limit()+", pos "+buffer.position()+"]]"; diff --git a/src/java/com/jogamp/common/nio/Buffers.java b/src/java/com/jogamp/common/nio/Buffers.java index 851aa69..c63a094 100644 --- a/src/java/com/jogamp/common/nio/Buffers.java +++ b/src/java/com/jogamp/common/nio/Buffers.java @@ -1,22 +1,22 @@ /* * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Copyright (c) 2010 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: - * + * * - Redistribution of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. - * + * * - Redistribution 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. - * + * * Neither the name of Sun Microsystems, Inc. or the names of * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. - * + * * This software is provided "AS IS," without a warranty of any kind. ALL * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A @@ -29,11 +29,11 @@ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * + * * You acknowledge that this software is not designed or intended for use * in the design, construction, operation or maintenance of any nuclear * facility. - * + * * Sun gratefully acknowledges that this software was originally authored * and developed by Kenneth Bradley Russell and Christopher John Kline. */ @@ -47,7 +47,7 @@ import com.jogamp.common.util.ValueConv; /** * Utility methods allowing easy {@link java.nio.Buffer} manipulations. - * + * * @author Kenneth Russel * @author Sven Gothel * @author Michael Bien @@ -213,7 +213,7 @@ public class Buffers { /** * Calls slice on the specified buffer while maintaining the byteorder. - * @see #slice(java.nio.Buffer, int, int) + * @see #slice(java.nio.Buffer, int, int) */ @SuppressWarnings("unchecked") public static <B extends Buffer> B slice(B buffer) { @@ -264,22 +264,22 @@ public class Buffers { * The returned sliced buffer's start position is not necessarily zero, * but the float position within the host ByteBuffer. * </p> - * <p> + * <p> * The returned sliced buffer is {@link FloatBuffer#mark() marked} at it's starting position. Hence - * {@link FloatBuffer#reset()} will rewind it to start after applying relative operations like {@link FloatBuffer#get()}. + * {@link FloatBuffer#reset()} will rewind it to start after applying relative operations like {@link FloatBuffer#get()}. * </p> - * <p> - * Using a ByteBuffer as the source guarantees - * keeping the source native order programmatically. - * This works around <a href="http://code.google.com/p/android/issues/detail?id=16434">Honeycomb / Android 3.0 Issue 16434</a>. + * <p> + * Using a ByteBuffer as the source guarantees + * keeping the source native order programmatically. + * This works around <a href="http://code.google.com/p/android/issues/detail?id=16434">Honeycomb / Android 3.0 Issue 16434</a>. * This bug is resolved at least in Android 3.2. * </p> - * - * @param buf source Buffer, maybe ByteBuffer (recommended) or FloatBuffer or <code>null</code>. + * + * @param buf source Buffer, maybe ByteBuffer (recommended) or FloatBuffer or <code>null</code>. * Buffer's position is ignored and floatPos is being used. * @param backing source float array or <code>null</code> * @param floatPos {@link Buffers#SIZEOF_FLOAT} position - * @param floatSize {@link Buffers#SIZEOF_FLOAT} size + * @param floatSize {@link Buffers#SIZEOF_FLOAT} size * @return FloatBuffer w/ native byte order as given ByteBuffer */ public static final FloatBuffer slice2Float(Buffer buf, float[] backing, int floatPos, int floatSize) { @@ -318,7 +318,7 @@ public class Buffers { return res; } - + /** * Helper routine to set a ByteBuffer to the native byte order, if * that operation is supported by the underlying NIO @@ -329,7 +329,7 @@ public class Buffers { } /** - * Returns the size of a single element of the given buffer in bytes + * Returns the size of a single element of the given buffer in bytes * or <code>0</code> if the given buffer is <code>null</code>. */ public static int sizeOfBufferElem(Object buffer) { @@ -358,7 +358,7 @@ public class Buffers { /** * Returns the number of remaining elements of the given anonymous <code>buffer</code>. - * + * * @param buffer Anonymous <i>Buffer</i> of type {@link NativeBuffer} or a derivation of {@link Buffer}. * @return If <code>buffer</code> is null, returns <code>0<code>, otherwise the remaining size in elements. * @throws IllegalArgumentException if <code>buffer</code> is of invalid type. @@ -375,10 +375,10 @@ public class Buffers { throw new IllegalArgumentException("Unsupported anonymous buffer type: "+buffer.getClass().getCanonicalName()); } } - + /** * Returns the number of remaining bytes of the given anonymous <code>buffer</code>. - * + * * @param buffer Anonymous <i>Buffer</i> of type {@link NativeBuffer} or a derivation of {@link Buffer}. * @return If <code>buffer</code> is null, returns <code>0<code>, otherwise the remaining size in bytes. * @throws IllegalArgumentException if <code>buffer</code> is of invalid type. @@ -434,11 +434,11 @@ public class Buffers { if (buf instanceof ByteBuffer) { return ((ByteBuffer) buf).isDirect(); } else if (buf instanceof IntBuffer) { - return ((IntBuffer) buf).isDirect(); + return ((IntBuffer) buf).isDirect(); } else if (buf instanceof ShortBuffer) { - return ((ShortBuffer) buf).isDirect(); + return ((ShortBuffer) buf).isDirect(); } else if (buf instanceof FloatBuffer) { - return ((FloatBuffer) buf).isDirect(); + return ((FloatBuffer) buf).isDirect(); } else if (buf instanceof DoubleBuffer) { return ((DoubleBuffer) buf).isDirect(); } else if (buf instanceof LongBuffer) { @@ -490,7 +490,7 @@ public class Buffers { * Helper routine to return the array backing store reference from * a Buffer object. * @throws UnsupportedOperationException if the passed Object does not have an array backing store - * @throws IllegalArgumentException if the passed Object is neither of type {@link java.nio.Buffer} or {@link NativeBuffer}. + * @throws IllegalArgumentException if the passed Object is neither of type {@link java.nio.Buffer} or {@link NativeBuffer}. */ public static Object getArray(Object buf) throws UnsupportedOperationException, IllegalArgumentException { if (buf == null) { @@ -557,7 +557,7 @@ public class Buffers { ByteBuffer dest = newDirectByteBuffer(orig.remaining()); dest.put(orig); dest.rewind(); - orig.position(op0); + orig.position(op0); return dest; } @@ -752,8 +752,8 @@ public class Buffers { //---------------------------------------------------------------------- // Convenient put methods with generic target Buffer w/o value range conversion, i.e. normalization - // - + // + @SuppressWarnings("unchecked") public static <B extends Buffer> B put(B dest, Buffer src) { if ((dest instanceof ByteBuffer) && (src instanceof ByteBuffer)) { @@ -841,7 +841,7 @@ public class Buffers { throw new IllegalArgumentException("Float doesn't match Buffer Class: " + dest); } } - + @SuppressWarnings("unchecked") public static <B extends Buffer> B putd(B dest, double v) { if (dest instanceof FloatBuffer) { @@ -855,15 +855,15 @@ public class Buffers { // Convenient put methods with generic target Buffer and value range conversion, i.e. normalization // - /** + /** * Store byte source value in given buffer after normalizing it to the destination value range * considering signed and unsigned source and destination representation. - * + * * @param dest One of {@link ByteBuffer}, {@link ShortBuffer}, {@link IntBuffer}, {@link FloatBuffer} * @param dSigned true if destination buffer holds signed values, false if destination buffer holds unsigned values * @param v source byte value to be put in dest buffer * @param sSigned true if source represents a signed value, false if source represents an unsigned value - */ + */ @SuppressWarnings("unchecked") public static <B extends Buffer> B putNb(B dest, boolean dSigned, byte v, boolean sSigned) { if (dest instanceof ByteBuffer) { @@ -872,22 +872,22 @@ public class Buffers { return (B) ((ShortBuffer) dest).put( ValueConv.byte_to_short(v, sSigned, dSigned) ); } else if (dest instanceof IntBuffer) { return (B) ((IntBuffer) dest).put( ValueConv.byte_to_int(v, sSigned, dSigned) ); - } else if (dest instanceof FloatBuffer) { + } else if (dest instanceof FloatBuffer) { return (B) ((FloatBuffer) dest).put( ValueConv.byte_to_float(v, sSigned) ); } else { throw new IllegalArgumentException("Byte doesn't match Buffer Class: " + dest); } } - /** + /** * Store short source value in given buffer after normalizing it to the destination value range * considering signed and unsigned source and destination representation. - * + * * @param dest One of {@link ByteBuffer}, {@link ShortBuffer}, {@link IntBuffer}, {@link FloatBuffer} * @param dSigned true if destination buffer holds signed values, false if destination buffer holds unsigned values * @param v source short value to be put in dest buffer * @param sSigned true if source represents a signed value, false if source represents an unsigned value - */ + */ @SuppressWarnings("unchecked") public static <B extends Buffer> B putNs(B dest, boolean dSigned, short v, boolean sSigned) { if (dest instanceof ByteBuffer) { @@ -896,22 +896,22 @@ public class Buffers { return (B) ((ShortBuffer) dest).put( v ); } else if (dest instanceof IntBuffer) { return (B) ((IntBuffer) dest).put( ValueConv.short_to_int(v, sSigned, dSigned) ); - } else if (dest instanceof FloatBuffer) { + } else if (dest instanceof FloatBuffer) { return (B) ((FloatBuffer) dest).put( ValueConv.short_to_float(v, sSigned) ); } else { throw new IllegalArgumentException("Byte doesn't match Buffer Class: " + dest); } } - - /** + + /** * Store short source value in given buffer after normalizing it to the destination value range * considering signed and unsigned source and destination representation. - * + * * @param dest One of {@link ByteBuffer}, {@link ShortBuffer}, {@link IntBuffer}, {@link FloatBuffer} * @param dSigned true if destination buffer holds signed values, false if destination buffer holds unsigned values * @param v source short value to be put in dest buffer * @param sSigned true if source represents a signed value, false if source represents an unsigned value - */ + */ @SuppressWarnings("unchecked") public static <B extends Buffer> B putNi(B dest, boolean dSigned, int v, boolean sSigned) { if (dest instanceof ByteBuffer) { @@ -920,21 +920,21 @@ public class Buffers { return (B) ((ShortBuffer) dest).put( ValueConv.int_to_short(v, sSigned, dSigned) ); } else if (dest instanceof IntBuffer) { return (B) ((IntBuffer) dest).put( v ); - } else if (dest instanceof FloatBuffer) { + } else if (dest instanceof FloatBuffer) { return (B) ((FloatBuffer) dest).put( ValueConv.int_to_float(v, sSigned) ); } else { throw new IllegalArgumentException("Byte doesn't match Buffer Class: " + dest); } } - - /** + + /** * Store float source value in given buffer after normalizing it to the destination value range * considering signed and unsigned destination representation. - * + * * @param dest One of {@link ByteBuffer}, {@link ShortBuffer}, {@link IntBuffer}, {@link FloatBuffer} * @param dSigned true if destination buffer holds signed values, false if destination buffer holds unsigned values * @param v source float value to be put in dest buffer - */ + */ @SuppressWarnings("unchecked") public static <B extends Buffer> B putNf(B dest, boolean dSigned, float v) { if (dest instanceof ByteBuffer) { @@ -943,17 +943,17 @@ public class Buffers { return (B) ((ShortBuffer) dest).put( ValueConv.float_to_short(v, dSigned) ); } else if (dest instanceof IntBuffer) { return (B) ((IntBuffer) dest).put( ValueConv.float_to_int(v, dSigned) ); - } else if (dest instanceof FloatBuffer) { + } else if (dest instanceof FloatBuffer) { return (B) ((FloatBuffer) dest).put( v ); } else { throw new IllegalArgumentException("Byte doesn't match Buffer Class: " + dest); } } - + //---------------------------------------------------------------------- - // Range check methods + // Range check methods // - + public static void rangeCheck(byte[] array, int offset, int minElementsRemaining) { if (array == null) { return; @@ -1049,13 +1049,13 @@ public class Buffers { throw new IndexOutOfBoundsException("Required " + minBytesRemaining + " remaining bytes in buffer, only had " + bytesRemaining); } } - + /** * Appends Buffer details inclusive data to a StringBuilder instance. * @param sb optional pass through StringBuilder - * @param f optional format string of one element, i.e. "%10.5f" for {@link FloatBuffer}, see {@link java.util.Formatter}, - * or <code>null</code> for unformatted output. - * <b>Note:</b> Caller is responsible to match the format string w/ the data type as expected in the given buffer. + * @param f optional format string of one element, i.e. "%10.5f" for {@link FloatBuffer}, see {@link java.util.Formatter}, + * or <code>null</code> for unformatted output. + * <b>Note:</b> Caller is responsible to match the format string w/ the data type as expected in the given buffer. * @param buffer Any valid Buffer instance * @return the modified StringBuilder containing the Buffer details */ @@ -1073,74 +1073,74 @@ public class Buffers { for(int i=0; i<b.limit(); i++) { if(0<i) { sb.append(", "); } if(null == f) { - sb.append(b.get(i)); + sb.append(b.get(i)); } else { - sb.append(String.format(f, b.get(i))); - } + sb.append(String.format(f, b.get(i))); + } } } else if (buffer instanceof FloatBuffer) { final FloatBuffer b = (FloatBuffer)buffer; for(int i=0; i<b.limit(); i++) { if(0<i) { sb.append(", "); } if(null == f) { - sb.append(b.get(i)); + sb.append(b.get(i)); } else { - sb.append(String.format(f, b.get(i))); - } + sb.append(String.format(f, b.get(i))); + } } } else if (buffer instanceof IntBuffer) { final IntBuffer b = (IntBuffer)buffer; for(int i=0; i<b.limit(); i++) { if(0<i) { sb.append(", "); } if(null == f) { - sb.append(b.get(i)); + sb.append(b.get(i)); } else { - sb.append(String.format(f, b.get(i))); - } + sb.append(String.format(f, b.get(i))); + } } } else if (buffer instanceof ShortBuffer) { final ShortBuffer b = (ShortBuffer)buffer; for(int i=0; i<b.limit(); i++) { if(0<i) { sb.append(", "); } if(null == f) { - sb.append(b.get(i)); + sb.append(b.get(i)); } else { - sb.append(String.format(f, b.get(i))); - } + sb.append(String.format(f, b.get(i))); + } } } else if (buffer instanceof DoubleBuffer) { final DoubleBuffer b = (DoubleBuffer)buffer; for(int i=0; i<b.limit(); i++) { if(0<i) { sb.append(", "); } if(null == f) { - sb.append(b.get(i)); + sb.append(b.get(i)); } else { - sb.append(String.format(f, b.get(i))); - } + sb.append(String.format(f, b.get(i))); + } } } else if (buffer instanceof LongBuffer) { final LongBuffer b = (LongBuffer)buffer; for(int i=0; i<b.limit(); i++) { if(0<i) { sb.append(", "); } if(null == f) { - sb.append(b.get(i)); + sb.append(b.get(i)); } else { - sb.append(String.format(f, b.get(i))); - } + sb.append(String.format(f, b.get(i))); + } } } else if (buffer instanceof CharBuffer) { final CharBuffer b = (CharBuffer)buffer; for(int i=0; i<b.limit(); i++) { if(0<i) { sb.append(", "); } if(null == f) { - sb.append(b.get(i)); + sb.append(b.get(i)); } else { - sb.append(String.format(f, b.get(i))); - } + sb.append(String.format(f, b.get(i))); + } } } sb.append("]"); return sb; } - + } diff --git a/src/java/com/jogamp/common/nio/CachedBufferFactory.java b/src/java/com/jogamp/common/nio/CachedBufferFactory.java index b9d75db..6ddff4a 100644 --- a/src/java/com/jogamp/common/nio/CachedBufferFactory.java +++ b/src/java/com/jogamp/common/nio/CachedBufferFactory.java @@ -4,14 +4,14 @@ * * 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 @@ -21,7 +21,7 @@ * 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. @@ -58,7 +58,7 @@ import java.nio.ShortBuffer; * <li>factories created with createSynchronized(...) are threadsafe</li> * </ul> * </p> - * + * * @author Michael Bien */ public class CachedBufferFactory { @@ -67,20 +67,20 @@ public class CachedBufferFactory { * default size for internal buffer allocation. */ public static final int DEFAULT_ALLOCATION_SIZE = 1024 * 1024; - + private final int ALLOCATION_SIZE; private ByteBuffer currentBuffer; - + private CachedBufferFactory() { this(DEFAULT_ALLOCATION_SIZE, DEFAULT_ALLOCATION_SIZE); } - + private CachedBufferFactory(int initialSize, int allocationSize) { currentBuffer = Buffers.newDirectByteBuffer(initialSize); ALLOCATION_SIZE = allocationSize; } - - + + /** * Creates a factory with initial size and allocation size set to * {@link #DEFAULT_ALLOCATION_SIZE}. @@ -88,7 +88,7 @@ public class CachedBufferFactory { public static CachedBufferFactory create() { return new CachedBufferFactory(); } - + /** * Creates a factory with the specified initial size. The allocation size is set to * {@link #DEFAULT_ALLOCATION_SIZE}. @@ -96,7 +96,7 @@ public class CachedBufferFactory { public static CachedBufferFactory create(int initialSize) { return new CachedBufferFactory(initialSize, DEFAULT_ALLOCATION_SIZE); } - + /** * Creates a factory with the specified initial size. The allocation size is set to * {@link #DEFAULT_ALLOCATION_SIZE}. @@ -106,43 +106,43 @@ public class CachedBufferFactory { public static CachedBufferFactory create(int initialSize, boolean fixed) { return new CachedBufferFactory(initialSize, fixed?-1:DEFAULT_ALLOCATION_SIZE); } - + /** * Creates a factory with the specified initial size and allocation size. */ public static CachedBufferFactory create(int initialSize, int allocationSize) { return new CachedBufferFactory(initialSize, allocationSize); } - - + + /** * Synchronized version of {@link #create()}. */ public static CachedBufferFactory createSynchronized() { return new SynchronizedCachedBufferFactory(); } - + /** * Synchronized version of {@link #create(int)}. */ public static CachedBufferFactory createSynchronized(int initialSize) { return new SynchronizedCachedBufferFactory(initialSize, DEFAULT_ALLOCATION_SIZE); } - + /** * Synchronized version of {@link #create(int, boolean)}. */ public static CachedBufferFactory createSynchronized(int initialSize, boolean fixed) { return new SynchronizedCachedBufferFactory(initialSize, fixed?-1:DEFAULT_ALLOCATION_SIZE); } - + /** * Synchronized version of {@link #create(int, int)}. */ public static CachedBufferFactory createSynchronized(int initialSize, int allocationSize) { return new CachedBufferFactory(initialSize, allocationSize); } - + /** * Returns true only if this factory does not allow to allocate more buffers * as limited by the initial size. @@ -150,7 +150,7 @@ public class CachedBufferFactory { public boolean isFixed() { return ALLOCATION_SIZE == -1; } - + /** * Returns the allocation size used to create new internal buffers. * 0 means that the buffer will not grows, see {@link #isFixed()}. @@ -158,7 +158,7 @@ public class CachedBufferFactory { public int getAllocationSize() { return ALLOCATION_SIZE; } - + /** * @return true if buffer cannot grow, otherwise false */ @@ -175,7 +175,7 @@ public class CachedBufferFactory { } } public ByteBuffer newDirectByteBuffer(int size) { - + // if large enough... just create it if (size > currentBuffer.capacity()) { checkIfFixed(); @@ -194,7 +194,7 @@ public class CachedBufferFactory { currentBuffer.limit(currentBuffer.capacity()); return result; } - + public ByteBuffer newDirectByteBuffer(byte[] values, int offset, int lenght) { return (ByteBuffer)newDirectByteBuffer(lenght).put(values, offset, lenght).rewind(); @@ -326,8 +326,8 @@ public class CachedBufferFactory { public String toString() { return getClass().getName()+"[static:"+isFixed()+" alloc size:"+getAllocationSize()+"]"; } - - + + // nothing special, just synchronized private static class SynchronizedCachedBufferFactory extends CachedBufferFactory { @@ -338,12 +338,12 @@ public class CachedBufferFactory { private SynchronizedCachedBufferFactory(int size, int step) { super(size, step); } - + @Override public synchronized ByteBuffer newDirectByteBuffer(int size) { return super.newDirectByteBuffer(size); } - + } } diff --git a/src/java/com/jogamp/common/nio/NativeBuffer.java b/src/java/com/jogamp/common/nio/NativeBuffer.java index 0273976..d81da9d 100644 --- a/src/java/com/jogamp/common/nio/NativeBuffer.java +++ b/src/java/com/jogamp/common/nio/NativeBuffer.java @@ -3,14 +3,14 @@ * * 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 @@ -20,12 +20,12 @@ * 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. */ - + /* * Created on Tuesday, March 30 2010 18:22 */ @@ -43,7 +43,7 @@ import java.nio.Buffer; public interface NativeBuffer<B extends NativeBuffer> { public int elementSize(); - + public int limit(); public int capacity(); @@ -66,8 +66,8 @@ public interface NativeBuffer<B extends NativeBuffer> { * otherwise 0. */ public int arrayOffset(); - - /** + + /** * @return the primitive backup array of the buffer if {@link #hasArray()} is true, * otherwise it throws {@link java.lang.UnsupportedOperationException}. * The returned primitive array maybe of type <code>int[]</code> or <code>long[]</code>, etc .. diff --git a/src/java/com/jogamp/common/nio/PointerBuffer.java b/src/java/com/jogamp/common/nio/PointerBuffer.java index df1c4b1..4a479f0 100644 --- a/src/java/com/jogamp/common/nio/PointerBuffer.java +++ b/src/java/com/jogamp/common/nio/PointerBuffer.java @@ -3,14 +3,14 @@ * * 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 @@ -20,7 +20,7 @@ * 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. @@ -60,22 +60,22 @@ public class PointerBuffer extends AbstractBuffer<PointerBuffer> { static PointerBuffer create(ByteBuffer bb) { return Platform.is32Bit() ? new PointerBuffer( bb.asIntBuffer() ) : new PointerBuffer( bb.asLongBuffer() ); } - + /** supports backup array */ PointerBuffer(IntBuffer b) { super(b, ELEMENT_SIZE, b.capacity()); } - + /** supports backup array */ PointerBuffer(LongBuffer b) { super(b, ELEMENT_SIZE, b.capacity()); } - + private final void validateDataMap() { if(null == dataMap) { dataMap = new LongObjectHashMap(); - dataMap.setKeyNotFoundValue(null); - } + dataMap.setKeyNotFoundValue(null); + } } /** Returns a non direct PointerBuffer in native order, having a backup array */ @@ -84,7 +84,7 @@ public class PointerBuffer extends AbstractBuffer<PointerBuffer> { return new PointerBuffer(IntBuffer.wrap(new int[size])); } else { return new PointerBuffer(LongBuffer.wrap(new long[size])); - } + } } /** Returns a direct PointerBuffer in native order, w/o backup array */ @@ -113,9 +113,9 @@ public class PointerBuffer extends AbstractBuffer<PointerBuffer> { npb.position = position; return npb; } - - /** - * Relative bulk get method. Copy the source values <code> src[position .. capacity] [</code> + + /** + * Relative bulk get method. Copy the source values <code> src[position .. capacity] [</code> * to this buffer and increment the position by <code>capacity-position</code>. */ public final PointerBuffer put(PointerBuffer src) { if (remaining() < src.remaining()) { @@ -145,7 +145,7 @@ public class PointerBuffer extends AbstractBuffer<PointerBuffer> { } return this; } - + /** Relative get method. Get the pointer value at the current position and increment the position by one. */ public final long get() { long r = get(position); @@ -164,9 +164,9 @@ public class PointerBuffer extends AbstractBuffer<PointerBuffer> { return ((LongBuffer) buffer).get(idx); } } - - /** - * Relative bulk get method. Copy the pointer values <code> [ position .. position+length [</code> + + /** + * Relative bulk get method. Copy the pointer values <code> [ position .. position+length [</code> * to the destination array <code> [ dest[offset] .. dest[offset+length] [ </code> * and increment the position by <code>length</code>. */ public final PointerBuffer get(long[] dest, int offset, int length) { @@ -203,8 +203,8 @@ public class PointerBuffer extends AbstractBuffer<PointerBuffer> { return this; } - /** - * Relative bulk put method. Put the pointer values <code> [ src[offset] .. src[offset+length] [</code> + /** + * Relative bulk put method. Put the pointer values <code> [ src[offset] .. src[offset+length] [</code> * at the current position and increment the position by <code>length</code>. */ public final PointerBuffer put(long[] src, int offset, int length) { if (src.length<offset+length) { @@ -223,8 +223,8 @@ public class PointerBuffer extends AbstractBuffer<PointerBuffer> { /** Put the address of the given direct Buffer at the given position of this pointer array. Adding a reference of the given direct Buffer to this object. - - @throws IllegalArgumentException if bb is null or not a direct buffer + + @throws IllegalArgumentException if bb is null or not a direct buffer */ public final PointerBuffer referenceBuffer(int index, Buffer bb) { if(null==bb) { @@ -239,7 +239,7 @@ public class PointerBuffer extends AbstractBuffer<PointerBuffer> { throw new RuntimeException("Couldn't determine native address of given Buffer: "+bb); } validateDataMap(); - put(index, bbAddr); + put(index, bbAddr); dataMap.put(bbAddr, bb); return this; } diff --git a/src/java/com/jogamp/common/nio/StructAccessor.java b/src/java/com/jogamp/common/nio/StructAccessor.java index eef9dc5..d6df083 100644 --- a/src/java/com/jogamp/common/nio/StructAccessor.java +++ b/src/java/com/jogamp/common/nio/StructAccessor.java @@ -1,22 +1,22 @@ /* * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Copyright (c) 2010 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: - * + * * - Redistribution of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. - * + * * - Redistribution 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. - * + * * Neither the name of Sun Microsystems, Inc. or the names of * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. - * + * * This software is provided "AS IS," without a warranty of any kind. ALL * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A @@ -29,11 +29,11 @@ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * + * * You acknowledge that this software is not designed or intended for use * in the design, construction, operation or maintenance of any nuclear * facility. - * + * * Sun gratefully acknowledges that this software was originally authored * and developed by Kenneth Bradley Russell and Christopher John Kline. */ @@ -58,7 +58,7 @@ public class StructAccessor { return bb; } - /** + /** * Returns a slice of the current ByteBuffer starting at the * specified byte offset and extending the specified number of * bytes. Note that this method is not thread-safe with respect to @@ -116,11 +116,11 @@ public class StructAccessor { /** Retrieves the int at the specified byteOffset. */ public final int getIntAt(int byteOffset, int nativeSizeInBytes) { switch(nativeSizeInBytes) { - case 2: + case 2: return (int) bb.getShort(byteOffset) & 0x0000FFFF ; - case 4: + case 4: return bb.getInt(byteOffset); - case 8: + case 8: return (int) ( bb.getLong(byteOffset) & 0x00000000FFFFFFFFL ) ; default: throw new InternalError("invalid nativeSizeInBytes "+nativeSizeInBytes); @@ -130,20 +130,20 @@ public class StructAccessor { /** Puts a int at the specified byteOffset. */ public final void setIntAt(int byteOffset, int v, int nativeSizeInBytes) { switch(nativeSizeInBytes) { - case 2: + case 2: bb.putShort(byteOffset, (short) ( v & 0x0000FFFF ) ); break; - case 4: + case 4: bb.putInt(byteOffset, v); break; - case 8: + case 8: bb.putLong(byteOffset, (long)v & 0x00000000FFFFFFFFL ); break; default: throw new InternalError("invalid nativeSizeInBytes "+nativeSizeInBytes); } } - + /** Retrieves the float at the specified byteOffset. */ public final float getFloatAt(int byteOffset) { return bb.getFloat(byteOffset); @@ -173,13 +173,13 @@ public class StructAccessor { public final void setLongAt(int byteOffset, long v) { bb.putLong(byteOffset, v); } - + /** Retrieves the long at the specified byteOffset. */ public final long getLongAt(int byteOffset, int nativeSizeInBytes) { switch(nativeSizeInBytes) { - case 4: + case 4: return (long) bb.getInt(byteOffset) & 0x00000000FFFFFFFFL; - case 8: + case 8: return bb.getLong(byteOffset); default: throw new InternalError("invalid nativeSizeInBytes "+nativeSizeInBytes); @@ -189,17 +189,17 @@ public class StructAccessor { /** Puts a long at the specified byteOffset. */ public final void setLongAt(int byteOffset, long v, int nativeSizeInBytes) { switch(nativeSizeInBytes) { - case 4: + case 4: bb.putInt(byteOffset, (int) ( v & 0x00000000FFFFFFFFL ) ); break; - case 8: + case 8: bb.putLong(byteOffset, v); break; default: throw new InternalError("invalid nativeSizeInBytes "+nativeSizeInBytes); } } - + public final void setBytesAt(int byteOffset, byte[] v) { for (int i = 0; i < v.length; i++) { bb.put(byteOffset++, v[i]); @@ -225,18 +225,18 @@ public class StructAccessor { } return v; } - + public final void setShortsAt(int byteOffset, short[] v) { for (int i = 0; i < v.length; i++, byteOffset+=2) { bb.putShort(byteOffset, v[i]); - } + } } - + public final short[] getShortsAt(int byteOffset, short[] v) { for (int i = 0; i < v.length; i++, byteOffset+=2) { v[i] = bb.getShort(byteOffset); } - return v; + return v; } public final void setIntsAt(int byteOffset, int[] v) { |