[Lemon-commits] Peter Kovacs: lgf_demo.cc is merged with reader_...

Lemon HG hg at lemon.cs.elte.hu
Sun Jul 6 08:49:28 CEST 2008


details:   http://lemon.cs.elte.hu/hg/lemon/rev/abc5b9d0c67e
changeset: 191:abc5b9d0c67e
user:      Peter Kovacs <kpeter [at] inf.elte.hu>
date:      Sat Jul 05 17:22:28 2008 +0200
description:
	lgf_demo.cc is merged with reader_writer_demo.cc (from SVN -r3501)

diffstat:

1 file changed, 17 insertions(+), 13 deletions(-)
demo/lgf_demo.cc |   30 +++++++++++++++++-------------

diffs (58 lines):

diff -r 1e6af6f0843c -r abc5b9d0c67e demo/lgf_demo.cc
--- a/demo/lgf_demo.cc	Fri Jul 04 16:12:31 2008 +0200
+++ b/demo/lgf_demo.cc	Sat Jul 05 17:22:28 2008 +0200
@@ -20,22 +20,21 @@
 ///\file
 ///\brief Demonstrating graph input and output
 ///
-/// This program gives an example of how to load a directed graph from
-/// an \ref lgf-format "LGF" file with the \ref lemon::DigraphReader
-/// "DigraphReader" class.
+/// This program gives an example of how to read and write a digraph
+/// and additional maps from/to a stream or a file using the 
+/// \ref lgf-format "LGF" format.
 ///
 /// The \c "digraph.lgf" file:
 /// \include digraph.lgf
 ///
-/// And the program which reads it:
+/// And the program which reads it and prints the digraph to the
+/// standard output:
 /// \include lgf_demo.cc
 
 #include <iostream>
 #include <lemon/smart_graph.h>
 #include <lemon/lgf_reader.h>
 #include <lemon/lgf_writer.h>
-#include <lemon/random.h>
-
 
 using namespace lemon;
 
@@ -43,14 +42,19 @@
   SmartDigraph g;
   SmartDigraph::ArcMap<int> cap(g);
   SmartDigraph::Node s, t;
+  
+  try {
+    digraphReader("digraph.lgf", g). // read the directed graph into g
+      arcMap("capacity", cap).       // read the 'capacity' arc map into cap
+      node("source", s).             // read 'source' node to s
+      node("target", t).             // read 'target' node to t
+      run();
+  } catch (DataFormatError& error) { // check if there was any error
+    std::cerr << "Error: " << error.what() << std::endl;
+    return -1;
+  }
 
-  digraphReader("digraph.lgf", g). // read the directeg graph into g
-    arcMap("capacity", cap).       // read the 'capacity' arc map into cap
-    node("source", s).             // read 'source' node to s
-    node("target", t).             // read 'target' node to t
-    run();
-
-  std::cout << "Digraph read from 'digraph.lgf'" << std::endl;
+  std::cout << "A digraph is read from 'digraph.lgf'." << std::endl;
   std::cout << "Number of nodes: " << countNodes(g) << std::endl;
   std::cout << "Number of arcs: " << countArcs(g) << std::endl;
 



More information about the Lemon-commits mailing list