aboutsummaryrefslogtreecommitdiff
path: root/src/stable/queuebuf.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/stable/queuebuf.h')
-rw-r--r--src/stable/queuebuf.h66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/stable/queuebuf.h b/src/stable/queuebuf.h
new file mode 100644
index 0000000..929ca35
--- /dev/null
+++ b/src/stable/queuebuf.h
@@ -0,0 +1,66 @@
1/*
2 * Copyright (C) 2007-2011 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
13namespace 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 virtual void close();
28 virtual Bu::size read( void *pBuf, Bu::size nBytes );
29 virtual Bu::size peek( void *pBuf, Bu::size nBytes );
30 virtual Bu::size peek( void *pBuf, Bu::size nBytes, Bu::size nSkip );
31 virtual Bu::size write( const void *pBuf, Bu::size nBytes );
32 virtual Bu::size tell();
33 virtual void seek( Bu::size offset );
34 virtual void setPos( Bu::size pos );
35 virtual void setPosEnd( Bu::size pos );
36 virtual bool isEos();
37 virtual bool isOpen();
38 virtual void flush();
39 virtual bool canRead();
40 virtual bool canWrite();
41 virtual bool isReadable();
42 virtual bool isWritable();
43 virtual bool isSeekable();
44 virtual bool isBlocking();
45 virtual void setBlocking( bool bBlocking=true );
46 virtual void setSize( Bu::size iSize );
47
48 virtual size getSize() const;
49 virtual size getBlockSize() const;
50 virtual Bu::String getLocation() const;
51
52 private:
53 void addBlock();
54 void removeBlock();
55
56 private:
57 int iBlockSize;
58 int iReadOffset;
59 int iWriteOffset;
60 Bu::size iTotalSize;
61 typedef Bu::List<char *> BlockList;
62 BlockList lBlocks;
63 };
64};
65
66#endif