Changeset 294:cbe3ec2d59d2 in lemon-1.2 for lemon/lgf_writer.h
- Timestamp:
- 10/01/08 13:56:40 (16 years ago)
- Branch:
- default
- Children:
- 295:7c796c1cf1b0, 296:9768e60aa4e1
- Parents:
- 293:47fbc814aa31 (diff), 292:e7af73f1805e (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - Phase:
- public
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
lemon/lgf_writer.h
r291 r294 353 353 354 354 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); 357 357 358 358 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); 361 361 362 362 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); 365 365 366 366 /// \ingroup lemon_io … … 383 383 /// 384 384 ///\code 385 /// DigraphWriter<Digraph>( std::cout, digraph).385 /// DigraphWriter<Digraph>(digraph, std::cout). 386 386 /// nodeMap("coordinates", coord_map). 387 387 /// nodeMap("size", size). … … 453 453 /// Construct a directed graph writer, which writes to the given 454 454 /// 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), 457 457 _skip_nodes(false), _skip_arcs(false) {} 458 458 … … 461 461 /// Construct a directed graph writer, which writes to the given 462 462 /// output file. 463 DigraphWriter(const std::string& fn, const Digraph& digraph)463 DigraphWriter(const Digraph& digraph, const std::string& fn) 464 464 : _os(new std::ofstream(fn.c_str())), local_os(true), _digraph(digraph), 465 465 _skip_nodes(false), _skip_arcs(false) { … … 471 471 /// Construct a directed graph writer, which writes to the given 472 472 /// output file. 473 DigraphWriter(const char* fn, const Digraph& digraph)473 DigraphWriter(const Digraph& digraph, const char* fn) 474 474 : _os(new std::ofstream(fn)), local_os(true), _digraph(digraph), 475 475 _skip_nodes(false), _skip_arcs(false) { … … 501 501 private: 502 502 503 friend DigraphWriter<Digraph> digraphWriter<>( std::ostream& os,504 const Digraph& digraph);505 friend DigraphWriter<Digraph> digraphWriter<>(const std::string& fn,506 const Digraph& digraph);507 friend DigraphWriter<Digraph> digraphWriter<>(const char *fn,508 const Digraph& digraph);503 friend DigraphWriter<Digraph> digraphWriter<>(const Digraph& digraph, 504 std::ostream& os); 505 friend DigraphWriter<Digraph> digraphWriter<>(const Digraph& digraph, 506 const std::string& fn); 507 friend DigraphWriter<Digraph> digraphWriter<>(const Digraph& digraph, 508 const char *fn); 509 509 510 510 DigraphWriter(DigraphWriter& other) … … 913 913 /// \relates DigraphWriter 914 914 template <typename Digraph> 915 DigraphWriter<Digraph> digraphWriter( std::ostream& os,916 const Digraph& digraph) {917 DigraphWriter<Digraph> tmp( os, digraph);915 DigraphWriter<Digraph> digraphWriter(const Digraph& digraph, 916 std::ostream& os = std::cout) { 917 DigraphWriter<Digraph> tmp(digraph, os); 918 918 return tmp; 919 919 } … … 924 924 /// \relates DigraphWriter 925 925 template <typename Digraph> 926 DigraphWriter<Digraph> digraphWriter(const std::string& fn,927 const Digraph& digraph) {928 DigraphWriter<Digraph> tmp( fn, digraph);926 DigraphWriter<Digraph> digraphWriter(const Digraph& digraph, 927 const std::string& fn) { 928 DigraphWriter<Digraph> tmp(digraph, fn); 929 929 return tmp; 930 930 } … … 935 935 /// \relates DigraphWriter 936 936 template <typename Digraph> 937 DigraphWriter<Digraph> digraphWriter(const char* fn,938 const Digraph& digraph) {939 DigraphWriter<Digraph> tmp( fn, digraph);937 DigraphWriter<Digraph> digraphWriter(const Digraph& digraph, 938 const char* fn) { 939 DigraphWriter<Digraph> tmp(digraph, fn); 940 940 return tmp; 941 941 } … … 945 945 946 946 template <typename Graph> 947 GraphWriter<Graph> graphWriter(std::ostream& os, const Graph& graph); 947 GraphWriter<Graph> graphWriter(const Graph& graph, 948 std::ostream& os = std::cout); 948 949 949 950 template <typename Graph> 950 GraphWriter<Graph> graphWriter(const std::string& fn, const Graph& graph);951 GraphWriter<Graph> graphWriter(const Graph& graph, const std::string& fn); 951 952 952 953 template <typename Graph> 953 GraphWriter<Graph> graphWriter(const char *fn, const Graph& graph);954 GraphWriter<Graph> graphWriter(const Graph& graph, const char *fn); 954 955 955 956 /// \ingroup lemon_io … … 1013 1014 /// Construct a directed graph writer, which writes to the given 1014 1015 /// output stream. 1015 GraphWriter( std::ostream& is, const Graph& graph)1016 : _os(& is), local_os(false), _graph(graph),1016 GraphWriter(const Graph& graph, std::ostream& os = std::cout) 1017 : _os(&os), local_os(false), _graph(graph), 1017 1018 _skip_nodes(false), _skip_edges(false) {} 1018 1019 … … 1021 1022 /// Construct a directed graph writer, which writes to the given 1022 1023 /// output file. 1023 GraphWriter(const std::string& fn, const Graph& graph)1024 GraphWriter(const Graph& graph, const std::string& fn) 1024 1025 : _os(new std::ofstream(fn.c_str())), local_os(true), _graph(graph), 1025 1026 _skip_nodes(false), _skip_edges(false) { … … 1031 1032 /// Construct a directed graph writer, which writes to the given 1032 1033 /// output file. 1033 GraphWriter(const char* fn, const Graph& graph)1034 GraphWriter(const Graph& graph, const char* fn) 1034 1035 : _os(new std::ofstream(fn)), local_os(true), _graph(graph), 1035 1036 _skip_nodes(false), _skip_edges(false) { … … 1061 1062 private: 1062 1063 1063 friend GraphWriter<Graph> graphWriter<>( std::ostream& os,1064 const Graph& graph);1065 friend GraphWriter<Graph> graphWriter<>(const std::string& fn,1066 const Graph& graph);1067 friend GraphWriter<Graph> graphWriter<>(const char *fn,1068 const Graph& graph);1064 friend GraphWriter<Graph> graphWriter<>(const Graph& graph, 1065 std::ostream& os); 1066 friend GraphWriter<Graph> graphWriter<>(const Graph& graph, 1067 const std::string& fn); 1068 friend GraphWriter<Graph> graphWriter<>(const Graph& graph, 1069 const char *fn); 1069 1070 1070 1071 GraphWriter(GraphWriter& other) … … 1519 1520 /// \relates GraphWriter 1520 1521 template <typename Graph> 1521 GraphWriter<Graph> graphWriter(std::ostream& os, const Graph& graph) { 1522 GraphWriter<Graph> tmp(os, graph); 1522 GraphWriter<Graph> graphWriter(const Graph& graph, 1523 std::ostream& os = std::cout) { 1524 GraphWriter<Graph> tmp(graph, os); 1523 1525 return tmp; 1524 1526 } … … 1529 1531 /// \relates GraphWriter 1530 1532 template <typename Graph> 1531 GraphWriter<Graph> graphWriter(const std::string& fn, const Graph& graph) {1532 GraphWriter<Graph> tmp( fn, graph);1533 GraphWriter<Graph> graphWriter(const Graph& graph, const std::string& fn) { 1534 GraphWriter<Graph> tmp(graph, fn); 1533 1535 return tmp; 1534 1536 } … … 1539 1541 /// \relates GraphWriter 1540 1542 template <typename Graph> 1541 GraphWriter<Graph> graphWriter(const char* fn, const Graph& graph) {1542 GraphWriter<Graph> tmp( fn, graph);1543 GraphWriter<Graph> graphWriter(const Graph& graph, const char* fn) { 1544 GraphWriter<Graph> tmp(graph, fn); 1543 1545 return tmp; 1544 1546 } -
lemon/lgf_writer.h
r293 r294 56 56 template <typename T> 57 57 bool operator<(const T&, const T&) { 58 throw DataFormatError("Label map is not comparable");58 throw FormatError("Label map is not comparable"); 59 59 } 60 60 … … 204 204 _map.find(str); 205 205 if (it == _map.end()) { 206 throw DataFormatError("Item not found");206 throw FormatError("Item not found"); 207 207 } 208 208 return it->second; … … 224 224 ::const_iterator it = _map.find(val); 225 225 if (it == _map.end()) { 226 throw DataFormatError("Item not found");226 throw FormatError("Item not found"); 227 227 } 228 228 return (_graph.direction(val) ? '+' : '-') + it->second; … … 463 463 DigraphWriter(const Digraph& digraph, const std::string& fn) 464 464 : _os(new std::ofstream(fn.c_str())), local_os(true), _digraph(digraph), 465 _skip_nodes(false), _skip_arcs(false) {} 465 _skip_nodes(false), _skip_arcs(false) { 466 if (!(*_os)) throw IoError("Cannot write file", fn); 467 } 466 468 467 469 /// \brief Constructor … … 471 473 DigraphWriter(const Digraph& digraph, const char* fn) 472 474 : _os(new std::ofstream(fn)), local_os(true), _digraph(digraph), 473 _skip_nodes(false), _skip_arcs(false) {} 475 _skip_nodes(false), _skip_arcs(false) { 476 if (!(*_os)) throw IoError("Cannot write file", fn); 477 } 474 478 475 479 /// \brief Destructor … … 1020 1024 GraphWriter(const Graph& graph, const std::string& fn) 1021 1025 : _os(new std::ofstream(fn.c_str())), local_os(true), _graph(graph), 1022 _skip_nodes(false), _skip_edges(false) {} 1026 _skip_nodes(false), _skip_edges(false) { 1027 if (!(*_os)) throw IoError("Cannot write file", fn); 1028 } 1023 1029 1024 1030 /// \brief Constructor … … 1028 1034 GraphWriter(const Graph& graph, const char* fn) 1029 1035 : _os(new std::ofstream(fn)), local_os(true), _graph(graph), 1030 _skip_nodes(false), _skip_edges(false) {} 1036 _skip_nodes(false), _skip_edges(false) { 1037 if (!(*_os)) throw IoError("Cannot write file", fn); 1038 } 1031 1039 1032 1040 /// \brief Destructor … … 1579 1587 /// Construct a section writer, which writes into the given file. 1580 1588 SectionWriter(const std::string& fn) 1581 : _os(new std::ofstream(fn.c_str())), local_os(true) {} 1589 : _os(new std::ofstream(fn.c_str())), local_os(true) { 1590 if (!(*_os)) throw IoError("Cannot write file", fn); 1591 } 1582 1592 1583 1593 /// \brief Constructor … … 1585 1595 /// Construct a section writer, which writes into the given file. 1586 1596 SectionWriter(const char* fn) 1587 : _os(new std::ofstream(fn)), local_os(true) {} 1597 : _os(new std::ofstream(fn)), local_os(true) { 1598 if (!(*_os)) throw IoError("Cannot write file", fn); 1599 } 1588 1600 1589 1601 /// \brief Destructor
Note: See TracChangeset
for help on using the changeset viewer.