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

org.purejava.appindicator._GMemVTable 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 _GMemVTable {
 *     gpointer (*malloc)(gsize);
 *     gpointer (*realloc)(gpointer, gsize);
 *     void (*free)(gpointer);
 *     gpointer (*calloc)(gsize, gsize);
 *     gpointer (*try_malloc)(gsize);
 *     gpointer (*try_realloc)(gpointer, gsize);
 * }
 * }
 */
public class _GMemVTable {

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

    private static final GroupLayout $LAYOUT = MemoryLayout.structLayout(
        app_indicator_h.C_POINTER.withName("malloc"),
        app_indicator_h.C_POINTER.withName("realloc"),
        app_indicator_h.C_POINTER.withName("free"),
        app_indicator_h.C_POINTER.withName("calloc"),
        app_indicator_h.C_POINTER.withName("try_malloc"),
        app_indicator_h.C_POINTER.withName("try_realloc")
    ).withName("_GMemVTable");

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

    /**
     * {@snippet lang=c :
     * gpointer (*malloc)(gsize)
     * }
     */
    public class malloc {

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

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

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

        private static final MethodHandle UP$MH = app_indicator_h.upcallHandle(malloc.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(malloc.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,long _x0) {
            try {
                return (MemorySegment) DOWN$MH.invokeExact(funcPtr, _x0);
            } catch (Throwable ex$) {
                throw new AssertionError("should not reach here", ex$);
            }
        }
    }

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

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

    private static final long malloc$OFFSET = 0;

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

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

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

    /**
     * {@snippet lang=c :
     * gpointer (*realloc)(gpointer, gsize)
     * }
     */
    public class realloc {

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

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

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

        private static final MethodHandle UP$MH = app_indicator_h.upcallHandle(realloc.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(realloc.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, long _x1) {
            try {
                return (MemorySegment) DOWN$MH.invokeExact(funcPtr, _x0, _x1);
            } catch (Throwable ex$) {
                throw new AssertionError("should not reach here", ex$);
            }
        }
    }

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

    /**
     * Layout for field:
     * {@snippet lang=c :
     * gpointer (*realloc)(gpointer, gsize)
     * }
     */
    public static final AddressLayout realloc$layout() {
        return realloc$LAYOUT;
    }

    private static final long realloc$OFFSET = 8;

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

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

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

    /**
     * {@snippet lang=c :
     * void (*free)(gpointer)
     * }
     */
    public class free {

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

        private static final FunctionDescriptor $DESC = FunctionDescriptor.ofVoid(
            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(free.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(free.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) {
            try {
                 DOWN$MH.invokeExact(funcPtr, _x0);
            } catch (Throwable ex$) {
                throw new AssertionError("should not reach here", ex$);
            }
        }
    }

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

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

    private static final long free$OFFSET = 16;

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

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

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

    /**
     * {@snippet lang=c :
     * gpointer (*calloc)(gsize, gsize)
     * }
     */
    public class calloc {

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

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

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

        private static final MethodHandle UP$MH = app_indicator_h.upcallHandle(calloc.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(calloc.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,long _x0, long _x1) {
            try {
                return (MemorySegment) DOWN$MH.invokeExact(funcPtr, _x0, _x1);
            } catch (Throwable ex$) {
                throw new AssertionError("should not reach here", ex$);
            }
        }
    }

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

    /**
     * Layout for field:
     * {@snippet lang=c :
     * gpointer (*calloc)(gsize, gsize)
     * }
     */
    public static final AddressLayout calloc$layout() {
        return calloc$LAYOUT;
    }

    private static final long calloc$OFFSET = 24;

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

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

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

    /**
     * {@snippet lang=c :
     * gpointer (*try_malloc)(gsize)
     * }
     */
    public class try_malloc {

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

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

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

        private static final MethodHandle UP$MH = app_indicator_h.upcallHandle(try_malloc.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(try_malloc.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,long _x0) {
            try {
                return (MemorySegment) DOWN$MH.invokeExact(funcPtr, _x0);
            } catch (Throwable ex$) {
                throw new AssertionError("should not reach here", ex$);
            }
        }
    }

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

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

    private static final long try_malloc$OFFSET = 32;

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

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

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

    /**
     * {@snippet lang=c :
     * gpointer (*try_realloc)(gpointer, gsize)
     * }
     */
    public class try_realloc {

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

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

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

        private static final MethodHandle UP$MH = app_indicator_h.upcallHandle(try_realloc.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(try_realloc.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, long _x1) {
            try {
                return (MemorySegment) DOWN$MH.invokeExact(funcPtr, _x0, _x1);
            } catch (Throwable ex$) {
                throw new AssertionError("should not reach here", ex$);
            }
        }
    }

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

    /**
     * Layout for field:
     * {@snippet lang=c :
     * gpointer (*try_realloc)(gpointer, gsize)
     * }
     */
    public static final AddressLayout try_realloc$layout() {
        return try_realloc$LAYOUT;
    }

    private static final long try_realloc$OFFSET = 40;

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

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

    /**
     * Setter for field:
     * {@snippet lang=c :
     * gpointer (*try_realloc)(gpointer, gsize)
     * }
     */
    public static void try_realloc(MemorySegment struct, MemorySegment fieldValue) {
        struct.set(try_realloc$LAYOUT, try_realloc$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