diff options
| author | daoge_cmd <3523206925@qq.com> | 2026-03-01 12:16:08 +0800 |
|---|---|---|
| committer | daoge_cmd <3523206925@qq.com> | 2026-03-01 12:16:08 +0800 |
| commit | b691c43c44ff180d10e7d4a9afc83b98551ff586 (patch) | |
| tree | 3e9849222cbc6ba49f2f1fc6e5fe7179632c7390 /Minecraft.World/Buffer.cpp | |
| parent | def8cb415354ac390b7e89052a50605285f1aca9 (diff) | |
Initial commit
Diffstat (limited to 'Minecraft.World/Buffer.cpp')
| -rw-r--r-- | Minecraft.World/Buffer.cpp | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/Minecraft.World/Buffer.cpp b/Minecraft.World/Buffer.cpp new file mode 100644 index 00000000..7fdf3b59 --- /dev/null +++ b/Minecraft.World/Buffer.cpp @@ -0,0 +1,73 @@ +#include "stdafx.h" +#include "Buffer.h" + +Buffer::Buffer( unsigned int capacity ) : m_capacity( capacity ), m_position( 0 ), m_limit( capacity ), hasBackingArray( false ) +{ +} + +//Clears this buffer. The position is set to zero, the limit is set to the capacity, and the mark is discarded. +//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 +Buffer *Buffer::clear() +{ + m_position = 0; + m_limit = m_capacity; + + return this; +} + +//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 +Buffer *Buffer::limit( unsigned int newLimit ) +{ + assert( newLimit <= m_capacity ); + + m_limit = newLimit; + + if( m_position > newLimit ) + m_position = newLimit; + + return this; +} + +unsigned int Buffer::limit() +{ + return m_limit; +} + +//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 +Buffer *Buffer::position( unsigned int newPosition ) +{ + assert( newPosition <= m_limit ); + + m_position = newPosition; + + return this; +} + +//Returns this buffer's position. +//Returns: +//The position of this buffer +unsigned int Buffer::position() +{ + return m_position; +} + +//Returns the number of elements between the current position and the limit. +//Returns: +//The number of elements remaining in this buffer +unsigned int Buffer::remaining() +{ + return m_limit - m_position; +}
\ No newline at end of file |
