xref: /haiku/headers/os/support/BufferIO.h (revision 4e3137c085bae361922078f123dceb92da700640)
1 /*
2  * Copyright 2007-2010 Haiku, Inc. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef _BUFFER_IO_H
6 #define _BUFFER_IO_H
7 
8 
9 #include <DataIO.h>
10 
11 
12 class BBufferIO : public BPositionIO {
13 public:
14 								BBufferIO(BPositionIO* stream,
15 									size_t bufferSize = 65536L,
16 									bool ownsStream = true);
17 	virtual						~BBufferIO();
18 
19 	// BPositionIO interface
20 	virtual	ssize_t				ReadAt(off_t pos, void* buffer, size_t size);
21 	virtual	ssize_t				WriteAt(off_t pos, const void* buffer,
22 									size_t size);
23 	virtual	off_t				Seek(off_t position, uint32 seekMode);
24 	virtual	off_t				Position() const;
25 	virtual	status_t			SetSize(off_t size);
26 	virtual	status_t			Flush();
27 
28 	// BBufferIO interface
29 			BPositionIO*		Stream() const;
30 			size_t				BufferSize() const;
31 			bool				OwnsStream() const;
32 			void				SetOwnsStream(bool ownsStream);
33 
34 			void				PrintToStream() const;
35 
36 private:
37 	virtual	status_t			_Reserved_BufferIO_0(void*);
38 	virtual	status_t			_Reserved_BufferIO_1(void*);
39 	virtual	status_t			_Reserved_BufferIO_2(void*);
40 	virtual	status_t			_Reserved_BufferIO_3(void*);
41 	virtual	status_t			_Reserved_BufferIO_4(void*);
42 
43 private:
44 			off_t				fBufferStart;
45 			BPositionIO*		fStream;
46 			char*				fBuffer;
47 			size_t				fBufferSize;
48 			size_t				fBufferUsed;
49 			off_t				fPosition;
50 
51 			uint32				_reserved_ints[4];
52 
53 			bool				fBufferIsDirty;
54 			bool				fOwnsStream;
55 
56 			bool				_reserved_bools[6];
57 };
58 
59 
60 #endif	// _BUFFER_IO_H
61