Loading...
Searching...
No Matches
Exiv2::BasicIo Class Referenceabstract

An interface for simple binary IO. More...

`#include <basicio.hpp>`

Inheritance diagram for Exiv2::BasicIo:
[legend]

## Public Types

enum | Position { beg , cur , end }
| Seek starting positions.
using | UniquePtr = std::unique_ptr<BasicIo>
| BasicIo auto_ptr type.

## Public Member Functions

Creators
virtual | ~BasicIo ()=default
| Destructor.
Manipulators
virtual int | open ()=0
| Open the IO source using the default access mode. The default mode should allow for reading and writing.
virtual int | close ()=0
| Close the IO source. After closing a BasicIo instance can not be read or written. Closing flushes any unwritten data. It is safe to call close on a closed instance.
virtual size_t | write (const byte *data, size_t wcount)=0
| Write data to the IO source. Current IO position is advanced by the number of bytes written.
virtual size_t | write (BasicIo &src)=0
| Write data that is read from another BasicIo instance to the IO source. Current IO position is advanced by the number of bytes written.
virtual int | putb (byte data)=0
| Write one byte to the IO source. Current IO position is advanced by one byte.
virtual DataBuf | read (size_t rcount)=0
| Read data from the IO source. Reading starts at the current IO position and the position is advanced by the number of bytes read.
virtual size_t | read (byte *buf, size_t rcount)=0
| Read data from the IO source. Reading starts at the current IO position and the position is advanced by the number of bytes read.
void | readOrThrow (byte *buf, size_t rcount, ErrorCode err=ErrorCode::kerCorruptedMetadata)
| Safe version of read() that checks for errors and throws an exception if the read was unsuccessful.
virtual int | getb ()=0
| Read one byte from the IO source. Current IO position is advanced by one byte.
virtual void | transfer (BasicIo &src)=0
| Remove all data from this object's IO source and then transfer data from the src BasicIo object into this object.
virtual int | seek (int64_t offset, Position pos)=0
| Move the current IO position.
void | seekOrThrow (int64_t offset, Position pos, ErrorCode err)
| Safe version of seek() that checks for errors and throws an exception if the seek was unsuccessful.
virtual byte * | mmap (bool isWriteable=false)=0
| Direct access to the IO data. For files, this is done by mapping the file into the process's address space; for memory blocks, this allows direct access to the memory block.
virtual int | munmap ()=0
| Remove a mapping established with mmap(). If the mapped area is writeable, this ensures that changes are written back.

## Accessors

byte * | bigBlock_ {}
| this is allocated and populated by mmap()
virtual size_t | tell () const =0
| Get the current IO position.
virtual size_t | size () const =0
| Get the current size of the IO source in bytes.
virtual bool | isopen () const =0
| Returns true if the IO source is open, otherwise false.
virtual int | error () const =0
| Returns 0 if the IO source is in a valid state, otherwise nonzero.
virtual bool | eof () const =0
| Returns true if the IO position has reached the end, otherwise false.
virtual const std::string & | path () const noexcept=0
| Return the path to the IO resource. Often used to form comprehensive error messages where only a BasicIo instance is available.
virtual void | populateFakeData ()=0
| Mark all the bNone blocks to bKnow. This avoids allocating memory for parts of the file that contain image-date (non-metadata/pixel data).

## Detailed Description

An interface for simple binary IO.

Designed to have semantics and names similar to those of C style FILE* operations. Subclasses should all behave the same so that they can be interchanged.

## Member Function Documentation

## close()

virtual int Exiv2::BasicIo::close | ( |  | ) |

pure virtual

Close the IO source. After closing a BasicIo instance can not be read or written. Closing flushes any unwritten data. It is safe to call close on a closed instance.

Returns
  0 if successful;
  Nonzero if failure.

Implemented in Exiv2::FileIo, Exiv2::MemIo, and Exiv2::RemoteIo.

Referenced by Exiv2::MemIo::transfer(), and Exiv2::RemoteIo::transfer().

## eof()

virtual bool Exiv2::BasicIo::eof | ( |  | ) | const

nodiscard pure virtual

Returns true if the IO position has reached the end, otherwise false.

Implemented in Exiv2::FileIo, Exiv2::MemIo, and Exiv2::RemoteIo.

Referenced by Exiv2::isAsfType(), Exiv2::isBmpType(), Exiv2::isCr2Type(), Exiv2::isCrwType(), Exiv2::ExvImage::isExvType, Exiv2::isGifType(), Exiv2::isJp2Type(), Exiv2::JpegImage::isJpegType, Exiv2::isMkvType(), Exiv2::isMrwType(), Exiv2::isOrfType(), Exiv2::isPgfType(), Exiv2::isPsdType(), Exiv2::isQTimeType(), Exiv2::isRafType(), Exiv2::isRiffType(), Exiv2::isRw2Type(), Exiv2::isTgaType(), Exiv2::isTiffType(), Exiv2::isXmpType(), and Exiv2::RemoteIo::write().

## error()

virtual int Exiv2::BasicIo::error | ( |  | ) | const

nodiscard pure virtual

Returns 0 if the IO source is in a valid state, otherwise nonzero.

