Logo Search packages:      
Sourcecode: qtjambi version File versions  Download package

com::trolltech::qt::QNativePointer Class Reference

List of all members.

Detailed Description

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);

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));

Definition at line 85 of file QNativePointer.java.

Public Types

enum  AutoDeleteMode { Free, Delete, DeleteArray, None }
enum  Type {
  Boolean, Byte, Char, Short,
  Int, Long, Float, Double,
  Pointer, String

Public Member Functions

AutoDeleteMode autoDeleteMode ()
boolean booleanAt (int pos)
boolean booleanValue ()
byte byteAt (int pos)
byte byteValue ()
char charAt (int pos)
char charValue ()
void delete ()
void deleteArray ()
double doubleAt (int pos)
double doubleValue ()
float floatAt (int pos)
float floatValue ()
void free ()
int indirections ()
int intAt (int pos)
int intValue ()
boolean isNull ()
long longAt (int pos)
long longValue ()
long pointer ()
QNativePointer pointerAt (int pos)
QNativePointer pointerValue ()
 QNativePointer (Type type, int size, int indirections)
 QNativePointer (Type type, int size)
 QNativePointer (Type type)
void setAutoDeleteMode (AutoDeleteMode autodelete)
void setBooleanAt (int pos, boolean value)
void setBooleanValue (boolean value)
void setByteAt (int pos, byte value)
void setByteValue (byte value)
void setCharAt (int pos, char value)
void setCharValue (char value)
void setDoubleAt (int pos, double value)
void setDoubleValue (double value)
void setFloatAt (int pos, float value)
void setFloatValue (float value)
void setIntAt (int pos, int value)
void setIntValue (int value)
void setLongAt (int pos, long value)
void setLongValue (long value)
void setPointerAt (int pos, QNativePointer value)
void setPointerValue (QNativePointer value)
void setShortAt (int pos, short value)
void setShortValue (short value)
void setStringAt (int pos, String value)
void setStringValue (String value)
void setVerificationEnabled (boolean a)
short shortAt (int pos)
short shortValue ()
String stringAt (int pos)
String stringValue ()
Type type ()
boolean verificationEnabled ()

Static Public Member Functions

static QNativePointer createCharPointer (String string)
static QNativePointer createCharPointerPointer (String strings[])
static QNativePointer fromNative (long ptr, int type, int indirections)
static QNativePointer fromNative (long ptr, Type type, int indirections)

Protected Member Functions

void finalize ()

Static Package Functions

 [static initializer]

Private Member Functions

 QNativePointer (int type, int size, int indirections)
void verifyAccess (Type type, int pos)

Static Private Member Functions

static native long createPointer (int type, int size, int indirections)
static native void deletePointer (long ptr, int type, int deleteMode)
static native boolean readBoolean (long ptr, int pos)
static native byte readByte (long ptr, int pos)
static native char readChar (long ptr, int pos)
static native double readDouble (long ptr, int pos)
static native float readFloat (long ptr, int pos)
static native int readInt (long ptr, int pos)
static native long readLong (long ptr, int pos)
static native long readPointer (long ptr, int pos)
static native short readShort (long ptr, int pos)
static native String readString (long ptr, int pos)
static Type typeOf (int type)
static native void writeBoolean (long ptr, int pos, boolean value)
static native void writeByte (long ptr, int pos, byte value)
static native void writeChar (long ptr, int pos, char value)
static native void writeDouble (long ptr, int pos, double value)
static native void writeFloat (long ptr, int pos, float value)
static native void writeInt (long ptr, int pos, int value)
static native void writeLong (long ptr, int pos, long value)
static native void writePointer (long ptr, int pos, long value)
static native void writeShort (long ptr, int pos, short value)
static native void writeString (long ptr, int pos, String value)

Private Attributes

AutoDeleteMode m_autodelete
int m_indirections
int m_knownSize
long m_ptr
Type m_type
boolean m_verification_enabled = true

The documentation for this class was generated from the following file:

Generated by  Doxygen 1.6.0   Back to index