summaryrefslogtreecommitdiff
path: root/src/stream.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/stream.h')
-rw-r--r--src/stream.h148
1 files changed, 132 insertions, 16 deletions
diff --git a/src/stream.h b/src/stream.h
index e086e28..1e236a6 100644
--- a/src/stream.h
+++ b/src/stream.h
@@ -1,27 +1,143 @@
1#ifndef STREAM_H 1#ifndef BU_STREAM_H
2#define STREAM_H 2#define BU_STREAM_H
3 3
4#include <stdint.h> 4#include <stdint.h>
5#include <stdio.h> 5#include <stdio.h>
6 6
7class Stream 7namespace Bu
8{ 8{
9public: 9 /**
10 Stream(); 10 * The basis for a completely general data transport mechanism. Anything
11 virtual ~Stream(); 11 * that inherits from this should provide at least the basic read and/or
12 * write functions, and very probably the close function. Any functions
13 * that aren't supported should throw an exception if called.
14 *
15 * The constructor of a child class should pretty much universally be used
16 * to open the stream. I can't think of anything that should require an
17 * exception.
18 */
19 class Stream
20 {
21 public:
22 Stream();
23 virtual ~Stream();
12 24
13 virtual void close() = 0; 25 /**
14 virtual size_t read( char *pBuf, size_t nBytes ) = 0; 26 * Close the stream.
15 virtual size_t write( const char *pBuf, size_t nBytes ) = 0; 27 */
28 virtual void close() = 0;
16 29
17 virtual long tell() = 0; 30 /**
18 virtual void seek( long offset ) = 0; 31 * Read data from the stream into a buffer.
19 virtual void setPos( long pos ) = 0; 32 *@param pBuf (void *) Buffer which will be filled.
20 virtual void setPosEnd( long pos ) = 0; 33 *@param nBytes (size_t) Max data to read.
21 virtual bool isEOS() = 0; 34 *@returns (size_t) Amount of data read.
35 */
36 virtual size_t read( void *pBuf, size_t nBytes ) = 0;
22 37
23private: 38 /**
39 * Write data to the stream.
40 *@param pBuf (const void *) The data to be written.
41 *@param nBytes (size_t) Amount of data to write from pBuf.
42 *@returns (size_t) Amount of data actually written.
43 */
44 virtual size_t write( const void *pBuf, size_t nBytes ) = 0;
24 45
25}; 46 /**
47 * Get the current position in the stream.
48 *@returns (long) The current position in the stream.
49 */
50 virtual long tell() = 0;
51
52 /**
53 * Seek to a position in the stream relative to the current position.
54 *@param offset (long) Offset from current position to seek to.
55 */
56 virtual void seek( long offset ) = 0;
57
58 /**
59 * Set position in the stream relative to the start of the stream.
60 *@param pos (long) The position.
61 */
62 virtual void setPos( long pos ) = 0;
63
64 /**
65 * Set position in the stream relative to the end of the stream.
66 *@param pos (long) The position.
67 */
68 virtual void setPosEnd( long pos ) = 0;
69
70 /**
71 * Are we at the end of the stream?
72 *@returns (bool) Are we at the end of the stream?
73 */
74 virtual bool isEOS() = 0;
75
76 /**
77 * Is the stream open?
78 *@returns (bool) Is the stream open?
79 */
80 virtual bool isOpen() = 0;
81
82 /**
83 * Flush any data still held in buffers.
84 */
85 virtual void flush() = 0;
86
87 /**
88 * In non-blocking streams this indicates if a read operation will
89 * return data at the moment or not. In blocking streams this should
90 * return the same value as isEOS().
91 */
92 virtual bool canRead() = 0;
93
94 /**
95 * In non-blocking streams this indicates if a write operation will
96 * succeed or fail. In some cases writing is not allowed (e.g.
97 * internal buffers are full) temporarilly. In blocking streams this
98 * should return the same value as isWritable.
99 */
100 virtual bool canWrite() = 0;
101
102 /**
103 * Indicates if the stream is capable of read operations. This does not
104 * indicate if such operations will return useful data, see canRead for
105 * that.
106 */
107 virtual bool isReadable() = 0;
108
109 /**
110 * Indicates if the stream is capable of write operations. This does
111 * not indicate if such operations will succeed or fail, see canWrite
112 * for that.
113 */
114 virtual bool isWritable() = 0;
115
116 /**
117 * Indicates if the stream is capable of seek operations. This is
118 * generally false for non-blocking streams. Some buffered streams may
119 * support limited in-buffer seeking.
120 */
121 virtual bool isSeekable() = 0;
122
123 /**
124 * Are we currently set to block mode?
125 *@returns (bool)
126 */
127 virtual bool isBlocking() = 0;
128
129 /**
130 * Set stream to blocking or non-blocking mode.
131 *@param bBlocking (bool) Whether we should block or not.
132 */
133 virtual void setBlocking( bool bBlocking=true ) = 0;
134
135 public: // Filters
136
137
138 private:
139
140 };
141}
26 142
27#endif 143#endif