diff options
Diffstat (limited to 'src/filter.h')
-rw-r--r-- | src/filter.h | 59 |
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 | |||
8 | namespace 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 | ||