package org.lwjgl.util.vma;

import java.nio.ByteBuffer;
import javax.annotation.Nullable;
import org.lwjgl.BufferUtils;
import org.lwjgl.system.Checks;
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 VmaTotalStatistics extends Struct<VmaTotalStatistics> implements NativeResource {
   public static final int SIZEOF;
   public static final int ALIGNOF;
   public static final int MEMORYTYPE;
   public static final int MEMORYHEAP;
   public static final int TOTAL;

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

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

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

   public int sizeof() {
      return SIZEOF;
   }

   @NativeType("VmaDetailedStatistics[32]")
   public VmaDetailedStatistics.Buffer memoryType() {
      return nmemoryType(this.address());
   }

   public VmaDetailedStatistics memoryType(int index) {
      return nmemoryType(this.address(), index);
   }

   @NativeType("VmaDetailedStatistics[16]")
   public VmaDetailedStatistics.Buffer memoryHeap() {
      return nmemoryHeap(this.address());
   }

   public VmaDetailedStatistics memoryHeap(int index) {
      return nmemoryHeap(this.address(), index);
   }

   public VmaDetailedStatistics total() {
      return ntotal(this.address());
   }

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

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

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

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

   @Nullable
   public static VmaTotalStatistics createSafe(long address) {
      return address == 0L ? null : new VmaTotalStatistics(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 VmaTotalStatistics malloc(MemoryStack stack) {
      return new VmaTotalStatistics(stack.nmalloc(ALIGNOF, SIZEOF), (ByteBuffer)null);
   }

   public static VmaTotalStatistics calloc(MemoryStack stack) {
      return new VmaTotalStatistics(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 VmaDetailedStatistics.Buffer nmemoryType(long struct) {
      return VmaDetailedStatistics.create(struct + (long)MEMORYTYPE, 32);
   }

   public static VmaDetailedStatistics nmemoryType(long struct, int index) {
      return VmaDetailedStatistics.create(struct + (long)MEMORYTYPE + Checks.check(index, 32) * (long)VmaDetailedStatistics.SIZEOF);
   }

   public static VmaDetailedStatistics.Buffer nmemoryHeap(long struct) {
      return VmaDetailedStatistics.create(struct + (long)MEMORYHEAP, 16);
   }

   public static VmaDetailedStatistics nmemoryHeap(long struct, int index) {
      return VmaDetailedStatistics.create(struct + (long)MEMORYHEAP + Checks.check(index, 16) * (long)VmaDetailedStatistics.SIZEOF);
   }

   public static VmaDetailedStatistics ntotal(long struct) {
      return VmaDetailedStatistics.create(struct + (long)TOTAL);
   }

   static {
      Struct.Layout layout = __struct(new Struct.Member[]{__array(VmaDetailedStatistics.SIZEOF, VmaDetailedStatistics.ALIGNOF, 32), __array(VmaDetailedStatistics.SIZEOF, VmaDetailedStatistics.ALIGNOF, 16), __member(VmaDetailedStatistics.SIZEOF, VmaDetailedStatistics.ALIGNOF)});
      SIZEOF = layout.getSize();
      ALIGNOF = layout.getAlignment();
      MEMORYTYPE = layout.offsetof(0);
      MEMORYHEAP = layout.offsetof(1);
      TOTAL = layout.offsetof(2);
   }

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

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

      @NativeType("VmaDetailedStatistics[32]")
      public VmaDetailedStatistics.Buffer memoryType() {
         return VmaTotalStatistics.nmemoryType(this.address());
      }

      public VmaDetailedStatistics memoryType(int index) {
         return VmaTotalStatistics.nmemoryType(this.address(), index);
      }

      @NativeType("VmaDetailedStatistics[16]")
      public VmaDetailedStatistics.Buffer memoryHeap() {
         return VmaTotalStatistics.nmemoryHeap(this.address());
      }

      public VmaDetailedStatistics memoryHeap(int index) {
         return VmaTotalStatistics.nmemoryHeap(this.address(), index);
      }

      public VmaDetailedStatistics total() {
         return VmaTotalStatistics.ntotal(this.address());
      }
   }
}
