aboutsummaryrefslogtreecommitdiff
path: root/src/stable/queuebuf.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/queuebuf.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 '')
-rw-r--r--src/stable/queuebuf.cpp316
1 files changed, 158 insertions, 158 deletions
diff --git a/src/stable/queuebuf.cpp b/src/stable/queuebuf.cpp
index 8a3397f..2d49684 100644
--- a/src/stable/queuebuf.cpp
+++ b/src/stable/queuebuf.cpp
@@ -11,181 +11,181 @@
11using Bu::sio; 11using Bu::sio;
12 12
13Bu::QueueBuf::QueueBuf( int iBlockSize /*=256*/ ) : 13Bu::QueueBuf::QueueBuf( int iBlockSize /*=256*/ ) :
14 iBlockSize( iBlockSize ), 14 iBlockSize( iBlockSize ),
15 iReadOffset( 0 ), 15 iReadOffset( 0 ),
16 iWriteOffset( 0 ), 16 iWriteOffset( 0 ),
17 iTotalSize( 0 ) 17 iTotalSize( 0 )
18{ 18{
19} 19}
20 20
21Bu::QueueBuf::~QueueBuf() 21Bu::QueueBuf::~QueueBuf()
22{ 22{
23 for( BlockList::iterator i = lBlocks.begin(); i; i++ ) 23 for( BlockList::iterator i = lBlocks.begin(); i; i++ )
24 delete[] *i; 24 delete[] *i;
25} 25}
26 26
27void Bu::QueueBuf::close() 27void Bu::QueueBuf::close()
28{ 28{
29 for( BlockList::iterator i = lBlocks.begin(); i; i++ ) 29 for( BlockList::iterator i = lBlocks.begin(); i; i++ )
30 delete[] *i; 30 delete[] *i;
31 lBlocks.clear(); 31 lBlocks.clear();
32 iReadOffset = iWriteOffset = iTotalSize = 0; 32 iReadOffset = iWriteOffset = iTotalSize = 0;
33} 33}
34 34
35Bu::size Bu::QueueBuf::read( void *pRawBuf, Bu::size nBytes ) 35Bu::size Bu::QueueBuf::read( void *pRawBuf, Bu::size nBytes )
36{ 36{
37 if( nBytes <= 0 ) 37 if( nBytes <= 0 )
38 return 0; 38 return 0;
39 39
40 if( lBlocks.isEmpty() ) 40 if( lBlocks.isEmpty() )
41 return 0; 41 return 0;
42 42
43 Bu::size iLeft = nBytes; 43 Bu::size iLeft = nBytes;
44 char *pBuf = (char *)pRawBuf; 44 char *pBuf = (char *)pRawBuf;
45 45
46 while( iLeft > 0 && iTotalSize > 0 ) 46 while( iLeft > 0 && iTotalSize > 0 )
47 { 47 {
48 if( iReadOffset == iBlockSize ) 48 if( iReadOffset == iBlockSize )
49 { 49 {
50 removeBlock(); 50 removeBlock();
51 if( lBlocks.isEmpty() ) 51 if( lBlocks.isEmpty() )
52 { 52 {
53 return nBytes-iLeft; 53 return nBytes-iLeft;
54 } 54 }
55 iReadOffset = 0; 55 iReadOffset = 0;
56 } 56 }
57 char *pBlock = lBlocks.first(); 57 char *pBlock = lBlocks.first();
58 Bu::size iCopy = iBlockSize-iReadOffset; 58 Bu::size iCopy = iBlockSize-iReadOffset;
59 if( iLeft < iCopy ) 59 if( iLeft < iCopy )
60 iCopy = iLeft; 60 iCopy = iLeft;
61 if( iTotalSize < iCopy ) 61 if( iTotalSize < iCopy )
62 iCopy = iTotalSize; 62 iCopy = iTotalSize;
63 memcpy( pBuf, pBlock+iReadOffset, iCopy ); 63 memcpy( pBuf, pBlock+iReadOffset, iCopy );
64 iReadOffset += iCopy; 64 iReadOffset += iCopy;
65 iLeft -= iCopy; 65 iLeft -= iCopy;
66 pBuf += iCopy; 66 pBuf += iCopy;
67 iTotalSize -= iCopy; 67 iTotalSize -= iCopy;
68// sio << "Read " << iCopy << " bytes, new size: " << iTotalSize << sio.nl; 68// sio << "Read " << iCopy << " bytes, new size: " << iTotalSize << sio.nl;
69 } 69 }
70 70
71 return nBytes - iLeft; 71 return nBytes - iLeft;
72} 72}
73 73
74Bu::size Bu::QueueBuf::peek( void *pBuf, Bu::size nBytes ) 74Bu::size Bu::QueueBuf::peek( void *pBuf, Bu::size nBytes )
75{ 75{
76 return peek( pBuf, nBytes, 0 ); 76 return peek( pBuf, nBytes, 0 );
77} 77}
78 78
79Bu::size Bu::QueueBuf::peek( void *pRawBuf, Bu::size nBytes, Bu::size nSkip ) 79Bu::size Bu::QueueBuf::peek( void *pRawBuf, Bu::size nBytes, Bu::size nSkip )
80{ 80{
81 if( nBytes <= 0 ) 81 if( nBytes <= 0 )
82 return 0; 82 return 0;
83 83
84 if( lBlocks.isEmpty() ) 84 if( lBlocks.isEmpty() )
85 return 0; 85 return 0;
86 86
87 Bu::size iLeft = nBytes; 87 Bu::size iLeft = nBytes;
88 char *pBuf = (char *)pRawBuf; 88 char *pBuf = (char *)pRawBuf;
89 89
90 int iTmpReadOffset = iReadOffset + nSkip; 90 int iTmpReadOffset = iReadOffset + nSkip;
91 Bu::size iTmpRemSize = iTotalSize; 91 Bu::size iTmpRemSize = iTotalSize;
92 BlockList::iterator iBlock = lBlocks.begin(); 92 BlockList::iterator iBlock = lBlocks.begin();
93 while( iTmpReadOffset > iBlockSize ) 93 while( iTmpReadOffset > iBlockSize )
94 { 94 {
95 iTmpReadOffset -= iBlockSize; 95 iTmpReadOffset -= iBlockSize;
96 iBlock++; 96 iBlock++;
97 } 97 }
98 while( iLeft > 0 && iTmpRemSize > 0 ) 98 while( iLeft > 0 && iTmpRemSize > 0 )
99 { 99 {
100 if( iTmpReadOffset == iBlockSize ) 100 if( iTmpReadOffset == iBlockSize )
101 { 101 {
102 iBlock++; 102 iBlock++;
103 if( iBlock == lBlocks.end() ) 103 if( iBlock == lBlocks.end() )
104 { 104 {
105 return nBytes-iLeft; 105 return nBytes-iLeft;
106 } 106 }
107 iTmpReadOffset = 0; 107 iTmpReadOffset = 0;
108 } 108 }
109 char *pBlock = *iBlock; 109 char *pBlock = *iBlock;
110 Bu::size iCopy = iBlockSize-iTmpReadOffset; 110 Bu::size iCopy = iBlockSize-iTmpReadOffset;
111 if( iLeft < iCopy ) 111 if( iLeft < iCopy )
112 iCopy = iLeft; 112 iCopy = iLeft;
113 if( iTmpRemSize < iCopy ) 113 if( iTmpRemSize < iCopy )
114 iCopy = iTmpRemSize; 114 iCopy = iTmpRemSize;
115 memcpy( pBuf, pBlock+iTmpReadOffset, iCopy ); 115 memcpy( pBuf, pBlock+iTmpReadOffset, iCopy );
116 iTmpReadOffset += iCopy; 116 iTmpReadOffset += iCopy;
117 iLeft -= iCopy; 117 iLeft -= iCopy;
118 pBuf += iCopy; 118 pBuf += iCopy;
119 iTmpRemSize -= iCopy; 119 iTmpRemSize -= iCopy;
120// sio << "Read (peek) " << iCopy << " bytes, new temp size: " 120// sio << "Read (peek) " << iCopy << " bytes, new temp size: "
121// << iTmpRemSize << sio.nl; 121// << iTmpRemSize << sio.nl;
122 } 122 }
123 123
124 return nBytes - iLeft; 124 return nBytes - iLeft;
125} 125}
126 126
127Bu::size Bu::QueueBuf::write( const void *pRawBuf, Bu::size nBytes ) 127Bu::size Bu::QueueBuf::write( const void *pRawBuf, Bu::size nBytes )
128{ 128{
129 if( nBytes <= 0 ) 129 if( nBytes <= 0 )
130 return 0; 130 return 0;
131 131
132 if( lBlocks.isEmpty() ) 132 if( lBlocks.isEmpty() )
133 { 133 {
134 addBlock(); 134 addBlock();
135 iWriteOffset = 0; 135 iWriteOffset = 0;
136 } 136 }
137 Bu::size iLeft = nBytes; 137 Bu::size iLeft = nBytes;
138 const char *pBuf = (const char *)pRawBuf; 138 const char *pBuf = (const char *)pRawBuf;
139 139
140 while( iLeft > 0 ) 140 while( iLeft > 0 )
141 { 141 {
142 if( iWriteOffset == iBlockSize ) 142 if( iWriteOffset == iBlockSize )
143 { 143 {
144 addBlock(); 144 addBlock();
145 iWriteOffset = 0; 145 iWriteOffset = 0;
146 } 146 }
147 char *pBlock = lBlocks.last(); 147 char *pBlock = lBlocks.last();
148 Bu::size iCopy = iBlockSize-iWriteOffset; 148 Bu::size iCopy = iBlockSize-iWriteOffset;
149 if( iLeft < iCopy ) 149 if( iLeft < iCopy )
150 iCopy = iLeft; 150 iCopy = iLeft;
151 memcpy( pBlock+iWriteOffset, pBuf, iCopy ); 151 memcpy( pBlock+iWriteOffset, pBuf, iCopy );
152 iWriteOffset += iCopy; 152 iWriteOffset += iCopy;
153 iLeft -= iCopy; 153 iLeft -= iCopy;
154 pBuf += iCopy; 154 pBuf += iCopy;
155 iTotalSize += iCopy; 155 iTotalSize += iCopy;
156// sio << "Wrote " << iCopy << " bytes, new size: " << iTotalSize 156// sio << "Wrote " << iCopy << " bytes, new size: " << iTotalSize
157// << sio.nl; 157// << sio.nl;
158 } 158 }
159 159
160 return nBytes; 160 return nBytes;
161} 161}
162 162
163Bu::size Bu::QueueBuf::tell() 163Bu::size Bu::QueueBuf::tell()
164{ 164{
165 return -1; 165 return -1;
166} 166}
167 167
168void Bu::QueueBuf::seek( Bu::size iAmnt ) 168void Bu::QueueBuf::seek( Bu::size iAmnt )
169{ 169{
170 if( iAmnt <= 0 ) 170 if( iAmnt <= 0 )
171 return; 171 return;
172 172
173 if( (Bu::size)iAmnt >= iTotalSize ) 173 if( (Bu::size)iAmnt >= iTotalSize )
174 { 174 {
175// sio << "seek: clear all data (" << iAmnt << ">=" << iTotalSize 175// sio << "seek: clear all data (" << iAmnt << ">=" << iTotalSize
176// << ")." << sio.nl; 176// << ")." << sio.nl;
177 close(); 177 close();
178 return; 178 return;
179 } 179 }
180 180
181 iReadOffset += iAmnt; 181 iReadOffset += iAmnt;
182 iTotalSize -= iAmnt; 182 iTotalSize -= iAmnt;
183 while( iReadOffset >= iBlockSize ) 183 while( iReadOffset >= iBlockSize )
184 { 184 {
185 removeBlock(); 185 removeBlock();
186 iReadOffset -= iBlockSize; 186 iReadOffset -= iBlockSize;
187// sio << "seek: removal step (" << iReadOffset << ")" << sio.nl; 187// sio << "seek: removal step (" << iReadOffset << ")" << sio.nl;
188 } 188 }
189} 189}
190 190
191void Bu::QueueBuf::setPos( Bu::size ) 191void Bu::QueueBuf::setPos( Bu::size )
@@ -198,12 +198,12 @@ void Bu::QueueBuf::setPosEnd( Bu::size )
198 198
199bool Bu::QueueBuf::isEos() 199bool Bu::QueueBuf::isEos()
200{ 200{
201 return iTotalSize == 0; 201 return iTotalSize == 0;
202} 202}
203 203
204bool Bu::QueueBuf::isOpen() 204bool Bu::QueueBuf::isOpen()
205{ 205{
206 return true; 206 return true;
207} 207}
208 208
209void Bu::QueueBuf::flush() 209void Bu::QueueBuf::flush()
@@ -212,32 +212,32 @@ void Bu::QueueBuf::flush()
212 212
213bool Bu::QueueBuf::canRead() 213bool Bu::QueueBuf::canRead()
214{ 214{
215 return iTotalSize > 0; 215 return iTotalSize > 0;
216} 216}
217 217
218bool Bu::QueueBuf::canWrite() 218bool Bu::QueueBuf::canWrite()
219{ 219{
220 return true; 220 return true;
221} 221}
222 222
223bool Bu::QueueBuf::isReadable() 223bool Bu::QueueBuf::isReadable()
224{ 224{
225 return true; 225 return true;
226} 226}
227 227
228bool Bu::QueueBuf::isWritable() 228bool Bu::QueueBuf::isWritable()
229{ 229{
230 return true; 230 return true;
231} 231}
232 232
233bool Bu::QueueBuf::isSeekable() 233bool Bu::QueueBuf::isSeekable()
234{ 234{
235 return false; 235 return false;
236} 236}
237 237
238bool Bu::QueueBuf::isBlocking() 238bool Bu::QueueBuf::isBlocking()
239{ 239{
240 return false; 240 return false;
241} 241}
242 242
243void Bu::QueueBuf::setBlocking( bool ) 243void Bu::QueueBuf::setBlocking( bool )
@@ -250,29 +250,29 @@ void Bu::QueueBuf::setSize( Bu::size )
250 250
251Bu::size Bu::QueueBuf::getSize() const 251Bu::size Bu::QueueBuf::getSize() const
252{ 252{
253 return iTotalSize; 253 return iTotalSize;
254} 254}
255 255
256Bu::size Bu::QueueBuf::getBlockSize() const 256Bu::size Bu::QueueBuf::getBlockSize() const
257{ 257{
258 return iBlockSize; 258 return iBlockSize;
259} 259}
260 260
261Bu::String Bu::QueueBuf::getLocation() const 261Bu::String Bu::QueueBuf::getLocation() const
262{ 262{
263 return ""; 263 return "";
264} 264}
265 265
266void Bu::QueueBuf::addBlock() 266void Bu::QueueBuf::addBlock()
267{ 267{
268 lBlocks.append( new char[iBlockSize] ); 268 lBlocks.append( new char[iBlockSize] );
269// sio << "Added new block." << sio.nl; 269// sio << "Added new block." << sio.nl;
270} 270}
271 271
272void Bu::QueueBuf::removeBlock() 272void Bu::QueueBuf::removeBlock()
273{ 273{
274 delete[] lBlocks.first(); 274 delete[] lBlocks.first();
275 lBlocks.erase( lBlocks.begin() ); 275 lBlocks.erase( lBlocks.begin() );
276// sio << "Removed block." << sio.nl; 276// sio << "Removed block." << sio.nl;
277} 277}
278 278