Class StructBuffer<T extends Struct,SELF extends StructBuffer<T,SELF>>
- java.lang.Object
-
- org.lwjgl.system.StructBuffer<T,SELF>
-
- All Implemented Interfaces:
- java.lang.AutoCloseable, NativeResource, Pointer
- Direct Known Subclasses:
- ChunkHooks.Buffer, CLBufferRegion.Buffer, CLBusAddressAMD.Buffer, CLDeviceTopologyAMD.Buffer, CLImageDesc.Buffer, CLImageFormat.Buffer, CLMemEXTHostPtr.Buffer, CLMotionEstimationDescINTEL.Buffer, DEVMODE.Buffer, DISPLAY_DEVICE.Buffer, EGLClientPixmapHI.Buffer, GLFWGammaRamp.Buffer, GLFWImage.Buffer, GLFWVidMode.Buffer, GLXStereoNotifyEventEXT.Buffer, GLYPHMETRICSFLOAT.Buffer, GPU_DEVICE.Buffer, JAWT.Buffer, JAWTDrawingSurface.Buffer, JAWTDrawingSurfaceInfo.Buffer, JAWTRectangle.Buffer, JAWTWin32DrawingSurfaceInfo.Buffer, JAWTX11DrawingSurfaceInfo.Buffer, MONITORINFOEX.Buffer, MSG.Buffer, NFDPathSet.Buffer, NVGColor.Buffer, NVGGlyphPosition.Buffer, NVGLUFramebuffer.Buffer, NVGPaint.Buffer, NVGTextRow.Buffer, ObjCMethodDescription.Buffer, ObjCPropertyAttribute.Buffer, OVRDetectResult.Buffer, OVRErrorInfo.Buffer, OVREyeRenderDesc.Buffer, OVRFovPort.Buffer, OVRGraphicsLuid.Buffer, OVRHmdDesc.Buffer, OVRInitParams.Buffer, OVRInputState.Buffer, OVRLayerEyeFov.Buffer, OVRLayerEyeMatrix.Buffer, OVRLayerHeader.Buffer, OVRLayerQuad.Buffer, OVRLayerUnion.Buffer, OVRMatrix4f.Buffer, OVRMirrorTextureDesc.Buffer, OVRPosef.Buffer, OVRPoseStatef.Buffer, OVRQuatf.Buffer, OVRRecti.Buffer, OVRSessionStatus.Buffer, OVRSizei.Buffer, OVRTextureSwapChainDesc.Buffer, OVRTimewarpProjectionDesc.Buffer, OVRTrackerDesc.Buffer, OVRTrackerPose.Buffer, OVRTrackingState.Buffer, OVRVector2f.Buffer, OVRVector2i.Buffer, OVRVector3f.Buffer, OVRViewScaleDesc.Buffer, ParShapesMesh.Buffer, PIXELFORMATDESCRIPTOR.Buffer, POINT.Buffer, POINTFLOAT.Buffer, POINTL.Buffer, RECT.Buffer, STBIIOCallbacks.Buffer, STBRPContext.Buffer, STBRPNode.Buffer, STBRPRect.Buffer, STBTTAlignedQuad.Buffer, STBTTBakedChar.Buffer, STBTTFontinfo.Buffer, STBTTPackContext.Buffer, STBTTPackedchar.Buffer, STBTTPackRange.Buffer, STBTTVertex.Buffer, STBVorbisAlloc.Buffer, STBVorbisInfo.Buffer, TOUCHINPUT.Buffer, Visual.Buffer, VkAllocationCallbacks.Buffer, VkApplicationInfo.Buffer, VkAttachmentDescription.Buffer, VkAttachmentReference.Buffer, VkBindSparseInfo.Buffer, VkBufferCopy.Buffer, VkBufferCreateInfo.Buffer, VkBufferImageCopy.Buffer, VkBufferMemoryBarrier.Buffer, VkBufferViewCreateInfo.Buffer, VkClearAttachment.Buffer, VkClearColorValue.Buffer, VkClearDepthStencilValue.Buffer, VkClearRect.Buffer, VkClearValue.Buffer, VkCommandBufferAllocateInfo.Buffer, VkCommandBufferBeginInfo.Buffer, VkCommandBufferInheritanceInfo.Buffer, VkCommandPoolCreateInfo.Buffer, VkComponentMapping.Buffer, VkComputePipelineCreateInfo.Buffer, VkCopyDescriptorSet.Buffer, VkDebugMarkerMarkerInfoEXT.Buffer, VkDebugMarkerObjectNameInfoEXT.Buffer, VkDebugMarkerObjectTagInfoEXT.Buffer, VkDebugReportCallbackCreateInfoEXT.Buffer, VkDescriptorBufferInfo.Buffer, VkDescriptorImageInfo.Buffer, VkDescriptorPoolCreateInfo.Buffer, VkDescriptorPoolSize.Buffer, VkDescriptorSetAllocateInfo.Buffer, VkDescriptorSetLayoutBinding.Buffer, VkDescriptorSetLayoutCreateInfo.Buffer, VkDeviceCreateInfo.Buffer, VkDeviceQueueCreateInfo.Buffer, VkDispatchIndirectCommand.Buffer, VkDisplayModeCreateInfoKHR.Buffer, VkDisplayModeParametersKHR.Buffer, VkDisplayModePropertiesKHR.Buffer, VkDisplayPlaneCapabilitiesKHR.Buffer, VkDisplayPlanePropertiesKHR.Buffer, VkDisplayPresentInfoKHR.Buffer, VkDisplayPropertiesKHR.Buffer, VkDisplaySurfaceCreateInfoKHR.Buffer, VkDrawIndexedIndirectCommand.Buffer, VkDrawIndirectCommand.Buffer, VkEventCreateInfo.Buffer, VkExtensionProperties.Buffer, VkExtent2D.Buffer, VkExtent3D.Buffer, VkFenceCreateInfo.Buffer, VkFormatProperties.Buffer, VkFramebufferCreateInfo.Buffer, VkGraphicsPipelineCreateInfo.Buffer, VkImageBlit.Buffer, VkImageCopy.Buffer, VkImageCreateInfo.Buffer, VkImageFormatProperties.Buffer, VkImageMemoryBarrier.Buffer, VkImageResolve.Buffer, VkImageSubresource.Buffer, VkImageSubresourceLayers.Buffer, VkImageSubresourceRange.Buffer, VkImageViewCreateInfo.Buffer, VkInstanceCreateInfo.Buffer, VkLayerProperties.Buffer, VkMappedMemoryRange.Buffer, VkMemoryAllocateInfo.Buffer, VkMemoryBarrier.Buffer, VkMemoryHeap.Buffer, VkMemoryRequirements.Buffer, VkMemoryType.Buffer, VkOffset2D.Buffer, VkOffset3D.Buffer, VkPhysicalDeviceFeatures.Buffer, VkPhysicalDeviceLimits.Buffer, VkPhysicalDeviceMemoryProperties.Buffer, VkPhysicalDeviceProperties.Buffer, VkPhysicalDeviceSparseProperties.Buffer, VkPipelineCacheCreateInfo.Buffer, VkPipelineColorBlendAttachmentState.Buffer, VkPipelineColorBlendStateCreateInfo.Buffer, VkPipelineDepthStencilStateCreateInfo.Buffer, VkPipelineDynamicStateCreateInfo.Buffer, VkPipelineInputAssemblyStateCreateInfo.Buffer, VkPipelineLayoutCreateInfo.Buffer, VkPipelineMultisampleStateCreateInfo.Buffer, VkPipelineRasterizationStateCreateInfo.Buffer, VkPipelineRasterizationStateRasterizationOrderAMD.Buffer, VkPipelineShaderStageCreateInfo.Buffer, VkPipelineTessellationStateCreateInfo.Buffer, VkPipelineVertexInputStateCreateInfo.Buffer, VkPipelineViewportStateCreateInfo.Buffer, VkPresentInfoKHR.Buffer, VkPushConstantRange.Buffer, VkQueryPoolCreateInfo.Buffer, VkQueueFamilyProperties.Buffer, VkRect2D.Buffer, VkRenderPassBeginInfo.Buffer, VkRenderPassCreateInfo.Buffer, VkSamplerCreateInfo.Buffer, VkSemaphoreCreateInfo.Buffer, VkShaderModuleCreateInfo.Buffer, VkSparseBufferMemoryBindInfo.Buffer, VkSparseImageFormatProperties.Buffer, VkSparseImageMemoryBind.Buffer, VkSparseImageMemoryBindInfo.Buffer, VkSparseImageMemoryRequirements.Buffer, VkSparseImageOpaqueMemoryBindInfo.Buffer, VkSparseMemoryBind.Buffer, VkSpecializationInfo.Buffer, VkSpecializationMapEntry.Buffer, VkStencilOpState.Buffer, VkSubmitInfo.Buffer, VkSubpassDependency.Buffer, VkSubpassDescription.Buffer, VkSubresourceLayout.Buffer, VkSurfaceCapabilitiesKHR.Buffer, VkSurfaceFormatKHR.Buffer, VkSwapchainCreateInfoKHR.Buffer, VkVertexInputAttributeDescription.Buffer, VkVertexInputBindingDescription.Buffer, VkViewport.Buffer, VkWin32SurfaceCreateInfoKHR.Buffer, VkWriteDescriptorSet.Buffer, VkXlibSurfaceCreateInfoKHR.Buffer, WINDOWPLACEMENT.Buffer, WNDCLASSEX.Buffer, XSetWindowAttributes.Buffer, XVisualInfo.Buffer, XXH32Canonical.Buffer, XXH64Canonical.Buffer
public abstract class StructBuffer<T extends Struct,SELF extends StructBuffer<T,SELF>> extends java.lang.Object implements Pointer, NativeResource
This is the base class of struct data container implementations. Its interface mirrors the NIO API for convenience.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.lwjgl.system.Pointer
Pointer.Default
-
-
Field Summary
-
Fields inherited from interface org.lwjgl.system.Pointer
POINTER_SHIFT, POINTER_SIZE
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description long
address()
Returns the memory address at the current buffer position.long
address(int position)
Returns the memory address at the specified buffer position.long
address0()
Returns the buffer's base address.int
capacity()
Returns this buffer's capacity.SELF
clear()
Clears this buffer.SELF
compact()
Compacts this buffer (optional operation).SELF
duplicate()
Creates a new struct buffer that shares this buffer's content.SELF
flip()
Flips this buffer.void
free()
Frees the struct buffer allocation.T
get()
Relative get method.T
get(int index)
Absolute get method.SELF
get(int index, T value)
Absolute get method.SELF
get(T value)
Relative get method.boolean
hasRemaining()
Tells whether there are any elements between the current position and the limit.int
limit()
Returns this buffer's limit.SELF
limit(int newLimit)
Sets this buffer's limit.SELF
mark()
Sets this buffer's mark at its position.int
position()
Returns this buffer's position.SELF
position(int newPosition)
Sets this buffer's position.SELF
put(int index, T value)
Absolute put method (optional operation).SELF
put(SELF src)
Relative bulk put method (optional operation).SELF
put(T value)
Relative put method (optional operation).int
remaining()
Returns the number of elements between the current position and the limit.SELF
reset()
Resets this buffer's position to the previously-marked position.SELF
rewind()
Rewinds this buffer.SELF
slice()
Creates a new struct buffer whose content is a shared subsequence of this buffer's content.SELF
slice(int offset, int capacity)
Returns a slice of this buffer between(buffer.position() + offset)
and(buffer.position() + offset + capacity)
.java.lang.String
toString()
Returns a string summarizing the state of this buffer.-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.lwjgl.system.NativeResource
close
-
-
-
-
Method Detail
-
address0
public long address0()
Returns the buffer's base address. [INTERNAL USE ONLY]
-
address
public long address()
Returns the memory address at the current buffer position.
-
address
public long address(int position)
Returns the memory address at the specified buffer position.
-
free
public void free()
Frees the struct buffer allocation.This method should not be used if the memory backing this struct buffer is not owned by the struct buffer.
- Specified by:
free
in interfaceNativeResource
-
capacity
public int capacity()
Returns this buffer's capacity.- Returns:
- the capacity of this buffer
-
position
public int position()
Returns this buffer's position.- Returns:
- the position of this buffer
-
position
public SELF position(int newPosition)
Sets this buffer's position. If the mark is defined and larger than the new position then it is discarded.- Parameters:
newPosition
- the new position value; must be non-negative and no larger than the current limit- Returns:
- This buffer
- Throws:
java.lang.IllegalArgumentException
- If the preconditions on newPosition do not hold
-
limit
public int limit()
Returns this buffer's limit.- Returns:
- the limit of this buffer
-
limit
public SELF limit(int newLimit)
Sets this buffer's limit. If the position is larger than the new limit then it is set to the new limit. If the mark is defined and larger than the new limit then it is discarded.- Parameters:
newLimit
- the new limit value; must be non-negative and no larger than this buffer's capacity- Returns:
- This buffer
- Throws:
java.lang.IllegalArgumentException
- If the preconditions on newLimit do not hold
-
mark
public SELF mark()
Sets this buffer's mark at its position.- Returns:
- This buffer
-
reset
public SELF reset()
Resets this buffer's position to the previously-marked position.Invoking this method neither changes nor discards the mark's value.
- Returns:
- This buffer
- Throws:
java.nio.InvalidMarkException
- If the mark has not been set
-
clear
public SELF clear()
Clears this buffer. The position is set to zero, the limit is set to the capacity, and the mark is discarded.Invoke this method before using a sequence of channel-read or put operations to fill this buffer. For example:
buf.clear(); // Prepare buffer for reading in.read(buf); // Read data
This method does not actually erase the data in the buffer, but it is named as if it did because it will most often be used in situations in which that might as well be the case.
- Returns:
- This buffer
-
flip
public SELF flip()
Flips this buffer. The limit is set to the current position and then the position is set to zero. If the mark is defined then it is discarded.After a sequence of channel-read or put operations, invoke this method to prepare for a sequence of channel-write or relative get operations. For example:
buf.put(magic); // Prepend header in.read(buf); // Read data into rest of buffer buf.flip(); // Flip buffer out.write(buf); // Write header + data to channel
This method is often used in conjunction with the
StructBuffer.compact()
method when transferring data from one place to another.- Returns:
- This buffer
-
rewind
public SELF rewind()
Rewinds this buffer. The position is set to zero and the mark is discarded.Invoke this method before a sequence of channel-write or get operations, assuming that the limit has already been set appropriately. For example:
out.write(buf); // Write remaining data buf.rewind(); // Rewind buffer buf.get(array); // Copy data into array
- Returns:
- This buffer
-
remaining
public int remaining()
Returns the number of elements between the current position and the limit.- Returns:
- the number of elements remaining in this buffer
-
hasRemaining
public boolean hasRemaining()
Tells whether there are any elements between the current position and the limit.- Returns:
- true if, and only if, there is at least one element remaining in this buffer
-
slice
public SELF slice()
Creates a new struct buffer whose content is a shared subsequence of this buffer's content.The content of the new buffer will start at this buffer's current position. Changes to this buffer's content will be visible in the new buffer, and vice versa; the two buffers' position, limit, and mark values will be independent.
The new buffer's position will be zero, its capacity and its limit will be the number of structs remaining in this buffer, and its mark will be undefined. The new buffer will be read-only if, and only if, this buffer is read-only.
- Returns:
- the new struct buffer
-
slice
public SELF slice(int offset, int capacity)
Returns a slice of this buffer between(buffer.position() + offset)
and(buffer.position() + offset + capacity)
.The position and limit of this buffer are preserved after a call to this method.
- Parameters:
offset
- the slice offset, it must be ≤this.remaining()
capacity
- the slice length, it must be ≤this.capacity() - (this.position() + offset)
- Returns:
- the sliced buffer
-
duplicate
public SELF duplicate()
Creates a new struct buffer that shares this buffer's content.The content of the new buffer will be that of this buffer. Changes to this buffer's content will be visible in the new buffer, and vice versa; the two buffers' position, limit, and mark values will be independent.
The new buffer's capacity, limit and position will be identical to those of this buffer.
- Returns:
- the new struct buffer
-
get
public T get()
Relative get method. Reads the struct at this buffer's current position, and then increments the position.The struct instance returned is a view of the buffer at the current position. Changes to this buffer's content will be visible in the struct instance and vice versa.
- Returns:
- the struct at the buffer's current position
- Throws:
java.nio.BufferUnderflowException
- If the buffer's current position is not smaller than its limit
-
get
public SELF get(T value)
Relative get method. Reads the struct data at this buffer's current position into the specified struct, and then increments the position.- Returns:
- the struct at the buffer's current position
- Throws:
java.nio.BufferUnderflowException
- If the buffer's current position is not smaller than its limit
-
put
public SELF put(T value)
Relative put method (optional operation).Writes the specified struct into this buffer at the current position, and then increments the position.
- Parameters:
value
- the struct to be written- Returns:
- This buffer
- Throws:
java.nio.BufferOverflowException
- If this buffer's current position is not smaller than its limitjava.nio.ReadOnlyBufferException
- If this buffer is read-only
-
get
public T get(int index)
Absolute get method. Reads the struct at the specified index.The struct instance returned is a view of the buffer at the specified position. Changes to this buffer's content will be visible in the struct instance and vice versa.
- Parameters:
index
- the index from which the struct will be read- Returns:
- the struct at the specified index
- Throws:
java.lang.IndexOutOfBoundsException
- If index is negative or not smaller than the buffer's limit
-
get
public SELF get(int index, T value)
Absolute get method. Reads the struct data at the specified index into the specified struct.- Parameters:
index
- the index from which the struct will be read- Returns:
- the struct at the specified index
- Throws:
java.lang.IndexOutOfBoundsException
- If index is negative or not smaller than the buffer's limit
-
put
public SELF put(int index, T value)
Absolute put method (optional operation).Writes the specified struct into this buffer at the specified index.
- Parameters:
index
- the index at which the struct will be writtenvalue
- the struct value to be written- Returns:
- This buffer
- Throws:
java.lang.IndexOutOfBoundsException
- If index is negative or not smaller than the buffer's limitjava.nio.ReadOnlyBufferException
- If this buffer is read-only
-
put
public SELF put(SELF src)
Relative bulk put method (optional operation).This method transfers the structs remaining in the specified source buffer into this buffer. If there are more structs remaining in the source buffer than in this buffer, that is, if src.remaining() > remaining(), then no structs are transferred and a
BufferOverflowException
is thrown.Otherwise, this method copies n = src.remaining() structs from the specified buffer into this buffer, starting at each buffer's current position. The positions of both buffers are then incremented by n.
In other words, an invocation of this method of the form dst.put(src) has exactly the same effect as the loop
while (src.hasRemaining()) dst.put(src.get());
except that it first checks that there is sufficient space in this buffer and it is potentially much more efficient.
- Parameters:
src
- the source buffer from which structs are to be read; must not be this buffer- Returns:
- This buffer
- Throws:
java.nio.BufferOverflowException
- If there is insufficient space in this buffer for the remaining structs in the source bufferjava.lang.IllegalArgumentException
- If the source buffer is this bufferjava.nio.ReadOnlyBufferException
- If this buffer is read-only
-
compact
public SELF compact()
Compacts this buffer (optional operation).The structs between the buffer's current position and its limit, if any, are copied to the beginning of the buffer. That is, the struct at index p = position() is copied to index zero, the struct at index p + 1 is copied to index one, and so forth until the struct at index limit() - 1 is copied to index n = limit() - 1 - p. The buffer's position is then set to n+1 and its limit is set to its capacity. The mark, if defined, is discarded.
The buffer's position is set to the number of structs copied, rather than to zero, so that an invocation of this method can be followed immediately by an invocation of another relative put method.
- Returns:
- This buffer
- Throws:
java.nio.ReadOnlyBufferException
- If this buffer is read-only
-
toString
public java.lang.String toString()
Returns a string summarizing the state of this buffer.- Overrides:
toString
in classjava.lang.Object
- Returns:
- A summary string
-
-