package org.lwjgl.util.vma;

import java.nio.ByteBuffer;
import javax.annotation.Nullable;
import org.lwjgl.BufferUtils;
import org.lwjgl.system.MemoryStack;
import org.lwjgl.system.MemoryUtil;
import org.lwjgl.system.NativeResource;
import org.lwjgl.system.NativeType;
import org.lwjgl.system.Struct;
import org.lwjgl.system.StructBuffer;

public class VmaDeviceMemoryCallbacks extends Struct<VmaDeviceMemoryCallbacks> implements NativeResource {
   public static final int SIZEOF;
   public static final int ALIGNOF;
   public static final int PFNALLOCATE;
   public static final int PFNFREE;
   public static final int PUSERDATA;

   protected VmaDeviceMemoryCallbacks(long address, @Nullable ByteBuffer container) {
      super(address, container);
   }

   protected VmaDeviceMemoryCallbacks create(long address, @Nullable ByteBuffer container) {
      return new VmaDeviceMemoryCallbacks(address, container);
   }

   public VmaDeviceMemoryCallbacks(ByteBuffer container) {
      super(MemoryUtil.memAddress(container), __checkContainer(container, SIZEOF));
   }

   public int sizeof() {
      return SIZEOF;
   }

   @Nullable
   @NativeType("PFN_vmaAllocateDeviceMemoryFunction")
   public VmaAllocateDeviceMemoryFunction pfnAllocate() {
      return npfnAllocate(this.address());
   }

   @Nullable
   @NativeType("PFN_vmaFreeDeviceMemoryFunction")
   public VmaFreeDeviceMemoryFunction pfnFree() {
      return npfnFree(this.address());
   }

   @NativeType("void *")
   public long pUserData() {
      return npUserData(this.address());
   }

   public VmaDeviceMemoryCallbacks pfnAllocate(@Nullable @NativeType("PFN_vmaAllocateDeviceMemoryFunction") VmaAllocateDeviceMemoryFunctionI value) {
      npfnAllocate(this.address(), value);
      return this;
   }

   public VmaDeviceMemoryCallbacks pfnFree(@Nullable @NativeType("PFN_vmaFreeDeviceMemoryFunction") VmaFreeDeviceMemoryFunctionI value) {
      npfnFree(this.address(), value);
      return this;
   }

   public VmaDeviceMemoryCallbacks pUserData(@NativeType("void *") long value) {
      npUserData(this.address(), value);
      return this;
   }

   public VmaDeviceMemoryCallbacks set(VmaAllocateDeviceMemoryFunctionI pfnAllocate, VmaFreeDeviceMemoryFunctionI pfnFree, long pUserData) {
      this.pfnAllocate(pfnAllocate);
      this.pfnFree(pfnFree);
      this.pUserData(pUserData);
      return this;
   }

   public VmaDeviceMemoryCallbacks set(VmaDeviceMemoryCallbacks src) {
      MemoryUtil.memCopy(src.address(), this.address(), (long)SIZEOF);
      return this;
   }

   public static VmaDeviceMemoryCallbacks malloc() {
      return new VmaDeviceMemoryCallbacks(MemoryUtil.nmemAllocChecked((long)SIZEOF), (ByteBuffer)null);
   }

   public static VmaDeviceMemoryCallbacks calloc() {
      return new VmaDeviceMemoryCallbacks(MemoryUtil.nmemCallocChecked(1L, (long)SIZEOF), (ByteBuffer)null);
   }

   public static VmaDeviceMemoryCallbacks create() {
      ByteBuffer container = BufferUtils.createByteBuffer(SIZEOF);
      return new VmaDeviceMemoryCallbacks(MemoryUtil.memAddress(container), container);
   }

   public static VmaDeviceMemoryCallbacks create(long address) {
      return new VmaDeviceMemoryCallbacks(address, (ByteBuffer)null);
   }

   @Nullable
   public static VmaDeviceMemoryCallbacks createSafe(long address) {
      return address == 0L ? null : new VmaDeviceMemoryCallbacks(address, (ByteBuffer)null);
   }

   public static Buffer malloc(int capacity) {
      return new Buffer(MemoryUtil.nmemAllocChecked(__checkMalloc(capacity, SIZEOF)), capacity);
   }

   public static Buffer calloc(int capacity) {
      return new Buffer(MemoryUtil.nmemCallocChecked((long)capacity, (long)SIZEOF), capacity);
   }

   public static Buffer create(int capacity) {
      ByteBuffer container = __create(capacity, SIZEOF);
      return new Buffer(MemoryUtil.memAddress(container), container, -1, 0, capacity, capacity);
   }

   public static Buffer create(long address, int capacity) {
      return new Buffer(address, capacity);
   }

   @Nullable
   public static Buffer createSafe(long address, int capacity) {
      return address == 0L ? null : new Buffer(address, capacity);
   }

   /** @deprecated */
   @Deprecated
   public static VmaDeviceMemoryCallbacks mallocStack() {
      return malloc(MemoryStack.stackGet());
   }

   /** @deprecated */
   @Deprecated
   public static VmaDeviceMemoryCallbacks callocStack() {
      return calloc(MemoryStack.stackGet());
   }

   /** @deprecated */
   @Deprecated
   public static VmaDeviceMemoryCallbacks mallocStack(MemoryStack stack) {
      return malloc(stack);
   }

   /** @deprecated */
   @Deprecated
   public static VmaDeviceMemoryCallbacks callocStack(MemoryStack stack) {
      return calloc(stack);
   }

