Plasma Engine  2.0
Loading...
Searching...
No Matches
plFileReader Class Reference

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

#include <FileReader.h>

Inheritance diagram for plFileReader:

Public Member Functions

 plFileReader ()=default
 Constructor, does nothing.
 
 ~plFileReader ()
 Destructor, closes the file, if it is still open (RAII).
 
plResult Open (plStringView sFile, plUInt32 uiCacheSize=1024 *64, plFileShareMode::Enum fileShareMode=plFileShareMode::Default, bool bAllowFileEvents=true)
 Opens the given file for reading. Returns PL_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 plUInt64 ReadBytes (void *pReadBuffer, plUInt64 uiBytesToRead) override
 Attempts to read the given number of bytes into the buffer. Returns the actual number of bytes read.
 
virtual plUInt64 SkipBytes (plUInt64 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 plFileReaderBase
plString128 GetFilePathAbsolute () const
 Returns the absolute path with which the file was opened (including the prefix of the data directory).
 
plString128 GetFilePathRelative () const
 Returns the relative path of the file within its data directory (excluding the prefix of the data directory).
 
plDataDirectoryTypeGetDataDirectory () const
 Returns the plDataDirectoryType over which this file has been opened.
 
bool IsOpen () const
 Returns true, if the file is currently open.
 
plUInt64 GetFileSize () const
 Returns the current total size of the file.
 
- Public Member Functions inherited from plStreamReader
 plStreamReader ()
 Constructor.
 
virtual ~plStreamReader ()
 Virtual destructor to ensure correct cleanup.
 
template<typename T >
plResult ReadWordValue (T *pWordValue)
 Helper method to read a word value correctly (copes with potentially different endianess)
 
template<typename T >
plResult ReadDWordValue (T *pDWordValue)
 Helper method to read a dword value correctly (copes with potentially different endianess)
 
template<typename T >
plResult ReadQWordValue (T *pQWordValue)
 Helper method to read a qword value correctly (copes with potentially different endianess)
 
template<typename ArrayType , typename ValueType >
plResult ReadArray (plArrayBase< ValueType, ArrayType > &inout_array)
 Reads an array of elements from the stream.
 
template<typename ValueType , plUInt16 uiSize, typename AllocatorWrapper >
plResult ReadArray (plSmallArray< ValueType, uiSize, AllocatorWrapper > &ref_array)
 Reads a small array of elements from the stream.
 
template<typename ValueType , plUInt32 uiSize>
plResult ReadArray (ValueType(&array)[uiSize])
 Writes a C style fixed array.
 
template<typename KeyType , typename Comparer >
plResult ReadSet (plSetBase< KeyType, Comparer > &inout_set)
 Reads a set.
 
template<typename KeyType , typename ValueType , typename Comparer >
plResult ReadMap (plMapBase< KeyType, ValueType, Comparer > &inout_map)
 Reads a map.
 
template<typename KeyType , typename ValueType , typename Hasher >
plResult ReadHashTable (plHashTableBase< KeyType, ValueType, Hasher > &inout_hashTable)
 Read a hash table (note that the entry order is not stable)
 
plResult ReadString (plStringBuilder &ref_sBuilder)
 Reads a string into an plStringBuilder.
 
plResult ReadString (plString &ref_sString)
 Reads a string into an plString.
 
PL_ALWAYS_INLINE plTypeVersion ReadVersion (plTypeVersion expectedMaxVersion)
 

Additional Inherited Members

- Protected Member Functions inherited from plFileReaderBase
plDataDirectoryReaderGetFileReader (plStringView sFile, plFileShareMode::Enum FileShareMode, bool bAllowFileEvents)
 
- Protected Attributes inherited from plFileReaderBase
plDataDirectoryReaderm_pDataDirReader
 

Detailed Description

The default class to use to read data from a file, implements the plStreamReader 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 plFileReader::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()

plResult plFileReader::Open ( plStringView sFile,
plUInt32 uiCacheSize = 1024 * 64,
plFileShareMode::Enum fileShareMode = plFileShareMode::Default,
bool bAllowFileEvents = true )

Opens the given file for reading. Returns PL_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()

plUInt64 plFileReader::ReadBytes ( void * pReadBuffer,
plUInt64 uiBytesToRead )
overridevirtual

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

Implements plStreamReader.

◆ SkipBytes()

plUInt64 plFileReader::SkipBytes ( plUInt64 uiBytesToSkip)
overridevirtual

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

Reimplemented from plStreamReader.


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