Class Structure
java.lang.Object
de.linusdev.lutils.struct.abstracts.Structure
- All Implemented Interfaces:
MemorySizeable,NativeParsable
- Direct Known Subclasses:
BBFloatMxN,BBVector,ModTrackingStructure,PrimitiveTypeArray
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ByteBufferprotected booleanprotected Structureprotected int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidallocate()Creates an 8 byte aligned direct byte buffer and callsuseBuffer(Structure, int).protected voidcallUseBufferOf(@NotNull Structure structure, @NotNull Structure mostParentStructure, int offset) CalluseBuffer(Structure, int)ofstructureprotected voidclaimBuffer(@NotNull ByteBuffer buffer) Will set theByteOrderto native order.static @NotNull StringgenerateStructCode(@NotNull Language language, @NotNull Class<? extends Structure> structClass) Generate struct code for givenstructClassintThe recommended alignment of this object in memory.TheByteBuffercontaining the native data.abstract @NotNull StructureInfogetInfo()Will never benullafter eitherclaimBuffer(ByteBuffer)oruseBuffer(Structure, int)has been called.intOffset in the byte buffer of themost parental structure.intRequired size including padding.booleanWhether thisNativeParsableis already backed by abuffer.booleanWill betrueafter a call tomodified(int, int).voidmodified()Mark the whole structure as modified.voidmodified(int offset, int size) Marksizebytes atoffsetas modified.protected voidonModification(int offset, int size) Called on the most parental structure if on it or any of its childrenmodified(int, int)is called.protected StringvoidMarks this structure has not modified.protected voidSet thisStructureto be a child ofmostParentStructure.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface de.linusdev.lutils.struct.abstracts.NativeParsable
getPointer
-
Field Details
-
mostParentStructure
-
byteBuf
-
offset
protected int offset -
modified
protected volatile boolean modified
-
-
Constructor Details
-
Structure
public Structure()
-
-
Method Details
-
generateStructCode
@NotNull public static @NotNull String generateStructCode(@NotNull @NotNull Language language, @NotNull @NotNull Class<? extends Structure> structClass) Generate struct code for givenstructClass- Parameters:
language-Languageto generate the struct code instructClass- Class of the structure to generate code for- Returns:
- struct code
- Throws:
IllegalArgumentException- if given class cannot generate struct code.
-
useBuffer
Set thisStructureto be a child ofmostParentStructure.- Parameters:
mostParentStructure- most parental structureoffset- start of this structure
-
callUseBufferOf
protected void callUseBufferOf(@NotNull @NotNull Structure structure, @NotNull @NotNull Structure mostParentStructure, int offset) CalluseBuffer(Structure, int)ofstructure -
claimBuffer
Will set theByteOrderto native order. The most parental structure will bethis.- Parameters:
buffer-ByteBufferto claim
-
allocate
public void allocate()Creates an 8 byte aligned direct byte buffer and callsuseBuffer(Structure, int). -
getInfo
-
getAlignment
public int getAlignment()Description copied from interface:MemorySizeableThe recommended alignment of this object in memory. Either1, 2, 4, 8or16.- Specified by:
getAlignmentin interfaceMemorySizeable- Returns:
- recommended alignment
-
getRequiredSize
public int getRequiredSize()Description copied from interface:MemorySizeableRequired size including padding.- Specified by:
getRequiredSizein interfaceMemorySizeable- Returns:
- the size required by this object in memory
-
getOffset
public int getOffset()Offset in the byte buffer of themost parental structure.- Returns:
- offset in bytes
-
getByteBuffer
Description copied from interface:NativeParsableTheByteBuffercontaining the native data. May not benullifNativeParsable.isInitialised()istrue.- Specified by:
getByteBufferin interfaceNativeParsable- Returns:
ByteBuffer
-
isInitialised
public boolean isInitialised()Description copied from interface:NativeParsableWhether thisNativeParsableis already backed by abuffer.- Specified by:
isInitialisedin interfaceNativeParsable- Returns:
trueif initialised
-
toString
- Parameters:
name- name of this structcontent- content to be inside the{content}- Returns:
- A nice string describing this structure
-
modified
public void modified(int offset, int size) Marksizebytes atoffsetas modified.- Parameters:
offset- region startsize- region size
-
modified
public void modified()Mark the whole structure as modified. -
unmodified
public void unmodified()Marks this structure has not modified. May only be called on the most parental structure. -
isModified
public boolean isModified()Will betrueafter a call tomodified(int, int). Will be reset byunmodified(). Note that modifications are only tracked on the most parental structure. The return value of this method is undefined, if it is not the most parental structure.- Returns:
- whether this
Structurehas been modified.
-
onModification
protected void onModification(int offset, int size) Called on the most parental structure if on it or any of its childrenmodified(int, int)is called.- Parameters:
offset- modified region startsize- modified region size
-
getMostParentStructure
Will never benullafter eitherclaimBuffer(ByteBuffer)oruseBuffer(Structure, int)has been called.- Returns:
- the most parental structure.
-