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 VmaVirtualAllocationCreateInfo extends Struct<VmaVirtualAllocationCreateInfo> implements NativeResource {
   public static final int SIZEOF;
   public static final int ALIGNOF;
   public static final int SIZE;
   public static final int ALIGNMENT;
   public static final int FLAGS;
   public static final int PUSERDATA;

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

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

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

   public int sizeof() {
      return SIZEOF;
   }

   @NativeType("VkDeviceSize")
   public long size() {
      return nsize(this.address());
   }

   @NativeType("VkDeviceSize")
   public long alignment() {
      return nalignment(this.address());
   }

   @NativeType("VmaVirtualAllocationCreateFlags")
   public int flags() {
      return nflags(this.address());
   }

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

   public VmaVirtualAllocationCreateInfo size(@NativeType("VkDeviceSize") long value) {
      nsize(this.address(), value);
      return this;
   }

   public VmaVirtualAllocationCreateInfo alignment(@NativeType("VkDeviceSize") long value) {
      nalignment(this.address(), value);
      return this;
   }

   public VmaVirtualAllocationCreateInfo flags(@NativeType("VmaVirtualAllocationCreateFlags") int value) {
      nflags(this.address(), value);
      return this;
   }

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

   public VmaVirtualAllocationCreateInfo set(long size, long alignment, int flags, long pUserData) {
      this.size(size);
      this.alignment(alignment);
      this.flags(flags);
      this.pUserData(pUserData);
      return this;
   }

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

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

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

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

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

   @Nullable
   public static VmaVirtualAllocationCreateInfo createSafe(long address) {
      return address == 0L ? null : new VmaVirtualAllocationCreateInfo(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);
   }

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

   public static VmaVirtualAllocationCreateInfo calloc(MemoryStack stack) {
      return new VmaVirtualAllocationCreateInfo(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);
   }

   public static long nsize(long struct) {
      return UNSAFE.getLong((Object)null, struct + (long)SIZE);
   }

   public static long nalignment(long struct) {
      return UNSAFE.getLong((Object)null, struct + (long)ALIGNMENT);
   }

   public static int nflags(long struct) {
      return UNSAFE.getInt((Object)null, struct + (long)FLAGS);
   }

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

   public static void nsize(long struct, long value) {
      UNSAFE.putLong((Object)null, struct + (long)SIZE, value);
   }

   public static void nalignment(long struct, long value) {
      UNSAFE.putLong((Object)null, struct + (long)ALIGNMENT, value);
   }

   public static void nflags(long struct, int value) {
      UNSAFE.putInt((Object)null, struct + (long)FLAGS, value);
   }

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

   static {
      Struct.Layout layout = __struct(new Struct.Member[]{__member(8), __member(8), __member(4), __member(POINTER_SIZE)});
      SIZEOF = layout.getSize();
      ALIGNOF = layout.getAlignment();
      SIZE = layout.offsetof(0);
      ALIGNMENT = layout.offsetof(1);
      FLAGS = layout.offsetof(2);
      PUSERDATA = layout.offsetof(3);
   }

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

      public Buffer(ByteBuffer container) {
         super(container, container.remaining() / VmaVirtualAllocationCreateInfo.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 VmaVirtualAllocationCreateInfo getElementFactory() {
         return ELEMENT_FACTORY;
      }

      @NativeType("VkDeviceSize")
      public long size() {
         return VmaVirtualAllocationCreateInfo.nsize(this.address());
      }

      @NativeType("VkDeviceSize")
      public long alignment() {
         return VmaVirtualAllocationCreateInfo.nalignment(this.address());
      }

      @NativeType("VmaVirtualAllocationCreateFlags")
      public int flags() {
         return VmaVirtualAllocationCreateInfo.nflags(this.address());
      }

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

      public Buffer size(@NativeType("VkDeviceSize") long value) {
         VmaVirtualAllocationCreateInfo.nsize(this.address(), value);
         return this;
      }

      public Buffer alignment(@NativeType("VkDeviceSize") long value) {
         VmaVirtualAllocationCreateInfo.nalignment(this.address(), value);
         return this;
      }

      public Buffer flags(@NativeType("VmaVirtualAllocationCreateFlags") int value) {
         VmaVirtualAllocationCreateInfo.nflags(this.address(), value);
         return this;
      }

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