Implemented in Exiv2::FileIo, Exiv2::MemIo, and Exiv2::RemoteIo.

Referenced by Exiv2::isAsfType(), Exiv2::isBmpType(), Exiv2::isCr2Type(), Exiv2::isCrwType(), Exiv2::isEpsType(), Exiv2::ExvImage::isExvType, Exiv2::isGifType(), Exiv2::isJp2Type(), Exiv2::JpegImage::isJpegType, Exiv2::isMkvType(), Exiv2::isMrwType(), Exiv2::isOrfType(), Exiv2::isPgfType(), Exiv2::isPsdType(), Exiv2::isQTimeType(), Exiv2::isRafType(), Exiv2::isRiffType(), Exiv2::isRw2Type(), Exiv2::isTgaType(), Exiv2::isTiffType(), Exiv2::isXmpType(), readOrThrow(), Exiv2::MemIo::transfer(), Exiv2::ExvImage::writeHeader(), and Exiv2::JpegImage::writeHeader().

## getb()

virtual int Exiv2::BasicIo::getb | ( |  | ) |

pure virtual

Read one byte from the IO source. Current IO position is advanced by one byte.

Returns
  The byte read from the IO source if successful;
  EOF if failure;

Implemented in Exiv2::FileIo, Exiv2::MemIo, and Exiv2::RemoteIo.

## isopen()

virtual bool Exiv2::BasicIo::isopen | ( |  | ) | const

nodiscard pure virtual

Returns true if the IO source is open, otherwise false.

Implemented in Exiv2::FileIo, Exiv2::MemIo, and Exiv2::RemoteIo.

Referenced by Exiv2::MemIo::write(), and Exiv2::RemoteIo::write().

## mmap()

virtual byte * Exiv2::BasicIo::mmap | ( | bool | isWriteable = false | ) |

pure virtual

Direct access to the IO data. For files, this is done by mapping the file into the process's address space; for memory blocks, this allows direct access to the memory block.

Parameters

  isWriteable | Set to true if the mapped area should be writeable (default is false).

Returns
  A pointer to the mapped area.

Exceptions

  Error | In case of failure.

Implemented in Exiv2::FileIo, Exiv2::MemIo, and Exiv2::RemoteIo.

## munmap()

virtual int Exiv2::BasicIo::munmap | ( |  | ) |

pure virtual

Remove a mapping established with mmap(). If the mapped area is writeable, this ensures that changes are written back.

Returns
  0 if successful;
  Nonzero if failure;

Implemented in Exiv2::FileIo, Exiv2::MemIo, and Exiv2::RemoteIo.

## open()

virtual int Exiv2::BasicIo::open | ( |  | ) |

pure virtual

Open the IO source using the default access mode. The default mode should allow for reading and writing.

This method can also be used to "reopen" an IO source which will flush any unwritten data and reset the IO position to the start. Subclasses may provide custom methods to allow for opening IO sources differently.

Returns
  0 if successful;
  Nonzero if failure.

Implemented in Exiv2::FileIo, Exiv2::MemIo, and Exiv2::RemoteIo.

Referenced by Exiv2::ImageFactory::getType(), Exiv2::ImageFactory::open(), Exiv2::MemIo::transfer(), and Exiv2::RemoteIo::transfer().

## path()

virtual const std::string & Exiv2::BasicIo::path | ( |  | ) | const

nodiscard pure virtual noexcept

Return the path to the IO resource. Often used to form comprehensive error messages where only a BasicIo instance is available.

Implemented in Exiv2::FileIo, Exiv2::MemIo, and Exiv2::RemoteIo.

Referenced by Exiv2::isTgaType(), Exiv2::ImageFactory::open(), Exiv2::RafImage::printStructure(), Exiv2::WebPImage::printStructure(), and Exiv2::MemIo::transfer().

## populateFakeData()

virtual void Exiv2::BasicIo::populateFakeData | ( |  | ) |

pure virtual

Mark all the bNone blocks to bKnow. This avoids allocating memory for parts of the file that contain image-date (non-metadata/pixel data).

Note
  This method should be only called after the concerned data (metadata) are all downloaded from the remote file to memory.

Implemented in Exiv2::FileIo, Exiv2::MemIo, and Exiv2::RemoteIo.

References populateFakeData().

Referenced by populateFakeData().

## putb()

virtual int Exiv2::BasicIo::putb | ( | byte | data | ) |

pure virtual

Write one byte to the IO source. Current 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;

Implemented in Exiv2::FileIo, Exiv2::MemIo, and Exiv2::RemoteIo.

## read() [1/2]

virtual size_t Exiv2::BasicIo::read | ( | byte * | buf,
|  | size_t | rcount )

pure virtual

Read data from the IO source. 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 IO source successfully;
  0 if failure;

Implemented in Exiv2::FileIo, Exiv2::MemIo, and Exiv2::RemoteIo.

References readOrThrow().

## read() [2/2]

virtual DataBuf Exiv2::BasicIo::read | ( | size_t | rcount | ) |

pure virtual

Read data from the IO source. 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.

Implemented in Exiv2::FileIo, Exiv2::MemIo, and Exiv2::RemoteIo.

