Base Framework
Public Types | Public Member Functions | Static Public Attributes | Protected Member Functions | List of all members
FileReader Class Reference

Optimal file reader. More...

#include <base/io/FileReader.h>

Inherits Object.

Public Types

typedef SequenceIterator< ReadIteratorTraits< uint8 > > ReadIterator
 

Public Member Functions

 FileReader (File &file, long long position, unsigned int windowSize=DEFAULT_WINDOW_SIZE)
 
const uint8 * getBytes () const noexcept
 
MemorySize getSize () const noexcept
 
long long getPosition () const noexcept
 
ReadIterator peek (unsigned int size)
 
void read (uint8 *buffer, unsigned int size)
 
void seek (long long position)
 
void skip (unsigned int size)
 

Static Public Attributes

static constexpr unsigned int DEFAULT_WINDOW_SIZE = 0x10000
 

Protected Member Functions

FileRegion fixRegion (const FileRegion &region) noexcept
 
void requestRegion (const FileRegion &region)
 

Detailed Description

Optimal file reader.

File reader utilizing the file mapping support.

Version
1.0

Member Typedef Documentation

◆ ReadIterator

Iterator used to traverse the elements within the current file mapping window.

Constructor & Destructor Documentation

◆ FileReader()

FileReader::FileReader ( File file,
long long  position,
unsigned int  windowSize = DEFAULT_WINDOW_SIZE 
)

Initializes the object.

Parameters
fileThe file.
positionThe initial position.
windowSizeThe preferred size of the mapping window. The actual window size used may be less or greater.

Member Function Documentation

◆ getBytes()

const uint8* FileReader::getBytes ( ) const
inlinenoexcept

Returns the bytes of the entire window.

◆ getPosition()

long long FileReader::getPosition ( ) const
inlinenoexcept

Returns the current position indexed from the beginning of the file.

◆ getSize()

MemorySize FileReader::getSize ( ) const
inlinenoexcept

Returns the available bytes.

◆ peek()

ReadIterator FileReader::peek ( unsigned int  size)
inline

Ensures that the specified number of bytes are mapped without changing the current position. Raises IOException if requested number of bytes cannot be mapped.

Parameters
sizeThe number of bytes to peek at.
Returns
A ReadIterator to the first element.

◆ read()

void FileReader::read ( uint8 *  buffer,
unsigned int  size 
)

Fills the specified buffer with the requested number of bytes and increments the position, respectively.

Parameters
bufferThe buffer.
sizeThe number of bytes the copy to the buffer.

◆ requestRegion()

void FileReader::requestRegion ( const FileRegion region)
protected

Requests mapping of the specified region.

Parameters
regionThe region to be mapped.

◆ seek()

void FileReader::seek ( long long  position)
inline

Sets the current position indexed from the beginning of the file. Used this method if you want to skip a large number of bytes. Raises IOException if the postion exceeds the end of the file.

Parameters
positionThe desired postion.

◆ skip()

void FileReader::skip ( unsigned int  size)
inline

Skips the specified number of bytes. Normally used to skip a small number of bytes.

Parameters
sizeThe number of bytes to skip.

Member Data Documentation

◆ DEFAULT_WINDOW_SIZE

constexpr unsigned int FileReader::DEFAULT_WINDOW_SIZE = 0x10000
staticconstexpr

The default preferred window size.