NDEVR
API Documentation

Contains methods for easily reading objects in an ascii stream using set deliminators and line logic. More...

Inheritance diagram for Scanner:
[legend]
Collaboration diagram for Scanner:
[legend]

Public Member Functions

 Scanner (const File &file, char delimiter='|', File::OpenMode mode=File::e_ascii_read)
 Constructs a Scanner that reads from a file.
 Scanner (const String &string, char delimiter='|')
 Constructs a Scanner that reads from a string.
 Scanner (const StringView &string, char delimiter='|')
 Constructs a Scanner that reads from a string view.
virtual ~Scanner ()
 Destructor.
StringcurrentLine ()
 Returns a mutable reference to the current line being parsed.
const StringcurrentLine () const
 Returns a const reference to the current line being parsed.
uint08 dataSize () const
 Returns the total size of the data source in bytes.
File file () const
 Returns the file associated with this scanner.
virtual uint01getByteArray ()
 Returns a pointer to the raw byte array at the current line position.
template<class t_type>
t_type getColumn (uint04 column)
 Skips to the specified column index and returns the token there as the specified type.
const char * getCurrent () const
 Returns a pointer to the current character position in the line.
uint08 getCurrentFilePosition ()
 Returns the current byte position within the file.
uint08 getCurrentLineNumber () const
 Returns the current line number in the stream.
TranslatedString getDebugPosition () const
 Returns a human-readable string describing the current file and line position for debugging.
fltp04 getFilePercent ()
 Returns the percentage of the file that has been read.
uint04 getLineLength () const
 Returns the length of the current line.
StringView getNext ()
 Reads and returns the next token as a StringView.
template<class t_type>
t_type getNext ()
 Reads and returns the next token parsed as the specified type.
void getNext (String &next)
 Reads the next token and stores it in the provided string.
template<class t_type>
t_type getNext (uint04 count)
 Reads the next token of a fixed character count and returns it as the specified type.
template<class t_type>
t_type getNextHex ()
 Reads the next token as a hexadecimal value and returns it as the specified type.
bool hasNext () const
 Checks whether there are more tokens available on the current line.
bool isComment (char comment) const
 Checks if the current line begins with a comment character.
uint04linePosition ()
 Returns a mutable reference to the current position within the line.
void moveForward (uint04 distance=1)
 Moves the line position forward by the specified distance.
virtual bool nextLine ()
 Advances the scanner to the next line in the stream.
virtual bool nextLine (String &string, bool clear_string=true)
 Advances to the next line and stores it in the provided string.
template<class t_type>
t_type peekNext ()
 Peeks at the next token without advancing the read position.
char quoteCharacter () const
 Returns the current quote character.
void resetLinePosition ()
 Resets the line position back to the beginning of the current line.
void setDelimiter (char delimiter)
 Sets the delimiter character used to separate tokens.
virtual void setFilePosition (uint08 file_position, bool read_line=true)
 Sets the file read position to the specified byte offset.
void setHasDelimiter (const bool has_delimiter)
 Sets whether the scanner expects delimiters between tokens.
void setIgnoreEmptyLines (bool ignore_new_lines)
 Sets whether empty lines should be skipped when reading.
void setIgnoreWhiteSpace (bool ignore_white_space)
 Sets whether leading whitespace should be ignored when reading tokens.
void setQuoteCharacter (char quote_character)
 Sets the character used to denote quoted strings.
uint04 skip ()
 Skips the current token and advances to the next delimiter.
bool skipTo (char location, bool ignore_case=false)
 Skips forward until the specified character is found.
bool skipTo (const Buffer< char > &locations, bool ignore_case=false)
 Skips forward until one of the specified characters is found.
bool skipTo (const char *location, bool ignore_case=false)
 Skips forward until the specified string is found.
uint04 skipWhiteSpace ()
 Skips over any whitespace characters at the current position.

Protected Attributes

uint04 m_cur_column
 The current column index for column-based reading.
uint04 m_cur_line_pos
 The current character index within the current line.
uint08 m_current_file_position
 The current byte offset within the file.
String m_current_line
 The contents of the current line being parsed.
uint08 m_current_line_number
 The current one-based line number in the stream.
uint04 m_current_line_size
 The length of the current line in characters.
uint08 m_data_size
 The total size of the data source in bytes.
char m_delimiter
 The delimiter character used to separate tokens.
File m_file
 The file being read, if constructed from a file.
bool m_has_delimiter
 Whether the scanner expects delimiters between tokens.
bool m_ignore_empty_lines
 Whether to skip empty lines when advancing.
bool m_ignore_white_space = false
 Whether to skip leading whitespace when reading tokens.
char m_quote_character
 The character used to denote quoted strings.
String m_time_format
 The format string used for parsing time values.

Detailed Description

Contains methods for easily reading objects in an ascii stream using set deliminators and line logic.


See also
BufferedScanner, File

Definition at line 46 of file Scanner.h.

Constructor & Destructor Documentation

