FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
FEAT::Xml::Scanner Class Reference

XML Scanner class. More...

#include <xml_scanner.hpp>

Classes

class  MarkupInfo
 Markup info class. More...
 

Public Member Functions

 Scanner (std::istream &stream, int lines_read=0)
 Creates a XML scanner for an input stream. More...
 
virtual ~Scanner ()
 virtual destructor More...
 
const std::map< String, String > & get_cur_attribs () const
 
int get_cur_iline () const
 
const Stringget_cur_name () const
 
const Stringget_cur_sline () const
 
bool is_cur_closed () const
 
bool is_cur_markup () const
 
bool is_cur_termin () const
 
void read_root ()
 Tries to read the XML root markup. More...
 
void scan ()
 Scans the stream. More...
 
void scan (std::shared_ptr< MarkupParser > root_parser)
 Scans the stream with a given root parser. More...
 
void set_root_parser (std::shared_ptr< MarkupParser > parser)
 Sets the root markup parser node. More...
 
void throw_content (const String &msg) const
 Throws a ContentError for the current line. More...
 
void throw_grammar (const String &msg) const
 Throws a GrammarError for the current line. More...
 
void throw_syntax (const String &msg) const
 Throws a SyntaxError for the current line. More...
 

Protected Member Functions

void create_top_parser ()
 Creates the top parser node. More...
 
void process_content ()
 Tries to process the current XML content line. More...
 
void process_markup ()
 Tries to process the current XML markup line. More...
 
bool read_next_line ()
 Reads the next non-empty line from the stream. More...
 
bool scan_markup ()
 Tries to interpret the current line as a XML markup line. More...
 

Private Attributes

std::map< String, String_cur_attribs
 specifies the markup attributes of the current line More...
 
int _cur_iline
 current line number More...
 
bool _cur_is_closed
 specifies whether the markup is closed More...
 
bool _cur_is_markup
 specifies whether this line is a markup More...
 
bool _cur_is_termin
 specifies whether the markup is a terminator More...
 
String _cur_name
 specifies the markup name of the current line More...
 
String _cur_sline
 current line string More...
 
bool _have_read_root
 specifies whether the root has been read More...
 
std::vector< MarkupInfo_markups
 the markup stack More...
 
std::istream & _stream
 the input stream More...
 

Detailed Description

XML Scanner class.

Todo:
document
Author
Peter Zajac

Definition at line 306 of file xml_scanner.hpp.

Constructor & Destructor Documentation

◆ Scanner()

FEAT::Xml::Scanner::Scanner ( std::istream &  stream,
int  lines_read = 0 
)
inlineexplicit

Creates a XML scanner for an input stream.

Parameters
[in]streamA resident reference to the input stream that is to be read from.
[in]lines_readThe number of lines already read from the stream.

Definition at line 375 of file xml_scanner.hpp.

References _cur_sline, and _markups.

◆ ~Scanner()

virtual FEAT::Xml::Scanner::~Scanner ( )
inlinevirtual

virtual destructor

Definition at line 392 of file xml_scanner.hpp.

Member Function Documentation

◆ create_top_parser()

void FEAT::Xml::Scanner::create_top_parser ( )
protected

Creates the top parser node.

This function checks whether the attributes match the top parser's requirements and, if so, calls the create() method of the parser.

Definition at line 388 of file xml_scanner.cpp.

References _cur_attribs, _cur_iline, _cur_is_closed, _cur_is_markup, _cur_name, _cur_sline, _markups, throw_grammar(), and XASSERTM.

Referenced by process_markup(), and set_root_parser().

◆ get_cur_attribs()

const std::map< String, String > & FEAT::Xml::Scanner::get_cur_attribs ( ) const
inline
Returns
the attribute map of the current markup line

Definition at line 433 of file xml_scanner.hpp.

References _cur_attribs.

Referenced by FEAT::Geometry::MeshFileReader::read_root_markup().

◆ get_cur_iline()

int FEAT::Xml::Scanner::get_cur_iline ( ) const
inline
Returns
the current line number

Definition at line 397 of file xml_scanner.hpp.

References _cur_iline.

◆ get_cur_name()

const String & FEAT::Xml::Scanner::get_cur_name ( ) const
inline
Returns
the name of the current markup line

Definition at line 427 of file xml_scanner.hpp.

