All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.purejava.appindicator._GActionInterface Maven / Gradle / Ivy

There is a newer version: 1.4.1
Show newest version
// Generated by jextract

package org.purejava.appindicator;

import java.lang.invoke.*;
import java.lang.foreign.*;
import java.nio.ByteOrder;
import java.util.*;
import java.util.function.*;
import java.util.stream.*;

import static java.lang.foreign.ValueLayout.*;
import static java.lang.foreign.MemoryLayout.PathElement.*;

/**
 * {@snippet lang=c :
 * struct _GActionInterface {
 *     GTypeInterface g_iface;
 *     const gchar *(*get_name)(GAction *);
 *     const GVariantType *(*get_parameter_type)(GAction *);
 *     const GVariantType *(*get_state_type)(GAction *);
 *     GVariant *(*get_state_hint)(GAction *);
 *     gboolean (*get_enabled)(GAction *);
 *     GVariant *(*get_state)(GAction *);
 *     void (*change_state)(GAction *, GVariant *);
 *     void (*activate)(GAction *, GVariant *);
 * }
 * }
 */
public class _GActionInterface {

    _GActionInterface() {
        // Should not be called directly
    }

    private static final GroupLayout $LAYOUT = MemoryLayout.structLayout(
        _GTypeInterface.layout().withName("g_iface"),
        app_indicator_h.C_POINTER.withName("get_name"),
        app_indicator_h.C_POINTER.withName("get_parameter_type"),
        app_indicator_h.C_POINTER.withName("get_state_type"),
        app_indicator_h.C_POINTER.withName("get_state_hint"),
        app_indicator_h.C_POINTER.withName("get_enabled"),
        app_indicator_h.C_POINTER.withName("get_state"),
        app_indicator_h.C_POINTER.withName("change_state"),
        app_indicator_h.C_POINTER.withName("activate")
    ).withName("_GActionInterface");

    /**
     * The layout of this struct
     */
    public static final GroupLayout layout() {
        return $LAYOUT;
    }

    private static final GroupLayout g_iface$LAYOUT = (GroupLayout)$LAYOUT.select(groupElement("g_iface"));

    /**
     * Layout for field:
     * {@snippet lang=c :
     * GTypeInterface g_iface
     * }
     */
    public static final GroupLayout g_iface$layout() {
        return g_iface$LAYOUT;
    }

    private static final long g_iface$OFFSET = 0;

    /**
     * Offset for field:
     * {@snippet lang=c :
     * GTypeInterface g_iface
     * }
     */
    public static final long g_iface$offset() {
        return g_iface$OFFSET;
    }

    /**
     * Getter for field:
     * {@snippet lang=c :
     * GTypeInterface g_iface
     * }
     */
    public static MemorySegment g_iface(MemorySegment struct) {
        return struct.asSlice(g_iface$OFFSET, g_iface$LAYOUT.byteSize());
    }

    /**
     * Setter for field:
     * {@snippet lang=c :
     * GTypeInterface g_iface
     * }
     */
    public static void g_iface(MemorySegment struct, MemorySegment fieldValue) {
        MemorySegment.copy(fieldValue, 0L, struct, g_iface$OFFSET, g_iface$LAYOUT.byteSize());
    }

    /**
     * {@snippet lang=c :
     * const gchar *(*get_name)(GAction *)
     * }
     */
    public class get_name {

        /**
         * The function pointer signature, expressed as a functional interface
         */
        public interface Function {
            MemorySegment apply(MemorySegment _x0);
        }

        private static final FunctionDescriptor $DESC = FunctionDescriptor.of(
            app_indicator_h.C_POINTER,
            app_indicator_h.C_POINTER
        );

        /**
         * The descriptor of this function pointer
         */
        public static FunctionDescriptor descriptor() {
            return $DESC;
        }

        private static final MethodHandle UP$MH = app_indicator_h.upcallHandle(get_name.Function.class, "apply", $DESC);

        /**
         * Allocates a new upcall stub, whose implementation is defined by {@code fi}.
         * The lifetime of the returned segment is managed by {@code arena}
         */
        public static MemorySegment allocate(get_name.Function fi, Arena arena) {
            return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena);
        }

