Exiv2
|
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>
Classes | |
class | Impl |
Internal Pimpl structure of class MemIo. More... | |
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. More... | |
~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. More... | |
virtual int | close () |
Does nothing on MemIo objects. More... | |
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. More... | |
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. More... | |
virtual int | putb (byte data) |
Write one byte to the memory block. The IO position is advanced by one byte. More... | |
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. More... | |
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. More... | |
virtual int | getb () |
Read one byte from the memory block. The IO position is advanced by one byte. More... | |
virtual void | transfer (BasicIo &src) |
Clear the memory block and then transfer data from the src BasicIo object into a new block of memory. More... | |
virtual int | seek (long offset, Position pos) |
Move the current IO position. More... | |
virtual byte * | mmap (bool=false) |
Allow direct access to the underlying data buffer. The buffer is not protected against write access in any way, the argument is ignored. More... | |
virtual int | munmap () |
Remove a mapping established with mmap(). If the mapped area is writeable, this ensures that changes are written back. More... | |
Accessors | |
virtual long | tell () const |
Get the current IO position. More... | |
virtual long | size () const |
Get the current memory buffer size in bytes. More... | |
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. More... | |
![]() | |
virtual | ~BasicIo () |
Destructor. | |
Additional Inherited Members | |
![]() | |
enum | Position { beg, cur, end } |
Seek starting positions. | |
typedef std::auto_ptr< BasicIo > | AutoPtr |
BasicIo auto_ptr type. | |
![]() | |
BasicIo () | |
Default Constructor. | |
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).
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.
data | Pointer to data. Data must be at least size bytes long |
size | Number of bytes to copy. |
|
virtual |
|
virtual |
Read one byte from the memory block. The IO position is advanced by one byte.
Implements Exiv2::BasicIo.
References Exiv2::MemIo::Impl::data_, Exiv2::MemIo::Impl::eof_, Exiv2::MemIo::Impl::idx_, and Exiv2::MemIo::Impl::size_.
|
virtual |
Allow direct access to the underlying data buffer. The buffer is not protected against write access in any way, the argument is ignored.
Implements Exiv2::BasicIo.
References Exiv2::MemIo::Impl::data_.
Referenced by Exiv2::Internal::TiffBinaryArray::doWrite(), and Exiv2::ExifParser::encode().
|
virtual |
Remove a mapping established with mmap(). If the mapped area is writeable, this ensures that changes are written back.
Implements Exiv2::BasicIo.
|
virtual |
Memory IO is always open for reading and writing. This method therefore only resets the IO position to the start.
Implements Exiv2::BasicIo.
References Exiv2::MemIo::Impl::eof_, and Exiv2::MemIo::Impl::idx_.
|
virtual |
Write one byte to the memory block. The IO position is advanced by one byte.
data | The single byte to be written. |
Implements Exiv2::BasicIo.
References Exiv2::MemIo::Impl::data_, Exiv2::MemIo::Impl::idx_, Exiv2::MemIo::Impl::isMalloced_, and Exiv2::MemIo::Impl::reserve().
|
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.
rcount | Maximum number of bytes to read. Fewer bytes may be read if rcount bytes are not available. |
Implements Exiv2::BasicIo.
References Exiv2::DataBuf::pData_, and Exiv2::DataBuf::size_.
|
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.
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. |
Implements Exiv2::BasicIo.
References Exiv2::MemIo::Impl::data_, Exiv2::MemIo::Impl::eof_, EXV_MIN, Exiv2::MemIo::Impl::idx_, and Exiv2::MemIo::Impl::size_.
|
virtual |
Move the current IO position.
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 |
Implements Exiv2::BasicIo.
References Exiv2::MemIo::Impl::eof_, Exiv2::MemIo::Impl::idx_, and Exiv2::MemIo::Impl::size_.
|
virtual |
Get the current memory buffer size in bytes.
Implements Exiv2::BasicIo.
References Exiv2::MemIo::Impl::size_.
Referenced by Exiv2::Internal::TiffBinaryArray::doWrite(), Exiv2::ExifParser::encode(), and Exiv2::MemIo::Impl::reserve().
|
virtual |
Get the current IO position.
Implements Exiv2::BasicIo.
References Exiv2::MemIo::Impl::idx_.
|
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.
Implements Exiv2::BasicIo.
|
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.
src | Reference to another BasicIo instance. The entire contents of src are transferred to this object. The src object is invalidated by the method. |
Error | In case of failure |
Implements Exiv2::BasicIo.
References Exiv2::BasicIo::close(), Exiv2::MemIo::Impl::data_, Exiv2::BasicIo::error(), error(), Exiv2::MemIo::Impl::idx_, Exiv2::MemIo::Impl::isMalloced_, Exiv2::BasicIo::open(), Exiv2::BasicIo::path(), Exiv2::MemIo::Impl::size_, Exiv2::strError(), and write().
|
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.
data | Pointer to data. Data must be at least wcount bytes long |
wcount | Number of bytes to be written. |
Implements Exiv2::BasicIo.
References Exiv2::MemIo::Impl::data_, Exiv2::MemIo::Impl::idx_, Exiv2::MemIo::Impl::isMalloced_, and Exiv2::MemIo::Impl::reserve().
Referenced by transfer(), and write().
|
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.
src | Reference to another BasicIo instance. Reading start at the source's current IO position |
Implements Exiv2::BasicIo.
References Exiv2::BasicIo::isopen(), Exiv2::BasicIo::read(), and write().