Google Custom Search

BPositionIO Class Reference
[Support Kit(libbe.so)]

Abstract interface that provides advanced read, write and seek access to data. More...

Inheritance diagram for BPositionIO:

BDataIO BBufferIO BMallocIO BMemoryIO List of all members.

Public Member Functions

 BPositionIO ()
 This constructor 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.
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.
virtual ~BPositionIO ()
 This destructor does nothing.

Detailed Description

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 reimplement 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 baseclass 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(). Reimplement the methods if you require a different behaviour.


Member Function Documentation

status_t BPositionIO::GetSize ( off_t *  size  )  const [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.

Parameters:
[out] size The size of the object is put into this parameter.
Returns:
This method returns B_OK on success or an error code on error.
See also:
Seek()

off_t BPositionIO::Position (  )  const [pure virtual]

Pure virtual to return the current position of the cursor.

Returns:
Your implementation should return the current position of the cursor.

Implemented in BBufferIO, BMemoryIO, and BMallocIO.

ssize_t BPositionIO::Read ( void *  buffer,
size_t  size 
) [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.

Implements BDataIO.

ssize_t BPositionIO::ReadAt ( off_t  position,
void *  buffer,
size_t  size 
) [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.

Returns:
The amount of bytes actually read, or an error code.

Implemented in BBufferIO, BMemoryIO, and BMallocIO.

off_t BPositionIO::Seek ( off_t  position,
uint32  seekMode 
) [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.

Parameters:
position An integer that defines a position.
seekMode You will get one of the following values:
  • SEEK_SET Set the cursor to the position indicated by position.
  • SEEK_END Set the cursor to the end of the buffer, and go position beyond that.
  • SEEK_CUR Set the cursor the the current position plus position.
Returns:
The new position.

Implemented in BBufferIO, BMemoryIO, and BMallocIO.

status_t BPositionIO::SetSize ( off_t  size  )  [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.

Returns:
Return B_OK if everything succeeded, else return the appropriate error code.

Reimplemented in BBufferIO, BMemoryIO, and BMallocIO.

ssize_t BPositionIO::Write ( const void *  buffer,
size_t  size 
) [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.

Implements BDataIO.

ssize_t BPositionIO::WriteAt ( off_t  position,
const void *  buffer,
size_t  size 
) [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.

Returns:
The amount of bytes actually written, or an error code.

Implemented in BBufferIO, BMemoryIO, and BMallocIO.


The Haiku Book pre-R1 - BPositionIO Class Reference
Generated on 14 Feb 2008