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