/** Ensure this memory has its size and layout calculated and its memory allocated. */ protected void ensureAllocated() { ensureAllocated(false); }
/** Call whenever a Structure setting is changed which might affect its * memory layout. */ private void layoutChanged() { if (this.size != CALCULATE_SIZE) { this.size = CALCULATE_SIZE; if (this.memory instanceof AutoAllocated) { this.memory = null; } // recalculate layout, since it was done once already ensureAllocated(); } }
/** Returns the size in memory occupied by this Structure. * @return Native size of this structure, in bytes. */ public int size() { ensureAllocated(); return this.size; }
/** Return a {@link Pointer} object to this structure. Note that if you * use the structure's pointer as a function argument, you are responsible * for calling {@link #write()} prior to the call and {@link #read()} * after the call. These calls are normally handled automatically by the * {@link Function} object when it encounters a {@link Structure} argument * or return value. * The returned pointer may not have meaning for {@link Structure.ByValue} * structure representations. * @return Native pointer representation of this structure. */ public Pointer getPointer() { ensureAllocated(); return memory; }
/** Returns the calculated offset of the given field. * @param name field to examine * @return return offset of the given field */ protected int fieldOffset(String name) { ensureAllocated(); StructField f = fields().get(name); if (f == null) throw new IllegalArgumentException("No such field: " + name); return f.offset; }
/** Write the given field to native memory. The current value in the Java * field will be translated into native memory. * @param name which field to synch * @throws IllegalArgumentException if no field exists with the given name */ public void writeField(String name) { ensureAllocated(); StructField f = fields().get(name); if (f == null) throw new IllegalArgumentException("No such field: " + name); writeField(f); }
/** Force a read of the given field from native memory. The Java field * will be updated from the current contents of native memory. * @param name field to be read * @return the new field value, after updating * @throws IllegalArgumentException if no field exists with the given name */ public Object readField(String name) { ensureAllocated(); StructField f = fields().get(name); if (f == null) throw new IllegalArgumentException("No such field: " + name); return readField(f); }
/** Clears the native memory associated with this Structure. */ public void clear() { ensureAllocated(); memory.clear(size()); }
/** 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. * @param name field to write * @param value value to write * @throws IllegalArgumentException if no field exists with the given name */ public void writeField(String name, Object value) { ensureAllocated(); StructField structField = fields().get(name); if (structField == null) throw new IllegalArgumentException("No such field: " + name); setFieldValue(structField.field, value); writeField(structField); }
private String toString(int indent, boolean showContents, boolean dumpMemory) { ensureAllocated(); String LS = System.getProperty("line.separator"); String name = format(getClass()) + "(" + getPointer() + ")";
ensureAllocated(); if (this.memory instanceof AutoAllocated) {
/** Ensure this memory has its size and layout calculated and its memory allocated. */ protected void ensureAllocated() { ensureAllocated(false); }
/** Returns the size in memory occupied by this Structure. * @return Native size of this structure, in bytes. */ public int size() { ensureAllocated(); return this.size; }
/** Call whenever a Structure setting is changed which might affect its * memory layout. */ private void layoutChanged() { if (this.size != CALCULATE_SIZE) { this.size = CALCULATE_SIZE; if (this.memory instanceof AutoAllocated) { this.memory = null; } // recalculate layout, since it was done once already ensureAllocated(); } }
/** Returns the calculated offset of the given field. * @param name field to examine * @return return offset of the given field */ protected int fieldOffset(String name) { ensureAllocated(); StructField f = fields().get(name); if (f == null) throw new IllegalArgumentException("No such field: " + name); return f.offset; }
/** Write the given field to native memory. The current value in the Java * field will be translated into native memory. * @param name which field to synch * @throws IllegalArgumentException if no field exists with the given name */ public void writeField(String name) { ensureAllocated(); StructField f = fields().get(name); if (f == null) throw new IllegalArgumentException("No such field: " + name); writeField(f); }
/** Force a read of the given field from native memory. The Java field * will be updated from the current contents of native memory. * @param name field to be read * @return the new field value, after updating * @throws IllegalArgumentException if no field exists with the given name */ public Object readField(String name) { ensureAllocated(); StructField f = fields().get(name); if (f == null) throw new IllegalArgumentException("No such field: " + name); return readField(f); }
/** Clears the native memory associated with this Structure. */ public void clear() { ensureAllocated(); memory.clear(size()); }