Exiv2: Exiv2::MemIo Class Reference

- Main Page
- Namespaces
- Classes
- Files
- Examples

- Search for |

- Alphabetical List
- Class List
- Class Hierarchy
- Class Members

# Exiv2::MemIo Class Reference

Provides binary IO on blocks of memory by implementing the BasicIo interface. A copy-on-write implementation ensures that the data passed in is only copied when necessary, i.e., as soon as data is written to the MemIo. The original data is only used for reading. If writes are performed, the changed data can be retrieved using the read methods (since the data used in construction is never modified). More...

`#include <basicio.hpp>`

Inheritance diagram for Exiv2::MemIo:

[legend]
Collaboration diagram for Exiv2::MemIo:

[legend]

List of all members.

## Public Member Functions
Creators
| MemIo ()
| Default constructor that results in an empty object.
| MemIo (const byte *data, long size)
| Constructor that accepts a block of memory. A copy-on-write algorithm allows read operations directly from the original data and will create a copy of the buffer on the first write operation.
| ~MemIo ()
| Destructor. Releases all managed memory.
Manipulators
virtual int | open ()
| Memory IO is always open for reading and writing. This method therefore only resets the IO position to the start.
virtual int | close ()
| Does nothing on MemIo objects.
virtual long | write (const byte *data, long wcount)
| Write data to the memory block. If needed, the size of the internal memory block is expanded. The IO position is advanced by the number of bytes written.
virtual long | write (BasicIo &src)
| Write data that is read from another BasicIo instance to the memory block. If needed, the size of the internal memory block is expanded. The IO position is advanced by the number of bytes written.
virtual int | putb (byte data)
| Write one byte to the memory block. The IO position is advanced by one byte.
virtual DataBuf | read (long rcount)
| Read data from the memory block. Reading starts at the current IO position and the position is advanced by the number of bytes read.
virtual long | read (byte *buf, long rcount)
| Read data from the memory block. Reading starts at the current IO position and the position is advanced by the number of bytes read.
virtual int | getb ()
| Read one byte from the memory block. The IO position is advanced by one byte.
virtual void | transfer (BasicIo &src)
| Clear the memory block and then transfer data from the src BasicIo object into a new block of memory.
virtual int | seek (long offset, Position pos)
| Move the current IO position.
virtual const byte * | mmap ()
| Allow direct access to the underlying data buffer. The buffer is not protected against write access except for the const specifier.
virtual void | munmap ()
| Remove a mapping established with mmap().
Accessors
virtual long | tell () const
| Get the current IO position.
virtual long | size () const
| Get the current memory buffer size in bytes.
virtual bool | isopen () const
| Always returns true.
virtual int | error () const
| Always returns 0.
virtual bool | eof () const
| Returns true if the IO position has reach the end, otherwise false.
virtual std::string | path () const
| Returns a dummy path, indicating that memory access is used.
virtual BasicIo::AutoPtr | temporary () const
| Returns a temporary data storage location. Currently returns an empty MemIo object, but callers should not rely on this behavior since it may change.

## Detailed Description

Provides binary IO on blocks of memory by implementing the BasicIo interface. A copy-on-write implementation ensures that the data passed in is only copied when necessary, i.e., as soon as data is written to the MemIo. The original data is only used for reading. If writes are performed, the changed data can be retrieved using the read methods (since the data used in construction is never modified).

Note:
  If read only usage of this class is common, it might be worth creating a specialized readonly class or changing this one to have a readonly mode.

## Constructor & Destructor Documentation

Exiv2::MemIo::MemIo | ( | const byte * | data,
|  | long | size |
| ) |  |  |

Constructor that accepts a block of memory. A copy-on-write algorithm allows read operations directly from the original data and will create a copy of the buffer on the first write operation.

Parameters:

  | data | Pointer to data. Data must be at least size bytes long
  | size | Number of bytes to copy.

## Member Function Documentation

virtual int Exiv2::MemIo::open | ( |  | ) | `[virtual]`

Memory IO is always open for reading and writing. This method therefore only resets the IO position to the start.

Returns:
  0

Implements Exiv2::BasicIo.

virtual int Exiv2::MemIo::close | ( |  | ) | `[virtual]`

Does nothing on MemIo objects.

Returns:
  0

Implements Exiv2::BasicIo.

virtual long Exiv2::MemIo::write | ( | const byte * | data,
|  | long | wcount |
| ) |  |  | `[virtual]`

Write data to the memory block. If needed, the size of the internal memory block is expanded. The IO position is advanced by the number of bytes written.

