aboutsummaryrefslogtreecommitdiff
path: root/src/stream.h
blob: ba070d3ee9815fa8a6f5c3a4a8c5760b2cdeb00a (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
74
75
76
77
78
79
80
81
82
83
84
85
#ifndef STREAM_H
#define STREAM_H

#include <stdint.h>
#include <stdio.h>

namespace Bu
{
	/**
	 * The basis for a completely general data transport mechanism.  Anything
	 * that inherits from this should provide at least the basic read and/or
	 * write functions, and very probably the close function.  Any functions
	 * that aren't supported should throw an exception if called.
	 *
	 * The constructor of a child class should pretty much universally be used
	 * to open the stream.  I can't think of anything that should require an
	 * exception.
	 */
	class Stream
	{
	public:
		Stream();
		virtual ~Stream();

		virtual void close() = 0;
		virtual size_t read( void *pBuf, size_t nBytes ) = 0;
		virtual size_t write( const void *pBuf, size_t nBytes ) = 0;

		virtual long tell() = 0;
		virtual void seek( long offset ) = 0;
		virtual void setPos( long pos ) = 0;
		virtual void setPosEnd( long pos ) = 0;
		virtual bool isEOS() = 0;
		virtual bool isOpen() = 0;

		virtual void flush() = 0;

		/**
		 * In non-blocking streams this indicates if a read operation will
		 * return data at the moment or not.  In blocking streams this should
		 * return the same value as isEOS().
		 */
		virtual bool canRead() = 0;

		/**
		 * In non-blocking streams this indicates if a write operation will
		 * succeed or fail.  In some cases writing is not allowed (e.g. 
		 * internal buffers are full) temporarilly.  In blocking streams this
		 * should return the same value as isWritable.
		 */
		virtual bool canWrite() = 0;

		/**
		 * Indicates if the stream is capable of read operations.  This does not
		 * indicate if such operations will return useful data, see canRead for
		 * that.
		 */
		virtual bool isReadable() = 0;

		/**
		 * Indicates if the stream is capable of write operations.  This does
		 * not indicate if such operations will succeed or fail, see canWrite
		 * for that.
		 */
		virtual bool isWritable() = 0;

		/**
		 * Indicates if the stream is capable of seek operations.  This is
		 * generally false for non-blocking streams.  Some buffered streams may
		 * support limited in-buffer seeking.
		 */
		virtual bool isSeekable() = 0;

		virtual bool isBlocking() = 0;
		virtual void setBlocking( bool bBlocking=true ) = 0;

	public: // Filters


	private:

	};
}

#endif