Package de.intarsys.nativec.type
Class NativeObject
- java.lang.Object
-
- de.intarsys.nativec.type.NativeObject
-
- All Implemented Interfaces:
INativeObject
- Direct Known Subclasses:
NativeArray,NativeBuffer,NativeReference,NativeSimple,NativeString,NativeStruct,NativeWideString
public abstract class NativeObject extends java.lang.Object implements INativeObject
An instance of an external (C memory) represented object. The C-object is represented using the handle (the pointer to the object in C memory) and its typeINativeType.Supported data types are
- primitive types (char, byte, int, short, long, String...)
- byte buffer
- array types
- structures
- references
-
-
Field Summary
Fields Modifier and Type Field Description static booleanDEBUGDEBUG flagprotected INativeHandlehandleThe handle to the memory chunk used by this object.static intSHIFT_INTstatic intSHIFT_LONGstatic intSHIFT_LONGLONGstatic intSIZE_BYTEstatic intSIZE_INTstatic intSIZE_LONGstatic intSIZE_LONGLONGstatic intSIZE_PTRstatic intSIZE_SHORT
-
Constructor Summary
Constructors Modifier Constructor Description protectedNativeObject()protectedNativeObject(INativeHandle handle)Create a new NativeObject in C-Memory at pointer "handle".
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidallocate()Manage the objects memory in Java.INativeObjectcast(INativeType declaration)This is a special form of the "createNative" signature, implementing a "type cast" on the same memory location.INativeObjectcreateReference()bytegetByte(int index)The byte at index as a native byte.byte[]getByteArray(int index, int count)The element at index as an array of native byte with dimension count.abstract intgetByteCount()The number of bytes occupied by this.byte[]getBytes()The bytes copied from C-memory that represent this.longgetCLong(int index)The element at index as a native long.intgetInt(int index)The element at index as a native int.INativeHandlegetNativeHandle()The C-Pointer where the associated memory is found.INativeHandlegetNativeHandle(int index)abstract INativeTypegetNativeType()The meta information and behavior for the NativeObject.shortgetShort(int index)The element at index as a native short.java.lang.StringgetString(int index)java.lang.StringgetWideString(int index)booleanisNull()Answertrueif this is "null".voidsetByte(int index, byte value)voidsetByteArray(int index, byte[] value, int valueOffset, int valueCount)voidsetCLong(int index, long value)voidsetInt(int index, int value)voidsetNativeHandle(int index, INativeHandle value)voidsetShort(int index, short value)voidsetString(int index, java.lang.String value)voidsetWideString(int index, java.lang.String value)java.lang.StringtoNestedString()A string for debugging purposes.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface de.intarsys.nativec.type.INativeObject
getValue, setValue
-
-
-
-
Field Detail
-
SIZE_BYTE
public static final int SIZE_BYTE
- See Also:
- Constant Field Values
-
SIZE_INT
public static final int SIZE_INT
- See Also:
- Constant Field Values
-
SHIFT_INT
public static final int SHIFT_INT
- See Also:
- Constant Field Values
-
SIZE_LONGLONG
public static final int SIZE_LONGLONG
- See Also:
- Constant Field Values
-
SHIFT_LONGLONG
public static final int SHIFT_LONGLONG
- See Also:
- Constant Field Values
-
SIZE_LONG
public static final int SIZE_LONG
-
SHIFT_LONG
public static final int SHIFT_LONG
-
SIZE_PTR
public static final int SIZE_PTR
-
SIZE_SHORT
public static final int SIZE_SHORT
- See Also:
- Constant Field Values
-
DEBUG
public static boolean DEBUG
DEBUG flag
-
handle
protected INativeHandle handle
The handle to the memory chunk used by this object. While in fact this is final, Java language semantics does not allow to declare so!The handle should only be assigned in the constructor, via parameter or "allocate".
-
-
Constructor Detail
-
NativeObject
protected NativeObject()
-
NativeObject
protected NativeObject(INativeHandle handle)
Create a new NativeObject in C-Memory at pointer "handle". The bytes belonging to this object may already have been copied from C-Memory and made available in bytes at location offset.- Parameters:
handle- The pointer in C-memory
-
-
Method Detail
-
allocate
protected void allocate()
Manage the objects memory in Java. C memory will be valid at least as long as we hold a reference to the buffer. C memory is undefined (but not a memory leak) and may be reclaimed at any time after dropping our pointer to the buffer.
-
cast
public INativeObject cast(INativeType declaration)
This is a special form of the "createNative" signature, implementing a "type cast" on the same memory location.- Parameters:
declaration- The new base declaration type.- Returns:
- The
INativeObjectat the same memory location as this, but of a different type.
-
createReference
public INativeObject createReference()
-
getByte
public byte getByte(int index)
The byte at index as a native byte.- Parameters:
index- The index of the element to be reported.- Returns:
- The element at index as a native byte.
-
getByteArray
public byte[] getByteArray(int index, int count)The element at index as an array of native byte with dimension count. This is a lightweight optimization.- Parameters:
index- The index of the element to be reported.- Returns:
- The element at index as an array of native byte with dimension count.
-
getByteCount
public abstract int getByteCount()
The number of bytes occupied by this.- Returns:
- The number of bytes occupied by this.
-
getBytes
public byte[] getBytes()
The bytes copied from C-memory that represent this.- Specified by:
getBytesin interfaceINativeObject- Returns:
- The bytes copied from C-memory that represent this.
-
getCLong
public long getCLong(int index)
The element at index as a native long. Only the "platform" number of bytes are read.- Parameters:
index- The index of the element to be reported.- Returns:
- The element at index as a native long.
-
getInt
public int getInt(int index)
The element at index as a native int.- Parameters:
index- The index of the element to be reported.- Returns:
- The element at index as a native int.
-
getNativeHandle
public INativeHandle getNativeHandle()
The C-Pointer where the associated memory is found.- Specified by:
getNativeHandlein interfaceINativeObject- Returns:
- The C-Pointer where the associated memory is found.
-
getNativeHandle
public INativeHandle getNativeHandle(int index)
-
getNativeType
public abstract INativeType getNativeType()
The meta information and behavior for the NativeObject.There is exactly one meta instance for all NativeObject instances of a certain type.
- Specified by:
getNativeTypein interfaceINativeObject- Returns:
- The meta information and behavior for the NativeObject.
-
getShort
public short getShort(int index)
The element at index as a native short. This is a lightweight optimization.- Parameters:
index- The index of the element to be reported.- Returns:
- The element at index as a native short.
-
getString
public java.lang.String getString(int index)
-
getWideString
public java.lang.String getWideString(int index)
-
isNull
public boolean isNull()
Answertrueif this is "null". This means the associated C-pointer is pointing to 0.- Returns:
- Answer
trueif this is "null".
-
setByte
public void setByte(int index, byte value)
-
setByteArray
public void setByteArray(int index, byte[] value, int valueOffset, int valueCount)
-
setCLong
public void setCLong(int index, long value)
-
setInt
public void setInt(int index, int value)
-
setNativeHandle
public void setNativeHandle(int index, INativeHandle value)
-
setShort
public void setShort(int index, short value)
-
setString
public void setString(int index, java.lang.String value)
-
setWideString
public void setWideString(int index, java.lang.String value)
-
toNestedString
public java.lang.String toNestedString()
A string for debugging purposes.- Returns:
- A string for debugging purposes.
-
-