Google Custom Search

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

A BPositionIO derived class that works on memory buffers. More...

Inheritance diagram for BMemoryIO:

BPositionIO BDataIO List of all members.

Public Member Functions

 BMemoryIO (const void *data, size_t length)
 Create a read-only object.
 BMemoryIO (void *data, size_t length)
 Create a read/write object.
virtual status_t GetSize (off_t *size) const
 Get the size of the object or data.
virtual off_t Position () const
 Return the current position.
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)
 Read from a given position.
virtual off_t Seek (off_t position, uint32 seekMode)
 Move the cursor to a given position.
virtual status_t SetSize (off_t size)
 Resize the buffer.
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)
 Write at a given position.
virtual ~BMemoryIO ()
 The destructor does nothing.

Detailed Description

A BPositionIO derived class that works on memory buffers.

This class is used if you require access that confirms to the BPositionIO interface on memory buffers that you created. If you would like to use that interface on new buffers, have a look at BMallocIO.

This class is particularly useful if you would like to use a class or method that are written to make use of the BPositionIO interface. It might also be used for 'secure' reading and writing from buffers, since this class automatically checks the bounds of anything you might want to do.

This class reimplements the Read(), Write(), ReadAt(), Writeat(), Seek() and Position() interface from BPositionIO.


Constructor & Destructor Documentation

BMemoryIO::BMemoryIO ( void *  data,
size_t  length 
)

Create a read/write object.

Parameters:
data A pointer to the buffer to adopt.
length The size of the buffer.
See also:
BMemoryIO(const void *buffer, size_t length) for a read-only implementation.

BMemoryIO::BMemoryIO ( const void *  buffer,
size_t  length 
)

Create a read-only object.

Parameters:
buffer A pointer to the const (read-only) buffer to adopt.
length The size of the buffer.
See also:
BMemoryIO(void *buffer, size_t length) for a read-write implementation.


Member Function Documentation

status_t BPositionIO::GetSize ( off_t *  size  )  const [virtual, inherited]

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()

ssize_t BPositionIO::Read ( void *  buffer,
size_t  size 
) [virtual, inherited]

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 BMemoryIO::ReadAt ( off_t  pos,
void *  buffer,
size_t  size 
) [virtual]

Read from a given position.

Parameters:
[in] pos The offset where to start reading data.
[out] buffer The buffer to copy the read bytes into.
[in] size The size of the buffer.
Returns:
The amount of read bytes or an error code.
Return values:
B_BAD_VALUE The position is less than zero or the buffer given on construction is invalid.

Implements BPositionIO.

off_t BMemoryIO::Seek ( off_t  position,
uint32  seek_mode 
) [virtual]

Move the cursor to a given position.

Parameters:
position The position to move the cursor to.
seek_mode The mode determines where the cursor is placed. Possibilities:
  • SEEK_SET The cursor is set to position.
  • SEEK_CUR The position is added to the current position of the cursor.
  • SEEK_END The cursor is put at the end of the data, plus position added to it.
Returns:
The new position.

Implements BPositionIO.

status_t BMemoryIO::SetSize ( off_t  size  )  [virtual]

Resize the buffer.

This method does not actually resize the buffer. If the new size is greater than the size of the buffer, resizing will fail. It will only succeed if the new size is less than the size of the buffer. The buffer itself will not be resized though.

This method might be useful in some cases. If the buffer is larger than the data it holds, changing the size will enable you to use the Seek() method with the flag SEEK_END and not get an error if you read or write from that position, since you actually have a buffer at the end.

Return values:
B_OK The buffer is resized.
B_NOT_ALLOWED The buffer is read-only.
B_ERROR The size is larger than the size of the buffer.

Reimplemented from BPositionIO.

ssize_t BPositionIO::Write ( const void *  buffer,
size_t  size 
) [virtual, inherited]

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 BMemoryIO::WriteAt ( off_t  pos,
const void *  buffer,
size_t  size 
) [virtual]

Write at a given position.

Parameters:
pos The offset to write to.
buffer The buffer to copy the bytes from.
size The number of bytes to write.
Returns:
The amount of bytes written or an error code.
Return values:
B_NOT_ALLOWED The object is constructed as a read-only object.
B_BAD_VALUE The position is less than zero or the buffer given on construction is invalid.

Implements BPositionIO.


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