XII Release 0.1.0
Loading...
Searching...
No Matches
xiiFileReader Class Reference

The default class to use to read data from a file, implements the xiiStreamReader interface. More...

#include <FileReader.h>

Inheritance diagram for xiiFileReader:
[legend]

Public Member Functions

 xiiFileReader ()=default
 Constructor, does nothing.
 
 ~xiiFileReader ()
 Destructor, closes the file, if it is still open (RAII).
 
xiiResult Open (xiiStringView sFile, xiiUInt32 uiCacheSize=1024 *64, xiiFileShareMode::Enum fileShareMode=xiiFileShareMode::Default, bool bAllowFileEvents=true)
 Opens the given file for reading. Returns XII_SUCCESS if the file could be opened. A cache is created to speed up small reads.
 
void Close ()
 Closes the file, if it is open.
 
virtual xiiUInt64 ReadBytes (void *pReadBuffer, xiiUInt64 uiBytesToRead) override
 Attempts to read the given number of bytes into the buffer. Returns the actual number of bytes read.
 
virtual xiiUInt64 SkipBytes (xiiUInt64 uiBytesToSkip) override
 Helper method to skip a number of bytes. Returns the actual number of bytes skipped.
 
bool IsEOF () const
 Whether the end of the file was reached during reading.
 
- Public Member Functions inherited from xiiFileReaderBase
xiiString128 GetFilePathAbsolute () const
 Returns the absolute path with which the file was opened (including the prefix of the data directory).
 
xiiString128 GetFilePathRelative () const
 Returns the relative path of the file within its data directory (excluding the prefix of the data directory).
 
xiiDataDirectoryTypeGetDataDirectory () const
 Returns the xiiDataDirectoryType over which this file has been opened.
 
bool IsOpen () const
 Returns true, if the file is currently open.
 
xiiUInt64 GetFileSize () const
 Returns the current total size of the file.
 
- Public Member Functions inherited from xiiStreamReader
 xiiStreamReader ()
 Constructor.
 
virtual ~xiiStreamReader ()
 Virtual destructor to ensure correct cleanup.
 
template<typename T>
xiiResult ReadWordValue (T *pWordValue)
 Helper method to read a word value correctly (copes with potentially different endianess).
 
template<typename T>
xiiResult ReadDWordValue (T *pDWordValue)
 Helper method to read a dword value correctly (copes with potentially different endianess).
 
template<typename T>
xiiResult ReadQWordValue (T *pQWordValue)
 Helper method to read a qword value correctly (copes with potentially different endianess).
 
template<typename ArrayType, typename ValueType>
xiiResult ReadArray (xiiArrayBase< ValueType, ArrayType > &ref_array)
 Reads an array of elements from the stream.
 
template<typename ValueType, xiiUInt16 uiSize, typename AllocatorWrapper>
xiiResult ReadArray (xiiSmallArray< ValueType, uiSize, AllocatorWrapper > &ref_array)
 Reads a small array of elements from the stream.
 
template<typename ValueType, xiiUInt32 uiSize>
xiiResult ReadArray (ValueType(&array)[uiSize])
 Writes a C style fixed array.
 
template<typename KeyType, typename Comparer>
xiiResult ReadSet (xiiSetBase< KeyType, Comparer > &ref_set)
 Reads a set.
 
template<typename KeyType, typename ValueType, typename Comparer>
xiiResult ReadMap (xiiMapBase< KeyType, ValueType, Comparer > &ref_map)
 Reads a map.
 
template<typename KeyType, typename ValueType, typename Hasher>
xiiResult ReadHashTable (xiiHashTableBase< KeyType, ValueType, Hasher > &ref_hashTable)
 Read a hash table (note that the entry order is not stable).
 
xiiResult ReadString (xiiStringBuilder &ref_sBuilder)
 Reads a string into a xiiStringBuilder.
 
xiiResult ReadString (xiiString &ref_sString)
 Reads a string into a xiiString.
 
XII_ALWAYS_INLINE xiiTypeVersion ReadVersion (xiiTypeVersion expectedMaxVersion)
 

Additional Inherited Members

- Protected Member Functions inherited from xiiFileReaderBase
xiiDataDirectoryReaderGetFileReader (xiiStringView sFile, xiiFileShareMode::Enum FileShareMode, bool bAllowFileEvents)
 
- Protected Attributes inherited from xiiFileReaderBase
xiiDataDirectoryReaderm_pDataDirReader
 

Detailed Description

The default class to use to read data from a file, implements the xiiStreamReader interface.

This file reader buffers reads up to a certain amount of bytes (configurable). It closes the file automatically once it goes out of scope.

Member Function Documentation

◆ IsEOF()

bool xiiFileReader::IsEOF ( ) const
inline

Whether the end of the file was reached during reading.

Note
This is not 100% accurate, it does not guarantee that if it returns false, that the next read will return any data.

◆ Open()

xiiResult xiiFileReader::Open ( xiiStringView sFile,
xiiUInt32 uiCacheSize = 1024 * 64,
xiiFileShareMode::Enum fileShareMode = xiiFileShareMode::Default,
bool bAllowFileEvents = true )

Opens the given file for reading. Returns XII_SUCCESS if the file could be opened. A cache is created to speed up small reads.

You should typically not disable bAllowFileEvents, unless you need to prevent recursive file events, which is only the case, if you are doing file accesses from within a File Event Handler.

◆ ReadBytes()

xiiUInt64 xiiFileReader::ReadBytes ( void * pReadBuffer,
xiiUInt64 uiBytesToRead )
overridevirtual

Attempts to read the given number of bytes into the buffer. Returns the actual number of bytes read.

Implements xiiStreamReader.

◆ SkipBytes()

xiiUInt64 xiiFileReader::SkipBytes ( xiiUInt64 uiBytesToSkip)
overridevirtual

Helper method to skip a number of bytes. Returns the actual number of bytes skipped.

Reimplemented from xiiStreamReader.


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