From abe35ea720882bf6fae390cbc412c2737cff1646 Mon Sep 17 00:00:00 2001 From: dmatetelki Date: Sat, 9 Aug 2014 16:25:44 +0200 Subject: [PATCH] small refoctoring of graph_xml.hpp --- lib/graph/graph_xml.hpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/graph/graph_xml.hpp b/lib/graph/graph_xml.hpp index 169ff03..1daa86d 100644 --- a/lib/graph/graph_xml.hpp +++ b/lib/graph/graph_xml.hpp @@ -9,8 +9,9 @@ namespace { template -void readVertices(Graph& g, F vertexCreator, const xmlNodePtr root_element) +Graph readVertices(F vertexCreator, const xmlNodePtr root_element) { + Graph g; for (xmlNodePtr cur_node = root_element->children; cur_node; cur_node = cur_node->next) if (cur_node->type == XML_ELEMENT_NODE) { @@ -26,6 +27,7 @@ void readVertices(Graph& g, F vertexCreator, const xmlNodePtr root_element) } g.setEdges(v, edges); } + return g; } } // anonym namespace @@ -38,15 +40,14 @@ Graph readGraphFromXML(const std::string& filename, F vertexCreator) if (!file.good()) throw std::runtime_error("Failed to open " + filename + " to read."); - xmlDocPtr doc = xmlReadFile(filename.c_str(), NULL, 0); + const char* encoding = NULL; + const int options = 0; + const xmlDocPtr doc = xmlReadFile(filename.c_str(), encoding, options); if (doc == NULL) throw std::runtime_error("Failed to parse " + filename); - xmlNodePtr root_element = NULL; - root_element = xmlDocGetRootElement(doc); - - Graph g; - readVertices(g, vertexCreator, root_element); + const xmlNodePtr root_element = xmlDocGetRootElement(doc); + const Graph g = readVertices(vertexCreator, root_element); xmlFreeDoc(doc); xmlCleanupParser();