Open
Graph Drawing
Framework

 v. snapshot-2017-02-16
 

OgmlParser.h
Go to the documentation of this file.
1 
32 //KK: Commented out the constraint stuff using //o
33 //CG: compound graph stuff has been removed with commit 2465
34 
35 #pragma once
36 
37 #include <ogdf/fileformats/Ogml.h>
39 #include <ogdf/basic/Hashing.h>
42 
43 namespace ogdf {
44 
47 {
48 private:
49 
50  // struct definitions for mapping of templates
51  struct OgmlNodeTemplate;
52  struct OgmlEdgeTemplate;
53 #if 0
54  struct OgmlLabelTemplate;
55 #endif
56 
57  struct OgmlSegment;
58 
59  class OgmlAttributeValue;
60  class OgmlAttribute;
61  class OgmlTag;
62 
63  friend ostream& operator<<(ostream& os, const OgmlParser::OgmlAttribute& oa);
64  friend ostream& operator<<(ostream& os, const OgmlParser::OgmlTag& ot);
65 
69 
70  enum Mode { compMode = 0, choiceMode, optMode };
71 
73 
75 
84  int validate(const XmlTagObject *xmlTag, int ogmlTag);
85 
86 #if 0
87 
91  bool validate(const char* fileName);
92 #endif
93 
95  void printValidityInfo(const OgmlTag &ot,
96  const XmlTagObject &xto,
97  int valStatus,
98  int line);
99 
100 #if 0
101 
107  bool getXmlTagObjectById(XmlTagObject *recTag, string id, XmlTagObject *&xmlTag);
108 #endif
109 
115  bool checkGraphType(const XmlTagObject *xmlTag) const;
116 
118  bool isGraphHierarchical(const XmlTagObject *xmlTag) const;
119 
121  bool isNodeHierarchical(const XmlTagObject *xmlTag) const;
122 
124 
125 
126  // id hash tables
127  // required variables for building
128  // hash table with id from file and node
132  // hash table for bend-points
134 
135  // hash table for checking uniqueness of ids
136  // (key:) int = id in the created graph
137  // (info:) string = id in the ogml file
141 
142  // build methods
143 
145  bool buildGraph(Graph &G);
146 
148  bool buildCluster(
149  const XmlTagObject *rootTag,
150  Graph &G,
151  ClusterGraph &CG);
152 
155  const XmlTagObject *xmlTag,
156  cluster parent,
157  Graph &G,
158  ClusterGraph &CG);
159 
161  bool addAttributes(
162  Graph &G,
163  GraphAttributes &GA,
165  const XmlTagObject *root);
166 
168  bool setLabelsRecursive(
169  Graph &G,
170  GraphAttributes &GA,
172  XmlTagObject *root);
173 
174  // helping pointer for constraints-loading
175  // this pointer is set in the building methods
176  // so we don't have to traverse the tree in buildConstraints
178 
179  // hashing lists for templates
180  // string = id
183  //Hashing<string, OgmlLabelTemplate> m_ogmlLabelTemplates;
184 
185  // auxiliary methods for mapping graph attributes
186 
188  FillPattern getFillPattern(string s);
189 
191  Shape getShape(string s);
192 
194  string getNodeTemplateFromOgmlValue(string s);
195 
197  StrokeType getStrokeType(string s);
198 
199  // arrow style, actually a "boolean" function
200  // because it returns only 0 or 1 according to GDE
201  // sot <=> source or target
202  int getArrowStyleAsInt(string s);
203 
204  // the matching method to getArrowStyleAsInt
205  EdgeArrow getArrowStyle(int i);
206 
207  // function that operates on a string
208  // the input string contains "&lt;" instead of "<"
209  // and "&gt;" instead of ">"
210  // to disable interpreting the string as xml-tags (by XmlParser)
211  // so this function substitutes "<" for "&lt;"
212  string getLabelCaptionFromString(string str);
213 
215  bool getIdFromString(string str, int &id);
216 
218  bool doRead(
219  istream &is,
220  Graph &G,
221  ClusterGraph *pCG,
222  GraphAttributes *pGA,
223  ClusterGraphAttributes *pCGA);
224 
225 public:
226 
228  OgmlParser();
229 
230  ~OgmlParser();
231 
232 
234 
239  bool read(istream &is, Graph &G) {
240  return doRead(is, G, nullptr, nullptr, nullptr);
241  }
242 
244 
250  bool read(istream &is, Graph &G, ClusterGraph &CG) {
251  return doRead(is, G, &CG, nullptr, nullptr);
252  }
253 
255 
261  bool read(
262  istream &is,
263  Graph &G,
264  GraphAttributes &GA)
265  {
266  return doRead(is, G, nullptr, &GA, nullptr);
267  }
268 
270 
277  bool read(
278  istream &is,
279  Graph &G,
280  ClusterGraph &CG,
282  {
283  return doRead(is, G, &CG, &CGA, &CGA);
284  }
285 };//end class OGMLParser
286 
287 }//end namespace ogdf
bool isGraphHierarchical(const XmlTagObject *xmlTag) const
Returns true iff subgraph is an hierarchical graph.
static const int line
Definition: GmlParser.h:86
Objects of this class represent a validating parser for files in Ogml.
Definition: OgmlParser.h:46
Hashing< int, OgmlTag > * m_tags
Hashtable for saving all ogml tags.
Definition: OgmlParser.h:66
Derived class of GraphObserver providing additional functionality to handle clustered graphs...
Hashing< int, string > m_edgeIds
Definition: OgmlParser.h:139
bool isNodeHierarchical(const XmlTagObject *xmlTag) const
Returns true iff node contains other nodes.
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:472
int getArrowStyleAsInt(string s)
Hashing< string, node > m_nodes
Definition: OgmlParser.h:123
bool read(istream &is, Graph &G, GraphAttributes &GA)
Reads a graph G with attributes GA from istream is in OGML format.
Definition: OgmlParser.h:261
FillPattern getFillPattern(string s)
Returns fill pattern of string s.
Declaration of classes used for hashing.
Contains diverse enumerations and string constants.
Hashing< int, OgmlAttributeValue > * m_attValues
Hashtable for saving all values of ogml attributes.
Definition: OgmlParser.h:68
Hashing< string, const XmlTagObject * > m_ids
Saves all ids of an ogml-file.
Definition: OgmlParser.h:74
FillPattern
Fill patterns.
Definition: graphics.h:88
EdgeArrow
Types for edge arrows.
Definition: graphics.h:142
Hashing< int, OgmlAttribute > * m_attributes
Hashtable for saving all ogml attributes.
Definition: OgmlParser.h:67
bool buildCluster(const XmlTagObject *rootTag, Graph &G, ClusterGraph &CG)
Builds a cluster graph.
GraphType
This enumeration is used for identifying graph types.
Definition: Ogml.h:290
string getLabelCaptionFromString(string str)
Hashing< string, DPoint > m_points
Definition: OgmlParser.h:133
string getNodeTemplateFromOgmlValue(string s)
Maps the OGML attribute values to corresponding GDE values.
Representation of clustered graphs.
Definition: ClusterGraph.h:291
OgmlParser()
Constructs an OGML parser.
Shape getShape(string s)
Returns the shape as an integer value.
Contains the struct declarations XmlAttributeObject, XmlTagObject and the class XmlParser.
Shape
Types for node shapes.
Definition: graphics.h:120
bool getIdFromString(string str, int &id)
Returns the integer value of the id at the end of the string (if it exists).
friend ostream & operator<<(ostream &os, const OgmlParser::OgmlAttribute &oa)
This struct represents a node in the XML parse tree.
Definition: XmlParser.h:104
Stores additional attributes of a graph (like layout information).
bool checkGraphType(const XmlTagObject *xmlTag) const
Checks the graph type and stores it in the member variable m_graphType xmlTag has to be the root or t...
void printValidityInfo(const OgmlTag &ot, const XmlTagObject &xto, int valStatus, int line)
Prints some useful information about un-/successful validation.
bool setLabelsRecursive(Graph &G, GraphAttributes &GA, ClusterGraphAttributes *pCGA, XmlTagObject *root)
Recursive method for setting labels of clusters and nodes.
bool buildGraph(Graph &G)
Builds a graph; ignores nodes which have hierarchical structure.
Stores additional attributes of a clustered graph (like layout information).
Hashing< string, OgmlEdgeTemplate * > m_ogmlEdgeTemplates
Definition: OgmlParser.h:182
Hashing< string, edge > m_edges
Definition: OgmlParser.h:130
bool doRead(istream &is, Graph &G, ClusterGraph *pCG, GraphAttributes *pGA, ClusterGraphAttributes *pCGA)
Unified read method for graphs.
int validate(const XmlTagObject *xmlTag, int ogmlTag)
Checks if all tags (XmlTagObject), their attributes (XmlAttributeObject) and their values are valid (...
bool addAttributes(Graph &G, GraphAttributes &GA, ClusterGraphAttributes *pCGA, const XmlTagObject *root)
Build a cluster graph with style/layout attributes.
Hashing< int, string > m_clusterIds
Definition: OgmlParser.h:140
bool read(istream &is, Graph &G, ClusterGraph &CG)
Reads a cluster graph CG from istream is in OGML format.
Definition: OgmlParser.h:250
XmlTagObject * m_constraintsTag
Definition: OgmlParser.h:177
Declares ClusterGraphAttributes, an extension of class GraphAttributes, to store clustergraph layout ...
bool buildClusterRecursive(const XmlTagObject *xmlTag, cluster parent, Graph &G, ClusterGraph &CG)
Recursive part of buildCluster.
Representation of clusters in a clustered graph.
Definition: ClusterGraph.h:53
bool read(istream &is, Graph &G, ClusterGraph &CG, ClusterGraphAttributes &CGA)
Reads a cluster graph CG with attributes CGA from istream is in OGML format.
Definition: OgmlParser.h:277
Ogml::GraphType m_graphType
Saves a graph type.
Definition: OgmlParser.h:72
StrokeType
Line types of strokes.
Definition: graphics.h:43
Hashing< int, string > m_nodeIds
Definition: OgmlParser.h:138
StrokeType getStrokeType(string s)
Returns the line type as an integer value.
Hashing< string, OgmlNodeTemplate * > m_ogmlNodeTemplates
Definition: OgmlParser.h:181
The namespace for all OGDF objects.
EdgeArrow getArrowStyle(int i)
Hashing< string, cluster > m_clusters
Definition: OgmlParser.h:131
Ogml::GraphType getGraphType()
Definition: OgmlParser.h:123
bool read(istream &is, Graph &G)
Reads a graph G from istream is in OGML format.
Definition: OgmlParser.h:239