aboutsummaryrefslogtreecommitdiff
path: root/src/myriadstream.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2010-02-10 18:20:40 +0000
committerMike Buland <eichlan@xagasoft.com>2010-02-10 18:20:40 +0000
commit79b7b631750b69cbe06daedb0453306595dea6ad (patch)
tree284dc89fa2ee6ec88e9b0625a412185d5d1348b0 /src/myriadstream.cpp
parent1f29dc180b5a86ddf2115f97ad410e0e9b1beb4b (diff)
downloadlibbu++-79b7b631750b69cbe06daedb0453306595dea6ad.tar.gz
libbu++-79b7b631750b69cbe06daedb0453306595dea6ad.tar.bz2
libbu++-79b7b631750b69cbe06daedb0453306595dea6ad.tar.xz
libbu++-79b7b631750b69cbe06daedb0453306595dea6ad.zip
Changed the name of nids to Myriad, I like it, but I'm not getting rid of nids
until I can safely migrate to Myriad.
Diffstat (limited to 'src/myriadstream.cpp')
-rw-r--r--src/myriadstream.cpp223
1 files changed, 223 insertions, 0 deletions
diff --git a/src/myriadstream.cpp b/src/myriadstream.cpp
new file mode 100644
index 0000000..c9b3326
--- /dev/null
+++ b/src/myriadstream.cpp
@@ -0,0 +1,223 @@
1/*
2 * Copyright (C) 2007-2008 Xagasoft, All rights reserved.
3 *
4 * This file is part of the libbu++ library and is released under the
5 * terms of the license contained in the file LICENSE.
6 */
7
8#include "bu/myriadstream.h"
9
10#include <string.h>
11
12Bu::MyriadStream::MyriadStream( Myriad &rMyriad, uint32_t uStream ) :
13 rMyriad( rMyriad ),
14 uStream( uStream ),
15 pCurBlock( NULL ),
16 uCurBlock( uStream ),
17 uSize( 0 ),
18 uBlockSize( rMyriad.iBlockSize ),
19 uPos( 0 )
20{
21 //printf("MyriadStream::allocated\n");
22 //pCurBlock = rMyriad.newBlock();
23 //rMyriad.getBlock( uStream, pCurBlock );
24 //uSize = pCurBlock->uBytesUsed;
25}
26
27Bu::MyriadStream::~MyriadStream()
28{
29 //printf("Destroying stream?\n");
30 //rMyriad.updateStreamSize( uStream, uSize );
31 //rMyriad.deleteBlock( pCurBlock );
32}
33
34void Bu::MyriadStream::close()
35{
36}
37
38size_t Bu::MyriadStream::read( void *pBuf, size_t nBytes )
39{
40 /*
41 if( nBytes == 0 )
42 return 0;
43 if( nBytes + uPos > uSize )
44 nBytes = uSize - uPos;
45 if( (uPos%uBlockSize)+nBytes < uBlockSize )
46 {
47 size_t iRead = nBytes;
48 if( iRead > pCurBlock->uBytesUsed-(uPos%uBlockSize) )
49 iRead = pCurBlock->uBytesUsed-(uPos%uBlockSize);
50 memcpy( pBuf, pCurBlock->pData+(uPos%uBlockSize), iRead );
51 //printf("read buffill: %ub, %u-%u/%u -> %d-%d/%d (a:%u)",
52 // iRead, uPos, uPos+iRead-1, uSize, 0, iRead-1, nBytes, uCurBlock );
53 uPos += iRead;
54 //printf(" -- %u\n", uPos%uBlockSize );
55 //printf("ra: block %u = %ub:%u (%ub total)\n",
56 // uCurBlock, uPos, nBytes, uSize );
57
58 // This can't happen, if we're right on a boundery, it goes to the
59 // other case
60 //if( uPos%uBlockSize == 0 )
61 // uCurBlock = rMyriad.getNextBlock( uCurBlock, pCurBlock, false );
62 return iRead;
63 }
64 else
65 {
66 size_t nTotal = 0;
67 for(;;)
68 {
69 uint32_t iRead = nBytes;
70 if( iRead > uBlockSize-(uPos%uBlockSize) )
71 iRead = uBlockSize-(uPos%uBlockSize);
72 if( iRead > pCurBlock->uBytesUsed-(uPos%uBlockSize) )
73 iRead = pCurBlock->uBytesUsed-(uPos%uBlockSize);
74 memcpy( ((char *)pBuf)+nTotal,
75 pCurBlock->pData+(uPos%uBlockSize), iRead );
76 //printf(" read buffill: %ub, %u-%u/%u -> %d-%d/%d (b:%u)\n",
77 // iRead, uPos, uPos+iRead-1, uSize,
78 // nTotal, nTotal+nBytes-1, nBytes, uCurBlock );
79 uPos += iRead;
80 nBytes -= iRead;
81 nTotal += iRead;
82 //printf("rb: block %u = %ub:%u (%ub total)\n",
83 // uCurBlock, uPos, iRead, uSize );
84 if( uPos%uBlockSize == 0 )
85 uCurBlock = rMyriad.getNextBlock( uCurBlock, pCurBlock, false );
86 if( nBytes == 0 || uPos >= uSize )
87 return nTotal;
88 }
89 }*/
90 return 0;
91}
92
93size_t Bu::MyriadStream::write( const void *pBuf, size_t nBytes )
94{
95 if( nBytes == 0 )
96 return 0;
97/* if( pCurBlock->uBytesUsed >= uBlockSize )
98 {
99 // We're at the end of our current block, allocate another before we do
100 // anything.
101 uCurBlock = rMyriad.getNextBlock( uCurBlock, pCurBlock );
102 } */
103 /*
104 if( (uPos%uBlockSize)+nBytes < uBlockSize )
105 {
106 //printf("wa: %u:%u:%u:%u -> ", uPos, uPos%uBlockSize, uSize, pCurBlock->uBytesUsed );
107 memcpy( pCurBlock->pData+(uPos%uBlockSize), pBuf, nBytes );
108 //printf("write buffill: %ub, %u-%u/%u -> %d-%d/%d (a:%u:%u)\n",
109 // nBytes, 0, nBytes-1, nBytes,
110 // uPos, uPos+nBytes-1, uSize, uCurBlock,
111 // pCurBlock->uBytesUsed );
112 if( (uPos%uBlockSize)+nBytes > pCurBlock->uBytesUsed )
113 pCurBlock->uBytesUsed = (uPos%uBlockSize)+nBytes;
114 rMyriad.setBlock( uCurBlock, pCurBlock );
115 uPos += nBytes;
116 if( uPos > uSize )
117 uSize = uPos;
118 //printf("block %u = %ub (%ub total) %d:%u\n",
119 // uCurBlock, pCurBlock->uBytesUsed, uSize, nBytes, uPos );
120 return nBytes;
121 }
122 else
123 {
124 size_t nTotal = 0;
125 for(;;)
126 {
127 uint32_t uNow = uBlockSize-(uPos%uBlockSize);
128 //printf("uNow: %u (%u-(%u%%%u)) %d req\n", uNow, uBlockSize, uPos, uBlockSize, nBytes );
129 if( nBytes < uNow )
130 uNow = nBytes;
131 memcpy( pCurBlock->pData+(uPos%uBlockSize),
132 &((char *)pBuf)[nTotal], uNow );
133 //printf("write buffill: %ub, %u-%u/%u -> %d-%d/%d (b:%u:%u)\n",
134 // uNow, nTotal, nTotal+uNow-1, nBytes,
135 // uPos, uPos+uNow-1, uSize, uCurBlock, pCurBlock->uBytesUsed );
136 if( (uPos%uBlockSize)+uNow > pCurBlock->uBytesUsed )
137 pCurBlock->uBytesUsed = (uPos%uBlockSize)+uNow;
138 rMyriad.setBlock( uCurBlock, pCurBlock );
139 uPos += uNow;
140 if( uPos > uSize )
141 uSize = uPos;
142 nTotal += uNow;
143 nBytes -= uNow;
144 //printf("wb: block %u = %ub (%ub total)\n",
145 // uCurBlock, pCurBlock->uBytesUsed, uSize );
146 //if( pCurBlock->uBytesUsed == uBlockSize )
147 if( uPos%uBlockSize == 0 )
148 uCurBlock = rMyriad.getNextBlock( uCurBlock, pCurBlock );
149 if( nBytes == 0 )
150 return nTotal;
151 }
152 }*/
153 return 0;
154}
155
156long Bu::MyriadStream::tell()
157{
158 return uPos;
159}
160
161void Bu::MyriadStream::seek( long offset )
162{
163 uPos += offset;
164}
165
166void Bu::MyriadStream::setPos( long pos )
167{
168 uPos = pos;
169}
170
171void Bu::MyriadStream::setPosEnd( long pos )
172{
173 uPos = uSize-pos-1;
174}
175
176bool Bu::MyriadStream::isEos()
177{
178 return true;
179}
180
181bool Bu::MyriadStream::isOpen()
182{
183 return true;
184}
185
186void Bu::MyriadStream::flush()
187{
188}
189
190bool Bu::MyriadStream::canRead()
191{
192 return true;
193}
194
195bool Bu::MyriadStream::canWrite()
196{
197 return true;
198}
199
200bool Bu::MyriadStream::isReadable()
201{
202 return true;
203}
204
205bool Bu::MyriadStream::isWritable()
206{
207 return true;
208}
209
210bool Bu::MyriadStream::isSeekable()
211{
212 return true;
213}
214
215bool Bu::MyriadStream::isBlocking()
216{
217 return true;
218}
219
220void Bu::MyriadStream::setBlocking( bool /*bBlocking*/ )
221{
222}
223