Parameters:

  | data | Pointer to data. Data must be at least wcount bytes long
  | wcount | Number of bytes to be written.

Returns:
  Number of bytes written to the memory block successfully;
  0 if failure;

Implements Exiv2::BasicIo.

virtual long Exiv2::MemIo::write | ( | BasicIo & | src | ) | `[virtual]`

Write data that is read from another BasicIo instance to the memory block. If needed, the size of the internal memory block is expanded. The IO position is advanced by the number of bytes written.

Parameters:

  | src | Reference to another BasicIo instance. Reading start at the source's current IO position

Returns:
  Number of bytes written to the memory block successfully;
  0 if failure;

Implements Exiv2::BasicIo.

virtual int Exiv2::MemIo::putb | ( | byte | data | ) | `[virtual]`

Write one byte to the memory block. The IO position is advanced by one byte.

Parameters:

  | data | The single byte to be written.

Returns:
  The value of the byte written if successful;
  EOF if failure;

Implements Exiv2::BasicIo.

virtual DataBuf Exiv2::MemIo::read | ( | long | rcount | ) | `[virtual]`

Read data from the memory block. Reading starts at the current IO position and the position is advanced by the number of bytes read.

Parameters:

  | rcount | Maximum number of bytes to read. Fewer bytes may be read if rcount bytes are not available.

Returns:
  DataBuf instance containing the bytes read. Use the DataBuf::size_ member to find the number of bytes read. DataBuf::size_ will be 0 on failure.

Implements Exiv2::BasicIo.

virtual long Exiv2::MemIo::read | ( | byte * | buf,
|  | long | rcount |
| ) |  |  | `[virtual]`

Read data from the memory block. Reading starts at the current IO position and the position is advanced by the number of bytes read.

Parameters:

  | buf | Pointer to a block of memory into which the read data is stored. The memory block must be at least rcount bytes long.
  | rcount | Maximum number of bytes to read. Fewer bytes may be read if rcount bytes are not available.

Returns:
  Number of bytes read from the memory block successfully;
  0 if failure;

Implements Exiv2::BasicIo.

virtual int Exiv2::MemIo::getb | ( |  | ) | `[virtual]`

Read one byte from the memory block. The IO position is advanced by one byte.

Returns:
  The byte read from the memory block if successful;
  EOF if failure;

Implements Exiv2::BasicIo.

virtual void Exiv2::MemIo::transfer | ( | BasicIo & | src | ) | `[virtual]`

Clear the memory block and then transfer data from the src BasicIo object into a new block of memory.

This method is optimized to simply swap memory block if the source object is another MemIo instance. The source BasicIo instance is invalidated by this operation and should not be used after this method returns. This method exists primarily to be used with the BasicIo::temporary() method.

Parameters:

  | src | Reference to another BasicIo instance. The entire contents of src are transferred to this object. The src object is invalidated by the method.

Exceptions:

  | Error | In case of failure

Implements Exiv2::BasicIo.

virtual int Exiv2::MemIo::seek | ( | long | offset,
|  | Position | pos |
| ) |  |  | `[virtual]`

Move the current IO position.

Parameters:

  | offset | Number of bytes to move the IO position relative to the starting position specified by pos
  | pos | Position from which the seek should start

Returns:
  0 if successful;
  Nonzero if failure;

Implements Exiv2::BasicIo.

virtual const byte* Exiv2::MemIo::mmap | ( |  | ) | `[inline, virtual]`

Allow direct access to the underlying data buffer. The buffer is not protected against write access except for the const specifier.

Note:
  The application must ensure that the memory pointed to by the returned pointer remains valid and allocated as long as the MemIo object is in scope.

Implements Exiv2::BasicIo.

virtual long Exiv2::MemIo::tell | ( |  | ) | const`[virtual]`

Get the current IO position.

Returns:
  Offset from the start of the memory block

Implements Exiv2::BasicIo.

virtual long Exiv2::MemIo::size | ( |  | ) | const`[virtual]`

Get the current memory buffer size in bytes.

Returns:
  Size of the in memory data in bytes;
  -1 if failure;

Implements Exiv2::BasicIo.

virtual BasicIo::AutoPtr Exiv2::MemIo::temporary | ( |  | ) | const`[virtual]`

Returns a temporary data storage location. Currently returns an empty MemIo object, but callers should not rely on this behavior since it may change.

Returns:
  An instance of BasicIo

Implements Exiv2::BasicIo.

The documentation for this class was generated from the following file:

- basicio.hpp