Loading...
Searching...
No Matches
Public Member Functions | List of all members
BMemoryIO Class Reference

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

Inherits BPositionIO.

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 ~BMemoryIO ()
 The destructor does nothing.
 
virtual off_t Position () const
 Return the 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 WriteAt (off_t position, const void *buffer, size_t size)
 Write at a given position.
 
- Public Member Functions inherited from BPositionIO
 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.
 

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.

Since
BeOS R3

Constructor & Destructor Documentation

◆ BMemoryIO() [1/2]

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

Create a read/write object.

Parameters
dataA pointer to the buffer to adopt.
lengthThe size of the buffer.
See also
BMemoryIO(const void *buffer, size_t length) for a read-only implementation.
Since
BeOS R3

◆ BMemoryIO() [2/2]

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

Create a read-only object.

Parameters
bufferA pointer to the const (read-only) buffer to adopt.
lengthThe size of the buffer.
See also
BMemoryIO(void *buffer, size_t length) for a read-write implementation.
Since
BeOS R3

◆ ~BMemoryIO()

BMemoryIO::~BMemoryIO ( )
virtual

The destructor does nothing.

Since
BeOS R3

Member Function Documentation

◆ Position()

off_t BMemoryIO::Position ( ) const
virtual

Return the current position.

Returns
The current position as an off_t.
Since
BeOS R3

Implements BPositionIO.

◆ ReadAt()

ssize_t BMemoryIO::ReadAt ( off_t  pos,
void *  buffer,
size_t  size 
)
virtual

Read from a given position.

Parameters
[in]posThe offset where to start reading data.
[out]bufferThe buffer to copy the read bytes into.
[in]sizeThe size of the buffer.
Returns
The amount of read bytes or an error code.
Return values
B_BAD_VALUEThe position is less than zero or the buffer given on construction is invalid.
Since
BeOS R3

Implements BPositionIO.

◆ Seek()

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

Move the cursor to a given position.

Parameters
positionThe position to move the cursor to.
seek_modeThe mode determines where the cursor is placed. Possibilities include:
  • 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.
Since
BeOS R3

Implements BPositionIO.

◆ SetSize()

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_OKThe buffer is resized.
B_NOT_ALLOWEDThe buffer is read-only.
B_ERRORThe size is larger than the size of the buffer.
Since
BeOS R3

Reimplemented from BPositionIO.

◆ WriteAt()

ssize_t BMemoryIO::WriteAt ( off_t  pos,
const void *  buffer,
size_t  size 
)
virtual

Write at a given position.

Parameters
posThe offset to write to.
bufferThe buffer to copy the bytes from.
sizeThe number of bytes to write.
Returns
The amount of bytes written or an error code.
Return values
B_NOT_ALLOWEDThe object is constructed as a read-only object.
B_BAD_VALUEThe position is less than zero or the buffer given on construction is invalid.
Since
BeOS R3

Implements BPositionIO.