diff options
author | Mike Buland <eichlan@xagasoft.com> | 2007-06-27 15:42:50 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2007-06-27 15:42:50 +0000 |
commit | 5ec9a131e12d021c42b46b601f5e79502485bebb (patch) | |
tree | 31d63d293a6c5bc6ea1d677474380ea48976add4 /src/membuf.cpp | |
parent | 01ecf54b07e75c17ca5f7039084daeefaea9a1c7 (diff) | |
download | libbu++-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 '')
-rw-r--r-- | src/membuf.cpp | 30 |
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 | ||
3 | using namespace Bu; | 3 | using namespace Bu; |
4 | 4 | ||
5 | Bu::MemBuf::MemBuf() | 5 | Bu::MemBuf::MemBuf() : |
6 | nPos( 0 ) | ||
6 | { | 7 | { |
7 | } | 8 | } |
8 | 9 | ||
@@ -16,35 +17,56 @@ void Bu::MemBuf::close() | |||
16 | 17 | ||
17 | size_t Bu::MemBuf::read( void *pBuf, size_t nBytes ) | 18 | size_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 | ||
22 | size_t Bu::MemBuf::write( const void *pBuf, size_t nBytes ) | 29 | size_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 | ||
26 | long Bu::MemBuf::tell() | 36 | long Bu::MemBuf::tell() |
27 | { | 37 | { |
38 | return nPos; | ||
28 | } | 39 | } |
29 | 40 | ||
30 | void Bu::MemBuf::seek( long offset ) | 41 | void 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 | ||
34 | void Bu::MemBuf::setPos( long pos ) | 48 | void 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 | ||
38 | void Bu::MemBuf::setPosEnd( long pos ) | 55 | void 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 | ||
42 | bool Bu::MemBuf::isEOS() | 62 | bool Bu::MemBuf::isEOS() |
43 | { | 63 | { |
64 | return (nPos == sBuf.getSize()); | ||
44 | } | 65 | } |
45 | 66 | ||
46 | bool Bu::MemBuf::isOpen() | 67 | bool Bu::MemBuf::isOpen() |
47 | { | 68 | { |
69 | return true; | ||
48 | } | 70 | } |
49 | 71 | ||
50 | void Bu::MemBuf::flush() | 72 | void Bu::MemBuf::flush() |
@@ -53,26 +75,32 @@ void Bu::MemBuf::flush() | |||
53 | 75 | ||
54 | bool Bu::MemBuf::canRead() | 76 | bool Bu::MemBuf::canRead() |
55 | { | 77 | { |
78 | return !isEOS(); | ||
56 | } | 79 | } |
57 | 80 | ||
58 | bool Bu::MemBuf::canWrite() | 81 | bool Bu::MemBuf::canWrite() |
59 | { | 82 | { |
83 | return isEOS(); | ||
60 | } | 84 | } |
61 | 85 | ||
62 | bool Bu::MemBuf::isReadable() | 86 | bool Bu::MemBuf::isReadable() |
63 | { | 87 | { |
88 | return true; | ||
64 | } | 89 | } |
65 | 90 | ||
66 | bool Bu::MemBuf::isWritable() | 91 | bool Bu::MemBuf::isWritable() |
67 | { | 92 | { |
93 | return true; | ||
68 | } | 94 | } |
69 | 95 | ||
70 | bool Bu::MemBuf::isSeekable() | 96 | bool Bu::MemBuf::isSeekable() |
71 | { | 97 | { |
98 | return true; | ||
72 | } | 99 | } |
73 | 100 | ||
74 | bool Bu::MemBuf::isBlocking() | 101 | bool Bu::MemBuf::isBlocking() |
75 | { | 102 | { |
103 | return true; | ||
76 | } | 104 | } |
77 | 105 | ||
78 | void Bu::MemBuf::setBlocking( bool bBlocking ) | 106 | void Bu::MemBuf::setBlocking( bool bBlocking ) |