summaryrefslogtreecommitdiff
path: root/src/old/sbuffer.cpp
blob: f84f8a3e1f11f03966956adacf9a1e10c94c537a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <string.h>
#include "sbuffer.h"

SBuffer::SBuffer() :
	nPos( 0 ),
	bOpen( true )
{
}

SBuffer::~SBuffer()
{
}

void SBuffer::close()
{
	bOpen = false;
	fbData.clearData();
}

size_t SBuffer::read( char *pBuf, size_t nBytes )
{
	size_t nLeft = fbData.getLength() - nPos;
	if( nBytes > nLeft )
		nBytes = nLeft;

	if( nLeft == 0 )
		return 0;

	memcpy( pBuf, fbData.getData()+nPos, nBytes );
	nPos += nBytes;

	return nBytes;
}

size_t SBuffer::write( const char *pBuf, size_t nBytes )
{
	fbData.appendData( pBuf, nBytes );
	nPos += nBytes;

	return nBytes;
}

long SBuffer::tell()
{
	return nPos;
}

void SBuffer::seek( long offset )
{
	nPos += offset;
}

void SBuffer::setPos( long pos )
{
	nPos = pos;
}

void SBuffer::setPosEnd( long pos )
{
	nPos = fbData.getLength() - pos;
}

bool SBuffer::isEOS()
{
	return nPos == fbData.getLength();
}