demo/reader_writer_demo.cc
changeset 1528 1aa71600000c
child 1530 d99c3c84f797
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/demo/reader_writer_demo.cc	Fri Jul 01 16:10:46 2005 +0000
     1.3 @@ -0,0 +1,83 @@
     1.4 +#include <iostream>
     1.5 +#include <lemon/smart_graph.h>
     1.6 +#include <lemon/invalid.h>
     1.7 +#include <lemon/graph_reader.h>
     1.8 +#include <lemon/graph_writer.h>
     1.9 +
    1.10 +
    1.11 +using namespace lemon;
    1.12 +
    1.13 +int main() {
    1.14 +  SmartGraph graph;
    1.15 +
    1.16 +  try {
    1.17 +    std::string filename="sample.lgf";
    1.18 +    GraphReader<SmartGraph> reader(filename,graph);
    1.19 +    SmartGraph::EdgeMap<int> cap(graph);
    1.20 +    reader.readEdgeMap("capacity",cap);
    1.21 +//     reader.readNode("source",s).readNode("target",t)
    1.22 +//       .readEdgeMap("capacity",cap).run();
    1.23 +    reader.run();
    1.24 +
    1.25 +    std::cout << "Hello! We have read a graph from file " << filename<< 
    1.26 +      " and some maps on it: now we write this to the standard output!" << 
    1.27 +      std::endl;
    1.28 +
    1.29 +
    1.30 +    GraphWriter<SmartGraph> writer(std::cout, graph);
    1.31 +    writer.writeEdgeMap("multiplicity", cap);
    1.32 +//     writer.writeNode("source", s);
    1.33 +//     writer.writeNode("target", t);
    1.34 +    writer.run();
    1.35 +     
    1.36 +//     LemonReader reader(std::cin);
    1.37 +
    1.38 +//     NodeSetReader<SmartGraph> nodeset(reader, graph);
    1.39 +//     SmartGraph::NodeMap<int> cost(graph);
    1.40 +//     nodeset.readMap("cost", cost);
    1.41 +//     SmartGraph::NodeMap<char> mmap(graph);
    1.42 +//     nodeset.readMap("mmap", mmap);
    1.43 +
    1.44 +//     EdgeSetReader<SmartGraph> edgeset(reader, graph, nodeset);
    1.45 +//     SmartGraph::EdgeMap<std::string> description(graph);
    1.46 +//     edgeset.readMap<QuotedStringReader>("description", description);
    1.47 +
    1.48 +//     NodeReader<SmartGraph> nodes(reader, nodeset);
    1.49 +//     SmartGraph::Node source;
    1.50 +//     nodes.readNode("source", source);
    1.51 +//     SmartGraph::Node target;
    1.52 +//     nodes.readNode("target", target);
    1.53 +
    1.54 +//     AttributeReader<> attribute(reader, "gui");
    1.55 +//     std::string author;
    1.56 +//     attribute.readAttribute<LineReader>("author", author);
    1.57 +//     int count;
    1.58 +//     attribute.readAttribute("count", count);
    1.59 +
    1.60 +//     PrintReader print(reader);
    1.61 +
    1.62 +//     reader.run();
    1.63 +
    1.64 +
    1.65 +//     for (SmartGraph::NodeIt it(graph); it != INVALID; ++it) {
    1.66 +//       std::cout << cost[it] << ' ' << mmap[it] << std::endl;
    1.67 +//     }
    1.68 +
    1.69 +//     for (SmartGraph::EdgeIt it(graph); it != INVALID; ++it) {
    1.70 +//       std::cout << description[it] << std::endl;
    1.71 +//     }
    1.72 +
    1.73 +//     std::cout << "author: " << author << std::endl;
    1.74 +//     std::cout << "count: " << count << std::endl;
    1.75 +
    1.76 +//     std::cout << "source cost: " << cost[source] << std::endl;
    1.77 +//     std::cout << "target cost: " << cost[target] << std::endl;
    1.78 +
    1.79 +//     std::cout.flush();
    1.80 +  } catch (DataFormatError& error) {
    1.81 +    std::cerr << error.what() << std::endl;
    1.82 +  }
    1.83 +
    1.84 +
    1.85 +  return 0;
    1.86 +}