◆ Scanner() [1/3]

Scanner::Scanner ( const File & file,
char delimiter = '|',
File::OpenMode mode = File::e_ascii_read )
explicit

Constructs a Scanner that reads from a file.

Parameters
[in]fileThe file to read from.
[in]delimiterThe character used to separate tokens on a line.
[in]modeThe file open mode to use when opening the file.

References File::e_ascii_read, and file().

◆ Scanner() [2/3]

Scanner::Scanner ( const StringView & string,
char delimiter = '|' )
explicit

Constructs a Scanner that reads from a string view.

Parameters
[in]stringThe string view to parse.
[in]delimiterThe character used to separate tokens.

◆ Scanner() [3/3]

Scanner::Scanner ( const String & string,
char delimiter = '|' )
explicit

Constructs a Scanner that reads from a string.

Parameters
[in]stringThe string to parse.
[in]delimiterThe character used to separate tokens.

Member Function Documentation

◆ currentLine() [1/2]

String & Scanner::currentLine ( )
inline

Returns a mutable reference to the current line being parsed.

Returns
The current line string.

Definition at line 113 of file Scanner.h.

References m_current_line.

◆ currentLine() [2/2]

const String & Scanner::currentLine ( ) const
inline

Returns a const reference to the current line being parsed.

Returns
The current line string.

Definition at line 108 of file Scanner.h.

References m_current_line.

Referenced by BoilerMaker::boiler(), ShaderTools::compileShader(), TranslationTools::processString(), and TranslationTools::setupFile().

◆ dataSize()

uint08 Scanner::dataSize ( ) const

Returns the total size of the data source in bytes.

Returns
The size of the file or string data being scanned.

◆ file()

File Scanner::file ( ) const
inline

Returns the file associated with this scanner.

Returns
The File object being read, or an invalid File if parsing a string.

Definition at line 194 of file Scanner.h.

References m_file.

Referenced by BufferedScanner::BufferedScanner(), and Scanner().

◆ getByteArray()

virtual uint01 * Scanner::getByteArray ( )
inlinevirtual

Returns a pointer to the raw byte array at the current line position.

Returns
A pointer to the current byte data within the line buffer.

Reimplemented in BufferedScanner.

Definition at line 302 of file Scanner.h.

References m_cur_line_pos, and m_current_line.

◆ getColumn()

template<class t_type>
t_type Scanner::getColumn ( uint04 column)
inline

Skips to the specified column index and returns the token there as the specified type.

Parameters
[in]columnThe zero-based column index to retrieve.
Returns
The value at the specified column converted to t_type.

Definition at line 262 of file Scanner.h.

References getNext(), m_cur_column, m_cur_line_pos, and skip().

◆ getCurrent()

const char * Scanner::getCurrent ( ) const

Returns a pointer to the current character position in the line.

Returns
A pointer to the current parse position within the line buffer.

◆ getCurrentFilePosition()

uint08 Scanner::getCurrentFilePosition ( )

Returns the current byte position within the file.

Returns
The byte offset of the current read position.

◆ getCurrentLineNumber()

uint08 Scanner::getCurrentLineNumber ( ) const

Returns the current line number in the stream.

Returns
The one-based line number currently being read.

◆ getDebugPosition()

TranslatedString Scanner::getDebugPosition ( ) const

Returns a human-readable string describing the current file and line position for debugging.

Returns
A TranslatedString with the current debug position information.

◆ getFilePercent()

fltp04 Scanner::getFilePercent ( )

Returns the percentage of the file that has been read.

Returns
A value between 0.0 and 1.0 representing read progress.

◆ getLineLength()

uint04 Scanner::getLineLength ( ) const

Returns the length of the current line.

Returns
The number of characters in the current line.

◆ getNext() [1/4]

StringView Scanner::getNext ( )

Reads and returns the next token as a StringView.

Returns
A StringView of the next delimited token.

◆ getNext() [2/4]

template<class t_type>
t_type Scanner::getNext ( )

Reads and returns the next token parsed as the specified type.

Returns
The next token converted to t_type.

Referenced by getColumn(), and peekNext().

◆ getNext() [3/4]

void Scanner::getNext ( String & next)

Reads the next token and stores it in the provided string.

Parameters
[in]nextThe string to receive the next token.

◆ getNext() [4/4]

template<class t_type>
t_type Scanner::getNext ( uint04 count)
inline

Reads the next token of a fixed character count and returns it as the specified type.

Parameters
[in]countThe number of characters to read.
Returns
The parsed value converted to t_type.

Definition at line 242 of file Scanner.h.

References StringView::getAs(), m_cur_line_pos, and m_current_line.

◆ getNextHex()

template<class t_type>
t_type Scanner::getNextHex ( )

Reads the next token as a hexadecimal value and returns it as the specified type.

Returns
The next hex token converted to t_type.

◆ hasNext()

bool Scanner::hasNext ( ) const

Checks whether there are more tokens available on the current line.

