aboutsummaryrefslogtreecommitdiff
path: root/src/stable/myriadstream.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2012-11-05 22:41:51 +0000
committerMike Buland <eichlan@xagasoft.com>2012-11-05 22:41:51 +0000
commitec05778d5718a7912e506764d443a78d6a6179e3 (patch)
tree78a9a01532180030c095acefc45763f07c14edb8 /src/stable/myriadstream.cpp
parentb20414ac1fe80a71a90601f4cd1767fa7014a9ba (diff)
downloadlibbu++-ec05778d5718a7912e506764d443a78d6a6179e3.tar.gz
libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.tar.bz2
libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.tar.xz
libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.zip
Converted tabs to spaces with tabconv.
Diffstat (limited to 'src/stable/myriadstream.cpp')
-rw-r--r--src/stable/myriadstream.cpp344
1 files changed, 172 insertions, 172 deletions
diff --git a/src/stable/myriadstream.cpp b/src/stable/myriadstream.cpp
index 58d3936..c33445a 100644
--- a/src/stable/myriadstream.cpp
+++ b/src/stable/myriadstream.cpp
@@ -9,7 +9,7 @@
9 9
10#include <string.h> 10#include <string.h>
11 11
12// #define MYRIAD_STREAM_DEBUG 1 12// #define MYRIAD_STREAM_DEBUG 1
13 13
14#ifdef MYRIAD_STREAM_DEBUG 14#ifdef MYRIAD_STREAM_DEBUG
15#include "bu/sio.h" 15#include "bu/sio.h"
@@ -19,27 +19,27 @@ using Bu::Fmt;
19#endif 19#endif
20 20
21Bu::MyriadStream::MyriadStream( Bu::Myriad &rMyriad, 21Bu::MyriadStream::MyriadStream( Bu::Myriad &rMyriad,
22 Bu::Myriad::Stream *pStream ) : 22 Bu::Myriad::Stream *pStream ) :
23 rMyriad( rMyriad ), 23 rMyriad( rMyriad ),
24 pStream( pStream ), 24 pStream( pStream ),
25 pCurBlock( NULL ), 25 pCurBlock( NULL ),
26 iPos( 0 ) 26 iPos( 0 )
27{ 27{
28#ifdef MYRIAD_STREAM_DEBUG 28#ifdef MYRIAD_STREAM_DEBUG
29 sio << "MyriadStream: " << __LINE__ << ": Created, iId=" << pStream->iId << ", iSize=" 29 sio << "MyriadStream: " << __LINE__ << ": Created, iId=" << pStream->iId << ", iSize="
30 << pStream->iSize << sio.nl; 30 << pStream->iSize << sio.nl;
31#endif 31#endif
32 //pCurBlock = rMyriad.newBlock(); 32 //pCurBlock = rMyriad.newBlock();
33 //rMyriad.getBlock( uStream, pCurBlock ); 33 //rMyriad.getBlock( uStream, pCurBlock );
34 //uSize = pCurBlock->uBytesUsed; 34 //uSize = pCurBlock->uBytesUsed;
35} 35}
36 36
37Bu::MyriadStream::~MyriadStream() 37Bu::MyriadStream::~MyriadStream()
38{ 38{
39 if( pCurBlock ) 39 if( pCurBlock )
40 rMyriad.releaseBlock( pCurBlock ); 40 rMyriad.releaseBlock( pCurBlock );
41 //rMyriad.updateStreamSize( uStream, uSize ); 41 //rMyriad.updateStreamSize( uStream, uSize );
42 //rMyriad.deleteBlock( pCurBlock ); 42 //rMyriad.deleteBlock( pCurBlock );
43} 43}
44 44
45void Bu::MyriadStream::close() 45void Bu::MyriadStream::close()
@@ -49,200 +49,200 @@ void Bu::MyriadStream::close()
49Bu::size Bu::MyriadStream::read( void *pBuf, Bu::size nBytes ) 49Bu::size Bu::MyriadStream::read( void *pBuf, Bu::size nBytes )
50{ 50{
51#ifdef MYRIAD_STREAM_DEBUG 51#ifdef MYRIAD_STREAM_DEBUG
52 sio << "MyriadStream: read: " << __LINE__ << ": Started, asked to read " << nBytes << "b." 52 sio << "MyriadStream: read: " << __LINE__ << ": Started, asked to read " << nBytes << "b."
53 << sio.nl; 53 << sio.nl;
54#endif 54#endif
55 if( nBytes > (Bu::size)pStream->iSize-iPos ) 55 if( nBytes > (Bu::size)pStream->iSize-iPos )
56 nBytes = pStream->iSize-iPos; 56 nBytes = pStream->iSize-iPos;
57 if( nBytes <= 0 ) 57 if( nBytes <= 0 )
58 return 0; 58 return 0;
59 int iLeft = nBytes; 59 int iLeft = nBytes;
60#ifdef MYRIAD_STREAM_DEBUG 60#ifdef MYRIAD_STREAM_DEBUG
61 sio << "MyriadStream: read: " << __LINE__ << ": Started, going to read " << nBytes << "b." 61 sio << "MyriadStream: read: " << __LINE__ << ": Started, going to read " << nBytes << "b."
62 << sio.nl; 62 << sio.nl;
63#endif 63#endif
64 if( pCurBlock == NULL ) 64 if( pCurBlock == NULL )
65 { 65 {
66#ifdef MYRIAD_STREAM_DEBUG 66#ifdef MYRIAD_STREAM_DEBUG
67 sio << "MyriadStream: read: " << __LINE__ << ": No block loaded, loading initial block." 67 sio << "MyriadStream: read: " << __LINE__ << ": No block loaded, loading initial block."
68 << sio.nl; 68 << sio.nl;
69#endif 69#endif
70 pCurBlock = rMyriad.getBlock( 70 pCurBlock = rMyriad.getBlock(
71 pStream->aBlocks[iPos/rMyriad.iBlockSize] 71 pStream->aBlocks[iPos/rMyriad.iBlockSize]
72 ); 72 );
73 } 73 }
74 while( iLeft > 0 ) 74 while( iLeft > 0 )
75 { 75 {
76 int iCurBlock = pStream->aBlocks[iPos/rMyriad.iBlockSize]; 76 int iCurBlock = pStream->aBlocks[iPos/rMyriad.iBlockSize];
77 if( pCurBlock->iBlockIndex != iCurBlock ) 77 if( pCurBlock->iBlockIndex != iCurBlock )
78 { 78 {
79#ifdef MYRIAD_STREAM_DEBUG 79#ifdef MYRIAD_STREAM_DEBUG
80 sio << "MyriadStream: read: " << __LINE__ << ": Loading new block " << iCurBlock << "." 80 sio << "MyriadStream: read: " << __LINE__ << ": Loading new block " << iCurBlock << "."
81 << sio.nl; 81 << sio.nl;
82#endif 82#endif
83 rMyriad.releaseBlock( pCurBlock ); 83 rMyriad.releaseBlock( pCurBlock );
84 pCurBlock = rMyriad.getBlock( iCurBlock ); 84 pCurBlock = rMyriad.getBlock( iCurBlock );
85 } 85 }
86 86
87 int iAmnt = Bu::buMin( 87 int iAmnt = Bu::buMin(
88 Bu::buMin( 88 Bu::buMin(
89 rMyriad.iBlockSize - iPos%rMyriad.iBlockSize, 89 rMyriad.iBlockSize - iPos%rMyriad.iBlockSize,
90 iLeft 90 iLeft
91 ), 91 ),
92 pStream->iSize-iPos 92 pStream->iSize-iPos
93 ); 93 );
94#ifdef MYRIAD_STREAM_DEBUG 94#ifdef MYRIAD_STREAM_DEBUG
95 sio << "MyriadStream: read: " << __LINE__ << ": Copying out bytes: " 95 sio << "MyriadStream: read: " << __LINE__ << ": Copying out bytes: "
96 << iPos << "(" << (iPos%rMyriad.iBlockSize) << ")+" 96 << iPos << "(" << (iPos%rMyriad.iBlockSize) << ")+"
97 << iAmnt 97 << iAmnt
98 << ", " << iLeft << "b left." << sio.nl; 98 << ", " << iLeft << "b left." << sio.nl;
99#endif 99#endif
100 memcpy( 100 memcpy(
101 pBuf, 101 pBuf,
102 pCurBlock->pData+(iPos%rMyriad.iBlockSize), 102 pCurBlock->pData+(iPos%rMyriad.iBlockSize),
103 iAmnt 103 iAmnt
104 ); 104 );
105 iPos += iAmnt; 105 iPos += iAmnt;
106 pBuf = &((char *)pBuf)[iAmnt]; 106 pBuf = &((char *)pBuf)[iAmnt];
107 iLeft -= iAmnt; 107 iLeft -= iAmnt;
108 } 108 }
109 return nBytes; 109 return nBytes;
110} 110}
111 111
112Bu::size Bu::MyriadStream::write( const void *pBuf, Bu::size nBytes ) 112Bu::size Bu::MyriadStream::write( const void *pBuf, Bu::size nBytes )
113{ 113{
114 if( nBytes <= 0 ) 114 if( nBytes <= 0 )
115 return 0; 115 return 0;
116 116
117#ifdef MYRIAD_STREAM_DEBUG 117#ifdef MYRIAD_STREAM_DEBUG
118 sio << "MyriadStream: write: " << __LINE__ << ": Started, asked to write " << nBytes << "b." 118 sio << "MyriadStream: write: " << __LINE__ << ": Started, asked to write " << nBytes << "b."
119 << sio.nl; 119 << sio.nl;
120#endif 120#endif
121 if( nBytes <= 0 ) 121 if( nBytes <= 0 )
122 return 0; 122 return 0;
123 int iLeft = nBytes; 123 int iLeft = nBytes;
124 /* 124 /*
125 if( pCurBlock == NULL ) 125 if( pCurBlock == NULL )
126 { 126 {
127#ifdef MYRIAD_STREAM_DEBUG 127#ifdef MYRIAD_STREAM_DEBUG
128 sio << "MyriadStream: write: No block loaded, loading initial block." 128 sio << "MyriadStream: write: No block loaded, loading initial block."
129 << sio.nl; 129 << sio.nl;
130#endif 130#endif
131 pCurBlock = rMyriad.getBlock( 131 pCurBlock = rMyriad.getBlock(
132 pStream->aBlocks[iPos/rMyriad.iBlockSize] 132 pStream->aBlocks[iPos/rMyriad.iBlockSize]
133 ); 133 );
134 }*/ 134 }*/
135 135
136 while( iLeft > 0 ) 136 while( iLeft > 0 )
137 { 137 {
138 int iCurBlock; 138 int iCurBlock;
139 if( iPos/rMyriad.iBlockSize < pStream->aBlocks.getSize() ) 139 if( iPos/rMyriad.iBlockSize < pStream->aBlocks.getSize() )
140 { 140 {
141 iCurBlock = pStream->aBlocks[iPos/rMyriad.iBlockSize]; 141 iCurBlock = pStream->aBlocks[iPos/rMyriad.iBlockSize];
142 } 142 }
143 else 143 else
144 { 144 {
145 iCurBlock = rMyriad.streamAddBlock( pStream ); 145 iCurBlock = rMyriad.streamAddBlock( pStream );
146#ifdef MYRIAD_STREAM_DEBUG 146#ifdef MYRIAD_STREAM_DEBUG
147 sio << "MyriadStream: write: " << __LINE__ << ": New block allocated and appended: " 147 sio << "MyriadStream: write: " << __LINE__ << ": New block allocated and appended: "
148 << iCurBlock << "." << sio.nl; 148 << iCurBlock << "." << sio.nl;
149 149
150#endif 150#endif
151 } 151 }
152 if( !pCurBlock || pCurBlock->iBlockIndex != iCurBlock ) 152 if( !pCurBlock || pCurBlock->iBlockIndex != iCurBlock )
153 { 153 {
154#ifdef MYRIAD_STREAM_DEBUG 154#ifdef MYRIAD_STREAM_DEBUG
155 sio << "MyriadStream: write: " << __LINE__ << ": Loading new block " << iCurBlock << "." 155 sio << "MyriadStream: write: " << __LINE__ << ": Loading new block " << iCurBlock << "."
156 << sio.nl; 156 << sio.nl;
157#endif 157#endif
158 rMyriad.releaseBlock( pCurBlock ); 158 rMyriad.releaseBlock( pCurBlock );
159 pCurBlock = rMyriad.getBlock( iCurBlock ); 159 pCurBlock = rMyriad.getBlock( iCurBlock );
160 } 160 }
161 pCurBlock->bChanged = true; 161 pCurBlock->bChanged = true;
162 162
163 // There are two main writing modes when it comes down to it. 163 // There are two main writing modes when it comes down to it.
164 // Overwrite mode and append mode. Append is what pretty much always 164 // Overwrite mode and append mode. Append is what pretty much always
165 // happens when creating a new stream. 165 // happens when creating a new stream.
166 if( iPos < pStream->iSize ) 166 if( iPos < pStream->iSize )
167 { 167 {
168 int iAmnt = Bu::buMin( 168 int iAmnt = Bu::buMin(
169 Bu::buMin( 169 Bu::buMin(
170 rMyriad.iBlockSize - iPos%rMyriad.iBlockSize, 170 rMyriad.iBlockSize - iPos%rMyriad.iBlockSize,
171 iLeft 171 iLeft
172 ), 172 ),
173 pStream->iSize-iPos 173 pStream->iSize-iPos
174 ); 174 );
175#ifdef MYRIAD_STREAM_DEBUG 175#ifdef MYRIAD_STREAM_DEBUG
176 sio << "MyriadStream: write (ovr): " << __LINE__ << ": Copying in bytes: " 176 sio << "MyriadStream: write (ovr): " << __LINE__ << ": Copying in bytes: "
177 << (iPos%rMyriad.iBlockSize) << "+" 177 << (iPos%rMyriad.iBlockSize) << "+"
178 << iAmnt 178 << iAmnt
179 << ", " << iLeft << "b left." << sio.nl; 179 << ", " << iLeft << "b left." << sio.nl;
180#endif 180#endif
181 memcpy( 181 memcpy(
182 pCurBlock->pData+(iPos%rMyriad.iBlockSize), 182 pCurBlock->pData+(iPos%rMyriad.iBlockSize),
183 pBuf, 183 pBuf,
184 iAmnt 184 iAmnt
185 ); 185 );
186 iPos += iAmnt; 186 iPos += iAmnt;
187 pBuf = &((char *)pBuf)[iAmnt]; 187 pBuf = &((char *)pBuf)[iAmnt];
188 iLeft -= iAmnt; 188 iLeft -= iAmnt;
189 } 189 }
190 else 190 else
191 { 191 {
192 int iAmnt = Bu::buMin( 192 int iAmnt = Bu::buMin(
193 rMyriad.iBlockSize - iPos%rMyriad.iBlockSize, 193 rMyriad.iBlockSize - iPos%rMyriad.iBlockSize,
194 iLeft 194 iLeft
195 ); 195 );
196#ifdef MYRIAD_STREAM_DEBUG 196#ifdef MYRIAD_STREAM_DEBUG
197 sio << "MyriadStream: write (app): " << __LINE__ << ": Copying in bytes: " 197 sio << "MyriadStream: write (app): " << __LINE__ << ": Copying in bytes: "
198 << (iPos%rMyriad.iBlockSize) << "+" 198 << (iPos%rMyriad.iBlockSize) << "+"
199 << iAmnt 199 << iAmnt
200 << ", " << iLeft << "b left." << sio.nl; 200 << ", " << iLeft << "b left." << sio.nl;
201#endif 201#endif
202 memcpy( 202 memcpy(
203 pCurBlock->pData+(iPos%rMyriad.iBlockSize), 203 pCurBlock->pData+(iPos%rMyriad.iBlockSize),
204 pBuf, 204 pBuf,
205 iAmnt 205 iAmnt
206 ); 206 );
207 iPos += iAmnt; 207 iPos += iAmnt;
208 pStream->iSize += iAmnt; 208 pStream->iSize += iAmnt;
209 rMyriad.headerChanged(); 209 rMyriad.headerChanged();
210 pBuf = &((char *)pBuf)[iAmnt]; 210 pBuf = &((char *)pBuf)[iAmnt];
211 iLeft -= iAmnt; 211 iLeft -= iAmnt;
212 } 212 }
213 } 213 }
214 214
215 return nBytes; 215 return nBytes;
216} 216}
217 217
218Bu::size Bu::MyriadStream::tell() 218Bu::size Bu::MyriadStream::tell()
219{ 219{
220 return iPos; 220 return iPos;
221} 221}
222 222
223void Bu::MyriadStream::seek( Bu::size offset ) 223void Bu::MyriadStream::seek( Bu::size offset )
224{ 224{
225 iPos += offset; 225 iPos += offset;
226} 226}
227 227
228void Bu::MyriadStream::setPos( Bu::size pos ) 228void Bu::MyriadStream::setPos( Bu::size pos )
229{ 229{
230 iPos = pos; 230 iPos = pos;
231} 231}
232 232
233void Bu::MyriadStream::setPosEnd( Bu::size pos ) 233void Bu::MyriadStream::setPosEnd( Bu::size pos )
234{ 234{
235 iPos = pStream->iSize-pos; 235 iPos = pStream->iSize-pos;
236} 236}
237 237
238bool Bu::MyriadStream::isEos() 238bool Bu::MyriadStream::isEos()
239{ 239{
240 return iPos >= pStream->iSize; 240 return iPos >= pStream->iSize;
241} 241}
242 242
243bool Bu::MyriadStream::isOpen() 243bool Bu::MyriadStream::isOpen()
244{ 244{
245 return true; 245 return true;
246} 246}
247 247
248void Bu::MyriadStream::flush() 248void Bu::MyriadStream::flush()
@@ -251,32 +251,32 @@ void Bu::MyriadStream::flush()
251 251
252bool Bu::MyriadStream::canRead() 252bool Bu::MyriadStream::canRead()
253{ 253{
254 return true; 254 return true;
255} 255}
256 256
257bool Bu::MyriadStream::canWrite() 257bool Bu::MyriadStream::canWrite()
258{ 258{
259 return true; 259 return true;
260} 260}
261 261
262bool Bu::MyriadStream::isReadable() 262bool Bu::MyriadStream::isReadable()
263{ 263{
264 return true; 264 return true;
265} 265}
266 266
267bool Bu::MyriadStream::isWritable() 267bool Bu::MyriadStream::isWritable()
268{ 268{
269 return true; 269 return true;
270} 270}
271 271
272bool Bu::MyriadStream::isSeekable() 272bool Bu::MyriadStream::isSeekable()
273{ 273{
274 return true; 274 return true;
275} 275}
276 276
277bool Bu::MyriadStream::isBlocking() 277bool Bu::MyriadStream::isBlocking()
278{ 278{
279 return true; 279 return true;
280} 280}
281 281
282void Bu::MyriadStream::setBlocking( bool /*bBlocking*/ ) 282void Bu::MyriadStream::setBlocking( bool /*bBlocking*/ )
@@ -285,25 +285,25 @@ void Bu::MyriadStream::setBlocking( bool /*bBlocking*/ )
285 285
286void Bu::MyriadStream::setSize( Bu::size iSize ) 286void Bu::MyriadStream::setSize( Bu::size iSize )
287{ 287{
288 if( iSize < 0 ) 288 if( iSize < 0 )
289 iSize = 0; 289 iSize = 0;
290 rMyriad.setStreamSize( pStream, iSize ); 290 rMyriad.setStreamSize( pStream, iSize );
291 if( iPos > iSize ) 291 if( iPos > iSize )
292 iPos = iSize; 292 iPos = iSize;
293} 293}
294 294
295Bu::size Bu::MyriadStream::getSize() const 295Bu::size Bu::MyriadStream::getSize() const
296{ 296{
297 return pStream->iSize; 297 return pStream->iSize;
298} 298}
299 299
300Bu::size Bu::MyriadStream::getBlockSize() const 300Bu::size Bu::MyriadStream::getBlockSize() const
301{ 301{
302 return rMyriad.getBlockSize(); 302 return rMyriad.getBlockSize();
303} 303}
304 304
305Bu::String Bu::MyriadStream::getLocation() const 305Bu::String Bu::MyriadStream::getLocation() const
306{ 306{
307 return Bu::String("%1").arg( pStream->iId ); 307 return Bu::String("%1").arg( pStream->iId );
308} 308}
309 309