Abstract interface that provides advanced read, write and seek access to data. More...
Inherits BDataIO.
Inherited by BBitmapStream, BBufferIO, BFile, BMallocIO, and BMemoryIO.
Public Member Functions | |
BPositionIO () | |
This constructor does nothing. | |
virtual | ~BPositionIO () |
This destructor does nothing. | |
virtual status_t | GetSize (off_t *size) const |
Get the size of the object or data. | |
virtual off_t | Position () const =0 |
Pure virtual to return the current position of the cursor. | |
virtual ssize_t | Read (void *buffer, size_t size) |
Read data from current position. | |
virtual ssize_t | ReadAt (off_t position, void *buffer, size_t size)=0 |
Pure virtual to read data from a certain position. | |
status_t | ReadAtExactly (off_t position, void *buffer, size_t size, size_t *_bytesRead=NULL) |
Reads an exact amount of data from the object at the specified position into a buffer. | |
virtual off_t | Seek (off_t position, uint32 seekMode)=0 |
Pure virtual to move the cursor to a certain position. | |
virtual status_t | SetSize (off_t size) |
Set the size of the object or data. | |
virtual ssize_t | Write (const void *buffer, size_t size) |
Write data to the current position. | |
virtual ssize_t | WriteAt (off_t position, const void *buffer, size_t size)=0 |
Pure virtual to write data to a certain position. | |
status_t | WriteAtExactly (off_t position, const void *buffer, size_t size, size_t *_bytesWritten=NULL) |
Writes an exact amount of data from a buffer to the object at the specified position. | |
Public Member Functions inherited from BDataIO | |
BDataIO () | |
This constructor does nothing. | |
virtual | ~BDataIO () |
This destructor does nothing. | |
virtual status_t | Flush () |
Writes pending data to underlying storage. | |
virtual ssize_t | Read (void *buffer, size_t size) |
Reads data from the object into a buffer. | |
status_t | ReadExactly (void *buffer, size_t size, size_t *_bytesRead=NULL) |
Reads an exact amount of data from the object into a buffer. | |
virtual ssize_t | Write (const void *buffer, size_t size) |
Writes data from a buffer to the object. | |
status_t | WriteExactly (const void *buffer, size_t size, size_t *_bytesWritten=NULL) |
Writes an exact amount of data from a buffer to the object. | |
Abstract interface that provides advanced read, write and seek access to data.
The interface of this object applies to objects or data that allows position-aware reading and writing of data. Classes that derive from this class should at least re-implement ReadAt(), WriteAt(), Seek(), Position(), SetSize() and GetSize() methods.
A good example of a form of data that can derive from this object, are files. The BFile class derives from BPositionIO and provides this interface to files. If your object or data only supports linear reading and writing, consider deriving from the base-class BDataIO.
A final note, from BDataIO this class inherits Read() and Write(). The default implementation is to read or write the data at the current position indicated by Position(). Re-implement the methods if you require a different behavior.
BPositionIO::BPositionIO | ( | ) |
This constructor does nothing.
|
virtual |
This destructor does nothing.
|
virtual |
Get the size of the object or data.
The default implementation uses Seek() with the SEEK_END
flag to determine the size of the buffer. If your data or object has a different way of determining size, reimplement this method.
Please check that NULL is not passed into size
if you reimplement it in your class.
[out] | size | The size of the object is put into this parameter. |
B_OK
on success or an error code on error.Reimplemented in BFile.
|
pure virtual |
Pure virtual to return the current position of the cursor.
Implemented in BFile, BBufferIO, BMemoryIO, BMallocIO, and BBitmapStream.
|
virtual |
Read data from current position.
This method is derived from BDataIO. The default implementation reads data from the current position of the cursor, pointed at by Position(). If you require different behaviour, please look at BDataIO::Read() for what is expected of this method.
Reimplemented from BDataIO.
Reimplemented in BFile.
|
pure virtual |
Pure virtual to read data from a certain position.
Your implementation should copy data from the position indicated by position into the buffer with the maximum size of size.
Implemented in BFile, BBitmapStream, BBufferIO, BMemoryIO, and BMallocIO.
status_t BPositionIO::ReadAtExactly | ( | off_t | position, |
void * | buffer, | ||
size_t | size, | ||
size_t * | _bytesRead = NULL |
||
) |
Reads an exact amount of data from the object at the specified position into a buffer.
This is a convenience wrapper method for ReadAt() for code that expects the exact number of bytes requested to be read. This method calls ReadAt() in a loop to read the data. It fails when ReadAt() returns an error or fails to read any more data (i.e. returns 0).
position | The object position at which to read the data. |
buffer | Pointer to pre-allocated storage of at least size bytes into which the data shall be read. Won't be dereferenced, when size is 0. |
size | The number of bytes to be read. |
_bytesRead | Optional pointer to a pre-allocated size_t into which the number of bytes actually read will be written. When the method returns B_OK this will always be size. Can be NULL . |
B_OK | All data have been read. |
B_PARTIAL_READ | ReadAt() didn't fail, but couldn't provide as many bytes as requested. |
|
pure virtual |
Pure virtual to move the cursor to a certain position.
Your implementation should move the position of the cursor to the provided point. What this actually means, depends on your object or data.
position | An integer that defines a position. |
seekMode | You will get one of the following values:
|
Implemented in BFile, BBufferIO, BMemoryIO, BMallocIO, and BBitmapStream.
|
virtual |
Set the size of the object or data.
The default implementation returns B_ERROR
. If your object or data allows the size to be changed, reimplement this method.
B_OK
if everything succeeded, else return the appropriate error code.Reimplemented in BFile, BBufferIO, BMemoryIO, BMallocIO, and BBitmapStream.
|
virtual |
Write data to the current position.
This method is derived from BDataIO. The default implementation writes data to the current position of the cursor, pointed at by Position(). If you require different behaviour, please look at BDataIO::Write() for what is expected of this method.
Reimplemented from BDataIO.
Reimplemented in BFile.
|
pure virtual |
Pure virtual to write data to a certain position.
Your implementation should copy data from buffer to the position indicated by buffer with the maximum size of size.
Implemented in BFile, BBitmapStream, BBufferIO, BMemoryIO, and BMallocIO.
status_t BPositionIO::WriteAtExactly | ( | off_t | position, |
const void * | buffer, | ||
size_t | size, | ||
size_t * | _bytesWritten = NULL |
||
) |
Writes an exact amount of data from a buffer to the object at the specified position.
This is a convenience wrapper method for WriteAt() for code that expects the exact number of bytes given to be written. This method calls WriteAt() in a loop to write the data. It fails when WriteAt() returns an error or fails to write any more data (i.e. returns 0).
position | The object position at which to write the data. |
buffer | Pointer to a buffer of at least size bytes containing the data to be written. Won't be dereferenced, when size is 0. |
size | The number of bytes to be written. |
_bytesWritten | Optional pointer to a pre-allocated size_t into which the number of bytes actually written will be written. When the method returns B_OK this will always be size. Can be NULL . |
B_OK | All data have been written. |
B_PARTIAL_READ | WriteAt() didn't fail, but couldn't write as many bytes as provided. |