BPositionIO¶
Constructor and Destructor¶
BPositionIO()
BPositionIO()
BPositionIO::BPositionIO()
Does nothing. Constructors in derived classes should initialize the object to default values—for example, set the current position to the beginning of the data.
~BPositionIO()
Does nothing.
Member Functions¶
Read(), ReadAt()
“Read(), ReadAt()”
virtual ssize_t BPositionIO::Read(void *buffer, size_t numBytes)
virtual ssize_t BPositionIO::ReadAt(off_t position, void *buffer, size_t numBytes) = 0
Read() copies numBytes bytes of data from the object to the buffer.
It returns the number of bytes actually read (which may be 0) or an error code if something goes
wrong. Read() is implemented using Seek()
, ReadAt(),
and BPositionIO::Position()
, all of which are pure virtual functions.
ReadAt() is a pure virtual that must be implemented by derived classes to read numBytes bytes of data beginning at position in the data source, and to place them in the buffer. It should return the number of bytes actually read, or an error code if something goes wrong.
Seek(), Position()
“Seek(), Position()”
virtual off_t BPositionIO::Seek(off_t position, int32 mode) = 0
virtual off_t BPositionIO::Position() const = 0
Seek() is implemented by derived classes to modify the current position maintained by the
object. The current position is an offset in bytes from the beginning of the object’s data. How the
{hparam{position
argument is interpreted will depend on the mode flag. Three possible
modes should be supported:
Constant |
Description |
---|---|
|
The position passed is an offset from the beginning of allocated memory; in other words, the current position should be set to position. |
|
The position argument is an offset from the current position; the current position should be incremented by position. |
|
The position argument is an offset from the end of the data; the current position should be the sum of position plus the number of bytes in the data. |
For the SEEK_SET
mode, position should be a positive value. The other modes permit negative offsets.
Seek() should return the new position.
Position() should return the current position.
SetSize()
SetSize()
virtual status_t BPositionIO::SetSize(off_t numBytes)
Returns B_ERROR
to indicate that, in general, BPositionIO objects can’t set
the amount of memory in the repositories they represent. However, the BMallocIO
class
in this kit and BFile
in the “Storage Kit” implement SetSize() functions
that override this default.
Write(), WriteAt()
virtual ssize_t BPositionIO::Write(const void *buffer, size_t numBytes)
virtual ssize_t BPositionIO::WriteAt(off_t position, const void *buffer, size_t numBytes) = 0
Write() copies numBytes bytes of data from the object into the
buffer. It returns the number of bytes actually written (which may be 0) or an error code
if something goes wrong. Write() is implemented using Seek()
,
Position()
, and {hmethod}WriteAt()`, all of which are pure virtual
functions.
WriteAt() is a pure virtual that must be implemented by derived classes to copy numBytes bytes of data from buffer and write them into the object, starting at byte position within the object. It should return the number of bytes actually read, or an error code if something goes wrong.