Returns
True if more tokens remain, false otherwise.

◆ isComment()

bool Scanner::isComment ( char comment) const

Checks if the current line begins with a comment character.

Parameters
[in]commentThe character that denotes a comment line.
Returns
True if the current line starts with the given comment character.

◆ linePosition()

uint04 & Scanner::linePosition ( )
inline

Returns a mutable reference to the current position within the line.

Returns
The current character index within the line.

Definition at line 179 of file Scanner.h.

References m_cur_line_pos.

◆ moveForward()

void Scanner::moveForward ( uint04 distance = 1)

Moves the line position forward by the specified distance.

Parameters
[in]distanceThe number of characters to advance.

◆ nextLine() [1/2]

virtual bool Scanner::nextLine ( )
virtual

Advances the scanner to the next line in the stream.

Returns
True if a new line was successfully read, false if end of stream.

Reimplemented in BufferedScanner.

Referenced by BoilerMaker::boiler(), TranslationTools::processString(), and TranslationTools::setupFile().

◆ nextLine() [2/2]

virtual bool Scanner::nextLine ( String & string,
bool clear_string = true )
virtual

Advances to the next line and stores it in the provided string.

Parameters
[in]stringThe string to receive the next line content.
[in]clear_stringWhether to clear the string before writing to it.
Returns
True if a new line was successfully read, false if end of stream.

Reimplemented in BufferedScanner.

◆ peekNext()

template<class t_type>
t_type Scanner::peekNext ( )
inline

Peeks at the next token without advancing the read position.

Returns
The next token converted to t_type, leaving the position unchanged.

Definition at line 207 of file Scanner.h.

References getNext(), m_cur_column, and m_cur_line_pos.

◆ quoteCharacter()

char Scanner::quoteCharacter ( ) const
inline

Returns the current quote character.

Returns
The character used for quoting strings.

Definition at line 189 of file Scanner.h.

References m_quote_character.

◆ setDelimiter()

void Scanner::setDelimiter ( char delimiter)

Sets the delimiter character used to separate tokens.

Parameters
[in]delimiterThe new delimiter character.

◆ setFilePosition()

virtual void Scanner::setFilePosition ( uint08 file_position,
bool read_line = true )
virtual

Sets the file read position to the specified byte offset.

Parameters
[in]file_positionThe byte offset to seek to.
[in]read_lineWhether to immediately read the next line after seeking.

Reimplemented in BufferedScanner.

◆ setHasDelimiter()

void Scanner::setHasDelimiter ( const bool has_delimiter)
inline

Sets whether the scanner expects delimiters between tokens.

Parameters
[in]has_delimiterTrue if delimiters are present between tokens.

Definition at line 174 of file Scanner.h.

References m_has_delimiter.

◆ setIgnoreEmptyLines()

void Scanner::setIgnoreEmptyLines ( bool ignore_new_lines)
inline

Sets whether empty lines should be skipped when reading.

Parameters
[in]ignore_new_linesTrue to skip empty lines automatically.

Definition at line 285 of file Scanner.h.

References m_ignore_empty_lines.

◆ setIgnoreWhiteSpace()

void Scanner::setIgnoreWhiteSpace ( bool ignore_white_space)
inline

Sets whether leading whitespace should be ignored when reading tokens.

Parameters
[in]ignore_white_spaceTrue to skip leading whitespace.

Definition at line 290 of file Scanner.h.

References m_ignore_white_space.

◆ setQuoteCharacter()

void Scanner::setQuoteCharacter ( char quote_character)
inline

Sets the character used to denote quoted strings.

Parameters
[in]quote_characterThe quote character to use.

Definition at line 184 of file Scanner.h.

References m_quote_character.

◆ skip()

uint04 Scanner::skip ( )

Skips the current token and advances to the next delimiter.

Returns
The number of characters skipped.

Referenced by getColumn().

◆ skipTo() [1/3]

bool Scanner::skipTo ( char location,
bool ignore_case = false )

Skips forward until the specified character is found.

Parameters
[in]locationThe character to search for.
[in]ignore_caseWhether to perform a case-insensitive search.
Returns
True if the character was found, false if end of line was reached.

◆ skipTo() [2/3]

bool Scanner::skipTo ( const Buffer< char > & locations,
bool ignore_case = false )

Skips forward until one of the specified characters is found.

Parameters
[in]locationsA buffer of characters to search for.
[in]ignore_caseWhether to perform a case-insensitive search.
Returns
True if one of the characters was found, false if end of line was reached.

◆ skipTo() [3/3]

bool Scanner::skipTo ( const char * location,
bool ignore_case = false )

Skips forward until the specified string is found.

Parameters
[in]locationThe string to search for.
[in]ignore_caseWhether to perform a case-insensitive search.
Returns
True if the string was found, false if end of line was reached.

◆ skipWhiteSpace()

uint04 Scanner::skipWhiteSpace ( )

Skips over any whitespace characters at the current position.

Returns
The number of whitespace characters skipped.

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