Class CPtr
java.lang.Object
|
+----CPtr
- Subclasses:
- CFunc, CMalloc
- public class CPtr
- extends java.lang.Object
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 as copyIn
, copyOut
,
getXXX
, and setXXX
, provide
means to indirect the underlying C pointer.
- Author:
- Sheng Liang
- See Also:
- CFunc
Field Summary
|
static CPtr
|
NULL
A canonical representation of C's NULL pointer.
|
static int
|
SIZE
The size of a C pointer on the platform this Java virtual machine is
running on.
|
Method Summary
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
void
|
copyIn(int bOff,
double[] buf,
int index,
int length)
Indirect the C pointer, copying into memory pointed to by C
pointer, from the specified array.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
void
|
copyOut(int bOff,
double[] buf,
int index,
int length)
Indirect the C pointer, copying from memory pointed to by C
pointer, into the specified array.
|
boolean
|
equals(java.lang.Object other)
Compares this CPtr to the specified object.
|
byte
|
getByte(int offset)
Indirect the C pointer as a pointer to byte .
|
CPtr
|
getCPtr(int offset)
Indirect the C pointer as a pointer to pointer.
|
double
|
getDouble(int offset)
Indirect the C pointer as a pointer to double .
|
float
|
getFloat(int offset)
Indirect the C pointer as a pointer to float .
|
int
|
getInt(int offset)
Indirect the C pointer as a pointer to int .
|
long
|
getLong(int offset)
Indirect the C pointer as a pointer to long .
|
short
|
getShort(int offset)
Indirect the C pointer as a pointer to short .
|
java.lang.String
|
getString(int offset)
Indirect the C pointer as a pointer to char * , a
NULL -terminated C string.
|
int
|
hashCode()
Returns a hashcode for the C pointer represented by this
Cptr object.
|
void
|
setByte(int offset,
byte value)
Set value at location being pointed to.
|
void
|
setCPtr(int offset,
CPtr value)
Set value at location being pointed to.
|
void
|
setDouble(int offset,
double value)
Set value at location being pointed to.
|
void
|
setFloat(int offset,
float value)
Set value at location being pointed to.
|
void
|
setInt(int offset,
int value)
Set value at location being pointed to.
|
void
|
setLong(int offset,
long value)
Set value at location being pointed to.
|
void
|
setShort(int offset,
short value)
Set value at location being pointed to.
|
void
|
setString(int offset,
java.lang.String value)
Copy string value to the location being pointed to.
|
Methods inherited from class java.lang.Object
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
SIZE
public static final int SIZE
- The size of a C pointer on the platform this Java virtual machine is
running on.
NULL
public static final CPtr NULL
- A canonical representation of C's NULL pointer.
equals
public boolean equals(java.lang.Object other)
- Compares this
CPtr
to the specified object.
- Parameters:
other
- a CPtr
- Returns:
- true if the class of this
CPtr
object and the
class of other
are exactly equal, and the C
pointers being pointed to by these objects are also
equal. Returns false otherwise. - Overrides:
- equals in class java.lang.Object
hashCode
public int hashCode()
- Returns a hashcode for the C pointer represented by this
Cptr
object.
- Returns:
- a hash code value for the represented C pointer.
- Overrides:
- hashCode in class java.lang.Object
copyIn
public 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.
- Parameters:
bOff
- byte offset from pointer into which data is copied
buf
- byte
array from which to copy
index
- array index from which to start copying
length
- number of elements from buf
that must be
copied
copyIn
public 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.
- Parameters:
bOff
- byte offset from pointer into which data is copied
buf
- short
array from which to copy
index
- array index from which to start copying
length
- number of elements from buf
that must be
copied
copyIn
public 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.
- Parameters:
bOff
- byte offset from pointer into which data is copied
buf
- char
array from which to copy
index
- array index from which to start copying
length
- number of elements from buf
that must be
copied
copyIn
public 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.
- Parameters:
bOff
- byte offset from pointer into which data is copied
buf
- int
array from which to copy
index
- array index from which to start copying
length
- number of elements from buf
that must be
copied
copyIn
public 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.
- Parameters:
bOff
- byte offset from pointer into which data is copied
buf
- long
array from which to copy
index
- array index from which to start copying
length
- number of elements from buf
that must be
copied
copyIn
public 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.
- Parameters:
bOff
- byte offset from pointer into which data is copied
buf
- float
array from which to copy
index
- array index from which to start copying
length
- number of elements from buf
that must be
copied
copyIn
public void copyIn(int bOff,
double[] buf,
int index,
int length)
- Indirect the C pointer, copying into memory pointed to by C
pointer, from the specified array.
- Parameters:
bOff
- byte offset from pointer into which data is copied
buf
- double
array from which to copy
index
- array index from which to start copying
length
- number of elements from buf
that must be
copied
copyOut
public 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.
- Parameters:
bOff
- byte offset from pointer into which data is copied
buf
- byte
array into which data is copied
index
- array index from which to start copying
length
- number of elements from C pointer that must be copied
copyOut
public 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.
- Parameters:
bOff
- byte offset from pointer from which data is copied
buf
- short
array into which data is copied
index
- array index to which data is copied
length
- number of elements from C pointer that must be copied
copyOut
public 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.
- Parameters:
bOff
- byte offset from pointer from which data is copied
buf
- char
array into which data is copied
index
- array index to which data is copied
length
- number of elements from C pointer that must be copied
copyOut
public 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.
- Parameters:
bOff
- byte offset from pointer from which data is copied
buf
- int
array into which data is copied
index
- array index to which data is copied
length
- number of elements from C pointer that must be copied
copyOut
public 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.
- Parameters:
bOff
- byte offset from pointer from which data is copied
buf
- long
array into which data is copied
index
- array index to which data is copied
length
- number of elements from C pointer that must be copied
copyOut
public 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.
- Parameters:
bOff
- byte offset from pointer from which data is copied
buf
- float
array into which data is copied
index
- array index to which data is copied
length
- number of elements from C pointer that must be copied
copyOut
public void copyOut(int bOff,
double[] buf,
int index,
int length)
- Indirect the C pointer, copying from memory pointed to by C
pointer, into the specified array.
- Parameters:
bOff
- byte offset from pointer from which data is copied
buf
- double
array into which data is copied
index
- array index to which data is copied
length
- number of elements from C pointer that must be copied
getByte
public byte getByte(int offset)
- Indirect the C pointer as a pointer to
byte
. This is
equivalent to the expression
*((jbyte *)((char *)cptr + * offset))
.
- Parameters:
offset
- offset from pointer to perform the indirection
- Returns:
- the
byte
value being pointed to
getShort
public short getShort(int offset)
- Indirect the C pointer as a pointer to
short
. This is
equivalent to the expression
*((jshort *)((char *)cptr + offset))
.
- Parameters:
offset
- byte offset from pointer to perform the indirection
- Returns:
- the
short
value being pointed to
getInt
public int getInt(int offset)
- Indirect the C pointer as a pointer to
int
. This is
equivalent to the expression
*((jint *)((char *)cptr + offset))
.
- Parameters:
offset
- byte offset from pointer to perform the indirection
- Returns:
- the
int
value being pointed to
getLong
public long getLong(int offset)
- Indirect the C pointer as a pointer to
long
. This is
equivalent to the expression
*((jlong *)((char *)cptr + offset))
.
- Parameters:
offset
- byte offset from pointer to perform the indirection
- Returns:
- the
long
value being pointed to
getFloat
public float getFloat(int offset)
- Indirect the C pointer as a pointer to
float
. This is
equivalent to the expression
*((jfloat *)((char *)cptr + offset))
.
- Parameters:
offset
- byte offset from pointer to perform the indirection
- Returns:
- the
float
value being pointed to
getDouble
public double getDouble(int offset)
- Indirect the C pointer as a pointer to
double
. This is
equivalent to the expression
*((jdouble *)((char *)cptr + offset))
.
- Parameters:
offset
- byte offset from pointer to perform the indirection
- Returns:
- the
double
value being pointed to
getCPtr
public CPtr getCPtr(int offset)
- Indirect the C pointer as a pointer to pointer. This is equivalent to
the expression
*((void **)((char *)cptr + offset))
.
- Parameters:
offset
- byte offset from pointer to perform the indirection
- Returns:
- the
pointer
value being pointed to
getString
public java.lang.String getString(int offset)
- Indirect the C pointer as a pointer to
char *
, a
NULL
-terminated C string. Convert the C string to a
java.lang.String
.
- Parameters:
offset
- byte offset from pointer to obtain the C string
- Returns:
- the
String
value being pointed to
setByte
public void setByte(int offset,
byte value)
- Set
value
at location being pointed to. This is equivalent
to the expression
*((jbyte *)((char *)cptr + offset)) = value
.
- Parameters:
offset
- byte offset from pointer at which value
must be set
value
- byte
value to set
setShort
public void setShort(int offset,
short value)
- Set
value
at location being pointed to. This is equivalent
to the expression
*((jshort *)((char *)cptr + offset)) = value
.
- Parameters:
offset
- byte offset from pointer at which value
must be set
value
- short
value to set
setInt
public void setInt(int offset,
int value)
- Set
value
at location being pointed to. This is equivalent
to the expression
*((jint *)((char *)cptr + offset)) = value
.
- Parameters:
offset
- byte offset from pointer at which value
must be set
value
- int
value to set
setLong
public void setLong(int offset,
long value)
- Set
value
at location being pointed to. This is equivalent
to the expression
*((jlong *)((char *)cptr + offset)) = value
.
- Parameters:
offset
- byte offset from pointer at which value
must be set
value
- long
value to set
setFloat
public void setFloat(int offset,
float value)
- Set
value
at location being pointed to. This is equivalent
to the expression
*((jfloat *)((char *)cptr + offset)) = value
.
- Parameters:
offset
- byte offset from pointer at which value
must be set
value
- float
value to set
setDouble
public void setDouble(int offset,
double value)
- Set
value
at location being pointed to. This is equivalent
to the expression
*((jdouble *)((char *)cptr + offset)) = value
.
- Parameters:
offset
- byte offset from pointer at which value
must be set
value
- double
value to set
setCPtr
public void setCPtr(int offset,
CPtr value)
- Set
value
at location being pointed to. This is equivalent
to the expression *((void **)((char *)cptr + offset)) = value.
- Parameters:
offset
- byte offset from pointer at which value
must be set
value
- CPtr
value to set
setString
public void setString(int offset,
java.lang.String value)
- Copy string
value
to the location being pointed to. Copy
each element in value
, converted to native encoding, at an
offset
from the location pointed to by this pointer.
- Parameters:
offset
- byte offset from pointer at which characters in
value
must be set
value
- java.lang.String
value to set