Refactor mapping to the native structs

This commit is contained in:
SpaiR committed 2020-08-23 16:49:16 +03:00
1 parent 1209caa518
commit 1dcf2328a4
17 files changed
+194 -251

No files matched your search

@@ -0,0 +1,18 @@
package imgui.binding;
import imgui.ImGui;
/**
* Class provides a communication layer between binding and Dear ImGui library though the "pointer" field.
*/
public abstract class ImGuiStruct {
/**
* Pointer to the natively allocated object,
*/
public long ptr;
public ImGuiStruct(final long ptr) {
ImGui.touch();
this.ptr = ptr;
}
}
@@ -0,0 +1,31 @@
package imgui.binding;
/**
* Class extends {@link ImGuiStruct} and provides additional API to allocated and de-allocate native objects.
*/
public abstract class ImGuiStructDestroyable extends ImGuiStruct {
/**
* Constructor, which creates natively allocated struct. Those structs should be manually disposed with {@link #destroy()} method.
*/
public ImGuiStructDestroyable() {
this(0);
ptr = create();
}
public ImGuiStructDestroyable(final long ptr) {
super(ptr);
}
protected abstract long create();
/**
* Method to free natively allocated memory for the struct mapped with pointer.
*/
public void destroy() {
nDestroy(ptr);
}
private native void nDestroy(long ptr); /*
delete (void*)ptr;
*/
}