Added a buffered DataIO subclass.

* Only the read path is tested so far.
This commit is contained in:
Axel Dörfler
2011-11-21 23:55:13 +01:00
parent 0cd972316d
commit 29e07dd0eb
3 changed files with 282 additions and 1 deletions
+56
View File
@@ -0,0 +1,56 @@
/*
* Copyright 2011, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _BUFFERED_DATA_IO_H
#define _BUFFERED_DATA_IO_H
#include <DataIO.h>
class BBufferedDataIO : public BDataIO {
public:
BBufferedDataIO(BDataIO& stream,
size_t bufferSize = 65536L,
bool ownsStream = true,
bool partialReads = false);
virtual ~BBufferedDataIO();
status_t InitCheck() const;
BDataIO* Stream() const;
size_t BufferSize() const;
bool OwnsStream() const;
void SetOwnsStream(bool ownsStream);
status_t Flush();
// BDataIO interface
virtual ssize_t Read(void* buffer, size_t size);
virtual ssize_t Write(const void* buffer, size_t size);
private:
virtual status_t _Reserved0(void*);
virtual status_t _Reserved1(void*);
virtual status_t _Reserved2(void*);
virtual status_t _Reserved3(void*);
virtual status_t _Reserved4(void*);
private:
BDataIO& fStream;
uint8* fBuffer;
size_t fBufferSize;
size_t fPosition;
size_t fSize;
uint32 _reserved_ints[4];
bool fDirty;
bool fOwnsStream;
bool fPartialReads;
bool _reserved_bools[5];
};
#endif // _BUFFERED_DATA_IO_H