Open
Graph Drawing
Framework

 v. snapshot-2017-02-16
 

XmlParser.h
Go to the documentation of this file.
1 
33 #pragma once
34 
35 #include <ogdf/basic/Stack.h>
36 #include <ogdf/basic/Hashing.h>
39 
40 
41 
42 namespace ogdf {
43 
45 
48 
53 
58 
61 
63  bool m_valid;
64 
67  : m_pAttributeName(name)
68  , m_pAttributeValue(value)
69  , m_pNextAttribute(nullptr)
70  , m_valid(false)
71  {}
72 
75 
77  const string& getName() const {
78  return m_pAttributeName->key();
79  }
80 
81  const string& getValue() const {
82  return m_pAttributeValue->key();
83  }
84 
85  bool valid() const {
86  return m_valid;
87  }
88 
90  void setValid() {
91  m_valid = true;
92  }
93 
94  void setInvalid() {
95  m_valid = false;
96  }
97 
98  // Overloaded new and delete operators
100 
101 }; // struct XmlAttributeObject
102 
105 
110 
116 
121 
130 
135 
138  m_pTagName(name),
139  m_pFirstAttribute(nullptr),
140  m_pTagValue(nullptr),
141  m_pFirstSon(nullptr),
142  m_pBrother(nullptr),
143  m_valid(0)
144  {};
145 
148 
150  mutable bool m_valid;
151 
153  int m_depth;
154 
157  int m_line;
158 
159 public:
160 
167  bool isLeaf() const;
168 
176  bool findSonXmlTagObjectByName( const string &sonsName,
177  XmlTagObject *&son) const;
178 
186  bool findSonXmlTagObjectByName( const string &sonsName,
187  List<XmlTagObject*> &sons) const;
188 
197  bool hasMoreSonXmlTagObject(const List<string> &sonNamesToIgnore) const;
198 
203  bool findXmlAttributeObjectByName(
204  const string &attName,
205  XmlAttributeObject*& attribute) const;
206 
213  bool isAttributeLess() const;
214 
216  const bool& valid() const {
217  return m_valid;
218  }
219 
220  const string& getName() const {
221  return m_pTagName->key();
222  }
223 
224  const string& getValue() const {
225  return m_pTagValue->key();
226  }
227 
229  void setValid() const {
230  m_valid = true;
231  }
232 
233  void setInvalid() {
234  m_valid = false;
235  }
236 
237  /* get for depth of xml-tag-object */
238  const int& getDepth() const {
239  return m_depth;
240  }
241 
242  /* setter for new depth */
243  void setDepth(int newDepth){
244  m_depth = newDepth;
245  }
246 
247 
248  /* get for line of xml-tag-object */
249  const int& getLine() const {
250  return m_line;
251  }
252 
253  /* setter for line */
254  void setLine(int line) {
255  m_line = line;
256  }
257 
258  // Overloaded new and delete operators
260 
261 }; // struct XmlTagObject
262 
263 
270 
271  friend OGDF_EXPORT ostream &operator<<(ostream&, const XmlParser &);
272 
273 private:
276 
279 
286 
292 
297 
299 
300 public:
304  explicit XmlParser(istream &is);
305 
307  ~XmlParser();
308 
311  void addNewHashElement(const string &key, int info){
312  OGDF_ASSERT(info >= m_hashTableInfoIndex);
313  m_hashTable.fastInsert(key, info);
314  m_hashTableInfoIndex = info + 1;
315  }
316 
320  bool createParseTree();
321 
323  const XmlTagObject &getRootTag() const {
324  return *m_pRootTag;
325  }
326 
334  bool traversePath(
335  const XmlTagObject &startTag,
336  const Array<int> &infoIndexPath,
337  const XmlTagObject *&targetTag) const;
338 
345  bool findSonXmlTagObject(
346  const XmlTagObject &father,
347  int sonInfoIndex,
348  const XmlTagObject *&son) const;
349 
356  bool findBrotherXmlTagObject(
357  const XmlTagObject &currentTag,
358  int brotherInfoIndex,
359  const XmlTagObject *&brother) const;
360 
367  bool findXmlAttributeObject(
368  const XmlTagObject &currentTag,
369  int attributeInfoIndex,
370  const XmlAttributeObject *&attribute) const;
371 
375  inline int getInputFileLineCounter() const {
376  return m_pScanner->getInputFileLineCounter();
377  }
378 
380  void printHashTable(ostream &os);
381 
382 private:
384  void destroyParseTree(XmlTagObject *root);
385 
391  XmlTagObject* parse();
392 
394  void appendAttributeObject(
395  XmlTagObject *tagObject,
396  XmlAttributeObject *attributeObject);
397 
399  void appendSonTagObject(
400  XmlTagObject *currentTagObject,
401  XmlTagObject *sonTagObject);
402 
409  HashedString *hashString(const string &str);
410 
414  void printXmlTagObjectTree(
415  ostream &os,
416  const XmlTagObject &rootObject,
417  int indent = 0) const;
418 
420  void printSpaces(ostream &os, int nOfSpaces) const;
421 
422  void reportError(
423  const char *functionName,
424  int sourceLine,
425  const char *message,
426  int inputFileLine = -1);
427 
428 }; // class XmlParser
429 
430 } // end namespace ogdf
static const int line
Definition: GmlParser.h:86
~XmlTagObject()
Destructor; will be performed in destroyParseTree().
Definition: XmlParser.h:147
Declaration of class GraphAttributes which extends a Graph by additional attributes.
bool m_valid
Flag denotes whether attribute is valid or not (default: invalid).
Definition: XmlParser.h:63
void setLine(int line)
Definition: XmlParser.h:254
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Definition: config.h:99
void setDepth(int newDepth)
Definition: XmlParser.h:243
int m_recursionDepth
Recursion depth of parse().
Definition: XmlParser.h:294
bool valid() const
Definition: XmlParser.h:85
Declaration of classes used for hashing.
HashedString * m_pTagName
The identifier of the tag, i.e.
Definition: XmlParser.h:109
HashedString * m_pAttributeValue
Contains the value assigned to this attribute without qoutes, i.e.
Definition: XmlParser.h:57
This class scans the characters of the input file and provides the detected token.
Definition: XmlScanner.h:62
int getInputFileLineCounter() const
Definition: XmlScanner.h:127
const string & getValue() const
Definition: XmlParser.h:81
const int & getLine() const
Definition: XmlParser.h:249
XmlAttributeObject * m_pNextAttribute
Pointer to the next attribute and 0 if this is the only attribute.
Definition: XmlParser.h:60
void addNewHashElement(const string &key, int info)
Creates a new hash element and inserts it into the hash table.
Definition: XmlParser.h:311
ostream & operator<<(ostream &os, const ogdf::Array< E, INDEX > &a)
Prints array a to output stream os.
Definition: Array.h:764
~XmlAttributeObject()
Destructor; will be performed in destroyParseTree().
Definition: XmlParser.h:74
int m_line
integer value that stores the line number of the tag in the parsed xml document
Definition: XmlParser.h:157
Stack< string > m_tagObserver
stack for checking correctness of correspondent closing tags
Definition: XmlParser.h:296
const XmlTagObject & getRootTag() const
Allows (non modifying) access to the parse tree.
Definition: XmlParser.h:323
XmlAttributeObject(HashedString *name, HashedString *value)
Constructor.
Definition: XmlParser.h:66
HashedString * m_pTagValue
Contains the characters inbetween the start tag and the end tag, i.e.
Definition: XmlParser.h:120
XmlTagObject * m_pFirstSon
Contains the pointer to the first son tag object, i.e.
Definition: XmlParser.h:129
XmlAttributeObject * m_pFirstAttribute
Pointer to the first attribute; if there is more than one attribute these are linked by m_pNextAttrib...
Definition: XmlParser.h:115
const bool & valid() const
Getter.
Definition: XmlParser.h:216
This struct represents a node in the XML parse tree.
Definition: XmlParser.h:104
Hashing< string, int > m_hashTable
Hash table for storing names of TagObjects and AttributeObjects in an efficient manner.
Definition: XmlParser.h:285
Doubly linked lists (maintaining the length of the list).
Definition: List.h:39
int getInputFileLineCounter() const
Returns line number of the most recently read line of the input file.
Definition: XmlParser.h:375
This struct represents an attribute associated to a tag.
Definition: XmlParser.h:47
void setValid()
Setter.
Definition: XmlParser.h:90
const int & getDepth() const
Definition: XmlParser.h:238
#define OGDF_NEW_DELETE
Makes the class use OGDF&#39;s memory allocator.
Definition: memory.h:84
void setValid() const
Setter.
Definition: XmlParser.h:229
XmlTagObject(HashedString *name)
Constructor.
Definition: XmlParser.h:137
XmlScanner * m_pScanner
Pointer to the scanner.
Definition: XmlParser.h:278
XmlTagObject * m_pBrother
Contains the pointer to a brother tag object or 0 if this object is the only child.
Definition: XmlParser.h:134
int m_depth
integer value for the depth in the xml parse tree
Definition: XmlParser.h:153
HashElement< K, I > * fastInsert(const K &key, const I &info)
Inserts a new element with key key and information info into the hash table.
Definition: Hashing.h:353
const string & getName() const
Definition: XmlParser.h:220
This class parses the XML input file and builds up a parse tree with linked elements XMLTagObject and...
Definition: XmlParser.h:269
const string & getName() const
Getter.
Definition: XmlParser.h:77
const string & getValue() const
Definition: XmlParser.h:224
The namespace for all OGDF objects.
Contains the enum XmlToken and the class XmlScanner.
HashedString * m_pAttributeName
Contains the name of the attribute, i.e.
Definition: XmlParser.h:52
XmlTagObject * m_pRootTag
Pointer to the root element of the parse tree.
Definition: XmlParser.h:275
const K & key() const
Returns the key value.
Definition: Hashing.h:196
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition: basic.h:41
int m_hashTableInfoIndex
The info element of the hash table is simply an integer number which is incremented for each new elem...
Definition: XmlParser.h:291
Declaration and implementation of list-based stacks (StackPure<E> and Stack<E>).