aboutsummaryrefslogtreecommitdiff
path: root/src/membuf.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2007-06-27 15:42:50 +0000
committerMike Buland <eichlan@xagasoft.com>2007-06-27 15:42:50 +0000
commit5ec9a131e12d021c42b46b601f5e79502485bebb (patch)
tree31d63d293a6c5bc6ea1d677474380ea48976add4 /src/membuf.cpp
parent01ecf54b07e75c17ca5f7039084daeefaea9a1c7 (diff)
downloadlibbu++-5ec9a131e12d021c42b46b601f5e79502485bebb.tar.gz
libbu++-5ec9a131e12d021c42b46b601f5e79502485bebb.tar.bz2
libbu++-5ec9a131e12d021c42b46b601f5e79502485bebb.tar.xz
libbu++-5ec9a131e12d021c42b46b601f5e79502485bebb.zip
The MemBuf works just fine, although it still can't over-write data in the
buffer.
Diffstat (limited to 'src/membuf.cpp')
-rw-r--r--src/membuf.cpp30
1 files changed, 29 insertions, 1 deletions
diff --git a/src/membuf.cpp b/src/membuf.cpp
index fdb4366..3c394b0 100644
--- a/src/membuf.cpp
+++ b/src/membuf.cpp
@@ -2,7 +2,8 @@
2 2
3using namespace Bu; 3using namespace Bu;
4 4
5Bu::MemBuf::MemBuf() 5Bu::MemBuf::MemBuf() :
6 nPos( 0 )
6{ 7{
7} 8}
8 9
@@ -16,35 +17,56 @@ void Bu::MemBuf::close()
16 17
17size_t Bu::MemBuf::read( void *pBuf, size_t nBytes ) 18size_t Bu::MemBuf::read( void *pBuf, size_t nBytes )
18{ 19{
20 if( (size_t)sBuf.getSize()-(size_t)nPos < nBytes )
21 nBytes = sBuf.getSize()-nPos;
19 22
23 memcpy( pBuf, sBuf.getStr()+nPos, nBytes );
24 nPos += nBytes;
25
26 return nBytes;
20} 27}
21 28
22size_t Bu::MemBuf::write( const void *pBuf, size_t nBytes ) 29size_t Bu::MemBuf::write( const void *pBuf, size_t nBytes )
23{ 30{
31 sBuf.append( (const char *)pBuf, nBytes );
32 nPos += nBytes;
33 return nBytes;
24} 34}
25 35
26long Bu::MemBuf::tell() 36long Bu::MemBuf::tell()
27{ 37{
38 return nPos;
28} 39}
29 40
30void Bu::MemBuf::seek( long offset ) 41void Bu::MemBuf::seek( long offset )
31{ 42{
43 nPos += offset;
44 if( nPos < 0 ) nPos = 0;
45 else if( nPos > sBuf.getSize() ) nPos = sBuf.getSize();
32} 46}
33 47
34void Bu::MemBuf::setPos( long pos ) 48void Bu::MemBuf::setPos( long pos )
35{ 49{
50 nPos = pos;
51 if( nPos < 0 ) nPos = 0;
52 else if( nPos > sBuf.getSize() ) nPos = sBuf.getSize();
36} 53}
37 54
38void Bu::MemBuf::setPosEnd( long pos ) 55void Bu::MemBuf::setPosEnd( long pos )
39{ 56{
57 nPos = sBuf.getSize()-pos;
58 if( nPos < 0 ) nPos = 0;
59 else if( nPos > sBuf.getSize() ) nPos = sBuf.getSize();
40} 60}
41 61
42bool Bu::MemBuf::isEOS() 62bool Bu::MemBuf::isEOS()
43{ 63{
64 return (nPos == sBuf.getSize());
44} 65}
45 66
46bool Bu::MemBuf::isOpen() 67bool Bu::MemBuf::isOpen()
47{ 68{
69 return true;
48} 70}
49 71
50void Bu::MemBuf::flush() 72void Bu::MemBuf::flush()
@@ -53,26 +75,32 @@ void Bu::MemBuf::flush()
53 75
54bool Bu::MemBuf::canRead() 76bool Bu::MemBuf::canRead()
55{ 77{
78 return !isEOS();
56} 79}
57 80
58bool Bu::MemBuf::canWrite() 81bool Bu::MemBuf::canWrite()
59{ 82{
83 return isEOS();
60} 84}
61 85
62bool Bu::MemBuf::isReadable() 86bool Bu::MemBuf::isReadable()
63{ 87{
88 return true;
64} 89}
65 90
66bool Bu::MemBuf::isWritable() 91bool Bu::MemBuf::isWritable()
67{ 92{
93 return true;
68} 94}
69 95
70bool Bu::MemBuf::isSeekable() 96bool Bu::MemBuf::isSeekable()
71{ 97{
98 return true;
72} 99}
73 100
74bool Bu::MemBuf::isBlocking() 101bool Bu::MemBuf::isBlocking()
75{ 102{
103 return true;
76} 104}
77 105
78void Bu::MemBuf::setBlocking( bool bBlocking ) 106void Bu::MemBuf::setBlocking( bool bBlocking )