BMemoryIO Class Reference

#include <DataIO.h>

Inheritance diagram for BMemoryIO:

BPositionIO BDataIO List of all members.

Detailed Description

BMemoryIO represents a buffer of memory.

You assign the buffer to a BMemoryIO object upon construction.


Public Member Functions

 BMemoryIO (void *p, size_t len)
 BMemoryIO (const void *p, size_t len)
virtual ~BMemoryIO ()
virtual ssize_t ReadAt (off_t pos, void *buffer, size_t size)
virtual ssize_t WriteAt (off_t pos, const void *buffer, size_t size)
virtual off_t Seek (off_t pos, uint32 seek_mode)
virtual off_t Position () const
virtual status_t SetSize (off_t size)


Constructor & Destructor Documentation

BMemoryIO void *  p,
size_t  len
 

The BMemoryIO constructor assigns the object a buffer p with at least len of available memory.

BMemoryIO const void *  p,
size_t  len
 

The BMemoryIO constructor assigns the object a buffer p with at least len of available memory. If the buffer is declared const, the object is read-only; calls to Write() and WriteAt() will fail. Otherwise, the buffer can be both read and written. In either case, the caller retains responsibility for the buffer; the BMemoryIO object won't free it.

~BMemoryIO  )  [virtual]
 

The BMemoryIO destructor does nothing.


Member Function Documentation

off_t Position void   )  const [virtual]
 

Returns:
The current position as an offset in bytes from the beginning of allocated memory.

Implements BPositionIO.

ssize_t ReadAt off_t  pos,
void *  buffer,
size_t  size
[virtual]
 

Copies up to size bytes of data from the object into the buffer and returns the actual number of bytes placed in the buffer. The data is read beginning at the pos offset.

This function doesn't read beyond the end of the data. If there are fewer than size of data available at the pos offset, it reads only through the last data byte and returns a smaller number than size. If pos is out of range, it returns 0.

Implements BPositionIO.

off_t Seek off_t  pos,
uint32  seek_mode
[virtual]
 

Sets the position in the data buffer where the Read() and Write() functions (inherited from BPositionIO) begin reading and writing. How the pos argument is understood depends on the seek_mode flag. There are three modes:

  • SEEK_SET. The pos passed is an offset from the beginning of allocated memory; in other words, the current position is set to pos. For this mode, pos should be a positive value.

  • SEEK_CUR. The pos argument is an offset from the current position; the value of the argument is added to the current position.

  • SEEK_END. The pos argument is an offset from the end of the object's data buffer. In this mode the pos argument must be negative.

Returns:
The current position as an offset in bytes from the beginning of allocated memory.

Implements BPositionIO.

status_t SetSize off_t  size  )  [virtual]
 

Reimplemented from BPositionIO.

ssize_t WriteAt off_t  pos,
const void *  buffer,
size_t  size
[virtual]
 

Copies size bytes of data from buffer into allocated memory beginning at pos, and returns the number of bytes written.

WriteAt() won't write outside the memory buffer. If pos is beyond the end of the buffer, it returns 0. If the object is read-only, it returns B_NOT_ALLOWED.

Implements BPositionIO.


Copyright 2005 by yellowTAB GmbH, Be Inc., Palm Source Inc. and their respective legal successors
All rights reserved.