   /** @deprecated */
   @Deprecated
   public static Buffer mallocStack(int capacity) {
      return malloc(capacity, MemoryStack.stackGet());
   }

   /** @deprecated */
   @Deprecated
   public static Buffer callocStack(int capacity) {
      return calloc(capacity, MemoryStack.stackGet());
   }

   /** @deprecated */
   @Deprecated
   public static Buffer mallocStack(int capacity, MemoryStack stack) {
      return malloc(capacity, stack);
   }

   /** @deprecated */
   @Deprecated
   public static Buffer callocStack(int capacity, MemoryStack stack) {
      return calloc(capacity, stack);
   }

   public static VmaDeviceMemoryCallbacks malloc(MemoryStack stack) {
      return new VmaDeviceMemoryCallbacks(stack.nmalloc(ALIGNOF, SIZEOF), (ByteBuffer)null);
   }

   public static VmaDeviceMemoryCallbacks calloc(MemoryStack stack) {
      return new VmaDeviceMemoryCallbacks(stack.ncalloc(ALIGNOF, 1, SIZEOF), (ByteBuffer)null);
   }

   public static Buffer malloc(int capacity, MemoryStack stack) {
      return new Buffer(stack.nmalloc(ALIGNOF, capacity * SIZEOF), capacity);
   }

   public static Buffer calloc(int capacity, MemoryStack stack) {
      return new Buffer(stack.ncalloc(ALIGNOF, capacity, SIZEOF), capacity);
   }

   @Nullable
   public static VmaAllocateDeviceMemoryFunction npfnAllocate(long struct) {
      return VmaAllocateDeviceMemoryFunction.createSafe(MemoryUtil.memGetAddress(struct + (long)PFNALLOCATE));
   }

   @Nullable
   public static VmaFreeDeviceMemoryFunction npfnFree(long struct) {
      return VmaFreeDeviceMemoryFunction.createSafe(MemoryUtil.memGetAddress(struct + (long)PFNFREE));
   }

   public static long npUserData(long struct) {
      return MemoryUtil.memGetAddress(struct + (long)PUSERDATA);
   }

   public static void npfnAllocate(long struct, @Nullable VmaAllocateDeviceMemoryFunctionI value) {
      MemoryUtil.memPutAddress(struct + (long)PFNALLOCATE, MemoryUtil.memAddressSafe(value));
   }

   public static void npfnFree(long struct, @Nullable VmaFreeDeviceMemoryFunctionI value) {
      MemoryUtil.memPutAddress(struct + (long)PFNFREE, MemoryUtil.memAddressSafe(value));
   }

   public static void npUserData(long struct, long value) {
      MemoryUtil.memPutAddress(struct + (long)PUSERDATA, value);
   }

   static {
      Struct.Layout layout = __struct(new Struct.Member[]{__member(POINTER_SIZE), __member(POINTER_SIZE), __member(POINTER_SIZE)});
      SIZEOF = layout.getSize();
      ALIGNOF = layout.getAlignment();
      PFNALLOCATE = layout.offsetof(0);
      PFNFREE = layout.offsetof(1);
      PUSERDATA = layout.offsetof(2);
   }

   public static class Buffer extends StructBuffer<VmaDeviceMemoryCallbacks, Buffer> implements NativeResource {
      private static final VmaDeviceMemoryCallbacks ELEMENT_FACTORY = VmaDeviceMemoryCallbacks.create(-1L);

      public Buffer(ByteBuffer container) {
         super(container, container.remaining() / VmaDeviceMemoryCallbacks.SIZEOF);
      }

      public Buffer(long address, int cap) {
         super(address, (ByteBuffer)null, -1, 0, cap, cap);
      }

      Buffer(long address, @Nullable ByteBuffer container, int mark, int pos, int lim, int cap) {
         super(address, container, mark, pos, lim, cap);
      }

      protected Buffer self() {
         return this;
      }

      protected VmaDeviceMemoryCallbacks getElementFactory() {
         return ELEMENT_FACTORY;
      }

      @Nullable
      @NativeType("PFN_vmaAllocateDeviceMemoryFunction")
      public VmaAllocateDeviceMemoryFunction pfnAllocate() {
         return VmaDeviceMemoryCallbacks.npfnAllocate(this.address());
      }

      @Nullable
      @NativeType("PFN_vmaFreeDeviceMemoryFunction")
      public VmaFreeDeviceMemoryFunction pfnFree() {
         return VmaDeviceMemoryCallbacks.npfnFree(this.address());
      }

      @NativeType("void *")
      public long pUserData() {
         return VmaDeviceMemoryCallbacks.npUserData(this.address());
      }

      public Buffer pfnAllocate(@Nullable @NativeType("PFN_vmaAllocateDeviceMemoryFunction") VmaAllocateDeviceMemoryFunctionI value) {
         VmaDeviceMemoryCallbacks.npfnAllocate(this.address(), value);
         return this;
      }

      public Buffer pfnFree(@Nullable @NativeType("PFN_vmaFreeDeviceMemoryFunction") VmaFreeDeviceMemoryFunctionI value) {
         VmaDeviceMemoryCallbacks.npfnFree(this.address(), value);
         return this;
      }

      public Buffer pUserData(@NativeType("void *") long value) {
         VmaDeviceMemoryCallbacks.npUserData(this.address(), value);
         return this;
      }
   }
}
