aboutsummaryrefslogtreecommitdiff
path: root/src/filter.h
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2007-06-07 19:56:20 +0000
committerMike Buland <eichlan@xagasoft.com>2007-06-07 19:56:20 +0000
commit9e8a4944e50fab432012878c66e1bdac20649f76 (patch)
tree412b0d49ae4086bb330045f9956513397b866807 /src/filter.h
parentc2e3879b965d297604804f03271ac71c8c5c81f3 (diff)
downloadlibbu++-9e8a4944e50fab432012878c66e1bdac20649f76.tar.gz
libbu++-9e8a4944e50fab432012878c66e1bdac20649f76.tar.bz2
libbu++-9e8a4944e50fab432012878c66e1bdac20649f76.tar.xz
libbu++-9e8a4944e50fab432012878c66e1bdac20649f76.zip
The Stream Filter archetecture is finished, it's actually much cooler than I
had anticipated, and much cleaner. I'll have to add some documentation to it, because it's not really obvious how any of it fits together from the outset, although I have to say that the bzip2 test program is the easiest general bzip2 compression program I've ever made...it just goes :) Decompression in Bu::BZip2 isn't finished yet, but that's ok, it's coming soon.
Diffstat (limited to 'src/filter.h')
-rw-r--r--src/filter.h59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/filter.h b/src/filter.h
new file mode 100644
index 0000000..b068206
--- /dev/null
+++ b/src/filter.h
@@ -0,0 +1,59 @@
1#ifndef FILTER_H
2#define FILTER_H
3
4#include <stdint.h>
5
6#include "bu/stream.h"
7
8namespace Bu
9{
10 /**
11 * Data filter base class. Each data filter should contain a read and write
12 * section. Effectively, the write applies the filter, the read un-applies
13 * the filter, if possible. For example, BZip2 is a filter that compresses
14 * on write and decompresses on read. All bi-directional filters should
15 * follow: x == read( write( x ) ) (byte-for-byte comparison)
16 *
17 * Also, all returned buffers should be owned by the filter, and deleted
18 * when the filter is deleted. This means that the output of a read or
19 * write operation must be used before the next call to read or write or the
20 * data will be destroyed. Also, the internal buffer may be changed or
21 * recreated between calls, so always get a new pointer from a call to
22 * read or write.
23 *
24 * The close function can also return data, so make sure to check for it,
25 * many filters such as compression filters will buffer data until they have
26 * enough to create a compression block, in these cases the leftover data
27 * will be returned by close.
28 */
29 class Filter : public Bu::Stream
30 {
31 public:
32 Filter( Bu::Stream &rNext );
33 virtual ~Filter();
34
35 virtual void start()=0;
36 virtual void stop()=0;
37 virtual void close();
38 virtual long tell();
39 virtual void seek( long offset );
40 virtual void setPos( long pos );
41 virtual void setPosEnd( long pos );
42 virtual bool isEOS();
43
44 virtual bool canRead();
45 virtual bool canWrite();
46 virtual bool canSeek();
47
48 virtual bool isBlocking();
49 virtual void setBlocking( bool bBlocking=true );
50
51 protected:
52 Bu::Stream &rNext;
53
54 private:
55
56 };
57}
58
59#endif