Open
Graph Drawing
Framework

 v. snapshot-2017-02-16
 

ogdf::XmlParser Class Reference

This class parses the XML input file and builds up a parse tree with linked elements XMLTagObject and XMLAttributeObject. More...

#include <ogdf/fileformats/XmlParser.h>

Public Member Functions

 XmlParser (istream &is)
 Constructor. More...
 
 ~XmlParser ()
 Destructor; destroys the parse tree. More...
 
void addNewHashElement (const string &key, int info)
 Creates a new hash element and inserts it into the hash table. More...
 
bool createParseTree ()
 Creates the parse tree and anchors it in m_pRootTag. More...
 
bool findBrotherXmlTagObject (const XmlTagObject &currentTag, int brotherInfoIndex, const XmlTagObject *&brother) const
 Searches for a specific brother (identified by brotherInfoIndex) of current. More...
 
bool findSonXmlTagObject (const XmlTagObject &father, int sonInfoIndex, const XmlTagObject *&son) const
 Searches for a specific son (identified by sonInfoIndex) of father. More...
 
bool findXmlAttributeObject (const XmlTagObject &currentTag, int attributeInfoIndex, const XmlAttributeObject *&attribute) const
 Searches for a specific attribute (identified by attributeInfoIndex) of current. More...
 
int getInputFileLineCounter () const
 Returns line number of the most recently read line of the input file. More...
 
const XmlTagObject & getRootTag () const
 Allows (non modifying) access to the parse tree. More...
 
void printHashTable (ostream &os)
 Prints the content of the hash table to os. More...
 
bool traversePath (const XmlTagObject &startTag, const Array< int > &infoIndexPath, const XmlTagObject *&targetTag) const
 Traverses the parseTree starting at startTag using the path description in path, which contains the infoIndices of the tags which have to be traversed. More...
 

Private Member Functions

void appendAttributeObject (XmlTagObject *tagObject, XmlAttributeObject *attributeObject)
 Append attributeObject to list of attributes of tagObject. More...
 
void appendSonTagObject (XmlTagObject *currentTagObject, XmlTagObject *sonTagObject)
 Appends sonTagObject to the list of sons of currentTagObject. More...
 
void destroyParseTree (XmlTagObject *root)
 Destroys the parse tree appended to root. More...
 
HashedString * hashString (const string &str)
 Returns the hash element for the given string. More...
 
XmlTagObject * parse ()
 Parses the token stream provided by the scanner until a complete XmlTagObject is identified which will be returned. More...
 
void printSpaces (ostream &os, int nOfSpaces) const
 Little helper that prints nOfSpaces space characters. More...
 
void printXmlTagObjectTree (ostream &os, const XmlTagObject &rootObject, int indent=0) const
 Prints the given XmlTagObject and its children recursively. More...
 
void reportError (const char *functionName, int sourceLine, const char *message, int inputFileLine=-1)
 

Private Attributes

Hashing< string, int > m_hashTable
 Hash table for storing names of TagObjects and AttributeObjects in an efficient manner. More...
 
int m_hashTableInfoIndex
 The info element of the hash table is simply an integer number which is incremented for each new element (starting at 0). More...
 
bool m_parseError
 
XmlTagObject * m_pRootTag
 Pointer to the root element of the parse tree. More...
 
XmlScanner * m_pScanner
 Pointer to the scanner. More...
 
int m_recursionDepth
 Recursion depth of parse(). More...
 
Stack< string > m_tagObserver
 stack for checking correctness of correspondent closing tags More...
 

Friends

ostream & operator<< (ostream &, const XmlParser &)
 

Detailed Description

This class parses the XML input file and builds up a parse tree with linked elements XMLTagObject and XMLAttributeObject.

The class XmlScanner is used to get the token for the parse process.

Definition at line 269 of file XmlParser.h.

Constructor & Destructor Documentation

◆ XmlParser()

ogdf::XmlParser::XmlParser ( istream &  is)
explicit

Constructor.

Inside the constructor the scanner is generated.

◆ ~XmlParser()

ogdf::XmlParser::~XmlParser ( )

Destructor; destroys the parse tree.

Member Function Documentation

◆ addNewHashElement()

void ogdf::XmlParser::addNewHashElement ( const string &  key,
int  info 
)
inline

Creates a new hash element and inserts it into the hash table.

Definition at line 311 of file XmlParser.h.

◆ appendAttributeObject()

void ogdf::XmlParser::appendAttributeObject ( XmlTagObject *  tagObject,
XmlAttributeObject *  attributeObject 
)
private

Append attributeObject to list of attributes of tagObject.

◆ appendSonTagObject()

void ogdf::XmlParser::appendSonTagObject ( XmlTagObject *  currentTagObject,
XmlTagObject *  sonTagObject 
)
private

Appends sonTagObject to the list of sons of currentTagObject.

◆ createParseTree()

bool ogdf::XmlParser::createParseTree ( )

Creates the parse tree and anchors it in m_pRootTag.

returns true to indicate if success; false if parse error.

◆ destroyParseTree()

