diff --git a/demo/lgf_demo.cc b/demo/lgf_demo.cc --- a/demo/lgf_demo.cc +++ b/demo/lgf_demo.cc @@ -44,7 +44,7 @@ SmartDigraph::Node s, t; try { - digraphReader("digraph.lgf", g). // read the directed graph into g + digraphReader(g, "digraph.lgf"). // 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 @@ -60,7 +60,7 @@ std::cout << "We can write it to the standard output:" << std::endl; - digraphWriter(std::cout, g). // write g to the standard output + digraphWriter(g). // write g to the standard output arcMap("capacity", cap). // write cap into 'capacity' node("source", s). // write s to 'source' node("target", t). // write t to 'target' diff --git a/lemon/lgf_reader.h b/lemon/lgf_reader.h --- a/lemon/lgf_reader.h +++ b/lemon/lgf_reader.h @@ -390,13 +390,14 @@ class DigraphReader; template - DigraphReader digraphReader(std::istream& is, Digraph& digraph); + DigraphReader digraphReader(Digraph& digraph, + std::istream& is = std::cin); template - DigraphReader digraphReader(const std::string& fn, Digraph& digraph); + DigraphReader digraphReader(Digraph& digraph, const std::string& fn); template - DigraphReader digraphReader(const char *fn, Digraph& digraph); + DigraphReader digraphReader(Digraph& digraph, const char *fn); /// \ingroup lemon_io /// @@ -419,7 +420,7 @@ /// rules. /// ///\code - /// DigraphReader(std::cin, digraph). + /// DigraphReader(digraph, std::cin). /// nodeMap("coordinates", coord_map). /// arcMap("capacity", cap_map). /// node("source", src). @@ -499,7 +500,7 @@ /// /// Construct a directed graph reader, which reads from the given /// input stream. - DigraphReader(std::istream& is, Digraph& digraph) + DigraphReader(Digraph& digraph, std::istream& is = std::cin) : _is(&is), local_is(false), _digraph(digraph), _use_nodes(false), _use_arcs(false), _skip_nodes(false), _skip_arcs(false) {} @@ -508,7 +509,7 @@ /// /// Construct a directed graph reader, which reads from the given /// file. - DigraphReader(const std::string& fn, Digraph& digraph) + DigraphReader(Digraph& digraph, const std::string& fn) : _is(new std::ifstream(fn.c_str())), local_is(true), _digraph(digraph), _use_nodes(false), _use_arcs(false), _skip_nodes(false), _skip_arcs(false) {} @@ -517,7 +518,7 @@ /// /// Construct a directed graph reader, which reads from the given /// file. - DigraphReader(const char* fn, Digraph& digraph) + DigraphReader(Digraph& digraph, const char* fn) : _is(new std::ifstream(fn)), local_is(true), _digraph(digraph), _use_nodes(false), _use_arcs(false), _skip_nodes(false), _skip_arcs(false) {} @@ -547,12 +548,12 @@ private: - friend DigraphReader digraphReader<>(std::istream& is, - Digraph& digraph); - friend DigraphReader digraphReader<>(const std::string& fn, - Digraph& digraph); - friend DigraphReader digraphReader<>(const char *fn, - Digraph& digraph); + friend DigraphReader digraphReader<>(Digraph& digraph, + std::istream& is); + friend DigraphReader digraphReader<>(Digraph& digraph, + const std::string& fn); + friend DigraphReader digraphReader<>(Digraph& digraph, + const char *fn); DigraphReader(DigraphReader& other) : _is(other._is), local_is(other.local_is), _digraph(other._digraph), @@ -1180,8 +1181,9 @@ /// This function just returns a \ref DigraphReader class. /// \relates DigraphReader template - DigraphReader digraphReader(std::istream& is, Digraph& digraph) { - DigraphReader tmp(is, digraph); + DigraphReader digraphReader(Digraph& digraph, + std::istream& is = std::cin) { + DigraphReader tmp(digraph, is); return tmp; } @@ -1190,9 +1192,9 @@ /// This function just returns a \ref DigraphReader class. /// \relates DigraphReader template - DigraphReader digraphReader(const std::string& fn, - Digraph& digraph) { - DigraphReader tmp(fn, digraph); + DigraphReader digraphReader(Digraph& digraph, + const std::string& fn) { + DigraphReader tmp(digraph, fn); return tmp; } @@ -1201,8 +1203,8 @@ /// This function just returns a \ref DigraphReader class. /// \relates DigraphReader template - DigraphReader digraphReader(const char* fn, Digraph& digraph) { - DigraphReader tmp(fn, digraph); + DigraphReader digraphReader(Digraph& digraph, const char* fn) { + DigraphReader tmp(digraph, fn); return tmp; } @@ -1210,13 +1212,14 @@ class GraphReader; template - GraphReader graphReader(std::istream& is, Graph& graph); + GraphReader graphReader(Graph& graph, + std::istream& is = std::cin); template - GraphReader graphReader(const std::string& fn, Graph& graph); + GraphReader graphReader(Graph& graph, const std::string& fn); template - GraphReader graphReader(const char *fn, Graph& graph); + GraphReader graphReader(Graph& graph, const char *fn); /// \ingroup lemon_io /// @@ -1283,7 +1286,7 @@ /// /// Construct an undirected graph reader, which reads from the given /// input stream. - GraphReader(std::istream& is, Graph& graph) + GraphReader(Graph& graph, std::istream& is = std::cin) : _is(&is), local_is(false), _graph(graph), _use_nodes(false), _use_edges(false), _skip_nodes(false), _skip_edges(false) {} @@ -1292,7 +1295,7 @@ /// /// Construct an undirected graph reader, which reads from the given /// file. - GraphReader(const std::string& fn, Graph& graph) + GraphReader(Graph& graph, const std::string& fn) : _is(new std::ifstream(fn.c_str())), local_is(true), _graph(graph), _use_nodes(false), _use_edges(false), _skip_nodes(false), _skip_edges(false) {} @@ -1301,7 +1304,7 @@ /// /// Construct an undirected graph reader, which reads from the given /// file. - GraphReader(const char* fn, Graph& graph) + GraphReader(Graph& graph, const char* fn) : _is(new std::ifstream(fn)), local_is(true), _graph(graph), _use_nodes(false), _use_edges(false), _skip_nodes(false), _skip_edges(false) {} @@ -1330,10 +1333,10 @@ } private: - friend GraphReader graphReader<>(std::istream& is, Graph& graph); - friend GraphReader graphReader<>(const std::string& fn, - Graph& graph); - friend GraphReader graphReader<>(const char *fn, Graph& graph); + friend GraphReader graphReader<>(Graph& graph, std::istream& is); + friend GraphReader graphReader<>(Graph& graph, + const std::string& fn); + friend GraphReader graphReader<>(Graph& graph, const char *fn); GraphReader(GraphReader& other) : _is(other._is), local_is(other.local_is), _graph(other._graph), @@ -2006,8 +2009,8 @@ /// This function just returns a \ref GraphReader class. /// \relates GraphReader template - GraphReader graphReader(std::istream& is, Graph& graph) { - GraphReader tmp(is, graph); + GraphReader graphReader(Graph& graph, std::istream& is = std::cin) { + GraphReader tmp(graph, is); return tmp; } @@ -2016,9 +2019,8 @@ /// This function just returns a \ref GraphReader class. /// \relates GraphReader template - GraphReader graphReader(const std::string& fn, - Graph& graph) { - GraphReader tmp(fn, graph); + GraphReader graphReader(Graph& graph, const std::string& fn) { + GraphReader tmp(graph, fn); return tmp; } @@ -2027,8 +2029,8 @@ /// This function just returns a \ref GraphReader class. /// \relates GraphReader template - GraphReader graphReader(const char* fn, Graph& graph) { - GraphReader tmp(fn, graph); + GraphReader graphReader(Graph& graph, const char* fn) { + GraphReader tmp(graph, fn); return tmp; } diff --git a/lemon/lgf_writer.h b/lemon/lgf_writer.h --- a/lemon/lgf_writer.h +++ b/lemon/lgf_writer.h @@ -352,16 +352,16 @@ class DigraphWriter; template - DigraphWriter digraphWriter(std::ostream& os, - const Digraph& digraph); + DigraphWriter digraphWriter(const Digraph& digraph, + std::ostream& os = std::cout); template - DigraphWriter digraphWriter(const std::string& fn, - const Digraph& digraph); + DigraphWriter digraphWriter(const Digraph& digraph, + const std::string& fn); template - DigraphWriter digraphWriter(const char *fn, - const Digraph& digraph); + DigraphWriter digraphWriter(const Digraph& digraph, + const char *fn); /// \ingroup lemon_io /// @@ -382,7 +382,7 @@ /// arc() functions are used to add attribute writing rules. /// ///\code - /// DigraphWriter(std::cout, digraph). + /// DigraphWriter(digraph, std::cout). /// nodeMap("coordinates", coord_map). /// nodeMap("size", size). /// nodeMap("title", title). @@ -452,15 +452,15 @@ /// /// Construct a directed graph writer, which writes to the given /// output stream. - DigraphWriter(std::ostream& is, const Digraph& digraph) - : _os(&is), local_os(false), _digraph(digraph), + DigraphWriter(const Digraph& digraph, std::ostream& os = std::cout) + : _os(&os), local_os(false), _digraph(digraph), _skip_nodes(false), _skip_arcs(false) {} /// \brief Constructor /// /// Construct a directed graph writer, which writes to the given /// output file. - DigraphWriter(const std::string& fn, const Digraph& digraph) + DigraphWriter(const Digraph& digraph, const std::string& fn) : _os(new std::ofstream(fn.c_str())), local_os(true), _digraph(digraph), _skip_nodes(false), _skip_arcs(false) {} @@ -468,7 +468,7 @@ /// /// Construct a directed graph writer, which writes to the given /// output file. - DigraphWriter(const char* fn, const Digraph& digraph) + DigraphWriter(const Digraph& digraph, const char* fn) : _os(new std::ofstream(fn)), local_os(true), _digraph(digraph), _skip_nodes(false), _skip_arcs(false) {} @@ -496,12 +496,12 @@ private: - friend DigraphWriter digraphWriter<>(std::ostream& os, - const Digraph& digraph); - friend DigraphWriter digraphWriter<>(const std::string& fn, - const Digraph& digraph); - friend DigraphWriter digraphWriter<>(const char *fn, - const Digraph& digraph); + friend DigraphWriter digraphWriter<>(const Digraph& digraph, + std::ostream& os); + friend DigraphWriter digraphWriter<>(const Digraph& digraph, + const std::string& fn); + friend DigraphWriter digraphWriter<>(const Digraph& digraph, + const char *fn); DigraphWriter(DigraphWriter& other) : _os(other._os), local_os(other.local_os), _digraph(other._digraph), @@ -908,9 +908,9 @@ /// This function just returns a \ref DigraphWriter class. /// \relates DigraphWriter template - DigraphWriter digraphWriter(std::ostream& os, - const Digraph& digraph) { - DigraphWriter tmp(os, digraph); + DigraphWriter digraphWriter(const Digraph& digraph, + std::ostream& os = std::cout) { + DigraphWriter tmp(digraph, os); return tmp; } @@ -919,9 +919,9 @@ /// This function just returns a \ref DigraphWriter class. /// \relates DigraphWriter template - DigraphWriter digraphWriter(const std::string& fn, - const Digraph& digraph) { - DigraphWriter tmp(fn, digraph); + DigraphWriter digraphWriter(const Digraph& digraph, + const std::string& fn) { + DigraphWriter tmp(digraph, fn); return tmp; } @@ -930,9 +930,9 @@ /// This function just returns a \ref DigraphWriter class. /// \relates DigraphWriter template - DigraphWriter digraphWriter(const char* fn, - const Digraph& digraph) { - DigraphWriter tmp(fn, digraph); + DigraphWriter digraphWriter(const Digraph& digraph, + const char* fn) { + DigraphWriter tmp(digraph, fn); return tmp; } @@ -940,13 +940,14 @@ class GraphWriter; template - GraphWriter graphWriter(std::ostream& os, const Graph& graph); + GraphWriter graphWriter(const Graph& graph, + std::ostream& os = std::cout); template - GraphWriter graphWriter(const std::string& fn, const Graph& graph); + GraphWriter graphWriter(const Graph& graph, const std::string& fn); template - GraphWriter graphWriter(const char *fn, const Graph& graph); + GraphWriter graphWriter(const Graph& graph, const char *fn); /// \ingroup lemon_io /// @@ -1008,15 +1009,15 @@ /// /// Construct a directed graph writer, which writes to the given /// output stream. - GraphWriter(std::ostream& is, const Graph& graph) - : _os(&is), local_os(false), _graph(graph), + GraphWriter(const Graph& graph, std::ostream& os = std::cout) + : _os(&os), local_os(false), _graph(graph), _skip_nodes(false), _skip_edges(false) {} /// \brief Constructor /// /// Construct a directed graph writer, which writes to the given /// output file. - GraphWriter(const std::string& fn, const Graph& graph) + GraphWriter(const Graph& graph, const std::string& fn) : _os(new std::ofstream(fn.c_str())), local_os(true), _graph(graph), _skip_nodes(false), _skip_edges(false) {} @@ -1024,7 +1025,7 @@ /// /// Construct a directed graph writer, which writes to the given /// output file. - GraphWriter(const char* fn, const Graph& graph) + GraphWriter(const Graph& graph, const char* fn) : _os(new std::ofstream(fn)), local_os(true), _graph(graph), _skip_nodes(false), _skip_edges(false) {} @@ -1052,12 +1053,12 @@ private: - friend GraphWriter graphWriter<>(std::ostream& os, - const Graph& graph); - friend GraphWriter graphWriter<>(const std::string& fn, - const Graph& graph); - friend GraphWriter graphWriter<>(const char *fn, - const Graph& graph); + friend GraphWriter graphWriter<>(const Graph& graph, + std::ostream& os); + friend GraphWriter graphWriter<>(const Graph& graph, + const std::string& fn); + friend GraphWriter graphWriter<>(const Graph& graph, + const char *fn); GraphWriter(GraphWriter& other) : _os(other._os), local_os(other.local_os), _graph(other._graph), @@ -1510,8 +1511,9 @@ /// This function just returns a \ref GraphWriter class. /// \relates GraphWriter template - GraphWriter graphWriter(std::ostream& os, const Graph& graph) { - GraphWriter tmp(os, graph); + GraphWriter graphWriter(const Graph& graph, + std::ostream& os = std::cout) { + GraphWriter tmp(graph, os); return tmp; } @@ -1520,8 +1522,8 @@ /// This function just returns a \ref GraphWriter class. /// \relates GraphWriter template - GraphWriter graphWriter(const std::string& fn, const Graph& graph) { - GraphWriter tmp(fn, graph); + GraphWriter graphWriter(const Graph& graph, const std::string& fn) { + GraphWriter tmp(graph, fn); return tmp; } @@ -1530,8 +1532,8 @@ /// This function just returns a \ref GraphWriter class. /// \relates GraphWriter template - GraphWriter graphWriter(const char* fn, const Graph& graph) { - GraphWriter tmp(fn, graph); + GraphWriter graphWriter(const Graph& graph, const char* fn) { + GraphWriter tmp(graph, fn); return tmp; } diff --git a/test/bfs_test.cc b/test/bfs_test.cc --- a/test/bfs_test.cc +++ b/test/bfs_test.cc @@ -144,7 +144,7 @@ Node s, t; std::istringstream input(test_lgf); - digraphReader(input, G). + digraphReader(G, input). node("source", s). node("target", t). run(); diff --git a/test/dfs_test.cc b/test/dfs_test.cc --- a/test/dfs_test.cc +++ b/test/dfs_test.cc @@ -146,7 +146,7 @@ Node s, t; std::istringstream input(test_lgf); - digraphReader(input, G). + digraphReader(G, input). node("source", s). node("target", t). run(); diff --git a/test/dijkstra_test.cc b/test/dijkstra_test.cc --- a/test/dijkstra_test.cc +++ b/test/dijkstra_test.cc @@ -142,7 +142,7 @@ LengthMap length(G); std::istringstream input(test_lgf); - digraphReader(input, G). + digraphReader(G, input). arcMap("length", length). node("source", s). node("target", t). diff --git a/test/heap_test.cc b/test/heap_test.cc --- a/test/heap_test.cc +++ b/test/heap_test.cc @@ -167,7 +167,7 @@ Node source; std::istringstream input(test_lgf); - digraphReader(input, digraph). + digraphReader(digraph, input). arcMap("capacity", length). node("source", source). run();