blob: f86d6c3b4fdc38ec5f26647e13c290d1ed4631ef (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
/*
* Copyright (C) 2007 Xagasoft, All rights reserved.
*
* This file is part of the libbu++ library and is released under the
* terms of the license contained in the file LICENSE.
*/
#ifndef BU_FILTER_H
#define BU_FILTER_H
#include <stdint.h>
#include "bu/stream.h"
namespace Bu
{
/**
* Data filter base class. Each data filter should contain a read and write
* section. Effectively, the write applies the filter, the read un-applies
* the filter, if possible. For example, BZip2 is a filter that compresses
* on write and decompresses on read. All bi-directional filters should
* follow: x == read( write( x ) ) (byte-for-byte comparison)
*
* Also, all returned buffers should be owned by the filter, and deleted
* when the filter is deleted. This means that the output of a read or
* write operation must be used before the next call to read or write or the
* data will be destroyed. Also, the internal buffer may be changed or
* recreated between calls, so always get a new pointer from a call to
* read or write.
*
* The close function can also return data, so make sure to check for it,
* many filters such as compression filters will buffer data until they have
* enough to create a compression block, in these cases the leftover data
* will be returned by close.
*@ingroup Streams
*/
class Filter : public Bu::Stream
{
public:
Filter( Bu::Stream &rNext );
virtual ~Filter();
virtual void start()=0;
virtual size_t stop()=0;
virtual void close();
virtual long tell();
virtual void seek( long offset );
virtual void setPos( long pos );
virtual void setPosEnd( long pos );
virtual bool isEOS();
virtual bool isOpen();
virtual void flush();
virtual bool canRead();
virtual bool canWrite();
virtual bool isReadable();
virtual bool isWritable();
virtual bool isSeekable();
virtual bool isBlocking();
virtual void setBlocking( bool bBlocking=true );
protected:
Bu::Stream &rNext;
private:
};
}
#endif
|