Monad Engine da02fba2
> Undercity Codex_
Loading...
Searching...
No Matches
mnd::FileReader Class Reference

Read helper bound to a single file path. More...

#include <FileReader.h>

Public Member Functions

 FileReader (const std::string &path)
 Bind the reader to the given file path.
 
bool Exists ()
 Check whether the file exists on disk.
 
std::vector< std::string > ReadLines ()
 Read the file line-by-line.
 
std::string ReadToString ()
 Read the entire file into a single string.
 
std::vector< u64ReadToBytes ()
 Read the file as raw bytes.
 
u64 GetSize ()
 Return the file size in bytes.
 
std::string GetPath ()
 Return the path this reader was constructed with.
 

Detailed Description

Read helper bound to a single file path.

All read methods open, read, and close the file on each call — there is no persistent file handle. Check Exists() before reading to avoid error logs.

Definition at line 34 of file FileReader.h.

Constructor & Destructor Documentation

◆ FileReader()

mnd::FileReader::FileReader ( const std::string &  path)
inlineexplicit

Bind the reader to the given file path.

Parameters
pathAbsolute or relative path to the file.

Definition at line 44 of file FileReader.h.

Member Function Documentation

◆ Exists()

bool mnd::FileReader::Exists ( )

Check whether the file exists on disk.

Returns
True if the path resolves to a regular file.

Definition at line 7 of file FileReader.cpp.

Referenced by GetPath(), GetSize(), ReadLines(), ReadToBytes(), and ReadToString().

◆ GetPath()

std::string mnd::FileReader::GetPath ( )

Return the path this reader was constructed with.

Returns
The path string passed to the constructor.

Definition at line 79 of file FileReader.cpp.

References Exists(), and LOG_ERROR.

◆ GetSize()

u64 mnd::FileReader::GetSize ( )

Return the file size in bytes.

Returns
Number of bytes, or 0 if the file cannot be opened.

Definition at line 65 of file FileReader.cpp.

References Exists(), and LOG_ERROR.

◆ ReadLines()

std::vector< std::string > mnd::FileReader::ReadLines ( )

Read the file line-by-line.

Returns
Vector of lines, each without a trailing newline.

Definition at line 28 of file FileReader.cpp.

References Exists(), and LOG_ERROR.

◆ ReadToBytes()

std::vector< u64 > mnd::FileReader::ReadToBytes ( )

Read the file as raw bytes.

Returns
Each byte of the file represented as a u64 value.

Definition at line 46 of file FileReader.cpp.

References Exists(), and LOG_ERROR.

◆ ReadToString()

std::string mnd::FileReader::ReadToString ( )

Read the entire file into a single string.

Returns
File contents as a UTF-8 string.

Definition at line 12 of file FileReader.cpp.

References Exists(), and LOG_ERROR.


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