Open
Graph Drawing
Framework

 v. snapshot-2017-02-16
 

GraphMLParser.h
Go to the documentation of this file.
1 
32 #pragma once
33 
35 
36 #include <ogdf/basic/HashArray.h>
38 
39 #include <sstream>
40 #include <unordered_map>
41 
42 namespace ogdf {
43 
45 private:
47  pugi::xml_node m_graphTag; // "Almost root" tag.
48 
49  // Maps GraphML node id to Graph node.
50  std::unordered_map<string, node> m_nodeId;
51 
52  // Maps attribute id to its name.
53  std::unordered_map<string, string> m_attrName;
54 
55  bool readData(
56  GraphAttributes &GA,
57  const node &v, const pugi::xml_node nodeData);
58  bool readData(
59  GraphAttributes &GA,
60  const edge &e, const pugi::xml_node edgeData);
61  bool readData(
63  const cluster &c, const pugi::xml_node clusterData);
64 
65  // Finds all data-keys for given element and calls appropiate "readData".
66  template <typename A, typename T>
67  bool readAttributes(A &GA, const T &elem, const pugi::xml_node xmlElem) {
68  for (pugi::xml_node dataTag : xmlElem.children("data")) {
69  const bool result = readData(GA, elem, dataTag);
70  if(!result) {
71  return false;
72  }
73  }
74 
75  return true;
76  }
77 
78  bool readNodes(
79  Graph &G, GraphAttributes *GA,
80  const pugi::xml_node rootTag);
81  bool readEdges(
82  Graph &G, GraphAttributes *GA,
83  const pugi::xml_node rootTag);
84  bool readClusters(
86  const cluster &rootCluster, const pugi::xml_node clusterRoot);
87 
88  bool m_error;
89 
90 public:
91  explicit GraphMLParser(istream &in);
93 
94  bool read(Graph &G);
95  bool read(Graph &G, GraphAttributes &GA);
96  bool read(Graph &G, ClusterGraph &C);
98 };
99 
100 
101 } // end namespace ogdf
Declaration and implementation of HashArray class.
pugi::xml_document m_xml
Definition: GraphMLParser.h:46
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:472
std::unordered_map< string, node > m_nodeId
Definition: GraphMLParser.h:50
GraphMLParser(istream &in)
std::unordered_map< string, string > m_attrName
Definition: GraphMLParser.h:53
Representation of clustered graphs.
Definition: ClusterGraph.h:291
bool read(Graph &G)
Stores additional attributes of a graph (like layout information).
pugi::xml_node m_graphTag
Definition: GraphMLParser.h:47
xml_object_range< xml_node_iterator > children() const
Class for the representation of edges.
Definition: Graph_d.h:291
Stores additional attributes of a clustered graph (like layout information).
bool readNodes(Graph &G, GraphAttributes *GA, const pugi::xml_node rootTag)
Class for the representation of nodes.
Definition: Graph_d.h:167
Representation of clusters in a clustered graph.
Definition: ClusterGraph.h:53
bool readData(GraphAttributes &GA, const node &v, const pugi::xml_node nodeData)
bool readEdges(Graph &G, GraphAttributes *GA, const pugi::xml_node rootTag)
bool readClusters(Graph &G, ClusterGraph &C, ClusterGraphAttributes *CA, const cluster &rootCluster, const pugi::xml_node clusterRoot)
The namespace for all OGDF objects.
bool readAttributes(A &GA, const T &elem, const pugi::xml_node xmlElem)
Definition: GraphMLParser.h:67
Declares class GraphIO which provides access to all graph read and write functionality.