diff options
| author | Mike Buland <eichlan@xagasoft.com> | 2010-05-10 03:31:08 +0000 | 
|---|---|---|
| committer | Mike Buland <eichlan@xagasoft.com> | 2010-05-10 03:31:08 +0000 | 
| commit | 8baf7e1e75a185c742dc6d5b27e50058635e5522 (patch) | |
| tree | 76ccf80b005c85df2d887ccda73679cae8d28a26 /src/queuebuf.h | |
| parent | 51c5bfa4881b5def142092e10dd402fd40e2e712 (diff) | |
| download | libbu++-8baf7e1e75a185c742dc6d5b27e50058635e5522.tar.gz libbu++-8baf7e1e75a185c742dc6d5b27e50058635e5522.tar.bz2 libbu++-8baf7e1e75a185c742dc6d5b27e50058635e5522.tar.xz libbu++-8baf7e1e75a185c742dc6d5b27e50058635e5522.zip | |
Added the new QueueBuf.  It's brilliant, and I've wanted it for a long time.
...I mean brilliant as in cool.
Diffstat (limited to 'src/queuebuf.h')
| -rw-r--r-- | src/queuebuf.h | 62 | 
1 files changed, 62 insertions, 0 deletions
| diff --git a/src/queuebuf.h b/src/queuebuf.h new file mode 100644 index 0000000..3591959 --- /dev/null +++ b/src/queuebuf.h | |||
| @@ -0,0 +1,62 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007-2010 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 | #ifndef BU_QUEUE_BUF_H | ||
| 9 | #define BU_QUEUE_BUF_H | ||
| 10 | |||
| 11 | #include "bu/stream.h" | ||
| 12 | |||
| 13 | namespace Bu | ||
| 14 | { | ||
| 15 | /** | ||
| 16 | * A queuing buffer stream class. All data written to this class is | ||
| 17 | * appended to it, there is no stored position. All data read is read | ||
| 18 | * from the begining and then thrown away. It operates by using a linked | ||
| 19 | * list of small buffers, and deallocating or reusing them when it can. | ||
| 20 | */ | ||
| 21 | class QueueBuf : public Bu::Stream | ||
| 22 | { | ||
| 23 | public: | ||
| 24 | QueueBuf( int iBlockSize=256 ); | ||
| 25 | virtual ~QueueBuf(); | ||
| 26 | |||
| 27 | int getSize(); | ||
| 28 | |||
| 29 | virtual void close(); | ||
| 30 | virtual size_t read( void *pBuf, size_t nBytes ); | ||
| 31 | virtual size_t peek( void *pBuf, size_t nBytes ); | ||
| 32 | virtual size_t write( const void *pBuf, size_t nBytes ); | ||
| 33 | virtual long tell(); | ||
| 34 | virtual void seek( long offset ); | ||
| 35 | virtual void setPos( long pos ); | ||
| 36 | virtual void setPosEnd( long pos ); | ||
| 37 | virtual bool isEos(); | ||
| 38 | virtual bool isOpen(); | ||
| 39 | virtual void flush(); | ||
| 40 | virtual bool canRead(); | ||
| 41 | virtual bool canWrite(); | ||
| 42 | virtual bool isReadable(); | ||
| 43 | virtual bool isWritable(); | ||
| 44 | virtual bool isSeekable(); | ||
| 45 | virtual bool isBlocking(); | ||
| 46 | virtual void setBlocking( bool bBlocking=true ); | ||
| 47 | |||
| 48 | private: | ||
| 49 | void addBlock(); | ||
| 50 | void removeBlock(); | ||
| 51 | |||
| 52 | private: | ||
| 53 | int iBlockSize; | ||
| 54 | int iReadOffset; | ||
| 55 | int iWriteOffset; | ||
| 56 | size_t iTotalSize; | ||
| 57 | typedef Bu::List<char *> BlockList; | ||
| 58 | BlockList lBlocks; | ||
| 59 | }; | ||
| 60 | }; | ||
| 61 | |||
| 62 | #endif | ||
