JNA API 3.5.1
com.sun.jna

Class Structure

    • Field Detail

      • isPPC

        static final boolean isPPC
      • isSPARC

        static final boolean isSPARC
      • isARM

        static final boolean isARM
      • ALIGN_DEFAULT

        public static final int ALIGN_DEFAULT
        Use the platform default alignment.
        See Also:
        Constant Field Values
      • ALIGN_NONE

        public static final int ALIGN_NONE
        No alignment, place all fields on nearest 1-byte boundary
        See Also:
        Constant Field Values
      • ALIGN_GNUC

        public static final int ALIGN_GNUC
        validated for 32-bit x86 linux/gcc; align field size, max 4 bytes
        See Also:
        Constant Field Values
      • ALIGN_MSVC

        public static final int ALIGN_MSVC
        validated for w32/msvc; align on field size
        See Also:
        Constant Field Values
      • MAX_GNUC_ALIGNMENT

        static final int MAX_GNUC_ALIGNMENT
        Align to an 8-byte boundary.
      • layoutInfo

        static final Map layoutInfo
      • fieldOrder

        static final Map fieldOrder
    • Constructor Detail

      • Structure

        protected Structure()
      • Structure

        protected Structure(TypeMapper mapper)
      • Structure

        protected Structure(int alignType)
      • Structure

        protected Structure(int alignType,
                 TypeMapper mapper)
      • Structure

        protected Structure(Pointer p)
        Create a structure cast onto pre-allocated memory.
      • Structure

        protected Structure(Pointer p,
                 int alignType)
    • Method Detail

      • fields

        Map fields()
        Return all fields in this structure (ordered). This represents the layout of the structure, and will be shared among Structures of the same class except when the Structure can have a variable size. NOTE: ensureAllocated() must be called prior to calling this method.
      • getTypeMapper

        TypeMapper getTypeMapper()
        Return the type mapper in effect for this Structure.
      • setTypeMapper

        protected void setTypeMapper(TypeMapper mapper)
        Deprecated. You should use one of Structure(TypeMapper) or Structure(Pointer,int,TypeMapper) constructors instead.
        Change the type mapping for this structure. May cause the structure to be resized and any existing memory to be reallocated. If null, the default mapper for the defining class will be used.
      • setAlignType

        protected void setAlignType(int alignType)
        Change the alignment of this structure. Re-allocates memory if necessary. If alignment is ALIGN_DEFAULT, the default alignment for the defining class will be used.
      • autoAllocate

        protected Memory autoAllocate(int size)
      • useMemory

        protected void useMemory(Pointer m)
        Set the memory used by this structure. This method is used to indicate the given structure is nested within another or otherwise overlaid on some other memory block and thus does not own its own memory.
      • useMemory

        protected void useMemory(Pointer m,
                     int offset)
        Set the memory used by this structure. This method is used to indicate the given structure is based on natively-allocated data, nested within another, or otherwise overlaid on existing memory and thus does not own its own memory allocation.
      • ensureAllocated

        protected void ensureAllocated()
        Ensure this memory has its size and layout calculated and its memory allocated.
      • allocateMemory

        protected void allocateMemory()
        Attempt to allocate memory if sufficient information is available. Returns whether the operation was successful.
      • allocateMemory

        protected void allocateMemory(int size)
        Provided for derived classes to indicate a different size than the default. Returns whether the operation was successful. Will leave memory untouched if it is non-null and not allocated by this class.
      • size

        public int size()
      • clear

        public void clear()
      • getPointer

        public Pointer getPointer()
        Return a Pointer object to this structure. Note that if you use the structure's pointer as a function argument, you are responsible for calling write() prior to the call and read() after the call. These calls are normally handled automatically by the Function object when it encounters a Structure argument or return value.
      • busy

        static Set busy()
      • reading

        static Map reading()
      • read

        public void read()
        Reads the fields of the struct from native memory
      • fieldOffset

        protected int fieldOffset(String name)
        Returns the calculated offset of the given field.
      • readField

        public Object readField(String name)
        Force a read of the given field from native memory. The Java field will be updated from the current contents of native memory.
        Returns:
        the new field value, after updating
        Throws:
        IllegalArgumentException - if no field exists with the given name
      • getFieldValue

        Object getFieldValue(Field field)
        Obtain the value currently in the Java field. Does not read from memory.
      • setFieldValue

        void setFieldValue(Field field,
                         Object value)
      • updateStructureByReference

        static Structure updateStructureByReference(Class type,
                                           Structure s,
                                           Pointer address)
        Only keep the original structure if its native address is unchanged. Otherwise replace it with a new object.
        Parameters:
        type - Structure subclass
        s - Original Structure object
        address - the native struct *
        Returns:
        Updated Structure.ByReference object
      • readField

        Object readField(Structure.StructField structField)
        Read the given field and return its value. The Java field will be updated from the contents of native memory.
      • write

        public void write()
        Writes the fields of the struct to native memory
      • writeField

        public void writeField(String name)
        Write the given field to native memory. The current value in the Java field will be translated into native memory.
        Throws:
        IllegalArgumentException - if no field exists with the given name
      • writeField

        public void writeField(String name,
                      Object value)
        Write the given field value to the field and native memory. The given value will be written both to the Java field and the corresponding native memory.
        Throws:
        IllegalArgumentException - if no field exists with the given name
      • getFieldOrder

        protected abstract List getFieldOrder()
        Return this Structure's field names in their proper order. For example,
        
         protected List getFieldOrder() {
             return Arrays.asList(new String[] { ... });
         }
         
        IMPORTANT When deriving from an existing Structure subclass, ensure that you augment the list provided by the superclass, e.g.
        
         protected List getFieldOrder() {
             List fields = new ArrayList(super.getFieldOrder());
             fields.addAll(Arrays.asList(new String[] { ... }));
             return fields;
         }
         
        Field order must be explicitly indicated, since the field order as returned by Class.getFields() is not guaranteed to be predictable.
      • setFieldOrder

        protected final void setFieldOrder(String[] fields)
        Deprecated. Use the required method getFieldOrder() instead to indicate the order of fields in this structure.
        Force a compile-time error on the old method of field definition
      • sortFields

        protected void sortFields(List fields,
                      List names)
        Sort the structure fields according to the given array of names.
      • getFieldList

        protected List getFieldList()
        Look up all fields in this class and superclasses.
      • getFields

        protected List getFields(boolean force)
        Returns all field names (sorted) provided so far by getFieldOrder()
        Parameters:
        force - set if results are required immediately
        Returns:
        null if not yet able to provide fields, and force is false.
        Throws:
        Error - if force is true and field order data not yet specified and can't be generated automatically.
      • calculateSize

        int calculateSize(boolean force,
                        boolean avoidFFIType)
      • calculateAlignedSize

        int calculateAlignedSize(int calculatedSize)
      • getStructAlignment

        protected int getStructAlignment()
      • getNativeAlignment

        protected int getNativeAlignment(Class type,
                             Object value,
                             boolean isFirstElement)
        Overridable in subclasses.
      • toString

        public String toString(boolean debug)
      • toArray

        public Structure[] toArray(Structure[] array)
        Returns a view of this structure's memory as an array of structures. Note that this Structure must have a public, no-arg constructor. If the structure is currently using auto-allocated Memory backing, the memory will be resized to fit the entire array.
      • toArray

        public Structure[] toArray(int size)
        Returns a view of this structure's memory as an array of structures. Note that this Structure must have a public, no-arg constructor. If the structure is currently using auto-allocated Memory backing, the memory will be resized to fit the entire array.
      • equals

        public boolean equals(Object o)
        This structure is equal to another based on the same data type and memory contents.
        Overrides:
        equals in class Object
      • cacheTypeInfo

        protected void cacheTypeInfo(Pointer p)
        Cache native type information for use in native code.
      • getTypeInfo

        Pointer getTypeInfo()
        Obtain native type information for this structure.
      • setAutoSynch

        public void setAutoSynch(boolean auto)
        Set whether the structure is automatically synchronized to native memory before and after a native function call. Convenience method for
        
                boolean auto = ...;
                setAutoRead(auto);
                setAutoWrite(auto);
                
      • setAutoRead

        public void setAutoRead(boolean auto)
        Set whether the structure is read from native memory prior to a native function call.
      • getAutoRead

        public boolean getAutoRead()
        Returns whether the structure is read from native memory prior to a native function call.
      • setAutoWrite

        public void setAutoWrite(boolean auto)
        Set whether the structure is written to native memory after a native function call.
      • getAutoWrite

        public boolean getAutoWrite()
        Returns whether the structure is written to native memory after a native function call.
      • getTypeInfo

        static Pointer getTypeInfo(Object obj)
        Exposed for testing purposes only.
      • autoRead

        public static void autoRead(Structure[] ss)
      • autoRead

        public void autoRead()
      • autoWrite

        public static void autoWrite(Structure[] ss)
      • autoWrite

        public void autoWrite()
      • getNativeSize

        protected int getNativeSize(Class nativeType)
        Return the native size of the given Java type, from the perspective of this Structure.
      • getNativeSize

        protected int getNativeSize(Class nativeType,
                        Object value)
        Return the native size of the given Java type, from the perspective of this Structure.
JNA API 3.5.1

Copyright © 2007-2012 Timothy Wall. All Rights Reserved.