![]() |
MAGE
v0.171.0
Matthias Advanced Game Engine
|
#include <line_reader.hpp>
Public Types | |
using | SelectionFunction = std::function< const std::ssub_match(const std::smatch &) > |
Public Member Functions | |
LineReader & | operator= (const LineReader &reader)=delete |
LineReader & | operator= (LineReader &&reader) noexcept |
void | ReadFromFile (std::filesystem::path path, std::regex regex=s_default_regex, SelectionFunction selection_function=s_default_selection_function) |
void | ReadFromMemory (const std::string &input, std::regex regex=s_default_regex, SelectionFunction selection_function=s_default_selection_function) |
Static Public Attributes | |
static const std::regex | s_default_regex = std::regex(R"((\"([^\"]*)\")|(\S+))") |
static const SelectionFunction | s_default_selection_function |
Protected Member Functions | |
LineReader () | |
LineReader (const LineReader &reader)=delete | |
LineReader (LineReader &&reader) noexcept | |
~LineReader () | |
const std::filesystem::path & | GetPath () const noexcept |
U32 | GetCurrentLineNumber () const noexcept |
template<typename T > | |
const T | Read () |
template<typename T , std::size_t N, size_t A = alignof(T)> | |
const Array< T, N, A > | Read () |
void | ReadRemainingTokens () |
template<typename T > | |
bool | Contains () const noexcept |
bool | ContainsTokens () const noexcept |
Private Member Functions | |
virtual void | Preprocess () |
void | Process (std::istream &stream) |
virtual void | ReadLine ()=0 |
virtual void | Postprocess () |
const std::string_view | GetCurrentToken () const noexcept |
Private Attributes | |
std::regex | m_regex |
SelectionFunction | m_selection_function |
std::filesystem::path | m_path |
std::sregex_iterator | m_iterator |
U32 | m_line_number |
A class of line readers for reading (non-binary) text files line by line.
using mage::LineReader::SelectionFunction = std::function< const std::ssub_match(const std::smatch&) > |
The selection function type for extracting one std::ssub_match from a given std::smatch.
|
protected |
Constructs a line reader.
|
protecteddelete |
Constructs a line reader from the given line reader.
[in] | reader | A reference to the line reader to copy. |
|
protectednoexcept |
Constructs a line reader by moving the given line reader.
[in] | reader | A reference to the line reader to move. |
|
protecteddefault |
Destructs this line reader.
|
protectednoexcept |
Checks whether the current token of this line reader is a T
value.
T | The data type. |
true
if the current token of this line reader is a T
value. false
otherwise.
|
protectednoexcept |
Checks whether this line reader has a current token.
true
if this line reader has a current token. false
otherwise.
|
protectednoexcept |
Returns the current line number of this line reader.
|
privatenoexcept |
Returns the current token of this line reader.
|
protectednoexcept |
Returns the current path of this line reader.
|
delete |
Copies the given line reader to this line reader.
[in] | reader | A reference to a line reader to copy. |
|
noexcept |
Moves the given line reader to this line reader.
[in] | reader | A reference to a line reader to move. |
|
privatevirtual |
Post-processes after reading.
Exception | Failed to finish post-processing successfully. |
Reimplemented in mage::rendering::loader::OBJReader< VertexT, IndexT >, and mage::rendering::loader::MDLReader< VertexT, IndexT >.
|
privatevirtual |
Pre-processes before reading.
Exception | Failed to finish the pre-processing successfully. |
Reimplemented in mage::rendering::loader::OBJReader< VertexT, IndexT >, and mage::rendering::loader::MDLReader< VertexT, IndexT >.
|
private |
Processes the given input stream (line by line).
[in] | stream | A reference to the input stream. |
Exception | Failed to process the given input stream. |
|
protected |
Reads and converts the current token of this line reader to T
value.
T | The data type. |
T
represented by the current token of this line reader. Exception | There is no current token or the current token does not represent a T value. |
|
protected |
Reads and converts the current N
tokens of this line reader to an Array
.
@tparam T The data type.
N | The number of values in the array. |
A | The alignment of the array. |
Array
represented by the current N
tokens of this line reader. Exception | There are no N current tokens or the current N tokens do not represent a T value. |
void mage::LineReader::ReadFromFile | ( | std::filesystem::path | path, |
std::regex | regex = s_default_regex , |
||
SelectionFunction | selection_function = s_default_selection_function |
||
) |
Reads from the file associated with the given path.
[in] | path | The path. |
[in] | regex | The (line) regex. |
[in] | selection_function | The selection function. |
Exception | Failed to read from the file. |
void mage::LineReader::ReadFromMemory | ( | const std::string & | input, |
std::regex | regex = s_default_regex , |
||
SelectionFunction | selection_function = s_default_selection_function |
||
) |
Reads from the given input string.
[in] | input | A reference to the input string. |
[in] | regex | The (line) regex. |
[in] | selection_function | The selection function. |
Exception | Failed to read from the given input string. |
|
privatepure virtual |
Reads the current line of this line reader.
Exception | Failed to the current line of this line reader. |
Implemented in mage::rendering::loader::OBJReader< VertexT, IndexT >, mage::rendering::loader::MDLReader< VertexT, IndexT >, mage::rendering::loader::MTLReader, and mage::loader::VARReader.
|
protected |
Reads the remaining tokens of the current line of this line reader.
|
private |
An iterator to the current token of the current line of this line reader.
|
private |
The current line number of this line reader.
|
private |
The current path of this line reader.
|
private |
The current (line) regex of this line reader.
|
private |
The function for selecting the target submatch from the match of the regular expression represented by the regex of this strategy.
|
static |
The default (line) regex for line readers.
|
static |
The default selection function for line readers.