void ogdf::XmlParser::destroyParseTree ( XmlTagObject *  root)
private

Destroys the parse tree appended to root.

◆ findBrotherXmlTagObject()

bool ogdf::XmlParser::findBrotherXmlTagObject ( const XmlTagObject &  currentTag,
int  brotherInfoIndex,
const XmlTagObject *&  brother 
) const

Searches for a specific brother (identified by brotherInfoIndex) of current.

Returns the brother via the referenced pointer brother. Returns true if brother is found. Returns false otherwise, brother is set to nullptr.

◆ findSonXmlTagObject()

bool ogdf::XmlParser::findSonXmlTagObject ( const XmlTagObject &  father,
int  sonInfoIndex,
const XmlTagObject *&  son 
) const

Searches for a specific son (identified by sonInfoIndex) of father.

Returns the son via the referenced pointer son. Returns true if son is found. Returns false otherwise, son is set to nullptr.

◆ findXmlAttributeObject()

bool ogdf::XmlParser::findXmlAttributeObject ( const XmlTagObject &  currentTag,
int  attributeInfoIndex,
const XmlAttributeObject *&  attribute 
) const

Searches for a specific attribute (identified by attributeInfoIndex) of current.

Returns the attribute via the referenced pointer attribute. Returns true if attribute is found. Returns false otherwise, attribute is set to nullptr.

◆ getInputFileLineCounter()

int ogdf::XmlParser::getInputFileLineCounter ( ) const
inline

Returns line number of the most recently read line of the input file.

Definition at line 375 of file XmlParser.h.

◆ getRootTag()

const XmlTagObject& ogdf::XmlParser::getRootTag ( ) const
inline

Allows (non modifying) access to the parse tree.

Definition at line 323 of file XmlParser.h.

◆ hashString()

HashedString* ogdf::XmlParser::hashString ( const string &  str)
private

Returns the hash element for the given string.

If the key str is not contained in the table yet, it is inserted together with a new info index and the new hash element is returned. If the key str exists, the associated hash element is returned.

◆ parse()

XmlTagObject* ogdf::XmlParser::parse ( )
private

Parses the token stream provided by the scanner until a complete XmlTagObject is identified which will be returned.

This function is likely to be called recursively due to the recursive structure of XML documents.

◆ printHashTable()

void ogdf::XmlParser::printHashTable ( ostream &  os)

Prints the content of the hash table to os.

◆ printSpaces()

void ogdf::XmlParser::printSpaces ( ostream &  os,
int  nOfSpaces 
) const
private

Little helper that prints nOfSpaces space characters.

◆ printXmlTagObjectTree()

void ogdf::XmlParser::printXmlTagObjectTree ( ostream &  os,
const XmlTagObject &  rootObject,
int  indent = 0 
) const
private

Prints the given XmlTagObject and its children recursively.

The parameter indent is used as indentation value.

◆ reportError()

void ogdf::XmlParser::reportError ( const char *  functionName,
int  sourceLine,
const char *  message,
int  inputFileLine = -1 
)
private

◆ traversePath()

bool ogdf::XmlParser::traversePath ( const XmlTagObject &  startTag,
const Array< int > &  infoIndexPath,
const XmlTagObject *&  targetTag 
) const

Traverses the parseTree starting at startTag using the path description in path, which contains the infoIndices of the tags which have to be traversed.

If the XmlTagObject associated to the last infoIndex in the path is found, it is returned via targetTag and the return value is true If the XmlTagObject is not found the return value is false.

Friends And Related Function Documentation

◆ operator<<

ostream& operator<< ( ostream &  ,
const XmlParser &   
)
friend

Member Data Documentation

◆ m_hashTable

Hashing<string,int> ogdf::XmlParser::m_hashTable
private

Hash table for storing names of TagObjects and AttributeObjects in an efficient manner.

The key element is string. The info element is int.

Definition at line 285 of file XmlParser.h.

◆ m_hashTableInfoIndex

int ogdf::XmlParser::m_hashTableInfoIndex
private

The info element of the hash table is simply an integer number which is incremented for each new element (starting at 0).

The value m_hashTableInfoIndex - 1 is the last used index.

Definition at line 291 of file XmlParser.h.

◆ m_parseError

bool ogdf::XmlParser::m_parseError
private

Definition at line 298 of file XmlParser.h.

◆ m_pRootTag

XmlTagObject* ogdf::XmlParser::m_pRootTag
private

Pointer to the root element of the parse tree.

Definition at line 275 of file XmlParser.h.

◆ m_pScanner

XmlScanner* ogdf::XmlParser::m_pScanner
private

Pointer to the scanner.

Definition at line 278 of file XmlParser.h.

◆ m_recursionDepth

int ogdf::XmlParser::m_recursionDepth
private

Recursion depth of parse().

Definition at line 294 of file XmlParser.h.

◆ m_tagObserver

Stack<string> ogdf::XmlParser::m_tagObserver
private

stack for checking correctness of correspondent closing tags

Definition at line 296 of file XmlParser.h.


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