summaryrefslogtreecommitdiff
path: root/src/stable/substream.h
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2012-03-25 20:00:08 +0000
committerMike Buland <eichlan@xagasoft.com>2012-03-25 20:00:08 +0000
commit469bbcf0701e1eb8a6670c23145b0da87357e178 (patch)
treeb5b062a16e46a6c5d3410b4e574cd0cc09057211 /src/stable/substream.h
parentee1b79396076edc4e30aefb285fada03bb45e80d (diff)
downloadlibbu++-469bbcf0701e1eb8a6670c23145b0da87357e178.tar.gz
libbu++-469bbcf0701e1eb8a6670c23145b0da87357e178.tar.bz2
libbu++-469bbcf0701e1eb8a6670c23145b0da87357e178.tar.xz
libbu++-469bbcf0701e1eb8a6670c23145b0da87357e178.zip
Code is all reorganized. We're about ready to release. I should write up a
little explenation of the arrangement.
Diffstat (limited to 'src/stable/substream.h')
-rw-r--r--src/stable/substream.h63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/stable/substream.h b/src/stable/substream.h
new file mode 100644
index 0000000..1db4d6c
--- /dev/null
+++ b/src/stable/substream.h
@@ -0,0 +1,63 @@
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_SUB_STREAM_H
9#define BU_SUB_STREAM_H
10
11#include "bu/filter.h"
12
13namespace Bu
14{
15 /**
16 * Creates a sub-stream of a given stream. This allows you to read and
17 * write safely to a section of another stream, keeping all data within
18 * the given bounds. The substream acts exactly like a top level stream
19 * when you reach the bounds of either the containing stream or the
20 * artificial bounds of the substream, except that unlike many stream types,
21 * when writing you cannot move beyond the bounds of the substream. Reads,
22 * on the other hand, work exactly the same way, returning less data than
23 * requested when the end of the stream is reached.
24 *
25 * The substream always begins at the current position in the base stream,
26 * if you would like to skip some data first, simply seek.
27 *
28 * The substream class is safe to use with all blocking and non-blocking
29 * base streams, including sockets, however it can have unpredictable
30 * results when used on a buffering stream that may read more data than
31 * requested in order to complete a request such as the buffer or bzip2
32 * filters.
33 */
34 class SubStream : public Bu::Filter
35 {
36 public:
37 SubStream( Bu::Stream &rNext, Bu::size iSize );
38 virtual ~SubStream();
39
40 virtual Bu::size read( void *pBuf, Bu::size nBytes );
41 virtual Bu::size write( const void *pBuf, Bu::size nBytes );
42 using Bu::Stream::write;
43
44 virtual void start();
45 virtual Bu::size stop();
46 virtual void close();
47 virtual Bu::size tell();
48 virtual void seek( Bu::size offset );
49 virtual void setPos( Bu::size pos );
50 virtual void setPosEnd( Bu::size pos );
51 virtual bool isEos();
52
53 virtual bool canRead();
54 virtual bool canWrite();
55
56 protected:
57 Bu::size iStart;
58 Bu::size iPos;
59 Bu::size iSize;
60 };
61};
62
63#endif