Exiv2: Exiv2::FileIo Class Reference

- Main Page
- Namespaces
- Classes
- Files
- Examples

- Search for |

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

# Exiv2::FileIo Class Reference

Provides binary file IO by implementing the BasicIo interface. More...

`#include <basicio.hpp>`

Inheritance diagram for Exiv2::FileIo:

[legend]
Collaboration diagram for Exiv2::FileIo:

[legend]

List of all members.

## Public Member Functions
Creators
| FileIo (const std::string &path)
| Constructor that accepts the file path on which IO will be performed. The constructor does not open the file, and therefore never failes.
virtual | ~FileIo ()
| Destructor. Flushes and closes an open file.
Manipulators
int | open (const std::string &mode)
| Open the file using using the specified mode.
virtual int | open ()
| Open the file using using the default access mode of "rb". This method can also be used to "reopen" a file which will flush any unwritten data and reset the IO position to the start.
virtual int | close ()
| Flush and unwritten data and close the file . It is safe to call close on an already closed instance.
virtual long | write (const byte *data, long wcount)
| Write data to the file. The file 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 file. The file position is advanced by the number of bytes written.
virtual int | putb (byte data)
| Write one byte to the file. The file position is advanced by one byte.
virtual DataBuf | read (long rcount)
| Read data from the file. Reading starts at the current file position and the position is advanced by the number of bytes read.
virtual long | read (byte *buf, long rcount)
| Read data from the file. Reading starts at the current file position and the position is advanced by the number of bytes read.
virtual int | getb ()
| Read one byte from the file. The file position is advanced by one byte.
virtual void | transfer (BasicIo &src)
| Remove the contents of the file and then transfer data from the src BasicIo object into the empty file.
virtual int | seek (long offset, Position pos)
| Move the current file position.
virtual const byte * | mmap ()
| Map the file into the process's address space. The file must be open before mmap() is called.
virtual void | munmap ()
| Remove a mapping established with mmap().
Accessors
virtual long | tell () const
| Get the current file position.
virtual long | size () const
| Flush any buffered writes and get the current file size in bytes.
virtual bool | isopen () const
| Returns true if the file is open, otherwise false.
virtual int | error () const
| Returns 0 if the file is in a valid state, otherwise nonzero.
virtual bool | eof () const
| Returns true if the file position has reach the end, otherwise false.
virtual std::string | path () const
| Returns the path of the file.
virtual BasicIo::AutoPtr | temporary () const
| Returns a temporary data storage location. The actual type returned depends upon the size of the file represented a FileIo object. For small files, a MemIo is returned while for large files a FileIo is returned. Callers should not rely on this behavior, however, since it may change.

## Detailed Description

Provides binary file IO by implementing the BasicIo interface.

## Constructor & Destructor Documentation

Exiv2::FileIo::FileIo | ( | const std::string & | path | ) |

Constructor that accepts the file path on which IO will be performed. The constructor does not open the file, and therefore never failes.

Parameters:

  | path | The full path of a file

## Member Function Documentation

int Exiv2::FileIo::open | ( | const std::string & | mode | ) |

Open the file using using the specified mode.

This method can also be used to "reopen" a file which will flush any unwritten data and reset the IO position to the start. Although files can be opened in binary or text mode, this class has only been tested carefully in binary mode.

Parameters:

  | mode | Specified that type of access allowed on the file. Valid values match those of the C fopen command exactly.

Returns:
  0 if successful;
  Nonzero if failure.

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

Open the file using using the default access mode of "rb". This method can also be used to "reopen" a file which will flush any unwritten data and reset the IO position to the start.

Returns:
  0 if successful;
  Nonzero if failure.

Implements Exiv2::BasicIo.

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

Flush and unwritten data and close the file . It is safe to call close on an already closed instance.

Returns:
  0 if successful;
  Nonzero if failure;

Implements Exiv2::BasicIo.

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

Write data to the file. The file 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 file successfully;
  0 if failure;

Implements Exiv2::BasicIo.

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

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

Implements Exiv2::BasicIo.

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

Write one byte to the file. The file 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::FileIo::read | ( | long | rcount | ) | `[virtual]`

Read data from the file. Reading starts at the current file 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::FileIo::read | ( | byte * | buf,
|  | long | rcount |
| ) |  |  | `[virtual]`

Read data from the file. Reading starts at the current file 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 file successfully;
  0 if failure;

Implements Exiv2::BasicIo.

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

Read one byte from the file. The file position is advanced by one byte.

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

Implements Exiv2::BasicIo.

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

Remove the contents of the file and then transfer data from the src BasicIo object into the empty file.

This method is optimized to simply rename the source file if the source object is another FileIo instance. The source BasicIo 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.

Note:
  If the caller doesn't have permissions to write to the file, an exception is raised and src is deleted.

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::FileIo::seek | ( | long | offset,
|  | Position | pos |
| ) |  |  | `[virtual]`

Move the current file position.

Parameters:

  | offset | Number of bytes to move the file 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::FileIo::mmap | ( |  | ) | `[virtual]`

Map the file into the process's address space. The file must be open before mmap() is called.

Note:
  The returned pointer is valid only as long as the MemIo object is in scope.

Implements Exiv2::BasicIo.

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

Get the current file position.

Returns:
  Offset from the start of the file if successful;
  -1 if failure;

Implements Exiv2::BasicIo.

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

Flush any buffered writes and get the current file size in bytes.

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

Implements Exiv2::BasicIo.

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

Returns a temporary data storage location. The actual type returned depends upon the size of the file represented a FileIo object. For small files, a MemIo is returned while for large files a FileIo is returned. Callers should not rely on this behavior, however, since it may change.

Returns:
  An instance of BasicIo on success

Exceptions:

  | Error | If opening the temporary file fails

Implements Exiv2::BasicIo.

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

- basicio.hpp