[Lemon-commits] Peter Kovacs: Change the parameter order in LGF ...
Lemon HG
hg at lemon.cs.elte.hu
Wed Oct 1 13:58:26 CEST 2008
details: http://lemon.cs.elte.hu/hg/lemon/rev/47fbc814aa31
changeset: 293:47fbc814aa31
user: Peter Kovacs <kpeter [at] inf.elte.hu>
date: Wed Oct 01 12:44:16 2008 +0200
description:
Change the parameter order in LGF reader and writer tools
diffstat:
7 files changed, 92 insertions(+), 88 deletions(-)
demo/lgf_demo.cc | 4 +-
lemon/lgf_reader.h | 76 ++++++++++++++++++++--------------------
lemon/lgf_writer.h | 92 +++++++++++++++++++++++++------------------------
test/bfs_test.cc | 2 -
test/dfs_test.cc | 2 -
test/dijkstra_test.cc | 2 -
test/heap_test.cc | 2 -
diffs (truncated from 495 to 300 lines):
diff -r d91884dcd572 -r 47fbc814aa31 demo/lgf_demo.cc
--- a/demo/lgf_demo.cc Mon Sep 29 12:34:08 2008 +0200
+++ b/demo/lgf_demo.cc Wed Oct 01 12:44:16 2008 +0200
@@ -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 -r d91884dcd572 -r 47fbc814aa31 lemon/lgf_reader.h
--- a/lemon/lgf_reader.h Mon Sep 29 12:34:08 2008 +0200
+++ b/lemon/lgf_reader.h Wed Oct 01 12:44:16 2008 +0200
@@ -390,13 +390,14 @@
class DigraphReader;
template <typename Digraph>
- DigraphReader<Digraph> digraphReader(std::istream& is, Digraph& digraph);
+ DigraphReader<Digraph> digraphReader(Digraph& digraph,
+ std::istream& is = std::cin);
template <typename Digraph>
- DigraphReader<Digraph> digraphReader(const std::string& fn, Digraph& digraph);
+ DigraphReader<Digraph> digraphReader(Digraph& digraph, const std::string& fn);
template <typename Digraph>
- DigraphReader<Digraph> digraphReader(const char *fn, Digraph& digraph);
+ DigraphReader<Digraph> digraphReader(Digraph& digraph, const char *fn);
/// \ingroup lemon_io
///
@@ -419,7 +420,7 @@
/// rules.
///
///\code
- /// DigraphReader<Digraph>(std::cin, digraph).
+ /// DigraphReader<Digraph>(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<Digraph> digraphReader<>(std::istream& is,
- Digraph& digraph);
- friend DigraphReader<Digraph> digraphReader<>(const std::string& fn,
- Digraph& digraph);
- friend DigraphReader<Digraph> digraphReader<>(const char *fn,
- Digraph& digraph);
+ friend DigraphReader<Digraph> digraphReader<>(Digraph& digraph,
+ std::istream& is);
+ friend DigraphReader<Digraph> digraphReader<>(Digraph& digraph,
+ const std::string& fn);
+ friend DigraphReader<Digraph> 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 <typename Digraph>
- DigraphReader<Digraph> digraphReader(std::istream& is, Digraph& digraph) {
- DigraphReader<Digraph> tmp(is, digraph);
+ DigraphReader<Digraph> digraphReader(Digraph& digraph,
+ std::istream& is = std::cin) {
+ DigraphReader<Digraph> tmp(digraph, is);
return tmp;
}
@@ -1190,9 +1192,9 @@
/// This function just returns a \ref DigraphReader class.
/// \relates DigraphReader
template <typename Digraph>
- DigraphReader<Digraph> digraphReader(const std::string& fn,
- Digraph& digraph) {
- DigraphReader<Digraph> tmp(fn, digraph);
+ DigraphReader<Digraph> digraphReader(Digraph& digraph,
+ const std::string& fn) {
+ DigraphReader<Digraph> tmp(digraph, fn);
return tmp;
}
@@ -1201,8 +1203,8 @@
/// This function just returns a \ref DigraphReader class.
/// \relates DigraphReader
template <typename Digraph>
- DigraphReader<Digraph> digraphReader(const char* fn, Digraph& digraph) {
- DigraphReader<Digraph> tmp(fn, digraph);
+ DigraphReader<Digraph> digraphReader(Digraph& digraph, const char* fn) {
+ DigraphReader<Digraph> tmp(digraph, fn);
return tmp;
}
@@ -1210,13 +1212,14 @@
class GraphReader;
template <typename Graph>
- GraphReader<Graph> graphReader(std::istream& is, Graph& graph);
+ GraphReader<Graph> graphReader(Graph& graph,
+ std::istream& is = std::cin);
template <typename Graph>
- GraphReader<Graph> graphReader(const std::string& fn, Graph& graph);
+ GraphReader<Graph> graphReader(Graph& graph, const std::string& fn);
template <typename Graph>
- GraphReader<Graph> graphReader(const char *fn, Graph& graph);
+ GraphReader<Graph> 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<Graph> graphReader<>(std::istream& is, Graph& graph);
- friend GraphReader<Graph> graphReader<>(const std::string& fn,
- Graph& graph);
- friend GraphReader<Graph> graphReader<>(const char *fn, Graph& graph);
+ friend GraphReader<Graph> graphReader<>(Graph& graph, std::istream& is);
+ friend GraphReader<Graph> graphReader<>(Graph& graph,
+ const std::string& fn);
+ friend GraphReader<Graph> 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 <typename Graph>
- GraphReader<Graph> graphReader(std::istream& is, Graph& graph) {
- GraphReader<Graph> tmp(is, graph);
+ GraphReader<Graph> graphReader(Graph& graph, std::istream& is = std::cin) {
+ GraphReader<Graph> tmp(graph, is);
return tmp;
}
@@ -2016,9 +2019,8 @@
/// This function just returns a \ref GraphReader class.
/// \relates GraphReader
template <typename Graph>
- GraphReader<Graph> graphReader(const std::string& fn,
- Graph& graph) {
- GraphReader<Graph> tmp(fn, graph);
+ GraphReader<Graph> graphReader(Graph& graph, const std::string& fn) {
+ GraphReader<Graph> tmp(graph, fn);
return tmp;
}
@@ -2027,8 +2029,8 @@
/// This function just returns a \ref GraphReader class.
/// \relates GraphReader
template <typename Graph>
- GraphReader<Graph> graphReader(const char* fn, Graph& graph) {
- GraphReader<Graph> tmp(fn, graph);
+ GraphReader<Graph> graphReader(Graph& graph, const char* fn) {
+ GraphReader<Graph> tmp(graph, fn);
return tmp;
}
diff -r d91884dcd572 -r 47fbc814aa31 lemon/lgf_writer.h
--- a/lemon/lgf_writer.h Mon Sep 29 12:34:08 2008 +0200
+++ b/lemon/lgf_writer.h Wed Oct 01 12:44:16 2008 +0200
@@ -352,16 +352,16 @@
class DigraphWriter;
template <typename Digraph>
- DigraphWriter<Digraph> digraphWriter(std::ostream& os,
- const Digraph& digraph);
+ DigraphWriter<Digraph> digraphWriter(const Digraph& digraph,
+ std::ostream& os = std::cout);
template <typename Digraph>
- DigraphWriter<Digraph> digraphWriter(const std::string& fn,
- const Digraph& digraph);
+ DigraphWriter<Digraph> digraphWriter(const Digraph& digraph,
+ const std::string& fn);
template <typename Digraph>
- DigraphWriter<Digraph> digraphWriter(const char *fn,
- const Digraph& digraph);
+ DigraphWriter<Digraph> 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<Digraph>(std::cout, digraph).
+ /// DigraphWriter<Digraph>(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<Digraph> digraphWriter<>(std::ostream& os,
- const Digraph& digraph);
- friend DigraphWriter<Digraph> digraphWriter<>(const std::string& fn,
- const Digraph& digraph);
- friend DigraphWriter<Digraph> digraphWriter<>(const char *fn,
- const Digraph& digraph);
More information about the Lemon-commits
mailing list