        private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC);

        /**
         * Invoke the upcall stub {@code funcPtr}, with given parameters
         */
        public static MemorySegment invoke(MemorySegment funcPtr,MemorySegment _x0) {
            try {
                return (MemorySegment) DOWN$MH.invokeExact(funcPtr, _x0);
            } catch (Throwable ex$) {
                throw new AssertionError("should not reach here", ex$);
            }
        }
    }

    private static final AddressLayout get_name$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("get_name"));

    /**
     * Layout for field:
     * {@snippet lang=c :
     * const gchar *(*get_name)(GAction *)
     * }
     */
    public static final AddressLayout get_name$layout() {
        return get_name$LAYOUT;
    }

    private static final long get_name$OFFSET = 16;

    /**
     * Offset for field:
     * {@snippet lang=c :
     * const gchar *(*get_name)(GAction *)
     * }
     */
    public static final long get_name$offset() {
        return get_name$OFFSET;
    }

    /**
     * Getter for field:
     * {@snippet lang=c :
     * const gchar *(*get_name)(GAction *)
     * }
     */
    public static MemorySegment get_name(MemorySegment struct) {
        return struct.get(get_name$LAYOUT, get_name$OFFSET);
    }

    /**
     * Setter for field:
     * {@snippet lang=c :
     * const gchar *(*get_name)(GAction *)
     * }
     */
    public static void get_name(MemorySegment struct, MemorySegment fieldValue) {
        struct.set(get_name$LAYOUT, get_name$OFFSET, fieldValue);
    }

    /**
     * {@snippet lang=c :
     * const GVariantType *(*get_parameter_type)(GAction *)
     * }
     */
    public class get_parameter_type {

        /**
         * The function pointer signature, expressed as a functional interface
         */
        public interface Function {
            MemorySegment apply(MemorySegment _x0);
        }

        private static final FunctionDescriptor $DESC = FunctionDescriptor.of(
            app_indicator_h.C_POINTER,
            app_indicator_h.C_POINTER
        );

        /**
         * The descriptor of this function pointer
         */
        public static FunctionDescriptor descriptor() {
            return $DESC;
        }

        private static final MethodHandle UP$MH = app_indicator_h.upcallHandle(get_parameter_type.Function.class, "apply", $DESC);

        /**
         * Allocates a new upcall stub, whose implementation is defined by {@code fi}.
         * The lifetime of the returned segment is managed by {@code arena}
         */
        public static MemorySegment allocate(get_parameter_type.Function fi, Arena arena) {
            return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena);
        }

        private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC);

        /**
         * Invoke the upcall stub {@code funcPtr}, with given parameters
         */
        public static MemorySegment invoke(MemorySegment funcPtr,MemorySegment _x0) {
            try {
                return (MemorySegment) DOWN$MH.invokeExact(funcPtr, _x0);
            } catch (Throwable ex$) {
                throw new AssertionError("should not reach here", ex$);
            }
        }
    }

    private static final AddressLayout get_parameter_type$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("get_parameter_type"));

    /**
     * Layout for field:
     * {@snippet lang=c :
     * const GVariantType *(*get_parameter_type)(GAction *)
     * }
     */
    public static final AddressLayout get_parameter_type$layout() {
        return get_parameter_type$LAYOUT;
    }

    private static final long get_parameter_type$OFFSET = 24;

    /**
     * Offset for field:
     * {@snippet lang=c :
     * const GVariantType *(*get_parameter_type)(GAction *)
     * }
     */
    public static final long get_parameter_type$offset() {
        return get_parameter_type$OFFSET;
    }

    /**
     * Getter for field:
     * {@snippet lang=c :
     * const GVariantType *(*get_parameter_type)(GAction *)
     * }
     */
    public static MemorySegment get_parameter_type(MemorySegment struct) {
        return struct.get(get_parameter_type$LAYOUT, get_parameter_type$OFFSET);
    }

    /**
     * Setter for field:
     * {@snippet lang=c :
     * const GVariantType *(*get_parameter_type)(GAction *)
     * }
     */
    public static void get_parameter_type(MemorySegment struct, MemorySegment fieldValue) {
        struct.set(get_parameter_type$LAYOUT, get_parameter_type$OFFSET, fieldValue);
    }

    /**
     * {@snippet lang=c :
     * const GVariantType *(*get_state_type)(GAction *)
     * }
     */
    public class get_state_type {

        /**
         * The function pointer signature, expressed as a functional interface
         */
        public interface Function {
            MemorySegment apply(MemorySegment _x0);
        }

        private static final FunctionDescriptor $DESC = FunctionDescriptor.of(
            app_indicator_h.C_POINTER,
            app_indicator_h.C_POINTER
        );

        /**
         * The descriptor of this function pointer
         */
        public static FunctionDescriptor descriptor() {
            return $DESC;
        }

        private static final MethodHandle UP$MH = app_indicator_h.upcallHandle(get_state_type.Function.class, "apply", $DESC);

        /**
         * Allocates a new upcall stub, whose implementation is defined by {@code fi}.
         * The lifetime of the returned segment is managed by {@code arena}
         */
        public static MemorySegment allocate(get_state_type.Function fi, Arena arena) {
            return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena);
        }

        private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC);

        /**
         * Invoke the upcall stub {@code funcPtr}, with given parameters
         */
        public static MemorySegment invoke(MemorySegment funcPtr,MemorySegment _x0) {
            try {
                return (MemorySegment) DOWN$MH.invokeExact(funcPtr, _x0);
            } catch (Throwable ex$) {
                throw new AssertionError("should not reach here", ex$);
            }
        }
    }

    private static final AddressLayout get_state_type$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("get_state_type"));

    /**
     * Layout for field:
     * {@snippet lang=c :
     * const GVariantType *(*get_state_type)(GAction *)
     * }
     */
    public static final AddressLayout get_state_type$layout() {
        return get_state_type$LAYOUT;
    }

    private static final long get_state_type$OFFSET = 32;

    /**
     * Offset for field:
     * {@snippet lang=c :
     * const GVariantType *(*get_state_type)(GAction *)
     * }
     */
    public static final long get_state_type$offset() {
        return get_state_type$OFFSET;
    }

    /**
     * Getter for field:
     * {@snippet lang=c :
     * const GVariantType *(*get_state_type)(GAction *)
     * }
     */
    public static MemorySegment get_state_type(MemorySegment struct) {
        return struct.get(get_state_type$LAYOUT, get_state_type$OFFSET);
    }

    /**
     * Setter for field:
     * {@snippet lang=c :
     * const GVariantType *(*get_state_type)(GAction *)
     * }
     */
    public static void get_state_type(MemorySegment struct, MemorySegment fieldValue) {
        struct.set(get_state_type$LAYOUT, get_state_type$OFFSET, fieldValue);
    }

    /**
     * {@snippet lang=c :
     * GVariant *(*get_state_hint)(GAction *)
     * }
     */
    public class get_state_hint {

        /**
         * The function pointer signature, expressed as a functional interface
         */
        public interface Function {
            MemorySegment apply(MemorySegment _x0);
        }

        private static final FunctionDescriptor $DESC = FunctionDescriptor.of(
            app_indicator_h.C_POINTER,
            app_indicator_h.C_POINTER
        );

        /**
         * The descriptor of this function pointer
         */
        public static FunctionDescriptor descriptor() {
            return $DESC;
        }

        private static final MethodHandle UP$MH = app_indicator_h.upcallHandle(get_state_hint.Function.class, "apply", $DESC);

        /**
         * Allocates a new upcall stub, whose implementation is defined by {@code fi}.
         * The lifetime of the returned segment is managed by {@code arena}
         */
        public static MemorySegment allocate(get_state_hint.Function fi, Arena arena) {
            return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena);
        }

        private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC);

        /**
         * Invoke the upcall stub {@code funcPtr}, with given parameters
         */
        public static MemorySegment invoke(MemorySegment funcPtr,MemorySegment _x0) {
            try {
                return (MemorySegment) DOWN$MH.invokeExact(funcPtr, _x0);
            } catch (Throwable ex$) {
                throw new AssertionError("should not reach here", ex$);
            }
        }
    }

    private static final AddressLayout get_state_hint$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("get_state_hint"));

    /**
     * Layout for field:
     * {@snippet lang=c :
     * GVariant *(*get_state_hint)(GAction *)
     * }
     */
    public static final AddressLayout get_state_hint$layout() {
        return get_state_hint$LAYOUT;
    }

    private static final long get_state_hint$OFFSET = 40;

    /**
     * Offset for field:
     * {@snippet lang=c :
     * GVariant *(*get_state_hint)(GAction *)
     * }
     */
    public static final long get_state_hint$offset() {
        return get_state_hint$OFFSET;
    }

    /**
     * Getter for field:
     * {@snippet lang=c :
     * GVariant *(*get_state_hint)(GAction *)
     * }
     */
    public static MemorySegment get_state_hint(MemorySegment struct) {
        return struct.get(get_state_hint$LAYOUT, get_state_hint$OFFSET);
    }

    /**
     * Setter for field:
     * {@snippet lang=c :
     * GVariant *(*get_state_hint)(GAction *)
     * }
     */
    public static void get_state_hint(MemorySegment struct, MemorySegment fieldValue) {
        struct.set(get_state_hint$LAYOUT, get_state_hint$OFFSET, fieldValue);
    }

    /**
     * {@snippet lang=c :
     * gboolean (*get_enabled)(GAction *)
     * }
     */
    public class get_enabled {

        /**
         * The function pointer signature, expressed as a functional interface
         */
        public interface Function {
            int apply(MemorySegment _x0);
        }

        private static final FunctionDescriptor $DESC = FunctionDescriptor.of(
            app_indicator_h.C_INT,
            app_indicator_h.C_POINTER
        );

        /**
         * The descriptor of this function pointer
         */
        public static FunctionDescriptor descriptor() {
            return $DESC;
        }

        private static final MethodHandle UP$MH = app_indicator_h.upcallHandle(get_enabled.Function.class, "apply", $DESC);

        /**
         * Allocates a new upcall stub, whose implementation is defined by {@code fi}.
         * The lifetime of the returned segment is managed by {@code arena}
         */
        public static MemorySegment allocate(get_enabled.Function fi, Arena arena) {
            return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena);
        }

        private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC);

        /**
         * Invoke the upcall stub {@code funcPtr}, with given parameters
         */
        public static int invoke(MemorySegment funcPtr,MemorySegment _x0) {
            try {
                return (int) DOWN$MH.invokeExact(funcPtr, _x0);
            } catch (Throwable ex$) {
                throw new AssertionError("should not reach here", ex$);
            }
        }
    }

    private static final AddressLayout get_enabled$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("get_enabled"));

    /**
     * Layout for field:
     * {@snippet lang=c :
     * gboolean (*get_enabled)(GAction *)
     * }
     */
    public static final AddressLayout get_enabled$layout() {
        return get_enabled$LAYOUT;
    }

    private static final long get_enabled$OFFSET = 48;

    /**
     * Offset for field:
     * {@snippet lang=c :
     * gboolean (*get_enabled)(GAction *)
     * }
     */
    public static final long get_enabled$offset() {
        return get_enabled$OFFSET;
    }

    /**
     * Getter for field:
     * {@snippet lang=c :
     * gboolean (*get_enabled)(GAction *)
     * }
     */
    public static MemorySegment get_enabled(MemorySegment struct) {
        return struct.get(get_enabled$LAYOUT, get_enabled$OFFSET);
    }

    /**
     * Setter for field:
     * {@snippet lang=c :
     * gboolean (*get_enabled)(GAction *)
     * }
     */
    public static void get_enabled(MemorySegment struct, MemorySegment fieldValue) {
        struct.set(get_enabled$LAYOUT, get_enabled$OFFSET, fieldValue);
    }

    /**
     * {@snippet lang=c :
     * GVariant *(*get_state)(GAction *)
     * }
     */
    public class get_state {

        /**
         * The function pointer signature, expressed as a functional interface
         */
        public interface Function {
            MemorySegment apply(MemorySegment _x0);
        }

        private static final FunctionDescriptor $DESC = FunctionDescriptor.of(
            app_indicator_h.C_POINTER,
            app_indicator_h.C_POINTER
        );

        /**
         * The descriptor of this function pointer
         */
        public static FunctionDescriptor descriptor() {
            return $DESC;
        }

        private static final MethodHandle UP$MH = app_indicator_h.upcallHandle(get_state.Function.class, "apply", $DESC);

        /**
         * Allocates a new upcall stub, whose implementation is defined by {@code fi}.
         * The lifetime of the returned segment is managed by {@code arena}
         */
        public static MemorySegment allocate(get_state.Function fi, Arena arena) {
            return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena);
        }

        private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC);

        /**
         * Invoke the upcall stub {@code funcPtr}, with given parameters
         */
        public static MemorySegment invoke(MemorySegment funcPtr,MemorySegment _x0) {
            try {
                return (MemorySegment) DOWN$MH.invokeExact(funcPtr, _x0);
            } catch (Throwable ex$) {
                throw new AssertionError("should not reach here", ex$);
            }
        }
    }

    private static final AddressLayout get_state$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("get_state"));

    /**
     * Layout for field:
     * {@snippet lang=c :
     * GVariant *(*get_state)(GAction *)
     * }
     */
    public static final AddressLayout get_state$layout() {
        return get_state$LAYOUT;
    }

    private static final long get_state$OFFSET = 56;

    /**
     * Offset for field:
     * {@snippet lang=c :
     * GVariant *(*get_state)(GAction *)
     * }
     */
    public static final long get_state$offset() {
        return get_state$OFFSET;
    }

    /**
     * Getter for field:
     * {@snippet lang=c :
     * GVariant *(*get_state)(GAction *)
     * }
     */
    public static MemorySegment get_state(MemorySegment struct) {
        return struct.get(get_state$LAYOUT, get_state$OFFSET);
    }

    /**
     * Setter for field:
     * {@snippet lang=c :
     * GVariant *(*get_state)(GAction *)
     * }
     */
    public static void get_state(MemorySegment struct, MemorySegment fieldValue) {
        struct.set(get_state$LAYOUT, get_state$OFFSET, fieldValue);
    }

    /**
     * {@snippet lang=c :
     * void (*change_state)(GAction *, GVariant *)
     * }
     */
    public class change_state {

        /**
         * The function pointer signature, expressed as a functional interface
         */
        public interface Function {
            void apply(MemorySegment _x0, MemorySegment _x1);
        }

        private static final FunctionDescriptor $DESC = FunctionDescriptor.ofVoid(
            app_indicator_h.C_POINTER,
            app_indicator_h.C_POINTER
        );

        /**
         * The descriptor of this function pointer
         */
        public static FunctionDescriptor descriptor() {
            return $DESC;
        }

        private static final MethodHandle UP$MH = app_indicator_h.upcallHandle(change_state.Function.class, "apply", $DESC);

        /**
         * Allocates a new upcall stub, whose implementation is defined by {@code fi}.
         * The lifetime of the returned segment is managed by {@code arena}
         */
        public static MemorySegment allocate(change_state.Function fi, Arena arena) {
            return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena);
        }

        private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC);

        /**
         * Invoke the upcall stub {@code funcPtr}, with given parameters
         */
        public static void invoke(MemorySegment funcPtr,MemorySegment _x0, MemorySegment _x1) {
            try {
                 DOWN$MH.invokeExact(funcPtr, _x0, _x1);
            } catch (Throwable ex$) {
                throw new AssertionError("should not reach here", ex$);
            }
        }
    }

    private static final AddressLayout change_state$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("change_state"));

    /**
     * Layout for field:
     * {@snippet lang=c :
     * void (*change_state)(GAction *, GVariant *)
     * }
     */
    public static final AddressLayout change_state$layout() {
        return change_state$LAYOUT;
    }

    private static final long change_state$OFFSET = 64;

    /**
     * Offset for field:
     * {@snippet lang=c :
     * void (*change_state)(GAction *, GVariant *)
     * }
     */
    public static final long change_state$offset() {
        return change_state$OFFSET;
    }

    /**
     * Getter for field:
     * {@snippet lang=c :
     * void (*change_state)(GAction *, GVariant *)
     * }
     */
    public static MemorySegment change_state(MemorySegment struct) {
        return struct.get(change_state$LAYOUT, change_state$OFFSET);
    }

    /**
     * Setter for field:
     * {@snippet lang=c :
     * void (*change_state)(GAction *, GVariant *)
     * }
     */
    public static void change_state(MemorySegment struct, MemorySegment fieldValue) {
        struct.set(change_state$LAYOUT, change_state$OFFSET, fieldValue);
    }

    /**
     * {@snippet lang=c :
     * void (*activate)(GAction *, GVariant *)
     * }
     */
    public class activate {

        /**
         * The function pointer signature, expressed as a functional interface
         */
        public interface Function {
            void apply(MemorySegment _x0, MemorySegment _x1);
        }

        private static final FunctionDescriptor $DESC = FunctionDescriptor.ofVoid(
            app_indicator_h.C_POINTER,
            app_indicator_h.C_POINTER
        );

        /**
         * The descriptor of this function pointer
         */
        public static FunctionDescriptor descriptor() {
            return $DESC;
        }

        private static final MethodHandle UP$MH = app_indicator_h.upcallHandle(activate.Function.class, "apply", $DESC);

        /**
         * Allocates a new upcall stub, whose implementation is defined by {@code fi}.
         * The lifetime of the returned segment is managed by {@code arena}
         */
        public static MemorySegment allocate(activate.Function fi, Arena arena) {
            return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena);
        }

        private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC);

        /**
         * Invoke the upcall stub {@code funcPtr}, with given parameters
         */
        public static void invoke(MemorySegment funcPtr,MemorySegment _x0, MemorySegment _x1) {
            try {
                 DOWN$MH.invokeExact(funcPtr, _x0, _x1);
            } catch (Throwable ex$) {
                throw new AssertionError("should not reach here", ex$);
            }
        }
    }

    private static final AddressLayout activate$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("activate"));

    /**
     * Layout for field:
     * {@snippet lang=c :
     * void (*activate)(GAction *, GVariant *)
     * }
     */
    public static final AddressLayout activate$layout() {
        return activate$LAYOUT;
    }

    private static final long activate$OFFSET = 72;

    /**
     * Offset for field:
     * {@snippet lang=c :
     * void (*activate)(GAction *, GVariant *)
     * }
     */
    public static final long activate$offset() {
        return activate$OFFSET;
    }

    /**
     * Getter for field:
     * {@snippet lang=c :
     * void (*activate)(GAction *, GVariant *)
     * }
     */
    public static MemorySegment activate(MemorySegment struct) {
        return struct.get(activate$LAYOUT, activate$OFFSET);
    }

    /**
     * Setter for field:
     * {@snippet lang=c :
     * void (*activate)(GAction *, GVariant *)
     * }
     */
    public static void activate(MemorySegment struct, MemorySegment fieldValue) {
        struct.set(activate$LAYOUT, activate$OFFSET, fieldValue);
    }

    /**
     * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}.
     * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()}
     */
    public static MemorySegment asSlice(MemorySegment array, long index) {
        return array.asSlice(layout().byteSize() * index);
    }

    /**
     * The size (in bytes) of this struct
     */
    public static long sizeof() { return layout().byteSize(); }

    /**
     * Allocate a segment of size {@code layout().byteSize()} using {@code allocator}
     */
    public static MemorySegment allocate(SegmentAllocator allocator) {
        return allocator.allocate(layout());
    }

    /**
     * Allocate an array of size {@code elementCount} using {@code allocator}.
     * The returned segment has size {@code elementCount * layout().byteSize()}.
     */
    public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) {
        return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout()));
    }

    /**
     * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction) (if any).
     * The returned segment has size {@code layout().byteSize()}
     */
    public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) {
        return reinterpret(addr, 1, arena, cleanup);
    }

    /**
     * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction) (if any).
     * The returned segment has size {@code elementCount * layout().byteSize()}
     */
    public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) {
        return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup);
    }
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy