6 * $Date: 2012-07-07 00:03:48 +0200 (Sa, 07. Jul 2012) $
7 ***************************************************************/
10 * \brief Declaration of class XmlParser.
12 * \author Sebastian Leipert and Carsten Gutwenger
15 * This file is part of the Open Graph Drawing Framework (OGDF).
19 * See README.txt in the root directory of the OGDF installation for details.
22 * This program is free software; you can redistribute it and/or
23 * modify it under the terms of the GNU General Public License
24 * Version 2 or 3 as published by the Free Software Foundation;
25 * see the file LICENSE.txt included in the packaging of this file
29 * This program is distributed in the hope that it will be useful,
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 * GNU General Public License for more details.
35 * You should have received a copy of the GNU General Public
36 * License along with this program; if not, write to the Free
37 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
38 * Boston, MA 02110-1301, USA.
40 * \see http://www.gnu.org/copyleft/gpl.html
41 ***************************************************************/
48 #ifndef OGDF_XML_PARSER_H
49 #define OGDF_XML_PARSER_H
52 #include <ogdf/basic/Hashing.h>
53 #include <ogdf/basic/String.h>
54 #include <ogdf/basic/GraphAttributes.h>
55 #include <ogdf/fileformats/XmlObject.h>
56 #include <ogdf/basic/SList.h>
63 //---------------------------------------------------------
65 // reads XML file and constructs XML parse tree
66 //---------------------------------------------------------
67 class OGDF_EXPORT XmlParser
{
68 Hashing
<String
,int> m_hashTable
; // hash table for tags
75 char *m_rLineBuffer
, *m_lineBuffer
, *m_pCurrent
, *m_pStore
, m_cStore
;
77 int m_intSymbol
; // integer attribute
78 double m_doubleSymbol
; // double attribute
79 const char *m_stringSymbol
; // string attribute
80 char *m_keyName
; // Tag name
81 XmlKey m_keySymbol
; // Tag name and Attribute Name in Hash Table
83 bool m_eoTag
; // end of Tag recognized
85 XmlObject
*m_objectTree
; // root node of XML parse tree
89 SList
<char*> m_objectBody
;
92 // predefined id constants for all used keys
93 enum PredefinedKey
{ idPredefKey
= 0, labelPredefKey
, CreatorPredefKey
,
94 namePredefKey
, graphPredefKey
, versionPredefKey
, directedPredefKey
,
95 nodePredefKey
, edgePredefKey
, graphicsPredefKey
, xPredefKey
,
96 yPredefKey
, wPredefKey
, hPredefKey
, nodetypePredefKey
, edgetypePredefKey
,
97 typePredefKey
, widthPredefKey
, heightPredefKey
, sizePredefKey
,
98 positionPredefKey
, pathPredefKey
,
99 sourcePredefKey
, targetPredefKey
, sensePredefKey
, arrowPredefKey
, LinePredefKey
,
100 pointPredefKey
, NEXTPREDEFKEY
};
102 // construction: creates object tree
103 // sets m_error flag if an error occured
104 XmlParser(const char *fileName
, bool doCheck
= false);
105 XmlParser(istream
&is
, bool doCheck
= false);
107 // destruction: destroys object tree
110 // returns root object
111 XmlObject
*root() { return m_objectTree
; }
113 // id of a string in hash table; -1 if not contained
114 int getId(const String
&tag
) const {
115 HashElement
<String
,int> *it
= m_hashTable
.lookup(tag
);
116 return (it
!= 0) ? it
->info() : -1;
119 // returns id of object
120 int id(XmlObject
*object
) const { return object
->m_key
->info(); }
122 // true <=> an error in XML files has been detected
123 bool error() const { return m_error
; }
124 // returns error message
125 const String
&errorString() const { return m_errorString
; }
127 // creates graph from XML parse tree
129 // creates attributed graph from XML parse tree
130 bool read(Graph
&G
, GraphAttributes
&AG
);
133 void createObjectTree(istream
&is
, bool doCheck
);
134 void initPredefinedKeys();
135 void setError(const char *errorString
);
137 XmlObject
*parseList(XmlObjectType closingKey
, XmlObjectType errorKey
, const char *objectBodyName
);
138 XmlObjectType
getNextSymbol();
141 XmlKey
hashString(const String
&str
);
143 XmlObject
*getNodeIdRange(
147 XmlObject
*graphObject
);
153 Array
<char*> & typeName
,
154 Array
<double> &typeWidth
,
155 Array
<double> &typeHeight
,
156 XmlObject
*graphObject
);
158 void closeLabels(Array
<char*> idMap
, Array
<char*> typeName
);
160 void readLineAttribute(XmlObject
*object
, DPolyline
&dpl
);
162 void destroyObjectList(XmlObject
*object
);
164 void indent(ostream
&os
, int d
);
165 void output(ostream
&os
, XmlObject
*object
, int d
);
170 } // end namespace ogdf