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