Referenced by Exiv2::isAsfType(), Exiv2::isBmpType(), Exiv2::isCr2Type(), Exiv2::isCrwType(), Exiv2::isEpsType(), Exiv2::ExvImage::isExvType, Exiv2::isGifType(), Exiv2::isJp2Type(), Exiv2::JpegImage::isJpegType, Exiv2::isMkvType(), Exiv2::isMrwType(), Exiv2::isOrfType(), Exiv2::isPgfType(), Exiv2::isPsdType(), Exiv2::isQTimeType(), Exiv2::isRafType(), Exiv2::isRiffType(), Exiv2::isRw2Type(), Exiv2::isTgaType(), Exiv2::isTiffType(), Exiv2::isXmpType(), readOrThrow(), Exiv2::MemIo::write(), and Exiv2::RemoteIo::write().

## readOrThrow()

void Exiv2::BasicIo::readOrThrow | ( | byte * | buf,
|  | size_t | rcount,
|  | ErrorCode | err = ErrorCode::kerCorruptedMetadata )

Safe version of read() that checks for errors and throws an exception if the read was unsuccessful.

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.
  err | Error code to use if an exception is thrown.

References Exiv2::Internal::enforce(), error(), and read().

Referenced by Exiv2::isWebPType(), and read().

## seek()

virtual int Exiv2::BasicIo::seek | ( | int64_t | offset,
|  | Position | pos )

pure virtual

Move the current IO position.

Parameters

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

Returns
  0 if successful;
  Nonzero if failure;

Implemented in Exiv2::FileIo, Exiv2::MemIo, and Exiv2::RemoteIo.

References seekOrThrow().

Referenced by Exiv2::isAsfType(), Exiv2::isBmpType(), Exiv2::isCr2Type(), Exiv2::isCrwType(), Exiv2::isEpsType(), Exiv2::ExvImage::isExvType, Exiv2::isGifType(), Exiv2::isJp2Type(), Exiv2::JpegImage::isJpegType, Exiv2::isMkvType(), Exiv2::isMrwType(), Exiv2::isOrfType(), Exiv2::isPgfType(), Exiv2::isPsdType(), Exiv2::isQTimeType(), Exiv2::isRafType(), Exiv2::isRiffType(), Exiv2::isRw2Type(), Exiv2::isTgaType(), Exiv2::isTiffType(), Exiv2::isWebPType(), Exiv2::isXmpType(), seekOrThrow(), Exiv2::RemoteIo::write(), and Exiv2::Internal::OffsetWriter::writeOffsets().

## seekOrThrow()

void Exiv2::BasicIo::seekOrThrow | ( | int64_t | offset,
|  | Position | pos,
|  | ErrorCode | err )

Safe version of seek() that checks for errors and throws an exception if the seek was unsuccessful.

Parameters

  offset | Number of bytes to move the position relative to the starting position specified by pos
  pos | Position from which the seek should start
  err | Error code to use if an exception is thrown.

References Exiv2::Internal::enforce(), and seek().

Referenced by seek().

## size()

virtual size_t Exiv2::BasicIo::size | ( |  | ) | const

nodiscard pure virtual

Get the current size of the IO source in bytes.

Returns
  Size of the IO source in bytes;
  -1 if failure;

Implemented in Exiv2::FileIo, Exiv2::MemIo, and Exiv2::RemoteIo.

Referenced by Exiv2::isWebPType(), and Exiv2::RemoteIo::write().

## tell()

virtual size_t Exiv2::BasicIo::tell | ( |  | ) | const

nodiscard pure virtual

Get the current IO position.

Returns
  Offset from the start of IO

Implemented in Exiv2::FileIo, Exiv2::MemIo, and Exiv2::RemoteIo.

Referenced by Exiv2::isEpsType(), and Exiv2::isTgaType().

## transfer()

virtual void Exiv2::BasicIo::transfer | ( | BasicIo & | src | ) |

pure virtual

Remove all data from this object's IO source and then transfer data from the src BasicIo object into this object.

The source object 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

Implemented in Exiv2::FileIo, Exiv2::MemIo, Exiv2::RemoteIo, and Exiv2::XPathIo.

Referenced by Exiv2::Internal::TiffParserWorker::encode().

## write() [1/2]

virtual size_t Exiv2::BasicIo::write | ( | BasicIo & | src | ) |

pure virtual

Write data that is read from another BasicIo instance to the IO source. Current 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 IO source successfully;
  0 if failure;

Implemented in Exiv2::FileIo, Exiv2::MemIo, and Exiv2::RemoteIo.

## write() [2/2]

virtual size_t Exiv2::BasicIo::write | ( | const byte * | data,
|  | size_t | wcount )

pure virtual

Write data to the IO source. Current 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 IO source successfully;
  0 if failure;

Implemented in Exiv2::FileIo, Exiv2::MemIo, and Exiv2::RemoteIo.

Referenced by Exiv2::ExvImage::writeHeader(), Exiv2::JpegImage::writeHeader(), and Exiv2::Internal::OffsetWriter::writeOffsets().

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

- basicio.hpp
- basicio.cpp