Don't import ogdf namespace
[TortoiseGit.git] / ext / OGDF / ogdf / fileformats / OgmlParser.h
blob05f47af74317f109586548dae91cfda7ed8c39f0
1 /*
2 * $Revision: 2523 $
4 * last checkin:
5 * $Author: gutwenger $
6 * $Date: 2012-07-02 20:59:27 +0200 (Mon, 02 Jul 2012) $
7 ***************************************************************/
9 /** \file
10 * \brief Implementation of auxiliary classes OgmlAttributeValue,
11 * OgmlAttribute and OgmlTag.
13 * \author Christian Wolf and Bernd Zey
15 * \par License:
16 * This file is part of the Open Graph Drawing Framework (OGDF).
18 * \par
19 * Copyright (C)<br>
20 * See README.txt in the root directory of the OGDF installation for details.
22 * \par
23 * This program is free software; you can redistribute it and/or
24 * modify it under the terms of the GNU General Public License
25 * Version 2 or 3 as published by the Free Software Foundation;
26 * see the file LICENSE.txt included in the packaging of this file
27 * for details.
29 * \par
30 * This program is distributed in the hope that it will be useful,
31 * but WITHOUT ANY WARRANTY; without even the implied warranty of
32 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 * GNU General Public License for more details.
35 * \par
36 * You should have received a copy of the GNU General Public
37 * License along with this program; if not, write to the Free
38 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
39 * Boston, MA 02110-1301, USA.
41 * \see http://www.gnu.org/copyleft/gpl.html
42 ***************************************************************/
45 #ifdef _MSC_VER
46 #pragma once
47 #endif
49 //KK: Commented out the constraint stuff using //o
50 //CG: compound graph stuff has been removed with commit 2465
52 #ifndef OGDF_OGML_PARSER_H
53 #define OGDF_OGML_PARSER_H
55 #include <ogdf/fileformats/Ogml.h>
56 #include <ogdf/fileformats/DinoXmlParser.h>
57 #include <ogdf/basic/Hashing.h>
58 #include <ogdf/basic/String.h>
59 #include <ogdf/cluster/ClusterGraph.h>
60 #include <ogdf/cluster/ClusterGraphAttributes.h>
62 // constraints
63 //o#include <ogdf/Constraints.h>
66 namespace ogdf {
69 // ---------- O g m l P a r s e r ------------------------
72 /**Objects of this class represent a validating parser for files in Ogml.
74 class OgmlParser
76 private:
78 // struct definitions for mapping of templates
79 struct OgmlNodeTemplate;
80 struct OgmlEdgeTemplate;
81 //struct OgmlLabelTemplate;
83 struct OgmlSegment;
85 class OgmlAttributeValue;
86 class OgmlAttribute;
87 class OgmlTag;
89 friend ostream& operator<<(ostream& os, const OgmlParser::OgmlAttribute& oa);
90 friend ostream& operator<<(ostream& os, const OgmlParser::OgmlTag& ot);
92 static Hashing<int, OgmlTag> *s_tags; //!< Hashtable for saving all ogml tags.
93 static Hashing<int, OgmlAttribute> *s_attributes; //!< Hashtable for saving all ogml attributes.
94 static Hashing<int, OgmlAttributeValue> *s_attValues; //!< Hashtable for saving all values of ogml attributes.
97 //! Builds hashtables for tags and attributes.
98 static void buildHashTables();
100 mutable Ogml::GraphType m_graphType; //!< Saves a graph type. Is set by checkGraphType.
102 Hashing<String, const XmlTagObject*> m_ids; //!< Saves all ids of an ogml-file.
105 * Checks if all tags (XmlTagObject), their attributes (XmlAttributeObject) and
106 * their values are valid (are tags expected, do they own the rigth attributes...)
107 * and sets a valid flag to these. Furthermore it checks if ids of tags are
108 * unique and if id references are valid.
109 * See OgmlTag.h for semantics of the encodings.
110 * Returns the validity state of the current processed tag.
112 int validate(const XmlTagObject *xmlTag, int ogmlTag);
115 * Wrapper method for validate method above.
116 * Returns true when validation is successfull, false otherwise.
118 //bool validate(const char* fileName);
120 //! Prints some useful information about un-/successful validation.
121 void printValidityInfo(const OgmlTag &ot,
122 const XmlTagObject &xto,
123 int valStatus,
124 int line);
127 * Finds the OGML-tag in the parse tree with the specified id,
128 * stores the tag in xmlTag
129 * recTag is the tag for recursive calls
130 * returns false if something goes wrong
132 //bool getXmlTagObjectById(XmlTagObject *recTag, String id, XmlTagObject *&xmlTag);
135 * Checks the graph type and stores it in the member variable m_graphType
136 * xmlTag has to be the root or the graph or the structure Ogml-tag
137 * returns false if something goes wrong
139 bool checkGraphType(const XmlTagObject *xmlTag) const;
141 //! Returns true iff subgraph is an hierarchical graph.
142 bool isGraphHierarchical(const XmlTagObject *xmlTag) const;
144 //! Returns true iff node contains other nodes.
145 bool isNodeHierarchical(const XmlTagObject *xmlTag) const;
147 Ogml::GraphType getGraphType() { return m_graphType; };
150 // id hash tables
151 // required variables for building
152 // hash table with id from file and node
153 Hashing<String, node> m_nodes;
154 Hashing<String, edge> m_edges;
155 Hashing<String, cluster> m_clusters;
156 // hash table for bend-points
157 Hashing<String, DPoint> m_points;
159 // hash table for checking uniqueness of ids
160 // (key:) int = id in the created graph
161 // (info:) String = id in the ogml file
162 Hashing<int, String> m_nodeIds;
163 Hashing<int, String> m_edgeIds;
164 Hashing<int, String> m_clusterIds;
166 // build methods
168 //! Builds a graph; ignores nodes which have hierarchical structure.
169 bool buildGraph(Graph &G);
171 //! Builds a cluster graph.
172 bool buildCluster(
173 const XmlTagObject *rootTag,
174 Graph &G,
175 ClusterGraph &CG);
177 //! Recursive part of buildCluster.
178 bool buildClusterRecursive(
179 const XmlTagObject *xmlTag,
180 cluster parent,
181 Graph &G,
182 ClusterGraph &CG);
184 //! Build a cluster graph with style/layout attributes.
185 bool buildAttributedClusterGraph(
186 Graph &G,
187 ClusterGraphAttributes &CGA,
188 const XmlTagObject *root);
190 //! Method for setting labels of clusters.
191 bool setLabelsRecursive(
192 Graph &G,
193 ClusterGraphAttributes &CGA,
194 XmlTagObject *root);
196 // helping pointer for constraints-loading
197 // this pointer is set in the building methods
198 // so we don't have to traverse the tree in buildConstraints
199 XmlTagObject* m_constraintsTag;
201 // hashing lists for templates
202 // string = id
203 Hashing<String, OgmlNodeTemplate*> m_ogmlNodeTemplates;
204 Hashing<String, OgmlEdgeTemplate*> m_ogmlEdgeTemplates;
205 //Hashing<String, OgmlLabelTemplate> m_ogmlLabelTemplates;
207 // auxiliary methods for mapping graph attributes
209 //! Returns int value for the pattern.
210 int getBrushPatternAsInt(String s);
212 //! Returns the shape as an integer value.
213 int getShapeAsInt(String s);
215 //! Maps the OGML attribute values to corresponding GDE values.
216 String getNodeTemplateFromOgmlValue(String s);
218 //! Returns the line type as an integer value.
219 int getLineTypeAsInt(String s);
221 //! Returns the image style as an integer value.
222 int getImageStyleAsInt(String s);
224 //! Returns the alignment of image as an integer value.
225 int getImageAlignmentAsInt(String s);
227 // arrow style, actually a "boolean" function
228 // because it returns only 0 or 1 according to GDE
229 // sot <=> source or target
230 int getArrowStyleAsInt(String s, String sot);
232 // the matching method to getArrowStyleAsInt
233 GraphAttributes::EdgeArrow getArrowStyle(int i);
235 // function that operates on a string
236 // the input string contains "&lt;" instead of "<"
237 // and "&gt;" instead of ">"
238 // to disable interpreting the string as xml-tags (by DinoXmlParser)
239 // so this function substitutes "<" for "&lt;"
240 String getLabelCaptionFromString(String str);
242 //! Returns the integer value of the id at the end of the string (if it exists).
243 bool getIdFromString(String str, int &id);
245 //! Validiation method.
246 void validate(const char* fileName);
248 public:
250 //! Constructs an OGML parser.
251 OgmlParser() { }
253 ~OgmlParser() { }
256 //! Reads a cluster graph \a CG from file \a fileName in OGML format.
258 * @param fileName is the name of the file to be parsed as OGML file.
259 * @param G is the graph to be build from the OGML file; must be the graph associated with \a CG.
260 * @param CG is the cluster graph to be build from the OGML file.
261 * @return true if succesfull, false otherwise.
263 bool read(
264 const char* fileName,
265 Graph &G,
266 ClusterGraph &CG);
268 //! Reads a cluster graph \a CG with attributes \a CGA from file \a fileName in OGML format.
270 * @param fileName is the name of the file to be parsed as OGML file.
271 * @param G is the graph to be build from the OGML file; must be the graph associated with \a CG.
272 * @param CG is the cluster graph to be build from the OGML file.
273 * @param CGA are the cluster graph attributes (associated with CG) in which layout and style information are stored.
274 * @return true if succesfull, false otherwise.
276 bool read(
277 const char* fileName,
278 Graph &G,
279 ClusterGraph &CG,
280 ClusterGraphAttributes &CGA);
282 };//end class OGMLParser
284 }//end namespace ogdf
286 #endif