References _cur_name.

Referenced by FEAT::Geometry::MeshFileReader::read_root_markup().

◆ get_cur_sline()

const String & FEAT::Xml::Scanner::get_cur_sline ( ) const
inline
Returns
the current line string

Definition at line 403 of file xml_scanner.hpp.

References _cur_sline.

◆ is_cur_closed()

bool FEAT::Xml::Scanner::is_cur_closed ( ) const
inline
Returns
true, if the current markup line is a closed markup

Definition at line 415 of file xml_scanner.hpp.

References _cur_is_closed.

◆ is_cur_markup()

bool FEAT::Xml::Scanner::is_cur_markup ( ) const
inline
Returns
true, if the current line is a markup line, otherwise false

Definition at line 409 of file xml_scanner.hpp.

References _cur_is_markup.

◆ is_cur_termin()

bool FEAT::Xml::Scanner::is_cur_termin ( ) const
inline
Returns
true, if the current markup line is a terminator

Definition at line 421 of file xml_scanner.hpp.

References _cur_is_termin.

◆ process_content()

void FEAT::Xml::Scanner::process_content ( )
protected

Tries to process the current XML content line.

This function passes the current content line to the top parser.

Definition at line 423 of file xml_scanner.cpp.

References _cur_iline, _cur_sline, _markups, and throw_grammar().

Referenced by scan().

◆ process_markup()

void FEAT::Xml::Scanner::process_markup ( )
protected

Tries to process the current XML markup line.

This function passes the current markup line to the top parser and checks whether a new top parser node has to be allocated.

This function throws a Xml::GrammarError if the current markup is not accepted by the parser.

Definition at line 341 of file xml_scanner.cpp.

References _cur_iline, _cur_is_closed, _cur_is_markup, _cur_is_termin, _cur_name, _cur_sline, _markups, create_top_parser(), throw_grammar(), throw_syntax(), and XASSERTM.

Referenced by scan().

◆ read_next_line()

bool FEAT::Xml::Scanner::read_next_line ( )
protected

Reads the next non-empty line from the stream.

Returns
true, if another non-empty line was read or false, if the end of the stream was reached

Definition at line 180 of file xml_scanner.cpp.

References _cur_iline, _cur_sline, _stream, and FEAT::String::trim_me().

Referenced by read_root(), and scan().

◆ read_root()

void FEAT::Xml::Scanner::read_root ( )

Tries to read the XML root markup.

This function reads the first non-empty line from the input stream and tries to interpret it as a XML markup representing the root markup.

If this function returns without throwing an Xml::SyntaxError, the information about the XML root markup can be read from this object by using the getter functions.

Definition at line 92 of file xml_scanner.cpp.

References _cur_is_closed, _cur_is_termin, _have_read_root, _markups, read_next_line(), scan_markup(), throw_syntax(), and XASSERTM.

Referenced by FEAT::Geometry::MeshFileReader::read_root_markup(), and scan().

◆ scan() [1/2]

void FEAT::Xml::Scanner::scan ( )

Scans the stream.

This function scans the streams and processes all lines until the root markup terminator is found.

Attention
This function can only be called after a root parser has been set by calling the set_root_parser function, otherwise an InternalError will be thrown.

Definition at line 137 of file xml_scanner.cpp.

References _cur_iline, _cur_sline, _markups, FEAT::String::ends_with(), process_content(), process_markup(), read_next_line(), scan_markup(), FEAT::String::starts_with(), throw_syntax(), and XASSERTM.

Referenced by scan().

◆ scan() [2/2]

void FEAT::Xml::Scanner::scan ( std::shared_ptr< MarkupParser root_parser)

Scans the stream with a given root parser.

This function effectively just calls the three functions

Definition at line 173 of file xml_scanner.cpp.

References read_root(), scan(), and set_root_parser().

◆ scan_markup()

bool FEAT::Xml::Scanner::scan_markup ( )
protected

Tries to interpret the current line as a XML markup line.

This function checks whether the current line seems to be a XML markup line and, if so, tries to decompose it into its parts.

Returns
true, if the current line is a valid XML markup line or false, if the current line seems to be a content line
Note
This function throws a Xml::SyntaxError if the line seems to be a markup line but violates the syntax rules.

Definition at line 198 of file xml_scanner.cpp.

