1.1 --- a/lemon/lgf_writer.h Tue Apr 07 14:50:20 2009 +0100
1.2 +++ b/lemon/lgf_writer.h Sat Apr 18 21:54:30 2009 +0200
1.3 @@ -347,19 +347,17 @@
1.4
1.5 }
1.6
1.7 - template <typename Digraph>
1.8 + template <typename DGR>
1.9 class DigraphWriter;
1.10
1.11 - template <typename Digraph>
1.12 - DigraphWriter<Digraph> digraphWriter(const Digraph& digraph,
1.13 - std::ostream& os = std::cout);
1.14 - template <typename Digraph>
1.15 - DigraphWriter<Digraph> digraphWriter(const Digraph& digraph,
1.16 - const std::string& fn);
1.17 + template <typename TDGR>
1.18 + DigraphWriter<TDGR> digraphWriter(const TDGR& digraph,
1.19 + std::ostream& os = std::cout);
1.20 + template <typename TDGR>
1.21 + DigraphWriter<TDGR> digraphWriter(const TDGR& digraph, const std::string& fn);
1.22
1.23 - template <typename Digraph>
1.24 - DigraphWriter<Digraph> digraphWriter(const Digraph& digraph,
1.25 - const char* fn);
1.26 + template <typename TDGR>
1.27 + DigraphWriter<TDGR> digraphWriter(const TDGR& digraph, const char* fn);
1.28
1.29
1.30 /// \ingroup lemon_io
1.31 @@ -381,7 +379,7 @@
1.32 /// arc() functions are used to add attribute writing rules.
1.33 ///
1.34 ///\code
1.35 - /// DigraphWriter<Digraph>(digraph, std::cout).
1.36 + /// DigraphWriter<DGR>(digraph, std::cout).
1.37 /// nodeMap("coordinates", coord_map).
1.38 /// nodeMap("size", size).
1.39 /// nodeMap("title", title).
1.40 @@ -406,12 +404,12 @@
1.41 /// section to the stream. The output stream can be retrieved with
1.42 /// the \c ostream() function, hence the second pass can append its
1.43 /// output to the output of the first pass.
1.44 - template <typename GR>
1.45 + template <typename DGR>
1.46 class DigraphWriter {
1.47 public:
1.48
1.49 - typedef GR Digraph;
1.50 - TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
1.51 + typedef DGR Digraph;
1.52 + TEMPLATE_DIGRAPH_TYPEDEFS(DGR);
1.53
1.54 private:
1.55
1.56 @@ -419,7 +417,7 @@
1.57 std::ostream* _os;
1.58 bool local_os;
1.59
1.60 - const Digraph& _digraph;
1.61 + const DGR& _digraph;
1.62
1.63 std::string _nodes_caption;
1.64 std::string _arcs_caption;
1.65 @@ -451,7 +449,7 @@
1.66 ///
1.67 /// Construct a directed graph writer, which writes to the given
1.68 /// output stream.
1.69 - DigraphWriter(const Digraph& digraph, std::ostream& os = std::cout)
1.70 + DigraphWriter(const DGR& digraph, std::ostream& os = std::cout)
1.71 : _os(&os), local_os(false), _digraph(digraph),
1.72 _skip_nodes(false), _skip_arcs(false) {}
1.73
1.74 @@ -459,7 +457,7 @@
1.75 ///
1.76 /// Construct a directed graph writer, which writes to the given
1.77 /// output file.
1.78 - DigraphWriter(const Digraph& digraph, const std::string& fn)
1.79 + DigraphWriter(const DGR& digraph, const std::string& fn)
1.80 : _os(new std::ofstream(fn.c_str())), local_os(true), _digraph(digraph),
1.81 _skip_nodes(false), _skip_arcs(false) {
1.82 if (!(*_os)) {
1.83 @@ -472,7 +470,7 @@
1.84 ///
1.85 /// Construct a directed graph writer, which writes to the given
1.86 /// output file.
1.87 - DigraphWriter(const Digraph& digraph, const char* fn)
1.88 + DigraphWriter(const DGR& digraph, const char* fn)
1.89 : _os(new std::ofstream(fn)), local_os(true), _digraph(digraph),
1.90 _skip_nodes(false), _skip_arcs(false) {
1.91 if (!(*_os)) {
1.92 @@ -505,15 +503,15 @@
1.93
1.94 private:
1.95
1.96 - template <typename DGR>
1.97 - friend DigraphWriter<DGR> digraphWriter(const DGR& digraph,
1.98 - std::ostream& os);
1.99 - template <typename DGR>
1.100 - friend DigraphWriter<DGR> digraphWriter(const DGR& digraph,
1.101 - const std::string& fn);
1.102 - template <typename DGR>
1.103 - friend DigraphWriter<DGR> digraphWriter(const DGR& digraph,
1.104 - const char *fn);
1.105 + template <typename TDGR>
1.106 + friend DigraphWriter<TDGR> digraphWriter(const TDGR& digraph,
1.107 + std::ostream& os);
1.108 + template <typename TDGR>
1.109 + friend DigraphWriter<TDGR> digraphWriter(const TDGR& digraph,
1.110 + const std::string& fn);
1.111 + template <typename TDGR>
1.112 + friend DigraphWriter<TDGR> digraphWriter(const TDGR& digraph,
1.113 + const char *fn);
1.114
1.115 DigraphWriter(DigraphWriter& other)
1.116 : _os(other._os), local_os(other.local_os), _digraph(other._digraph),
1.117 @@ -724,8 +722,8 @@
1.118 }
1.119
1.120 if (label == 0) {
1.121 - IdMap<Digraph, Node> id_map(_digraph);
1.122 - _writer_bits::MapLess<IdMap<Digraph, Node> > id_less(id_map);
1.123 + IdMap<DGR, Node> id_map(_digraph);
1.124 + _writer_bits::MapLess<IdMap<DGR, Node> > id_less(id_map);
1.125 std::sort(nodes.begin(), nodes.end(), id_less);
1.126 } else {
1.127 label->sort(nodes);
1.128 @@ -809,8 +807,8 @@
1.129 }
1.130
1.131 if (label == 0) {
1.132 - IdMap<Digraph, Arc> id_map(_digraph);
1.133 - _writer_bits::MapLess<IdMap<Digraph, Arc> > id_less(id_map);
1.134 + IdMap<DGR, Arc> id_map(_digraph);
1.135 + _writer_bits::MapLess<IdMap<DGR, Arc> > id_less(id_map);
1.136 std::sort(arcs.begin(), arcs.end(), id_less);
1.137 } else {
1.138 label->sort(arcs);
1.139 @@ -915,14 +913,41 @@
1.140 /// @}
1.141 };
1.142
1.143 + /// \ingroup lemon_io
1.144 + ///
1.145 /// \brief Return a \ref DigraphWriter class
1.146 ///
1.147 - /// This function just returns a \ref DigraphWriter class.
1.148 + /// This function just returns a \ref DigraphWriter class.
1.149 + ///
1.150 + /// With this function a digraph can be write to a file or output
1.151 + /// stream in \ref lgf-format "LGF" format with several maps and
1.152 + /// attributes. For example, with the following code a network flow
1.153 + /// problem can be written to the standard output, i.e. a digraph
1.154 + /// with a \e capacity map on the arcs and \e source and \e target
1.155 + /// nodes:
1.156 + ///
1.157 + ///\code
1.158 + ///ListDigraph digraph;
1.159 + ///ListDigraph::ArcMap<int> cap(digraph);
1.160 + ///ListDigraph::Node src, trg;
1.161 + /// // Setting the capacity map and source and target nodes
1.162 + ///digraphWriter(digraph, std::cout).
1.163 + /// arcMap("capacity", cap).
1.164 + /// node("source", src).
1.165 + /// node("target", trg).
1.166 + /// run();
1.167 + ///\endcode
1.168 + ///
1.169 + /// For a complete documentation, please see the \ref DigraphWriter
1.170 + /// class documentation.
1.171 + /// \warning Don't forget to put the \ref DigraphWriter::run() "run()"
1.172 + /// to the end of the parameter list.
1.173 /// \relates DigraphWriter
1.174 - template <typename Digraph>
1.175 - DigraphWriter<Digraph> digraphWriter(const Digraph& digraph,
1.176 - std::ostream& os) {
1.177 - DigraphWriter<Digraph> tmp(digraph, os);
1.178 + /// \sa digraphWriter(const TDGR& digraph, const std::string& fn)
1.179 + /// \sa digraphWriter(const TDGR& digraph, const char* fn)
1.180 + template <typename TDGR>
1.181 + DigraphWriter<TDGR> digraphWriter(const TDGR& digraph, std::ostream& os) {
1.182 + DigraphWriter<TDGR> tmp(digraph, os);
1.183 return tmp;
1.184 }
1.185
1.186 @@ -930,10 +955,11 @@
1.187 ///
1.188 /// This function just returns a \ref DigraphWriter class.
1.189 /// \relates DigraphWriter
1.190 - template <typename Digraph>
1.191 - DigraphWriter<Digraph> digraphWriter(const Digraph& digraph,
1.192 - const std::string& fn) {
1.193 - DigraphWriter<Digraph> tmp(digraph, fn);
1.194 + /// \sa digraphWriter(const TDGR& digraph, std::ostream& os)
1.195 + template <typename TDGR>
1.196 + DigraphWriter<TDGR> digraphWriter(const TDGR& digraph,
1.197 + const std::string& fn) {
1.198 + DigraphWriter<TDGR> tmp(digraph, fn);
1.199 return tmp;
1.200 }
1.201
1.202 @@ -941,23 +967,22 @@
1.203 ///
1.204 /// This function just returns a \ref DigraphWriter class.
1.205 /// \relates DigraphWriter
1.206 - template <typename Digraph>
1.207 - DigraphWriter<Digraph> digraphWriter(const Digraph& digraph,
1.208 - const char* fn) {
1.209 - DigraphWriter<Digraph> tmp(digraph, fn);
1.210 + /// \sa digraphWriter(const TDGR& digraph, std::ostream& os)
1.211 + template <typename TDGR>
1.212 + DigraphWriter<TDGR> digraphWriter(const TDGR& digraph, const char* fn) {
1.213 + DigraphWriter<TDGR> tmp(digraph, fn);
1.214 return tmp;
1.215 }
1.216
1.217 - template <typename Graph>
1.218 + template <typename GR>
1.219 class GraphWriter;
1.220
1.221 - template <typename Graph>
1.222 - GraphWriter<Graph> graphWriter(const Graph& graph,
1.223 - std::ostream& os = std::cout);
1.224 - template <typename Graph>
1.225 - GraphWriter<Graph> graphWriter(const Graph& graph, const std::string& fn);
1.226 - template <typename Graph>
1.227 - GraphWriter<Graph> graphWriter(const Graph& graph, const char* fn);
1.228 + template <typename TGR>
1.229 + GraphWriter<TGR> graphWriter(const TGR& graph, std::ostream& os = std::cout);
1.230 + template <typename TGR>
1.231 + GraphWriter<TGR> graphWriter(const TGR& graph, const std::string& fn);
1.232 + template <typename TGR>
1.233 + GraphWriter<TGR> graphWriter(const TGR& graph, const char* fn);
1.234
1.235 /// \ingroup lemon_io
1.236 ///
1.237 @@ -979,7 +1004,7 @@
1.238 public:
1.239
1.240 typedef GR Graph;
1.241 - TEMPLATE_GRAPH_TYPEDEFS(Graph);
1.242 + TEMPLATE_GRAPH_TYPEDEFS(GR);
1.243
1.244 private:
1.245
1.246 @@ -987,7 +1012,7 @@
1.247 std::ostream* _os;
1.248 bool local_os;
1.249
1.250 - const Graph& _graph;
1.251 + const GR& _graph;
1.252
1.253 std::string _nodes_caption;
1.254 std::string _edges_caption;
1.255 @@ -1019,7 +1044,7 @@
1.256 ///
1.257 /// Construct a directed graph writer, which writes to the given
1.258 /// output stream.
1.259 - GraphWriter(const Graph& graph, std::ostream& os = std::cout)
1.260 + GraphWriter(const GR& graph, std::ostream& os = std::cout)
1.261 : _os(&os), local_os(false), _graph(graph),
1.262 _skip_nodes(false), _skip_edges(false) {}
1.263
1.264 @@ -1027,7 +1052,7 @@
1.265 ///
1.266 /// Construct a directed graph writer, which writes to the given
1.267 /// output file.
1.268 - GraphWriter(const Graph& graph, const std::string& fn)
1.269 + GraphWriter(const GR& graph, const std::string& fn)
1.270 : _os(new std::ofstream(fn.c_str())), local_os(true), _graph(graph),
1.271 _skip_nodes(false), _skip_edges(false) {
1.272 if (!(*_os)) {
1.273 @@ -1040,7 +1065,7 @@
1.274 ///
1.275 /// Construct a directed graph writer, which writes to the given
1.276 /// output file.
1.277 - GraphWriter(const Graph& graph, const char* fn)
1.278 + GraphWriter(const GR& graph, const char* fn)
1.279 : _os(new std::ofstream(fn)), local_os(true), _graph(graph),
1.280 _skip_nodes(false), _skip_edges(false) {
1.281 if (!(*_os)) {
1.282 @@ -1073,15 +1098,13 @@
1.283
1.284 private:
1.285
1.286 - template <typename Graph>
1.287 - friend GraphWriter<Graph> graphWriter(const Graph& graph,
1.288 - std::ostream& os);
1.289 - template <typename Graph>
1.290 - friend GraphWriter<Graph> graphWriter(const Graph& graph,
1.291 - const std::string& fn);
1.292 - template <typename Graph>
1.293 - friend GraphWriter<Graph> graphWriter(const Graph& graph,
1.294 - const char *fn);
1.295 + template <typename TGR>
1.296 + friend GraphWriter<TGR> graphWriter(const TGR& graph, std::ostream& os);
1.297 + template <typename TGR>
1.298 + friend GraphWriter<TGR> graphWriter(const TGR& graph,
1.299 + const std::string& fn);
1.300 + template <typename TGR>
1.301 + friend GraphWriter<TGR> graphWriter(const TGR& graph, const char *fn);
1.302
1.303 GraphWriter(GraphWriter& other)
1.304 : _os(other._os), local_os(other.local_os), _graph(other._graph),
1.305 @@ -1168,10 +1191,10 @@
1.306 GraphWriter& arcMap(const std::string& caption, const Map& map) {
1.307 checkConcept<concepts::ReadMap<Arc, typename Map::Value>, Map>();
1.308 _writer_bits::MapStorageBase<Edge>* forward_storage =
1.309 - new _writer_bits::GraphArcMapStorage<Graph, true, Map>(_graph, map);
1.310 + new _writer_bits::GraphArcMapStorage<GR, true, Map>(_graph, map);
1.311 _edge_maps.push_back(std::make_pair('+' + caption, forward_storage));
1.312 _writer_bits::MapStorageBase<Edge>* backward_storage =
1.313 - new _writer_bits::GraphArcMapStorage<Graph, false, Map>(_graph, map);
1.314 + new _writer_bits::GraphArcMapStorage<GR, false, Map>(_graph, map);
1.315 _edge_maps.push_back(std::make_pair('-' + caption, backward_storage));
1.316 return *this;
1.317 }
1.318 @@ -1185,11 +1208,11 @@
1.319 const Converter& converter = Converter()) {
1.320 checkConcept<concepts::ReadMap<Arc, typename Map::Value>, Map>();
1.321 _writer_bits::MapStorageBase<Edge>* forward_storage =
1.322 - new _writer_bits::GraphArcMapStorage<Graph, true, Map, Converter>
1.323 + new _writer_bits::GraphArcMapStorage<GR, true, Map, Converter>
1.324 (_graph, map, converter);
1.325 _edge_maps.push_back(std::make_pair('+' + caption, forward_storage));
1.326 _writer_bits::MapStorageBase<Edge>* backward_storage =
1.327 - new _writer_bits::GraphArcMapStorage<Graph, false, Map, Converter>
1.328 + new _writer_bits::GraphArcMapStorage<GR, false, Map, Converter>
1.329 (_graph, map, converter);
1.330 _edge_maps.push_back(std::make_pair('-' + caption, backward_storage));
1.331 return *this;
1.332 @@ -1247,7 +1270,7 @@
1.333 ///
1.334 /// Add an arc writing rule to writer.
1.335 GraphWriter& arc(const std::string& caption, const Arc& arc) {
1.336 - typedef _writer_bits::GraphArcLookUpConverter<Graph> Converter;
1.337 + typedef _writer_bits::GraphArcLookUpConverter<GR> Converter;
1.338 Converter converter(_graph, _edge_index);
1.339 _writer_bits::ValueStorageBase* storage =
1.340 new _writer_bits::ValueStorage<Arc, Converter>(arc, converter);
1.341 @@ -1338,8 +1361,8 @@
1.342 }
1.343
1.344 if (label == 0) {
1.345 - IdMap<Graph, Node> id_map(_graph);
1.346 - _writer_bits::MapLess<IdMap<Graph, Node> > id_less(id_map);
1.347 + IdMap<GR, Node> id_map(_graph);
1.348 + _writer_bits::MapLess<IdMap<GR, Node> > id_less(id_map);
1.349 std::sort(nodes.begin(), nodes.end(), id_less);
1.350 } else {
1.351 label->sort(nodes);
1.352 @@ -1423,8 +1446,8 @@
1.353 }
1.354
1.355 if (label == 0) {
1.356 - IdMap<Graph, Edge> id_map(_graph);
1.357 - _writer_bits::MapLess<IdMap<Graph, Edge> > id_less(id_map);
1.358 + IdMap<GR, Edge> id_map(_graph);
1.359 + _writer_bits::MapLess<IdMap<GR, Edge> > id_less(id_map);
1.360 std::sort(edges.begin(), edges.end(), id_less);
1.361 } else {
1.362 label->sort(edges);
1.363 @@ -1529,14 +1552,37 @@
1.364 /// @}
1.365 };
1.366
1.367 + /// \ingroup lemon_io
1.368 + ///
1.369 /// \brief Return a \ref GraphWriter class
1.370 ///
1.371 - /// This function just returns a \ref GraphWriter class.
1.372 + /// This function just returns a \ref GraphWriter class.
1.373 + ///
1.374 + /// With this function a graph can be write to a file or output
1.375 + /// stream in \ref lgf-format "LGF" format with several maps and
1.376 + /// attributes. For example, with the following code a weighted
1.377 + /// matching problem can be written to the standard output, i.e. a
1.378 + /// graph with a \e weight map on the edges:
1.379 + ///
1.380 + ///\code
1.381 + ///ListGraph graph;
1.382 + ///ListGraph::EdgeMap<int> weight(graph);
1.383 + /// // Setting the weight map
1.384 + ///graphWriter(graph, std::cout).
1.385 + /// edgeMap("weight", weight).
1.386 + /// run();
1.387 + ///\endcode
1.388 + ///
1.389 + /// For a complete documentation, please see the \ref GraphWriter
1.390 + /// class documentation.
1.391 + /// \warning Don't forget to put the \ref GraphWriter::run() "run()"
1.392 + /// to the end of the parameter list.
1.393 /// \relates GraphWriter
1.394 - template <typename Graph>
1.395 - GraphWriter<Graph> graphWriter(const Graph& graph,
1.396 - std::ostream& os) {
1.397 - GraphWriter<Graph> tmp(graph, os);
1.398 + /// \sa graphWriter(const TGR& graph, const std::string& fn)
1.399 + /// \sa graphWriter(const TGR& graph, const char* fn)
1.400 + template <typename TGR>
1.401 + GraphWriter<TGR> graphWriter(const TGR& graph, std::ostream& os) {
1.402 + GraphWriter<TGR> tmp(graph, os);
1.403 return tmp;
1.404 }
1.405
1.406 @@ -1544,9 +1590,10 @@
1.407 ///
1.408 /// This function just returns a \ref GraphWriter class.
1.409 /// \relates GraphWriter
1.410 - template <typename Graph>
1.411 - GraphWriter<Graph> graphWriter(const Graph& graph, const std::string& fn) {
1.412 - GraphWriter<Graph> tmp(graph, fn);
1.413 + /// \sa graphWriter(const TGR& graph, std::ostream& os)
1.414 + template <typename TGR>
1.415 + GraphWriter<TGR> graphWriter(const TGR& graph, const std::string& fn) {
1.416 + GraphWriter<TGR> tmp(graph, fn);
1.417 return tmp;
1.418 }
1.419
1.420 @@ -1554,9 +1601,10 @@
1.421 ///
1.422 /// This function just returns a \ref GraphWriter class.
1.423 /// \relates GraphWriter
1.424 - template <typename Graph>
1.425 - GraphWriter<Graph> graphWriter(const Graph& graph, const char* fn) {
1.426 - GraphWriter<Graph> tmp(graph, fn);
1.427 + /// \sa graphWriter(const TGR& graph, std::ostream& os)
1.428 + template <typename TGR>
1.429 + GraphWriter<TGR> graphWriter(const TGR& graph, const char* fn) {
1.430 + GraphWriter<TGR> tmp(graph, fn);
1.431 return tmp;
1.432 }
1.433
1.434 @@ -1746,10 +1794,18 @@
1.435
1.436 };
1.437
1.438 + /// \ingroup lemon_io
1.439 + ///
1.440 /// \brief Return a \ref SectionWriter class
1.441 ///
1.442 /// This function just returns a \ref SectionWriter class.
1.443 + ///
1.444 + /// Please see SectionWriter documentation about the custom section
1.445 + /// output.
1.446 + ///
1.447 /// \relates SectionWriter
1.448 + /// \sa sectionWriter(const std::string& fn)
1.449 + /// \sa sectionWriter(const char *fn)
1.450 inline SectionWriter sectionWriter(std::ostream& os) {
1.451 SectionWriter tmp(os);
1.452 return tmp;
1.453 @@ -1759,6 +1815,7 @@
1.454 ///
1.455 /// This function just returns a \ref SectionWriter class.
1.456 /// \relates SectionWriter
1.457 + /// \sa sectionWriter(std::ostream& os)
1.458 inline SectionWriter sectionWriter(const std::string& fn) {
1.459 SectionWriter tmp(fn);
1.460 return tmp;
1.461 @@ -1768,6 +1825,7 @@
1.462 ///
1.463 /// This function just returns a \ref SectionWriter class.
1.464 /// \relates SectionWriter
1.465 + /// \sa sectionWriter(std::ostream& os)
1.466 inline SectionWriter sectionWriter(const char* fn) {
1.467 SectionWriter tmp(fn);
1.468 return tmp;