DataIO.h revision 0d8b44e2
1/*
2 * Copyright 2005-2014, Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 */
5#ifndef _DATA_IO_H
6#define _DATA_IO_H
7
8
9#include <SupportDefs.h>
10
11
12class BDataIO {
13public:
14								BDataIO();
15	virtual						~BDataIO();
16
17	virtual	ssize_t				Read(void* buffer, size_t size);
18	virtual	ssize_t				Write(const void* buffer, size_t size);
19
20			status_t			ReadExactly(void* buffer, size_t size,
21									size_t* _bytesRead = NULL);
22			status_t			WriteExactly(const void* buffer, size_t size,
23									size_t* _bytesWritten = NULL);
24
25private:
26								BDataIO(const BDataIO&);
27			BDataIO&			operator=(const BDataIO&);
28
29	virtual	void				_ReservedDataIO1();
30	virtual	void				_ReservedDataIO2();
31	virtual	void				_ReservedDataIO3();
32	virtual	void				_ReservedDataIO4();
33	virtual	void				_ReservedDataIO5();
34	virtual	void				_ReservedDataIO6();
35	virtual	void				_ReservedDataIO7();
36	virtual	void				_ReservedDataIO8();
37	virtual	void				_ReservedDataIO9();
38	virtual	void				_ReservedDataIO10();
39	virtual	void				_ReservedDataIO11();
40	virtual	void				_ReservedDataIO12();
41
42private:
43			uint32				_reserved[2];
44};
45
46
47class BPositionIO : public BDataIO {
48public:
49								BPositionIO();
50	virtual						~BPositionIO();
51
52	// BDataIO interface (implemented via ReadAt/WriteAt)
53	virtual	ssize_t				Read(void* buffer, size_t size);
54	virtual	ssize_t				Write(const void* buffer, size_t size);
55
56	// BPositionIO interface
57	virtual	ssize_t				ReadAt(off_t position, void* buffer,
58									size_t size) = 0;
59	virtual	ssize_t				WriteAt(off_t position, const void* buffer,
60									size_t size) = 0;
61
62	virtual	off_t				Seek(off_t position, uint32 seekMode) = 0;
63	virtual	off_t				Position() const = 0;
64
65	virtual	status_t			SetSize(off_t size);
66	virtual	status_t			GetSize(off_t* size) const;
67
68private:
69	virtual	void				_ReservedPositionIO2();
70	virtual	void				_ReservedPositionIO3();
71	virtual	void				_ReservedPositionIO4();
72	virtual	void				_ReservedPositionIO5();
73	virtual	void				_ReservedPositionIO6();
74	virtual	void				_ReservedPositionIO7();
75	virtual	void				_ReservedPositionIO8();
76	virtual	void				_ReservedPositionIO9();
77	virtual	void				_ReservedPositionIO10();
78	virtual	void				_ReservedPositionIO11();
79	virtual	void				_ReservedPositionIO12();
80
81private:
82			uint32				_reserved[2];
83};
84
85
86class BMemoryIO : public BPositionIO {
87public:
88								BMemoryIO(void* data, size_t length);
89								BMemoryIO(const void* data, size_t length);
90	virtual						~BMemoryIO();
91
92	virtual	ssize_t				ReadAt(off_t position, void* buffer,
93									size_t size);
94	virtual	ssize_t				WriteAt(off_t position, const void* buffer,
95									size_t size);
96
97	virtual	off_t				Seek(off_t position, uint32 seekMode);
98	virtual off_t				Position() const;
99
100	virtual	status_t			SetSize(off_t size);
101
102private:
103								BMemoryIO(const BMemoryIO&);
104			BMemoryIO&			operator=(const BMemoryIO&);
105
106	virtual	void				_ReservedMemoryIO1();
107	virtual	void				_ReservedMemoryIO2();
108
109private:
110			bool				fReadOnly;
111			char*				fBuffer;
112			size_t				fLength;
113			size_t				fBufferSize;
114			size_t				fPosition;
115
116			uint32				_reserved[1];
117};
118
119
120class BMallocIO : public BPositionIO {
121public:
122								BMallocIO();
123	virtual						~BMallocIO();
124
125	virtual	ssize_t				ReadAt(off_t position, void* buffer,
126									size_t size);
127	virtual	ssize_t				WriteAt(off_t position, const void* buffer,
128									size_t size);
129
130	virtual	off_t				Seek(off_t position, uint32 seekMode);
131	virtual	off_t				Position() const;
132
133	virtual	status_t			SetSize(off_t size);
134
135	// BMallocIO interface
136			void				SetBlockSize(size_t blockSize);
137
138			const void*			Buffer() const;
139			size_t				BufferLength() const;
140
141private:
142								BMallocIO(const BMallocIO&);
143			BMallocIO&			operator=(const BMallocIO&);
144
145	virtual	void				_ReservedMallocIO1();
146	virtual void				_ReservedMallocIO2();
147
148private:
149			size_t				fBlockSize;
150			size_t				fMallocSize;
151			size_t				fLength;
152			char*				fData;
153			off_t				fPosition;
154
155			uint32				_reserved[1];
156};
157
158
159#endif	// _DATA_IO_H
160