aboutsummaryrefslogtreecommitdiff
path: root/src/membuf.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/membuf.cpp')
-rw-r--r--src/membuf.cpp120
1 files changed, 120 insertions, 0 deletions
diff --git a/src/membuf.cpp b/src/membuf.cpp
new file mode 100644
index 0000000..45ff5bd
--- /dev/null
+++ b/src/membuf.cpp
@@ -0,0 +1,120 @@
1#include "bu/membuf.h"
2
3using namespace Bu;
4
5Bu::MemBuf::MemBuf() :
6 nPos( 0 )
7{
8}
9
10Bu::MemBuf::MemBuf( const Bu::FString &str ) :
11 sBuf( str ),
12 nPos( 0 )
13{
14}
15
16Bu::MemBuf::~MemBuf()
17{
18}
19
20void Bu::MemBuf::close()
21{
22}
23
24size_t Bu::MemBuf::read( void *pBuf, size_t nBytes )
25{
26 if( (size_t)sBuf.getSize()-(size_t)nPos < nBytes )
27 nBytes = sBuf.getSize()-nPos;
28
29 memcpy( pBuf, sBuf.getStr()+nPos, nBytes );
30 nPos += nBytes;
31
32 return nBytes;
33}
34
35size_t Bu::MemBuf::write( const void *pBuf, size_t nBytes )
36{
37 sBuf.append( (const char *)pBuf, nBytes );
38 nPos += nBytes;
39 return nBytes;
40}
41
42long Bu::MemBuf::tell()
43{
44 return nPos;
45}
46
47void Bu::MemBuf::seek( long offset )
48{
49 nPos += offset;
50 if( nPos < 0 ) nPos = 0;
51 else if( nPos > sBuf.getSize() ) nPos = sBuf.getSize();
52}
53
54void Bu::MemBuf::setPos( long pos )
55{
56 nPos = pos;
57 if( nPos < 0 ) nPos = 0;
58 else if( nPos > sBuf.getSize() ) nPos = sBuf.getSize();
59}
60
61void Bu::MemBuf::setPosEnd( long pos )
62{
63 nPos = sBuf.getSize()-pos;
64 if( nPos < 0 ) nPos = 0;
65 else if( nPos > sBuf.getSize() ) nPos = sBuf.getSize();
66}
67
68bool Bu::MemBuf::isEOS()
69{
70 return (nPos == sBuf.getSize());
71}
72
73bool Bu::MemBuf::isOpen()
74{
75 return true;
76}
77
78void Bu::MemBuf::flush()
79{
80}
81
82bool Bu::MemBuf::canRead()
83{
84 return !isEOS();
85}
86
87bool Bu::MemBuf::canWrite()
88{
89 return isEOS();
90}
91
92bool Bu::MemBuf::isReadable()
93{
94 return true;
95}
96
97bool Bu::MemBuf::isWritable()
98{
99 return true;
100}
101
102bool Bu::MemBuf::isSeekable()
103{
104 return true;
105}
106
107bool Bu::MemBuf::isBlocking()
108{
109 return true;
110}
111
112void Bu::MemBuf::setBlocking( bool bBlocking )
113{
114}
115
116Bu::FString &Bu::MemBuf::getString()
117{
118 return sBuf;
119}
120