COIN-OR::LEMON - Graph Library

Ticket #156: 47fbc814aa31.patch

File 47fbc814aa31.patch, 19.3 KB (added by Peter Kovacs, 16 years ago)
  • demo/lgf_demo.cc

    # HG changeset patch
    # User Peter Kovacs <kpeter@inf.elte.hu>
    # Date 1222857856 -7200
    # Node ID 47fbc814aa31e11f181b22cb79022ad4fa25558c
    # Parent  d91884dcd572f8f69253ac1d304f0a4a651da76c
    Change the parameter order in LGF reader and writer tools
    
    diff --git a/demo/lgf_demo.cc b/demo/lgf_demo.cc
    a b  
    4444  SmartDigraph::Node s, t;
    4545
    4646  try {
    47     digraphReader("digraph.lgf", g). // read the directed graph into g
     47    digraphReader(g, "digraph.lgf"). // read the directed graph into g
    4848      arcMap("capacity", cap).       // read the 'capacity' arc map into cap
    4949      node("source", s).             // read 'source' node to s
    5050      node("target", t).             // read 'target' node to t
     
    6060
    6161  std::cout << "We can write it to the standard output:" << std::endl;
    6262
    63   digraphWriter(std::cout, g).     // write g to the standard output
     63  digraphWriter(g).                // write g to the standard output
    6464    arcMap("capacity", cap).       // write cap into 'capacity'
    6565    node("source", s).             // write s to 'source'
    6666    node("target", t).             // write t to 'target'
  • lemon/lgf_reader.h

    diff --git a/lemon/lgf_reader.h b/lemon/lgf_reader.h
    a b  
    390390  class DigraphReader;
    391391
    392392  template <typename Digraph>
    393   DigraphReader<Digraph> digraphReader(std::istream& is, Digraph& digraph);
     393  DigraphReader<Digraph> digraphReader(Digraph& digraph,
     394                                       std::istream& is = std::cin);
    394395
    395396  template <typename Digraph>
    396   DigraphReader<Digraph> digraphReader(const std::string& fn, Digraph& digraph);
     397  DigraphReader<Digraph> digraphReader(Digraph& digraph, const std::string& fn);
    397398
    398399  template <typename Digraph>
    399   DigraphReader<Digraph> digraphReader(const char *fn, Digraph& digraph);
     400  DigraphReader<Digraph> digraphReader(Digraph& digraph, const char *fn);
    400401
    401402  /// \ingroup lemon_io
    402403  ///
     
    419420  /// rules.
    420421  ///
    421422  ///\code
    422   /// DigraphReader<Digraph>(std::cin, digraph).
     423  /// DigraphReader<Digraph>(digraph, std::cin).
    423424  ///   nodeMap("coordinates", coord_map).
    424425  ///   arcMap("capacity", cap_map).
    425426  ///   node("source", src).
     
    499500    ///
    500501    /// Construct a directed graph reader, which reads from the given
    501502    /// input stream.
    502     DigraphReader(std::istream& is, Digraph& digraph)
     503    DigraphReader(Digraph& digraph, std::istream& is = std::cin)
    503504      : _is(&is), local_is(false), _digraph(digraph),
    504505        _use_nodes(false), _use_arcs(false),
    505506        _skip_nodes(false), _skip_arcs(false) {}
     
    508509    ///
    509510    /// Construct a directed graph reader, which reads from the given
    510511    /// file.
    511     DigraphReader(const std::string& fn, Digraph& digraph)
     512    DigraphReader(Digraph& digraph, const std::string& fn)
    512513      : _is(new std::ifstream(fn.c_str())), local_is(true), _digraph(digraph),
    513514        _use_nodes(false), _use_arcs(false),
    514515        _skip_nodes(false), _skip_arcs(false) {}
     
    517518    ///
    518519    /// Construct a directed graph reader, which reads from the given
    519520    /// file.
    520     DigraphReader(const char* fn, Digraph& digraph)
     521    DigraphReader(Digraph& digraph, const char* fn)
    521522      : _is(new std::ifstream(fn)), local_is(true), _digraph(digraph),
    522523        _use_nodes(false), _use_arcs(false),
    523524        _skip_nodes(false), _skip_arcs(false) {}
     
    547548
    548549  private:
    549550
    550     friend DigraphReader<Digraph> digraphReader<>(std::istream& is,
    551                                                   Digraph& digraph);
    552     friend DigraphReader<Digraph> digraphReader<>(const std::string& fn,
    553                                                   Digraph& digraph);
    554     friend DigraphReader<Digraph> digraphReader<>(const char *fn,
    555                                                   Digraph& digraph);
     551    friend DigraphReader<Digraph> digraphReader<>(Digraph& digraph,
     552                                                  std::istream& is);
     553    friend DigraphReader<Digraph> digraphReader<>(Digraph& digraph,
     554                                                  const std::string& fn);
     555    friend DigraphReader<Digraph> digraphReader<>(Digraph& digraph,
     556                                                  const char *fn);
    556557
    557558    DigraphReader(DigraphReader& other)
    558559      : _is(other._is), local_is(other.local_is), _digraph(other._digraph),
     
    11801181  /// This function just returns a \ref DigraphReader class.
    11811182  /// \relates DigraphReader
    11821183  template <typename Digraph>
    1183   DigraphReader<Digraph> digraphReader(std::istream& is, Digraph& digraph) {
    1184     DigraphReader<Digraph> tmp(is, digraph);
     1184  DigraphReader<Digraph> digraphReader(Digraph& digraph,
     1185                                       std::istream& is = std::cin) {
     1186    DigraphReader<Digraph> tmp(digraph, is);
    11851187    return tmp;
    11861188  }
    11871189
     
    11901192  /// This function just returns a \ref DigraphReader class.
    11911193  /// \relates DigraphReader
    11921194  template <typename Digraph>
    1193   DigraphReader<Digraph> digraphReader(const std::string& fn,
    1194                                        Digraph& digraph) {
    1195     DigraphReader<Digraph> tmp(fn, digraph);
     1195  DigraphReader<Digraph> digraphReader(Digraph& digraph,
     1196                                       const std::string& fn) {
     1197    DigraphReader<Digraph> tmp(digraph, fn);
    11961198    return tmp;
    11971199  }
    11981200
     
    12011203  /// This function just returns a \ref DigraphReader class.
    12021204  /// \relates DigraphReader
    12031205  template <typename Digraph>
    1204   DigraphReader<Digraph> digraphReader(const char* fn, Digraph& digraph) {
    1205     DigraphReader<Digraph> tmp(fn, digraph);
     1206  DigraphReader<Digraph> digraphReader(Digraph& digraph, const char* fn) {
     1207    DigraphReader<Digraph> tmp(digraph, fn);
    12061208    return tmp;
    12071209  }
    12081210
     
    12101212  class GraphReader;
    12111213
    12121214  template <typename Graph>
    1213   GraphReader<Graph> graphReader(std::istream& is, Graph& graph);
     1215  GraphReader<Graph> graphReader(Graph& graph,
     1216                                 std::istream& is = std::cin);
    12141217
    12151218  template <typename Graph>
    1216   GraphReader<Graph> graphReader(const std::string& fn, Graph& graph);
     1219  GraphReader<Graph> graphReader(Graph& graph, const std::string& fn);
    12171220
    12181221  template <typename Graph>
    1219   GraphReader<Graph> graphReader(const char *fn, Graph& graph);
     1222  GraphReader<Graph> graphReader(Graph& graph, const char *fn);
    12201223
    12211224  /// \ingroup lemon_io
    12221225  ///
     
    12831286    ///
    12841287    /// Construct an undirected graph reader, which reads from the given
    12851288    /// input stream.
    1286     GraphReader(std::istream& is, Graph& graph)
     1289    GraphReader(Graph& graph, std::istream& is = std::cin)
    12871290      : _is(&is), local_is(false), _graph(graph),
    12881291        _use_nodes(false), _use_edges(false),
    12891292        _skip_nodes(false), _skip_edges(false) {}
     
    12921295    ///
    12931296    /// Construct an undirected graph reader, which reads from the given
    12941297    /// file.
    1295     GraphReader(const std::string& fn, Graph& graph)
     1298    GraphReader(Graph& graph, const std::string& fn)
    12961299      : _is(new std::ifstream(fn.c_str())), local_is(true), _graph(graph),
    12971300        _use_nodes(false), _use_edges(false),
    12981301        _skip_nodes(false), _skip_edges(false) {}
     
    13011304    ///
    13021305    /// Construct an undirected graph reader, which reads from the given
    13031306    /// file.
    1304     GraphReader(const char* fn, Graph& graph)
     1307    GraphReader(Graph& graph, const char* fn)
    13051308      : _is(new std::ifstream(fn)), local_is(true), _graph(graph),
    13061309        _use_nodes(false), _use_edges(false),
    13071310        _skip_nodes(false), _skip_edges(false) {}
     
    13301333    }
    13311334
    13321335  private:
    1333     friend GraphReader<Graph> graphReader<>(std::istream& is, Graph& graph);
    1334     friend GraphReader<Graph> graphReader<>(const std::string& fn,
    1335                                             Graph& graph);
    1336     friend GraphReader<Graph> graphReader<>(const char *fn, Graph& graph);
     1336    friend GraphReader<Graph> graphReader<>(Graph& graph, std::istream& is);
     1337    friend GraphReader<Graph> graphReader<>(Graph& graph,
     1338                                            const std::string& fn);
     1339    friend GraphReader<Graph> graphReader<>(Graph& graph, const char *fn);
    13371340
    13381341    GraphReader(GraphReader& other)
    13391342      : _is(other._is), local_is(other.local_is), _graph(other._graph),
     
    20062009  /// This function just returns a \ref GraphReader class.
    20072010  /// \relates GraphReader
    20082011  template <typename Graph>
    2009   GraphReader<Graph> graphReader(std::istream& is, Graph& graph) {
    2010     GraphReader<Graph> tmp(is, graph);
     2012  GraphReader<Graph> graphReader(Graph& graph, std::istream& is = std::cin) {
     2013    GraphReader<Graph> tmp(graph, is);
    20112014    return tmp;
    20122015  }
    20132016
     
    20162019  /// This function just returns a \ref GraphReader class.
    20172020  /// \relates GraphReader
    20182021  template <typename Graph>
    2019   GraphReader<Graph> graphReader(const std::string& fn,
    2020                                        Graph& graph) {
    2021     GraphReader<Graph> tmp(fn, graph);
     2022  GraphReader<Graph> graphReader(Graph& graph, const std::string& fn) {
     2023    GraphReader<Graph> tmp(graph, fn);
    20222024    return tmp;
    20232025  }
    20242026
     
    20272029  /// This function just returns a \ref GraphReader class.
    20282030  /// \relates GraphReader
    20292031  template <typename Graph>
    2030   GraphReader<Graph> graphReader(const char* fn, Graph& graph) {
    2031     GraphReader<Graph> tmp(fn, graph);
     2032  GraphReader<Graph> graphReader(Graph& graph, const char* fn) {
     2033    GraphReader<Graph> tmp(graph, fn);
    20322034    return tmp;
    20332035  }
    20342036
  • lemon/lgf_writer.h

    diff --git a/lemon/lgf_writer.h b/lemon/lgf_writer.h
    a b  
    352352  class DigraphWriter;
    353353
    354354  template <typename Digraph>
    355   DigraphWriter<Digraph> digraphWriter(std::ostream& os,
    356                                        const Digraph& digraph);
     355  DigraphWriter<Digraph> digraphWriter(const Digraph& digraph,
     356                                       std::ostream& os = std::cout);
    357357
    358358  template <typename Digraph>
    359   DigraphWriter<Digraph> digraphWriter(const std::string& fn,
    360                                        const Digraph& digraph);
     359  DigraphWriter<Digraph> digraphWriter(const Digraph& digraph,
     360                                       const std::string& fn);
    361361
    362362  template <typename Digraph>
    363   DigraphWriter<Digraph> digraphWriter(const char *fn,
    364                                        const Digraph& digraph);
     363  DigraphWriter<Digraph> digraphWriter(const Digraph& digraph,
     364                                       const char *fn);
    365365
    366366  /// \ingroup lemon_io
    367367  ///
     
    382382  /// arc() functions are used to add attribute writing rules.
    383383  ///
    384384  ///\code
    385   /// DigraphWriter<Digraph>(std::cout, digraph).
     385  /// DigraphWriter<Digraph>(digraph, std::cout).
    386386  ///   nodeMap("coordinates", coord_map).
    387387  ///   nodeMap("size", size).
    388388  ///   nodeMap("title", title).
     
    452452    ///
    453453    /// Construct a directed graph writer, which writes to the given
    454454    /// output stream.
    455     DigraphWriter(std::ostream& is, const Digraph& digraph)
    456       : _os(&is), local_os(false), _digraph(digraph),
     455    DigraphWriter(const Digraph& digraph, std::ostream& os = std::cout)
     456      : _os(&os), local_os(false), _digraph(digraph),
    457457        _skip_nodes(false), _skip_arcs(false) {}
    458458
    459459    /// \brief Constructor
    460460    ///
    461461    /// Construct a directed graph writer, which writes to the given
    462462    /// output file.
    463     DigraphWriter(const std::string& fn, const Digraph& digraph)
     463    DigraphWriter(const Digraph& digraph, const std::string& fn)
    464464      : _os(new std::ofstream(fn.c_str())), local_os(true), _digraph(digraph),
    465465        _skip_nodes(false), _skip_arcs(false) {}
    466466
     
    468468    ///
    469469    /// Construct a directed graph writer, which writes to the given
    470470    /// output file.
    471     DigraphWriter(const char* fn, const Digraph& digraph)
     471    DigraphWriter(const Digraph& digraph, const char* fn)
    472472      : _os(new std::ofstream(fn)), local_os(true), _digraph(digraph),
    473473        _skip_nodes(false), _skip_arcs(false) {}
    474474
     
    496496
    497497  private:
    498498
    499     friend DigraphWriter<Digraph> digraphWriter<>(std::ostream& os,
    500                                                   const Digraph& digraph);
    501     friend DigraphWriter<Digraph> digraphWriter<>(const std::string& fn,
    502                                                   const Digraph& digraph);
    503     friend DigraphWriter<Digraph> digraphWriter<>(const char *fn,
    504                                                   const Digraph& digraph);
     499    friend DigraphWriter<Digraph> digraphWriter<>(const Digraph& digraph,
     500                                                  std::ostream& os);
     501    friend DigraphWriter<Digraph> digraphWriter<>(const Digraph& digraph,
     502                                                  const std::string& fn);
     503    friend DigraphWriter<Digraph> digraphWriter<>(const Digraph& digraph,
     504                                                  const char *fn);
    505505
    506506    DigraphWriter(DigraphWriter& other)
    507507      : _os(other._os), local_os(other.local_os), _digraph(other._digraph),
     
    908908  /// This function just returns a \ref DigraphWriter class.
    909909  /// \relates DigraphWriter
    910910  template <typename Digraph>
    911   DigraphWriter<Digraph> digraphWriter(std::ostream& os,
    912                                        const Digraph& digraph) {
    913     DigraphWriter<Digraph> tmp(os, digraph);
     911  DigraphWriter<Digraph> digraphWriter(const Digraph& digraph,
     912                                       std::ostream& os = std::cout) {
     913    DigraphWriter<Digraph> tmp(digraph, os);
    914914    return tmp;
    915915  }
    916916
     
    919919  /// This function just returns a \ref DigraphWriter class.
    920920  /// \relates DigraphWriter
    921921  template <typename Digraph>
    922   DigraphWriter<Digraph> digraphWriter(const std::string& fn,
    923                                        const Digraph& digraph) {
    924     DigraphWriter<Digraph> tmp(fn, digraph);
     922  DigraphWriter<Digraph> digraphWriter(const Digraph& digraph,
     923                                       const std::string& fn) {
     924    DigraphWriter<Digraph> tmp(digraph, fn);
    925925    return tmp;
    926926  }
    927927
     
    930930  /// This function just returns a \ref DigraphWriter class.
    931931  /// \relates DigraphWriter
    932932  template <typename Digraph>
    933   DigraphWriter<Digraph> digraphWriter(const char* fn,
    934                                        const Digraph& digraph) {
    935     DigraphWriter<Digraph> tmp(fn, digraph);
     933  DigraphWriter<Digraph> digraphWriter(const Digraph& digraph,
     934                                       const char* fn) {
     935    DigraphWriter<Digraph> tmp(digraph, fn);
    936936    return tmp;
    937937  }
    938938
     
    940940  class GraphWriter;
    941941
    942942  template <typename Graph>
    943   GraphWriter<Graph> graphWriter(std::ostream& os, const Graph& graph);
     943  GraphWriter<Graph> graphWriter(const Graph& graph,
     944                                 std::ostream& os = std::cout);
    944945
    945946  template <typename Graph>
    946   GraphWriter<Graph> graphWriter(const std::string& fn, const Graph& graph);
     947  GraphWriter<Graph> graphWriter(const Graph& graph, const std::string& fn);
    947948
    948949  template <typename Graph>
    949   GraphWriter<Graph> graphWriter(const char *fn, const Graph& graph);
     950  GraphWriter<Graph> graphWriter(const Graph& graph, const char *fn);
    950951
    951952  /// \ingroup lemon_io
    952953  ///
     
    10081009    ///
    10091010    /// Construct a directed graph writer, which writes to the given
    10101011    /// output stream.
    1011     GraphWriter(std::ostream& is, const Graph& graph)
    1012       : _os(&is), local_os(false), _graph(graph),
     1012    GraphWriter(const Graph& graph, std::ostream& os = std::cout)
     1013      : _os(&os), local_os(false), _graph(graph),
    10131014        _skip_nodes(false), _skip_edges(false) {}
    10141015
    10151016    /// \brief Constructor
    10161017    ///
    10171018    /// Construct a directed graph writer, which writes to the given
    10181019    /// output file.
    1019     GraphWriter(const std::string& fn, const Graph& graph)
     1020    GraphWriter(const Graph& graph, const std::string& fn)
    10201021      : _os(new std::ofstream(fn.c_str())), local_os(true), _graph(graph),
    10211022        _skip_nodes(false), _skip_edges(false) {}
    10221023
     
    10241025    ///
    10251026    /// Construct a directed graph writer, which writes to the given
    10261027    /// output file.
    1027     GraphWriter(const char* fn, const Graph& graph)
     1028    GraphWriter(const Graph& graph, const char* fn)
    10281029      : _os(new std::ofstream(fn)), local_os(true), _graph(graph),
    10291030        _skip_nodes(false), _skip_edges(false) {}
    10301031
     
    10521053
    10531054  private:
    10541055
    1055     friend GraphWriter<Graph> graphWriter<>(std::ostream& os,
    1056                                             const Graph& graph);
    1057     friend GraphWriter<Graph> graphWriter<>(const std::string& fn,
    1058                                             const Graph& graph);
    1059     friend GraphWriter<Graph> graphWriter<>(const char *fn,
    1060                                             const Graph& graph);
     1056    friend GraphWriter<Graph> graphWriter<>(const Graph& graph,
     1057                                            std::ostream& os);
     1058    friend GraphWriter<Graph> graphWriter<>(const Graph& graph,
     1059                                            const std::string& fn);
     1060    friend GraphWriter<Graph> graphWriter<>(const Graph& graph,
     1061                                            const char *fn);
    10611062
    10621063    GraphWriter(GraphWriter& other)
    10631064      : _os(other._os), local_os(other.local_os), _graph(other._graph),
     
    15101511  /// This function just returns a \ref GraphWriter class.
    15111512  /// \relates GraphWriter
    15121513  template <typename Graph>
    1513   GraphWriter<Graph> graphWriter(std::ostream& os, const Graph& graph) {
    1514     GraphWriter<Graph> tmp(os, graph);
     1514  GraphWriter<Graph> graphWriter(const Graph& graph,
     1515                                 std::ostream& os = std::cout) {
     1516    GraphWriter<Graph> tmp(graph, os);
    15151517    return tmp;
    15161518  }
    15171519
     
    15201522  /// This function just returns a \ref GraphWriter class.
    15211523  /// \relates GraphWriter
    15221524  template <typename Graph>
    1523   GraphWriter<Graph> graphWriter(const std::string& fn, const Graph& graph) {
    1524     GraphWriter<Graph> tmp(fn, graph);
     1525  GraphWriter<Graph> graphWriter(const Graph& graph, const std::string& fn) {
     1526    GraphWriter<Graph> tmp(graph, fn);
    15251527    return tmp;
    15261528  }
    15271529
     
    15301532  /// This function just returns a \ref GraphWriter class.
    15311533  /// \relates GraphWriter
    15321534  template <typename Graph>
    1533   GraphWriter<Graph> graphWriter(const char* fn, const Graph& graph) {
    1534     GraphWriter<Graph> tmp(fn, graph);
     1535  GraphWriter<Graph> graphWriter(const Graph& graph, const char* fn) {
     1536    GraphWriter<Graph> tmp(graph, fn);
    15351537    return tmp;
    15361538  }
    15371539
  • test/bfs_test.cc

    diff --git a/test/bfs_test.cc b/test/bfs_test.cc
    a b  
    144144  Node s, t;
    145145
    146146  std::istringstream input(test_lgf);
    147   digraphReader(input, G).
     147  digraphReader(G, input).
    148148    node("source", s).
    149149    node("target", t).
    150150    run();
  • test/dfs_test.cc

    diff --git a/test/dfs_test.cc b/test/dfs_test.cc
    a b  
    146146  Node s, t;
    147147
    148148  std::istringstream input(test_lgf);
    149   digraphReader(input, G).
     149  digraphReader(G, input).
    150150    node("source", s).
    151151    node("target", t).
    152152    run();
  • test/dijkstra_test.cc

    diff --git a/test/dijkstra_test.cc b/test/dijkstra_test.cc
    a b  
    142142  LengthMap length(G);
    143143
    144144  std::istringstream input(test_lgf);
    145   digraphReader(input, G).
     145  digraphReader(G, input).
    146146    arcMap("length", length).
    147147    node("source", s).
    148148    node("target", t).
  • test/heap_test.cc

    diff --git a/test/heap_test.cc b/test/heap_test.cc
    a b  
    167167  Node source;
    168168
    169169  std::istringstream input(test_lgf);
    170   digraphReader(input, digraph).
     170  digraphReader(digraph, input).
    171171    arcMap("capacity", length).
    172172    node("source", source).
    173173    run();