References _cur_attribs, _cur_is_closed, _cur_is_markup, _cur_is_termin, _cur_name, _cur_sline, FEAT::String::ends_with(), FEAT::String::pop_back(), FEAT::String::pop_front(), FEAT::String::starts_with(), throw_syntax(), FEAT::String::trim(), and FEAT::String::whitespaces().

Referenced by read_root(), and scan().

◆ set_root_parser()

void FEAT::Xml::Scanner::set_root_parser ( std::shared_ptr< MarkupParser parser)

Sets the root markup parser node.

This function sets the parser for the root markup.

Attention
This function can only be called after the read_root function has been called.
Parameters
[in]parserThe MarkupParser object responsible for parsing the root node.

Definition at line 118 of file xml_scanner.cpp.

References _cur_iline, _cur_name, _have_read_root, _markups, create_top_parser(), and XASSERTM.

Referenced by scan().

◆ throw_content()

void FEAT::Xml::Scanner::throw_content ( const String msg) const
inline

Throws a ContentError for the current line.

Parameters
[in]msgThe error message.

Definition at line 515 of file xml_scanner.hpp.

References _cur_iline, and _cur_sline.

Referenced by FEAT::Geometry::MeshFileReader::read_root_markup().

◆ throw_grammar()

void FEAT::Xml::Scanner::throw_grammar ( const String msg) const
inline

Throws a GrammarError for the current line.

Parameters
[in]msgThe error message.

Definition at line 504 of file xml_scanner.hpp.

References _cur_iline, and _cur_sline.

Referenced by create_top_parser(), process_content(), process_markup(), and FEAT::Geometry::MeshFileReader::read_root_markup().

◆ throw_syntax()

void FEAT::Xml::Scanner::throw_syntax ( const String msg) const
inline

Throws a SyntaxError for the current line.

Parameters
[in]msgThe error message.

Definition at line 493 of file xml_scanner.hpp.

References _cur_iline, and _cur_sline.

Referenced by process_markup(), read_root(), scan(), and scan_markup().

Member Data Documentation

◆ _cur_attribs

std::map<String,String> FEAT::Xml::Scanner::_cur_attribs
private

specifies the markup attributes of the current line

Definition at line 363 of file xml_scanner.hpp.

Referenced by create_top_parser(), get_cur_attribs(), and scan_markup().

◆ _cur_iline

int FEAT::Xml::Scanner::_cur_iline
private

◆ _cur_is_closed

bool FEAT::Xml::Scanner::_cur_is_closed
private

specifies whether the markup is closed

Definition at line 357 of file xml_scanner.hpp.

Referenced by create_top_parser(), is_cur_closed(), process_markup(), read_root(), and scan_markup().

◆ _cur_is_markup

bool FEAT::Xml::Scanner::_cur_is_markup
private

specifies whether this line is a markup

Definition at line 355 of file xml_scanner.hpp.

Referenced by create_top_parser(), is_cur_markup(), process_markup(), and scan_markup().

◆ _cur_is_termin

bool FEAT::Xml::Scanner::_cur_is_termin
private

specifies whether the markup is a terminator

Definition at line 359 of file xml_scanner.hpp.

Referenced by is_cur_termin(), process_markup(), read_root(), and scan_markup().

◆ _cur_name

String FEAT::Xml::Scanner::_cur_name
private

specifies the markup name of the current line

Definition at line 361 of file xml_scanner.hpp.

Referenced by create_top_parser(), get_cur_name(), process_markup(), scan_markup(), and set_root_parser().

◆ _cur_sline

String FEAT::Xml::Scanner::_cur_sline
private

◆ _have_read_root

bool FEAT::Xml::Scanner::_have_read_root
private

specifies whether the root has been read

Definition at line 349 of file xml_scanner.hpp.

Referenced by read_root(), and set_root_parser().

◆ _markups

std::vector<MarkupInfo> FEAT::Xml::Scanner::_markups
private

the markup stack

Definition at line 347 of file xml_scanner.hpp.

Referenced by Scanner(), create_top_parser(), process_content(), process_markup(), read_root(), scan(), and set_root_parser().

◆ _stream

std::istream& FEAT::Xml::Scanner::_stream
private

the input stream

Definition at line 345 of file xml_scanner.hpp.

Referenced by read_next_line().


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