aboutsummaryrefslogtreecommitdiff
path: root/src/stable/membuf.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/stable/membuf.cpp122
1 files changed, 61 insertions, 61 deletions
diff --git a/src/stable/membuf.cpp b/src/stable/membuf.cpp
index dea9a0e..4d6e8e6 100644
--- a/src/stable/membuf.cpp
+++ b/src/stable/membuf.cpp
@@ -10,13 +10,13 @@
10using namespace Bu; 10using namespace Bu;
11 11
12Bu::MemBuf::MemBuf() : 12Bu::MemBuf::MemBuf() :
13 nPos( 0 ) 13 nPos( 0 )
14{ 14{
15} 15}
16 16
17Bu::MemBuf::MemBuf( const Bu::String &str ) : 17Bu::MemBuf::MemBuf( const Bu::String &str ) :
18 sBuf( str ), 18 sBuf( str ),
19 nPos( 0 ) 19 nPos( 0 )
20{ 20{
21} 21}
22 22
@@ -30,76 +30,76 @@ void Bu::MemBuf::close()
30 30
31size Bu::MemBuf::read( void *pBuf, size nBytes ) 31size Bu::MemBuf::read( void *pBuf, size nBytes )
32{ 32{
33 if( (size)sBuf.getSize()-(size)nPos < nBytes ) 33 if( (size)sBuf.getSize()-(size)nPos < nBytes )
34 nBytes = sBuf.getSize()-nPos; 34 nBytes = sBuf.getSize()-nPos;
35 35
36 memcpy( pBuf, sBuf.getStr()+nPos, nBytes ); 36 memcpy( pBuf, sBuf.getStr()+nPos, nBytes );
37 nPos += nBytes; 37 nPos += nBytes;
38 38
39 return nBytes; 39 return nBytes;
40} 40}
41 41
42size Bu::MemBuf::write( const void *pBuf, size nBytes ) 42size Bu::MemBuf::write( const void *pBuf, size nBytes )
43{ 43{
44 if( nPos == sBuf.getSize() ) 44 if( nPos == sBuf.getSize() )
45 { 45 {
46 // Easiest, just append the data. 46 // Easiest, just append the data.
47 sBuf.append( (const char *)pBuf, nBytes ); 47 sBuf.append( (const char *)pBuf, nBytes );
48 nPos += nBytes; 48 nPos += nBytes;
49 return nBytes; 49 return nBytes;
50 } 50 }
51 else 51 else
52 { 52 {
53 // Trickier, we must do this in two parts, overwrite, then append 53 // Trickier, we must do this in two parts, overwrite, then append
54 // Frist, overwrite. 54 // Frist, overwrite.
55 size iOver = sBuf.getSize() - nPos; 55 size iOver = sBuf.getSize() - nPos;
56 if( iOver > nBytes ) 56 if( iOver > nBytes )
57 iOver = nBytes; 57 iOver = nBytes;
58 memcpy( sBuf.getStr()+nPos, pBuf, iOver ); 58 memcpy( sBuf.getStr()+nPos, pBuf, iOver );
59 // Then append 59 // Then append
60 if( iOver < nBytes ) 60 if( iOver < nBytes )
61 { 61 {
62 sBuf.append( ((const char *)pBuf)+iOver, nBytes-iOver ); 62 sBuf.append( ((const char *)pBuf)+iOver, nBytes-iOver );
63 } 63 }
64 nPos += nBytes; 64 nPos += nBytes;
65 return nBytes; 65 return nBytes;
66 } 66 }
67} 67}
68 68
69size Bu::MemBuf::tell() 69size Bu::MemBuf::tell()
70{ 70{
71 return nPos; 71 return nPos;
72} 72}
73 73
74void Bu::MemBuf::seek( size offset ) 74void Bu::MemBuf::seek( size offset )
75{ 75{
76 nPos += offset; 76 nPos += offset;
77 if( nPos < 0 ) nPos = 0; 77 if( nPos < 0 ) nPos = 0;
78 else if( nPos > sBuf.getSize() ) nPos = sBuf.getSize(); 78 else if( nPos > sBuf.getSize() ) nPos = sBuf.getSize();
79} 79}
80 80
81void Bu::MemBuf::setPos( size pos ) 81void Bu::MemBuf::setPos( size pos )
82{ 82{
83 nPos = pos; 83 nPos = pos;
84 if( nPos < 0 ) nPos = 0; 84 if( nPos < 0 ) nPos = 0;
85 else if( nPos > sBuf.getSize() ) nPos = sBuf.getSize(); 85 else if( nPos > sBuf.getSize() ) nPos = sBuf.getSize();
86} 86}
87 87
88void Bu::MemBuf::setPosEnd( size pos ) 88void Bu::MemBuf::setPosEnd( size pos )
89{ 89{
90 nPos = sBuf.getSize()-pos; 90 nPos = sBuf.getSize()-pos;
91 if( nPos < 0 ) nPos = 0; 91 if( nPos < 0 ) nPos = 0;
92 else if( nPos > sBuf.getSize() ) nPos = sBuf.getSize(); 92 else if( nPos > sBuf.getSize() ) nPos = sBuf.getSize();
93} 93}
94 94
95bool Bu::MemBuf::isEos() 95bool Bu::MemBuf::isEos()
96{ 96{
97 return (nPos == sBuf.getSize()); 97 return (nPos == sBuf.getSize());
98} 98}
99 99
100bool Bu::MemBuf::isOpen() 100bool Bu::MemBuf::isOpen()
101{ 101{
102 return true; 102 return true;
103} 103}
104 104
105void Bu::MemBuf::flush() 105void Bu::MemBuf::flush()
@@ -108,32 +108,32 @@ void Bu::MemBuf::flush()
108 108
109bool Bu::MemBuf::canRead() 109bool Bu::MemBuf::canRead()
110{ 110{
111 return !isEos(); 111 return !isEos();
112} 112}
113 113
114bool Bu::MemBuf::canWrite() 114bool Bu::MemBuf::canWrite()
115{ 115{
116 return true; 116 return true;
117} 117}
118 118
119bool Bu::MemBuf::isReadable() 119bool Bu::MemBuf::isReadable()
120{ 120{
121 return true; 121 return true;
122} 122}
123 123
124bool Bu::MemBuf::isWritable() 124bool Bu::MemBuf::isWritable()
125{ 125{
126 return true; 126 return true;
127} 127}
128 128
129bool Bu::MemBuf::isSeekable() 129bool Bu::MemBuf::isSeekable()
130{ 130{
131 return true; 131 return true;
132} 132}
133 133
134bool Bu::MemBuf::isBlocking() 134bool Bu::MemBuf::isBlocking()
135{ 135{
136 return true; 136 return true;
137} 137}
138 138
139void Bu::MemBuf::setBlocking( bool ) 139void Bu::MemBuf::setBlocking( bool )
@@ -142,36 +142,36 @@ void Bu::MemBuf::setBlocking( bool )
142 142
143void Bu::MemBuf::setSize( size iSize ) 143void Bu::MemBuf::setSize( size iSize )
144{ 144{
145 if( iSize < 0 ) 145 if( iSize < 0 )
146 iSize = 0; 146 iSize = 0;
147 sBuf.setSize( iSize ); 147 sBuf.setSize( iSize );
148 if( nPos > iSize ) 148 if( nPos > iSize )
149 nPos = iSize; 149 nPos = iSize;
150} 150}
151 151
152Bu::size Bu::MemBuf::getSize() const 152Bu::size Bu::MemBuf::getSize() const
153{ 153{
154 return sBuf.getSize(); 154 return sBuf.getSize();
155} 155}
156 156
157Bu::size Bu::MemBuf::getBlockSize() const 157Bu::size Bu::MemBuf::getBlockSize() const
158{ 158{
159 return sBuf.getSize(); 159 return sBuf.getSize();
160} 160}
161 161
162Bu::String Bu::MemBuf::getLocation() const 162Bu::String Bu::MemBuf::getLocation() const
163{ 163{
164 return ""; 164 return "";
165} 165}
166 166
167Bu::String &Bu::MemBuf::getString() 167Bu::String &Bu::MemBuf::getString()
168{ 168{
169 return sBuf; 169 return sBuf;
170} 170}
171 171
172void Bu::MemBuf::setString( const Bu::String &sNewData ) 172void Bu::MemBuf::setString( const Bu::String &sNewData )
173{ 173{
174 sBuf = sNewData; 174 sBuf = sNewData;
175 nPos = 0; 175 nPos = 0;
176} 176}
177 177