Open
Graph Drawing
Framework

 v. 2025.10-dev (Foxglove)
 

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