Copyright (c) 1998 Sun Microsystems, Inc. All Rights Reserved.
Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
modify and redistribute this software in source and binary code form,
provided that i) this copyright notice and license appear on all copies of
the software; and ii) Licensee does not utilize the software in a manner
which is disparaging to Sun.
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 PARTICULAR PURPOSE OR
NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
This software is not designed or intended for use in on-line control of
aircraft, air traffic, aircraft navigation or aircraft communications; or in
the design, construction, operation or maintenance of any nuclear
facility. Licensee represents and warrants that it will not use or
redistribute the Software for such purposes.
/*
* @(#)CPtr.java 1.8 98/03/22
*
* Copyright (c) 1998 Sun Microsystems, Inc. All Rights Reserved.
*
* See also the LICENSE file in this distribution.
*/
/**
* An abstraction for a C pointer data type. A CPtr instance represents, on
* the Java side, a C pointer. The C pointer could be any type of C
* pointer. Methods such ascopyIn
,copyOut
,
*getXXX
, andsetXXX
, provide
* means to indirect the underlying C pointer.
*
* @author Sheng Liang
* @see CFunc
*/
public class CPtr {
/**
* The size of a C pointer on the platform this Java virtual machine is
* running on.
*/
public static final int SIZE;
/**
* A canonical representation of C's NULL pointer.
*/
public static final CPtr NULL;
/**
* Compares thisCPtr
to the specified object.
*
* @param other aCPtr
* @return true if the class of thisCPtr
object and the
* class ofother
are exactly equal, and the C
* pointers being pointed to by these objects are also
* equal. Returns false otherwise.
*/
public boolean equals(Object other) {
if (other == null)
return false;
if (other == this)
return true;
if (CPtr.class != other.getClass())
return false;
return peer == ((CPtr)other).peer;
}
/**
* Returns a hashcode for the C pointer represented by this
*Cptr
object.
*
* @return a hash code value for the represented C pointer.
*/
public int hashCode() {
return (int)((peer >>> 32) + (peer & 0xFFFFFFFF));
}
/**
* Indirect the C pointer, copying into memory pointed to by C
* pointer, from the specified array.
*
* @param bOff byte offset from pointer into which data is copied
* @param bufbyte
array from which to copy
* @param index array index from which to start copying
* @param length number of elements frombuf
that must be
* copied
*/
public native void copyIn(int bOff, byte[] buf, int index, int length);
/**
* Indirect the C pointer, copying into memory pointed to by C
* pointer, from the specified array.
*
* @param bOff byte offset from pointer into which data is copied
* @param bufshort
array from which to copy
* @param index array index from which to start copying
* @param length number of elements frombuf
that must be
* copied
*/
public native void copyIn(int bOff, short[] buf, int index, int length);
/**
* Indirect the C pointer, copying into memory pointed to by C
* pointer, from the specified array.
*
* @param bOff byte offset from pointer into which data is copied
* @param bufchar
array from which to copy
* @param index array index from which to start copying
* @param length number of elements frombuf
that must be
* copied
*/
public native void copyIn(int bOff, char[] buf, int index, int length);
/**
* Indirect the C pointer, copying into memory pointed to by C
* pointer, from the specified array.
*
* @param bOff byte offset from pointer into which data is copied
* @param bufint
array from which to copy
* @param index array index from which to start copying
* @param length number of elements frombuf
that must be
* copied
*/
public native void copyIn(int bOff, int[] buf, int index, int length);
/**
* Indirect the C pointer, copying into memory pointed to by C
* pointer, from the specified array.
*
* @param bOff byte offset from pointer into which data is copied
* @param buflong
array from which to copy
* @param index array index from which to start copying
* @param length number of elements frombuf
that must be
* copied
*/
public native void copyIn(int bOff, long[] buf, int index, int length);
/**
* Indirect the C pointer, copying into memory pointed to by C
* pointer, from the specified array.
*
* @param bOff byte offset from pointer into which data is copied
* @param buffloat
array from which to copy
* @param index array index from which to start copying
* @param length number of elements frombuf
that must be
* copied
*/
public native void copyIn(int bOff, float[] buf, int index, int length);
/**
* Indirect the C pointer, copying into memory pointed to by C
* pointer, from the specified array.
*
* @param bOff byte offset from pointer into which data is copied
* @param bufdouble
array from which to copy
* @param index array index from which to start copying
* @param length number of elements frombuf
that must be
* copied
*/
public native void copyIn(int bOff, double[] buf, int index, int length);
/**
* Indirect the C pointer, copying from memory pointed to by C
* pointer, into the specified array.
*
* @param bOff byte offset from pointer into which data is copied
* @param bufbyte
array into which data is copied
* @param index array index from which to start copying
* @param length number of elements from C pointer that must be copied
*/
public native void copyOut(int bOff, byte[] buf, int index, int length);
/**
* Indirect the C pointer, copying from memory pointed to by C
* pointer, into the specified array.
*
* @param bOff byte offset from pointer from which data is copied
* @param bufshort
array into which data is copied
* @param index array index to which data is copied
* @param length number of elements from C pointer that must be copied
*/
public native void copyOut(int bOff, short[] buf, int index, int length);
/**
* Indirect the C pointer, copying from memory pointed to by C
* pointer, into the specified array.
*
* @param bOff byte offset from pointer from which data is copied
* @param bufchar
array into which data is copied
* @param index array index to which data is copied
* @param length number of elements from C pointer that must be copied
*/
public native void copyOut(int bOff, char[] buf, int index, int length);
/**
* Indirect the C pointer, copying from memory pointed to by C
* pointer, into the specified array.
*
* @param bOff byte offset from pointer from which data is copied
* @param bufint
array into which data is copied
* @param index array index to which data is copied
* @param length number of elements from C pointer that must be copied
*/
public native void copyOut(int bOff, int[] buf, int index, int length);
/**
* Indirect the C pointer, copying from memory pointed to by C
* pointer, into the specified array.
*
* @param bOff byte offset from pointer from which data is copied
* @param buflong
array into which data is copied
* @param index array index to which data is copied
* @param length number of elements from C pointer that must be copied
*/
public native void copyOut(int bOff, long[] buf, int index, int length);
/**
* Indirect the C pointer, copying from memory pointed to by C
* pointer, into the specified array.
*
* @param bOff byte offset from pointer from which data is copied
* @param buffloat
array into which data is copied
* @param index array index to which data is copied
* @param length number of elements from C pointer that must be copied
*/
public native void copyOut(int bOff, float[] buf, int index, int length);
/**
* Indirect the C pointer, copying from memory pointed to by C
* pointer, into the specified array.
*
* @param bOff byte offset from pointer from which data is copied
* @param bufdouble
array into which data is copied
* @param index array index to which data is copied
* @param length number of elements from C pointer that must be copied
*/
public native void copyOut(int bOff, double[] buf, int index, int length);
/**
* Indirect the C pointer as a pointer tobyte
. This is
* equivalent to the expression
**((jbyte *)((char *)cptr + * offset))
.
*
* @param offset offset from pointer to perform the indirection
* @return thebyte
value being pointed to
*/
public native byte getByte(int offset);
/**
* Indirect the C pointer as a pointer toshort
. This is
* equivalent to the expression
**((jshort *)((char *)cptr + offset))
.
*
* @param offset byte offset from pointer to perform the indirection
* @return theshort
value being pointed to
*/
public native short getShort(int offset);
/**
* Indirect the C pointer as a pointer toint
. This is
* equivalent to the expression
**((jint *)((char *)cptr + offset))
.
*
* @param offset byte offset from pointer to perform the indirection
* @return theint
value being pointed to
*/
public native int getInt(int offset);
/**
* Indirect the C pointer as a pointer tolong
. This is
* equivalent to the expression
**((jlong *)((char *)cptr + offset))
.
*
* @param offset byte offset from pointer to perform the indirection
* @return thelong
value being pointed to
*/
public native long getLong(int offset);
/**
* Indirect the C pointer as a pointer tofloat
. This is
* equivalent to the expression
**((jfloat *)((char *)cptr + offset))
.
*
* @param offset byte offset from pointer to perform the indirection
* @return thefloat
value being pointed to
*/
public native float getFloat(int offset);
/**
* Indirect the C pointer as a pointer todouble
. This is
* equivalent to the expression
**((jdouble *)((char *)cptr + offset))
.
*
* @param offset byte offset from pointer to perform the indirection
* @return thedouble
value being pointed to
*/
public native double getDouble(int offset);
/**
* Indirect the C pointer as a pointer to pointer. This is equivalent to
* the expression*((void **)((char *)cptr + offset))
.
*
* @param offset byte offset from pointer to perform the indirection
* @return thepointer
value being pointed to
*/
public native CPtr getCPtr(int offset);
/**
* Indirect the C pointer as a pointer tochar *
, a
*NULL
-terminated C string. Convert the C string to a
*java.lang.String
.
*
* @param offset byte offset from pointer to obtain the C string
* @return theString
value being pointed to
*/
public native String getString(int offset);
/**
* Setvalue
at location being pointed to. This is equivalent
* to the expression
**((jbyte *)((char *)cptr + offset)) = value
.
*
* @param offset byte offset from pointer at whichvalue
* must be set
* @param valuebyte
value to set
*/
public native void setByte(int offset, byte value);
/**
* Setvalue
at location being pointed to. This is equivalent
* to the expression
**((jshort *)((char *)cptr + offset)) = value
.
*
* @param offset byte offset from pointer at whichvalue
* must be set
* @param valueshort
value to set
*/
public native void setShort(int offset, short value);
/**
* Setvalue
at location being pointed to. This is equivalent
* to the expression
**((jint *)((char *)cptr + offset)) = value
.
*
* @param offset byte offset from pointer at whichvalue
* must be set
* @param valueint
value to set
*/
public native void setInt(int offset, int value);
/**
* Setvalue
at location being pointed to. This is equivalent
* to the expression
**((jlong *)((char *)cptr + offset)) = value
.
*
* @param offset byte offset from pointer at whichvalue
* must be set
* @param valuelong
value to set
*/
public native void setLong(int offset, long value);
/**
* Setvalue
at location being pointed to. This is equivalent
* to the expression
**((jfloat *)((char *)cptr + offset)) = value
.
*
* @param offset byte offset from pointer at whichvalue
* must be set
* @param valuefloat
value to set
*/
public native void setFloat(int offset, float value);
/**
* Setvalue
at location being pointed to. This is equivalent
* to the expression
**((jdouble *)((char *)cptr + offset)) = value
.
*
* @param offset byte offset from pointer at whichvalue
* must be set
* @param valuedouble
value to set
*/
public native void setDouble(int offset, double value);
/**
* Setvalue
at location being pointed to. This is equivalent
* to the expression *((void **)((char *)cptr + offset)) = value.
*
* @param offset byte offset from pointer at whichvalue
* must be set
* @param valueCPtr
value to set
*/
public native void setCPtr(int offset, CPtr value);
/**
* Copy stringvalue
to the location being pointed to. Copy
* each element invalue
, converted to native encoding, at an
*offset
from the location pointed to by this pointer.
*
* @param offset byte offset from pointer at which characters in
*value
must be set
* @param valuejava.lang.String
value to set
*/
public native void setString(int offset, String value);
/* Initialize field and method IDs for native methods of this class. */
private static native int initIDs(CPtr p);
static {
System.loadLibrary("disp");
NULL = new CPtr();
SIZE = initIDs(NULL);
}
/* peer and the no-args constructor are deliberately package private, so
all classes that are abstractions of a C pointer will can only be in
one isolated package. */
/* Pointer value of the real C pointer. Use long to be 64-bit safe. */
long peer;
/* No-args constructor, see comment above. */
CPtr() {}
}
feedme java project
is free software, licensed under the terms of the GNU General Public License, that feeds/imports media from anywhere to xbox360 media center extenders, ipods, web servers, file servers, etc. using Java.
Please read the license here.
Please read the license here.
Thursday, September 6, 2007
CPtr.java
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment