the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
1#include "stdafx.h"
2#include "Buffer.h"
3
4Buffer::Buffer( unsigned int capacity ) : m_capacity( capacity ), m_position( 0 ), m_limit( capacity ), hasBackingArray( false )
5{
6}
7
8//Clears this buffer. The position is set to zero, the limit is set to the capacity, and the mark is discarded.
9//This method does not actually erase the data in the buffer, but it is named as if it did because it will most often
10//be used in situations in which that might as well be the case.
11//
12//Returns:
13//This buffer
14Buffer *Buffer::clear()
15{
16 m_position = 0;
17 m_limit = m_capacity;
18
19 return this;
20}
21
22//Sets this buffer's limit. If the position is larger than the new limit then it is set to the new limit.
23//If the mark is defined and larger than the new limit then it is discarded.
24//Parameters:
25//newLimit - The new limit value; must be non-negative and no larger than this buffer's capacity
26//Returns:
27//This buffer
28Buffer *Buffer::limit( unsigned int newLimit )
29{
30 assert( newLimit <= m_capacity );
31
32 m_limit = newLimit;
33
34 if( m_position > newLimit )
35 m_position = newLimit;
36
37 return this;
38}
39
40unsigned int Buffer::limit()
41{
42 return m_limit;
43}
44
45//Sets this buffer's position. If the mark is defined and larger than the new position then it is discarded.
46//Parameters:
47//newPosition - The new position value; must be non-negative and no larger than the current limit
48//Returns:
49//This buffer
50Buffer *Buffer::position( unsigned int newPosition )
51{
52 assert( newPosition <= m_limit );
53
54 m_position = newPosition;
55
56 return this;
57}
58
59//Returns this buffer's position.
60//Returns:
61//The position of this buffer
62unsigned int Buffer::position()
63{
64 return m_position;
65}
66
67//Returns the number of elements between the current position and the limit.
68//Returns:
69//The number of elements remaining in this buffer
70unsigned int Buffer::remaining()
71{
72 return m_limit - m_position;
73}