Imported Upstream version 1.57.0
[platform/upstream/boost.git] / libs / graph / src / graphml.cpp
index 4a17fca..76ef0a2 100644 (file)
@@ -34,17 +34,23 @@ public:
     }
 
     static void get_graphs(const boost::property_tree::ptree& top,
+                           size_t desired_idx /* or -1 for all */,
                            std::vector<const boost::property_tree::ptree*>& result) {
       using boost::property_tree::ptree;
+      size_t current_idx = 0;
       BOOST_FOREACH(const ptree::value_type& n, top) {
         if (n.first == "graph") {
-          result.push_back(&n.second);
-          get_graphs(n.second, result);
+          if (current_idx == desired_idx || desired_idx == (size_t)(-1)) {
+            result.push_back(&n.second);
+            get_graphs(n.second, (size_t)(-1), result);
+            if (desired_idx != (size_t)(-1)) break;
+          }
+          ++current_idx;
         }
       }
     }
     
-    void run(std::istream& in)
+    void run(std::istream& in, size_t desired_idx)
     {
       using boost::property_tree::ptree;
       ptree pt;
@@ -65,6 +71,7 @@ public:
         else if (for_ == "port") kind = port_key;
         else if (for_ == "endpoint") kind = endpoint_key;
         else if (for_ == "all") kind = all_key;
+        else if (for_ == "graphml") kind = graphml_key;
         else {BOOST_THROW_EXCEPTION(parse_error("Attribute for is not valid: " + for_));}
         m_keys[id] = kind;
         m_key_name[id] = name;
@@ -74,7 +81,7 @@ public:
       }
       // Search for graphs
       std::vector<const ptree*> graphs;
-      get_graphs(gml, graphs);
+      get_graphs(gml, desired_idx, graphs);
       BOOST_FOREACH(const ptree* gr, graphs) {
         // Search for nodes
         BOOST_FOREACH(const ptree::value_type& node, *gr) {
@@ -126,7 +133,8 @@ private:
         hyperedge_key,
         port_key,
         endpoint_key, 
-        all_key
+        all_key,
+        graphml_key
     };
 
     void 
@@ -209,9 +217,9 @@ private:
 namespace boost
 {
 void BOOST_GRAPH_DECL
-read_graphml(std::istream& in, mutate_graph& g)
+read_graphml(std::istream& in, mutate_graph& g, size_t desired_idx)
 {    
     graphml_reader reader(g);
-    reader.run(in);
+    reader.run(in, desired_idx);
 }
 }