Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

GraphMLParser.h
Go to the documentation of this file.
1 
32 #pragma once
33 
34 #include <ogdf/basic/Graph.h>
35 #include <ogdf/basic/basic.h>
37 
39 
40 #include <sstream>
41 #include <string>
42 #include <unordered_map>
43 
44 namespace ogdf {
45 class ClusterGraphAttributes;
46 class GraphAttributes;
47 
49 private:
51  pugi::xml_node m_graphTag; // "Almost root" tag.
52 
53  // Maps GraphML node id to Graph node.
54  std::unordered_map<string, node> m_nodeId;
55 
56  // Maps attribute id to its name.
57  std::unordered_map<string, string> m_attrName;
58 
59  bool readData(GraphAttributes& GA, const node& v, const pugi::xml_node nodeData);
60  bool readData(GraphAttributes& GA, const edge& e, const pugi::xml_node edgeData);
61  bool readData(ClusterGraphAttributes& CA, const cluster& c, const pugi::xml_node clusterData);
62 
63  // Finds all data-keys for given element and calls appropiate "readData".
64  template<typename A, typename T>
65  bool readAttributes(A& GA, const T& elem, const pugi::xml_node xmlElem) {
66  for (pugi::xml_node dataTag : xmlElem.children("data")) {
67  const bool result = readData(GA, elem, dataTag);
68  if (!result) {
69  return false;
70  }
71  }
72 
73  return true;
74  }
75 
76  bool readNodes(Graph& G, GraphAttributes* GA, const pugi::xml_node rootTag);
77  bool readEdges(Graph& G, GraphAttributes* GA, const pugi::xml_node rootTag);
79  const cluster& rootCluster, const pugi::xml_node clusterRoot);
80 
81  bool m_error;
82 
83 public:
84  explicit GraphMLParser(std::istream& in);
86 
87  bool read(Graph& G);
88  bool read(Graph& G, GraphAttributes& GA);
89  bool read(Graph& G, ClusterGraph& C);
91 };
92 
93 }
ogdf
The namespace for all OGDF objects.
Definition: multilevelmixer.cpp:39
ogdf::GraphAttributes
Stores additional attributes of a graph (like layout information).
Definition: GraphAttributes.h:72
Graph.h
Includes declaration of graph class.
ogdf::GraphMLParser::readAttributes
bool readAttributes(A &GA, const T &elem, const pugi::xml_node xmlElem)
Definition: GraphMLParser.h:65
ogdf::GraphMLParser::readEdges
bool readEdges(Graph &G, GraphAttributes *GA, const pugi::xml_node rootTag)
pugixml.h
pugi::xml_node::children
xml_object_range< xml_node_iterator > children() const
ogdf::GraphMLParser::GraphMLParser
GraphMLParser(std::istream &in)
ogdf::GraphMLParser::readData
bool readData(GraphAttributes &GA, const node &v, const pugi::xml_node nodeData)
ogdf::ClusterElement
Representation of clusters in a clustered graph.
Definition: ClusterGraph.h:62
ogdf::ClusterGraphAttributes
Stores additional attributes of a clustered graph (like layout information).
Definition: ClusterGraphAttributes.h:52
ogdf::GraphMLParser::m_xml
pugi::xml_document m_xml
Definition: GraphMLParser.h:50
ogdf::GraphMLParser::m_error
bool m_error
Definition: GraphMLParser.h:81
ogdf::GraphMLParser::~GraphMLParser
~GraphMLParser()
ogdf::GraphMLParser::m_graphTag
pugi::xml_node m_graphTag
Definition: GraphMLParser.h:51
pugi::xml_node
Definition: pugixml.h:401
ogdf::Graph
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:869
ogdf::GraphMLParser::read
bool read(Graph &G)
basic.h
Basic declarations, included by all source files.
ogdf::GraphMLParser::m_nodeId
std::unordered_map< string, node > m_nodeId
Definition: GraphMLParser.h:54
ogdf::GraphMLParser::readNodes
bool readNodes(Graph &G, GraphAttributes *GA, const pugi::xml_node rootTag)
ogdf::GraphMLParser::m_attrName
std::unordered_map< string, string > m_attrName
Definition: GraphMLParser.h:57
pugi::xml_document
Definition: pugixml.h:943
ogdf::EdgeElement
Class for the representation of edges.
Definition: Graph_d.h:363
ClusterGraph.h
Derived class of GraphObserver providing additional functionality to handle clustered graphs.
ogdf::GraphMLParser
Definition: GraphMLParser.h:48
ogdf::GraphMLParser::readClusters
bool readClusters(Graph &G, ClusterGraph &C, ClusterGraphAttributes *CA, const cluster &rootCluster, const pugi::xml_node clusterRoot)
ogdf::ClusterGraph
Representation of clustered graphs.
Definition: ClusterGraph.h:346
ogdf::NodeElement
Class for the representation of nodes.
Definition: Graph_d.h:240