|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.trolltech.qt.QNativePointer
public class QNativePointer
QNativePointer encapsulates a native C++ pointer. The class provides the functionality that you would get if you had direct access to the pointer through function calls. It is as such a low-level memory manager that should be used sparsely; its intended and legitimate use is for JNI bindings not handled by generator. Examples can be found in the generator example.
QNativePointer does type checking of pointers. Also, if the pointer is pointing to an array, you must also specify the array length; array bounds checking is enforced by QNativePointer. Any number of indirections are allowed (i.e., arrays can have any number of dimensions).
The QNativePointer will by default delete the internal pointer when being garbage collected. However, if the ownership of the pointer is given to a c++ class, you do not want this behavior. The AutoDeleteMode enum values defines the ways in which deletion of the pointer can be handled.
The data types that can be pointed to are defined by the Type enum. An allocation of an Integer pointer can, for example, be done like this:
QNativePointer ptr =
new QNativePointer(QNativePointer.Type.Int);
ptr.setIntValue(10);
An array of length 5 is created in the following way:
QNativePointer ptr = new QNativePointer(QNativePointer.Type.Int, 5);
for (int i = 0; i < 5, ++i)
ptr.setIntAt(i, i*i);
If you are creating a multi dimensional array, you have two possibilities. You can make QNativePointers of the Pointer type or specify the number indirections of a single QNativePointer. We recommend the second alternative since it creates type safe pointers. Here is an example using the first alternative:
QNativePointer ptr = new QNativePointer(QNativePointer.Type.Pointer, 2);
QNativePointer charArray1 = new QNativePointer(QNativePointer.Type.Char, 5);
ptr.setPointerAt(0, carArray1);
And here is the code for the second:
QNativePointer ptr = new QNativePointer(Type.Char, 5, 2);
ptr.setPointerAt(0, createCharPointer(myString));
Nested Class Summary | |
---|---|
static class |
QNativePointer.AutoDeleteMode
The AutoDeleteMode enum describes how garbage collection of the QNativePointer handles the deletion of the native pointer. |
static class |
QNativePointer.Type
The Type enum describe the Java types that can be used by a QNativePointer. |
Constructor Summary | |
---|---|
QNativePointer(QNativePointer.Type type)
Creates a native pointer of the specified type . |
|
QNativePointer(QNativePointer.Type type,
int size)
Creates a native pointer to an array with size
length of the specified type . |
|
QNativePointer(QNativePointer.Type type,
int size,
int indirections)
Creates a native pointer of the specified type . |
Method Summary | |
---|---|
QNativePointer.AutoDeleteMode |
autoDeleteMode()
Returns the auto-delete mode of the pointer. |
boolean |
booleanAt(int pos)
Returns the value of the native pointer at the specified position. |
boolean |
booleanValue()
If the native pointer is of boolean type, this function returns its value. |
byte |
byteAt(int pos)
Returns the value of the native pointer at the specified position. |
byte |
byteValue()
If the native pointer is of byte type, this function returns its value. |
char |
charAt(int pos)
Returns the value of the native pointer at the specified position. |
char |
charValue()
If the native pointer is of char type, this function returns its value. |
static QNativePointer |
createCharPointer(java.lang.String string)
Creates a char* from the input string |
static QNativePointer |
createCharPointerPointer(java.lang.String[] strings)
Creates a char** native pointer from the array of input strings. |
void |
delete()
This function deletes the internal pointer. |
void |
deleteArray()
This function deletes elements in the array of this QNativePointer. |
double |
doubleAt(int pos)
Returns the value of the native pointer at the specified position. |
double |
doubleValue()
If the native pointer is of double type, this function returns its value. |
protected void |
finalize()
|
float |
floatAt(int pos)
Returns the value of the native pointer at the specified position. |
float |
floatValue()
If the native pointer is of float type, this function returns its value. |
void |
free()
This function deletes the internal pointer. |
static QNativePointer |
fromNative(long ptr,
int type,
int indirections)
This is an overloaded function provided for convenience. |
static QNativePointer |
fromNative(long ptr,
QNativePointer.Type type,
int indirections)
This function creates a QNativePointer from an existing c++ pointer. |
int |
indirections()
Returns the number of indirections of the pointer. |
int |
intAt(int pos)
Returns the value of the native pointer at the specified position. |
int |
intValue()
If the native pointer is of int type, this function returns its value. |
boolean |
isNull()
Returns true if the native pointer is 0; otherwise false. |
long |
longAt(int pos)
Returns the value of the native pointer at the specified position. |
long |
longValue()
If the native pointer is of long type, this function returns its value. |
long |
pointer()
Returns the native pointer. |
QNativePointer |
pointerAt(int pos)
Returns the value of the native pointer at the specified position. |
QNativePointer |
pointerValue()
If the native pointer is of pointer type, this function returns its value. |
void |
setAutoDeleteMode(QNativePointer.AutoDeleteMode autodelete)
This function sets the auto delete mode of the QNativePointer. |
void |
setBooleanAt(int pos,
boolean value)
Sets the value of the array element at pos to
which this native pointer points. |
void |
setBooleanValue(boolean value)
Sets the value of this pointer to value . |
void |
setByteAt(int pos,
byte value)
Sets the value of the array element at pos to
which this native pointer points. |
void |
setByteValue(byte value)
Sets the value of this pointer to value . |
void |
setCharAt(int pos,
char value)
Sets the value of the array element at pos to
which this native pointer points. |
void |
setCharValue(char value)
Sets the value of this pointer to value . |
void |
setDoubleAt(int pos,
double value)
Sets the value of the array element at pos to
which this native pointer points. |
void |
setDoubleValue(double value)
Sets the value of this pointer to value . |
void |
setFloatAt(int pos,
float value)
Sets the value of the array element at pos to
which this native pointer points. |
void |
setFloatValue(float value)
Sets the value of this pointer to value . |
void |
setIntAt(int pos,
int value)
Sets the value of the array element at pos to
which this native pointer points. |
void |
setIntValue(int value)
Sets the value of this pointer to value . |
void |
setLongAt(int pos,
long value)
Sets the value of the array element at pos to
which this native pointer points. |
void |
setLongValue(long value)
Sets the value of this pointer to value . |
void |
setPointerAt(int pos,
QNativePointer value)
Sets the value of the array element at pos to
which this native pointer points. |
void |
setPointerValue(QNativePointer value)
Sets the value of this pointer to value . |
void |
setShortAt(int pos,
short value)
Sets the value of the array element at pos to
which this native pointer points. |
void |
setShortValue(short value)
Sets the value of this pointer to value . |
void |
setStringAt(int pos,
java.lang.String value)
Sets the value of the array element at pos to
which this native pointer points. |
void |
setStringValue(java.lang.String value)
Sets the value of this pointer to value . |
void |
setVerificationEnabled(boolean a)
Sets if the any accesses should be type verified or not. |
short |
shortAt(int pos)
Returns the value of the native pointer at the specified position. |
short |
shortValue()
If the native pointer is of short type, this function returns its value. |
java.lang.String |
stringAt(int pos)
Returns the value of the native pointer at the specified position. |
java.lang.String |
stringValue()
If the native pointer is of string type, this function returns its value. |
QNativePointer.Type |
type()
Returns the type of the native pointer. |
boolean |
verificationEnabled()
Returns if verification is enabled or not. |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public QNativePointer(QNativePointer.Type type)
type
.
The object has an indirection of 1 and the internal pointer
will be deleted when the QNativePointer object is deleted.
type
- the type of pointer to create.public QNativePointer(QNativePointer.Type type, int size)
size
length of the specified type
. The pointer will
have an indirection of 1 and be deleted when the QNativePointer
is garbage collected.
type
- the type of pointer to create.size
- the size of the array.public QNativePointer(QNativePointer.Type type, int size, int indirections)
type
.
It will be an array if size
is larger than one and
have an indirection of indirections
. For instance,
the following Java statement will create a **char
pointer with the first array dimension of length 5:
QNativePointer ptr = new
QNativePointer(QNativePointer.Type.Int, 5, 2);
type
- the type of pointer to create.size
- the length of the array.indirections
- the number of indirections for the pointer.Method Detail |
---|
public boolean booleanValue()
public byte byteValue()
public char charValue()
public short shortValue()
public int intValue()
public long longValue()
public float floatValue()
public double doubleValue()
public QNativePointer pointerValue()
public java.lang.String stringValue()
public void setBooleanValue(boolean value)
value
.
The type of the pointer must be boolean.
value
- the value to which the pointer is set.public void setByteValue(byte value)
value
.
The type of the pointer must be byte.
value
- the value to which the pointer is set.public void setCharValue(char value)
value
.
The type of the pointer must be char.
value
- the value to which the pointer is set.public void setShortValue(short value)
value
.
The type of the pointer must be short.
value
- the value to which the pointer is set.public void setIntValue(int value)
value
.
The type of the pointer must be int.
value
- the value to which the pointer is set.public void setLongValue(long value)
value
.
The type of the pointer must be long.
value
- the value to which the pointer is set.public void setFloatValue(float value)
value
.
The type of the pointer must be float.
value
- the value to which the pointer is set.public void setDoubleValue(double value)
value
.
The type of the pointer must double.
value
- the value to which the pointer is set.public void setPointerValue(QNativePointer value)
value
.
The pointer must be of pointer type.
value
- the value to which the pointer is set.public void setStringValue(java.lang.String value)
value
.
The pointer must point to a string.
value
- the value to which the pointer is set.public boolean booleanAt(int pos)
pos
is larger than 1, QNativePointer
will check that the position is within the array bounds.
pos
- the array indexpublic byte byteAt(int pos)
pos
is larger than 1, QNativePointer
will check that the position is within the array bounds.
pos
- the array indexpublic char charAt(int pos)
pos
is larger than 1, QNativePointer
will check that the position is within the array bounds.
pos
- the array indexpublic short shortAt(int pos)
pos
is larger than 1, QNativePointer
will check that the position is within the array bounds.
pos
- the array indexpublic int intAt(int pos)
pos
is larger than 1, QNativePointer
will check that the position is within the array bounds.
pos
- the array indexpublic long longAt(int pos)
pos
is larger than 1, QNativePointer
will check that the position is within the array bounds.
pos
- the array indexpublic float floatAt(int pos)
pos
is larger than 1, QNativePointer
will check that the position is within the array bounds.
pos
- the array indexpublic double doubleAt(int pos)
pos
is larger than 1, QNativePointer
will check that the position is within the array bounds.
pos
- the array indexpublic QNativePointer pointerAt(int pos)
pos
is larger than 1, QNativePointer
will check that the position is within the array bounds.
pos
- the array indexpublic java.lang.String stringAt(int pos)
pos
is larger than 1, QNativePointer
will check that the position is within the array bounds.
pos
- the array indexpublic void setBooleanAt(int pos, boolean value)
pos
to
which this native pointer points.
pos
- the array indexvalue
- the value to set the index topublic void setByteAt(int pos, byte value)
pos
to
which this native pointer points.
pos
- the array indexvalue
- the value to set the index topublic void setCharAt(int pos, char value)
pos
to
which this native pointer points.
pos
- the array indexvalue
- the value to set the index topublic void setShortAt(int pos, short value)
pos
to
which this native pointer points.
pos
- the array indexvalue
- the value to set the index topublic void setIntAt(int pos, int value)
pos
to
which this native pointer points.
pos
- the array indexvalue
- the value to set the index topublic void setLongAt(int pos, long value)
pos
to
which this native pointer points.
pos
- the array indexvalue
- the value to set the index topublic void setFloatAt(int pos, float value)
pos
to
which this native pointer points.
pos
- the array indexvalue
- the value to set the index topublic void setDoubleAt(int pos, double value)
pos
to
which this native pointer points.
pos
- the array indexvalue
- the value to set the index topublic void setPointerAt(int pos, QNativePointer value)
pos
to
which this native pointer points.
pos
- the array indexvalue
- the value to set the index topublic void setStringAt(int pos, java.lang.String value)
pos
to
which this native pointer points.
pos
- the array indexvalue
- the value to set the index topublic QNativePointer.Type type()
public int indirections()
public boolean isNull()
public QNativePointer.AutoDeleteMode autoDeleteMode()
public void setAutoDeleteMode(QNativePointer.AutoDeleteMode autodelete)
autodelete
- the new auto delete mode.public void free()
public void delete()
public void deleteArray()
public long pointer()
void *
value in c++.
public static QNativePointer fromNative(long ptr, QNativePointer.Type type, int indirections)
void *
(i.e., address)
value of the pointer. There are several ways of acquiring a native pointer. For instance,
QNativePointer internal pointer is returned by pointer(), and
QtJambiObject.nativeId() returns the c++ pointer to its Qt object.
ptr
- the void * value of the pointer.type
- the Type of the pointerindirections
- the number of pointer indirections
public boolean verificationEnabled()
public void setVerificationEnabled(boolean a)
a
- Set to true if verification should be enabled.public static QNativePointer fromNative(long ptr, int type, int indirections)
QNativePointer.fromNative(long ptr, Type type, int indirections)
public static QNativePointer createCharPointerPointer(java.lang.String[] strings)
strings
- the input strings
public static QNativePointer createCharPointer(java.lang.String string)
string
- The input string
protected void finalize()
finalize
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |