aboutsummaryrefslogtreecommitdiff
path: root/src/sbuffer.cpp
blob: 00324b5a04d743ea3208ad8c271b5a6b94ac24da (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
#include <string.h>
#include "sbuffer.h"

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

SBuffer::~SBuffer()
{
}

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

size_t SBuffer::read( char *pBuf, size_t nBytes )
{
	long 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;
}