1 /** \file 2 * \brief Declaration of GEXF format reading utilities. 3 * 4 * \author Łukasz Hanuszczak 5 * 6 * \par License: 7 * This file is part of the Open Graph Drawing Framework (OGDF). 8 * 9 * \par 10 * Copyright (C)<br> 11 * See README.md in the OGDF root directory for details. 12 * 13 * \par 14 * This program is free software; you can redistribute it and/or 15 * modify it under the terms of the GNU General Public License 16 * Version 2 or 3 as published by the Free Software Foundation; 17 * see the file LICENSE.txt included in the packaging of this file 18 * for details. 19 * 20 * \par 21 * This program is distributed in the hope that it will be useful, 22 * but WITHOUT ANY WARRANTY; without even the implied warranty of 23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 * GNU General Public License for more details. 25 * 26 * \par 27 * You should have received a copy of the GNU General Public 28 * License along with this program; if not, see 29 * http://www.gnu.org/copyleft/gpl.html 30 */ 31 32 #pragma once 33 34 #include <ogdf/basic/Graph.h> 35 #include <ogdf/basic/GraphAttributes.h> 36 #include <ogdf/cluster/ClusterGraph.h> 37 #include <ogdf/cluster/ClusterGraphAttributes.h> 38 #include <ogdf/lib/pugixml/pugixml.h> 39 40 #include <unordered_map> 41 #include <memory> 42 #include <sstream> 43 44 45 namespace ogdf { 46 47 namespace gexf { 48 49 50 class Parser { 51 private: 52 std::istream &m_is; 53 54 pugi::xml_document m_xml; 55 pugi::xml_node m_graphTag, m_nodesTag, m_edgesTag; 56 57 std::unordered_map<std::string, node> m_nodeId; 58 std::unordered_map<std::string, cluster> m_clusterId; 59 60 std::unordered_map<std::string, std::string> m_nodeAttr, m_edgeAttr; 61 62 bool init(); 63 bool readNodes(Graph &G, GraphAttributes *GA); 64 bool readEdges(Graph &G, ClusterGraph *C, GraphAttributes *GA); 65 bool readCluster( 66 Graph &G, ClusterGraph &C, ClusterGraphAttributes *CA, 67 cluster rootCluster, 68 const pugi::xml_node rootTag); 69 bool readAttributes( 70 GraphAttributes &GA, node v, 71 const pugi::xml_node nodeTag); 72 bool readAttributes( 73 GraphAttributes &GA, edge e, 74 const pugi::xml_node edgeTag); 75 76 static void error(const pugi::xml_node tag, const std::string &msg); 77 78 public: 79 explicit Parser(std::istream &is); 80 81 bool read(Graph &G); 82 bool read(Graph &G, GraphAttributes &GA); 83 bool read(Graph &G, ClusterGraph &C); 84 bool read(Graph &G, ClusterGraph &C, ClusterGraphAttributes &CA); 85 }; 86 87 } 88 } 89