diff options
Diffstat (limited to 'src/filter.h')
| -rw-r--r-- | src/filter.h | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/filter.h b/src/filter.h new file mode 100644 index 0000000..bd557b2 --- /dev/null +++ b/src/filter.h | |||
| @@ -0,0 +1,65 @@ | |||
| 1 | #ifndef BU_FILTER_H | ||
| 2 | #define BU_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 size_t 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 | virtual bool isOpen(); | ||
| 44 | |||
| 45 | virtual void flush(); | ||
| 46 | |||
| 47 | virtual bool canRead(); | ||
| 48 | virtual bool canWrite(); | ||
| 49 | |||
| 50 | virtual bool isReadable(); | ||
| 51 | virtual bool isWritable(); | ||
| 52 | virtual bool isSeekable(); | ||
| 53 | |||
| 54 | virtual bool isBlocking(); | ||
| 55 | virtual void setBlocking( bool bBlocking=true ); | ||
| 56 | |||
| 57 | protected: | ||
| 58 | Bu::Stream &rNext; | ||
| 59 | |||
| 60 | private: | ||
| 61 | |||
| 62 | }; | ||
| 63 | } | ||
| 64 | |||
| 65 | #endif | ||
