1.1 --- a/lemon/lgf_writer.h Fri Jul 04 15:21:48 2008 +0200
1.2 +++ b/lemon/lgf_writer.h Fri Jul 04 16:12:31 2008 +0200
1.3 @@ -304,6 +304,21 @@
1.4 }
1.5
1.6 }
1.7 +
1.8 + template <typename Digraph>
1.9 + class DigraphWriter;
1.10 +
1.11 + template <typename Digraph>
1.12 + DigraphWriter<Digraph> digraphWriter(std::ostream& os,
1.13 + const Digraph& digraph);
1.14 +
1.15 + template <typename Digraph>
1.16 + DigraphWriter<Digraph> digraphWriter(const std::string& fn,
1.17 + const Digraph& digraph);
1.18 +
1.19 + template <typename Digraph>
1.20 + DigraphWriter<Digraph> digraphWriter(const char *fn,
1.21 + const Digraph& digraph);
1.22
1.23 /// \ingroup lemon_io
1.24 ///
1.25 @@ -362,7 +377,7 @@
1.26 std::ostream* _os;
1.27 bool local_os;
1.28
1.29 - Digraph& _digraph;
1.30 + const Digraph& _digraph;
1.31
1.32 std::string _nodes_caption;
1.33 std::string _arcs_caption;
1.34 @@ -394,7 +409,7 @@
1.35 ///
1.36 /// Construct a directed graph writer, which writes to the given
1.37 /// output stream.
1.38 - DigraphWriter(std::ostream& is, Digraph& digraph)
1.39 + DigraphWriter(std::ostream& is, const Digraph& digraph)
1.40 : _os(&is), local_os(false), _digraph(digraph),
1.41 _skip_nodes(false), _skip_arcs(false) {}
1.42
1.43 @@ -402,7 +417,7 @@
1.44 ///
1.45 /// Construct a directed graph writer, which writes to the given
1.46 /// output file.
1.47 - DigraphWriter(const std::string& fn, Digraph& digraph)
1.48 + DigraphWriter(const std::string& fn, const Digraph& digraph)
1.49 : _os(new std::ofstream(fn.c_str())), local_os(true), _digraph(digraph),
1.50 _skip_nodes(false), _skip_arcs(false) {}
1.51
1.52 @@ -410,33 +425,10 @@
1.53 ///
1.54 /// Construct a directed graph writer, which writes to the given
1.55 /// output file.
1.56 - DigraphWriter(const char* fn, Digraph& digraph)
1.57 + DigraphWriter(const char* fn, const Digraph& digraph)
1.58 : _os(new std::ofstream(fn)), local_os(true), _digraph(digraph),
1.59 _skip_nodes(false), _skip_arcs(false) {}
1.60
1.61 - /// \brief Copy constructor
1.62 - ///
1.63 - /// The copy constructor transfers all data from the other writer,
1.64 - /// therefore the copied writer will not be usable more.
1.65 - DigraphWriter(DigraphWriter& other)
1.66 - : _os(other._os), local_os(other.local_os), _digraph(other._digraph),
1.67 - _skip_nodes(other._skip_nodes), _skip_arcs(other._skip_arcs) {
1.68 -
1.69 - other._os = 0;
1.70 - other.local_os = false;
1.71 -
1.72 - _node_index.swap(other._node_index);
1.73 - _arc_index.swap(other._arc_index);
1.74 -
1.75 - _node_maps.swap(other._node_maps);
1.76 - _arc_maps.swap(other._arc_maps);
1.77 - _attributes.swap(other._attributes);
1.78 -
1.79 - _nodes_caption = other._nodes_caption;
1.80 - _arcs_caption = other._arcs_caption;
1.81 - _attributes_caption = other._attributes_caption;
1.82 - }
1.83 -
1.84 /// \brief Destructor
1.85 ~DigraphWriter() {
1.86 for (typename NodeMaps::iterator it = _node_maps.begin();
1.87 @@ -460,6 +452,32 @@
1.88 }
1.89
1.90 private:
1.91 +
1.92 + friend DigraphWriter<Digraph> digraphWriter<>(std::ostream& os,
1.93 + const Digraph& digraph);
1.94 + friend DigraphWriter<Digraph> digraphWriter<>(const std::string& fn,
1.95 + const Digraph& digraph);
1.96 + friend DigraphWriter<Digraph> digraphWriter<>(const char *fn,
1.97 + const Digraph& digraph);
1.98 +
1.99 + DigraphWriter(DigraphWriter& other)
1.100 + : _os(other._os), local_os(other.local_os), _digraph(other._digraph),
1.101 + _skip_nodes(other._skip_nodes), _skip_arcs(other._skip_arcs) {
1.102 +
1.103 + other._os = 0;
1.104 + other.local_os = false;
1.105 +
1.106 + _node_index.swap(other._node_index);
1.107 + _arc_index.swap(other._arc_index);
1.108 +
1.109 + _node_maps.swap(other._node_maps);
1.110 + _arc_maps.swap(other._arc_maps);
1.111 + _attributes.swap(other._attributes);
1.112 +
1.113 + _nodes_caption = other._nodes_caption;
1.114 + _arcs_caption = other._arcs_caption;
1.115 + _attributes_caption = other._attributes_caption;
1.116 + }
1.117
1.118 DigraphWriter& operator=(const DigraphWriter&);
1.119
1.120 @@ -844,7 +862,8 @@
1.121
1.122 /// \relates DigraphWriter
1.123 template <typename Digraph>
1.124 - DigraphWriter<Digraph> digraphWriter(std::ostream& os, Digraph& digraph) {
1.125 + DigraphWriter<Digraph> digraphWriter(std::ostream& os,
1.126 + const Digraph& digraph) {
1.127 DigraphWriter<Digraph> tmp(os, digraph);
1.128 return tmp;
1.129 }
1.130 @@ -852,18 +871,31 @@
1.131 /// \relates DigraphWriter
1.132 template <typename Digraph>
1.133 DigraphWriter<Digraph> digraphWriter(const std::string& fn,
1.134 - Digraph& digraph) {
1.135 + const Digraph& digraph) {
1.136 DigraphWriter<Digraph> tmp(fn, digraph);
1.137 return tmp;
1.138 }
1.139
1.140 /// \relates DigraphWriter
1.141 template <typename Digraph>
1.142 - DigraphWriter<Digraph> digraphWriter(const char* fn, Digraph& digraph) {
1.143 + DigraphWriter<Digraph> digraphWriter(const char* fn,
1.144 + const Digraph& digraph) {
1.145 DigraphWriter<Digraph> tmp(fn, digraph);
1.146 return tmp;
1.147 }
1.148
1.149 + template <typename Graph>
1.150 + class GraphWriter;
1.151 +
1.152 + template <typename Graph>
1.153 + GraphWriter<Graph> graphWriter(std::ostream& os, const Graph& graph);
1.154 +
1.155 + template <typename Graph>
1.156 + GraphWriter<Graph> graphWriter(const std::string& fn, const Graph& graph);
1.157 +
1.158 + template <typename Graph>
1.159 + GraphWriter<Graph> graphWriter(const char *fn, const Graph& graph);
1.160 +
1.161 /// \ingroup lemon_io
1.162 ///
1.163 /// \brief LGF writer for directed graphs
1.164 @@ -914,7 +946,7 @@
1.165 ///
1.166 /// Construct a directed graph writer, which writes to the given
1.167 /// output stream.
1.168 - GraphWriter(std::ostream& is, Graph& graph)
1.169 + GraphWriter(std::ostream& is, const Graph& graph)
1.170 : _os(&is), local_os(false), _graph(graph),
1.171 _skip_nodes(false), _skip_edges(false) {}
1.172
1.173 @@ -922,7 +954,7 @@
1.174 ///
1.175 /// Construct a directed graph writer, which writes to the given
1.176 /// output file.
1.177 - GraphWriter(const std::string& fn, Graph& graph)
1.178 + GraphWriter(const std::string& fn, const Graph& graph)
1.179 : _os(new std::ofstream(fn.c_str())), local_os(true), _graph(graph),
1.180 _skip_nodes(false), _skip_edges(false) {}
1.181
1.182 @@ -930,33 +962,10 @@
1.183 ///
1.184 /// Construct a directed graph writer, which writes to the given
1.185 /// output file.
1.186 - GraphWriter(const char* fn, Graph& graph)
1.187 + GraphWriter(const char* fn, const Graph& graph)
1.188 : _os(new std::ofstream(fn)), local_os(true), _graph(graph),
1.189 _skip_nodes(false), _skip_edges(false) {}
1.190
1.191 - /// \brief Copy constructor
1.192 - ///
1.193 - /// The copy constructor transfers all data from the other writer,
1.194 - /// therefore the copied writer will not be usable more.
1.195 - GraphWriter(GraphWriter& other)
1.196 - : _os(other._os), local_os(other.local_os), _graph(other._graph),
1.197 - _skip_nodes(other._skip_nodes), _skip_edges(other._skip_edges) {
1.198 -
1.199 - other._os = 0;
1.200 - other.local_os = false;
1.201 -
1.202 - _node_index.swap(other._node_index);
1.203 - _edge_index.swap(other._edge_index);
1.204 -
1.205 - _node_maps.swap(other._node_maps);
1.206 - _edge_maps.swap(other._edge_maps);
1.207 - _attributes.swap(other._attributes);
1.208 -
1.209 - _nodes_caption = other._nodes_caption;
1.210 - _edges_caption = other._edges_caption;
1.211 - _attributes_caption = other._attributes_caption;
1.212 - }
1.213 -
1.214 /// \brief Destructor
1.215 ~GraphWriter() {
1.216 for (typename NodeMaps::iterator it = _node_maps.begin();
1.217 @@ -978,9 +987,35 @@
1.218 delete _os;
1.219 }
1.220 }
1.221 +
1.222 + private:
1.223
1.224 - private:
1.225 -
1.226 + friend GraphWriter<Graph> graphWriter<>(std::ostream& os,
1.227 + const Graph& graph);
1.228 + friend GraphWriter<Graph> graphWriter<>(const std::string& fn,
1.229 + const Graph& graph);
1.230 + friend GraphWriter<Graph> graphWriter<>(const char *fn,
1.231 + const Graph& graph);
1.232 +
1.233 + GraphWriter(GraphWriter& other)
1.234 + : _os(other._os), local_os(other.local_os), _graph(other._graph),
1.235 + _skip_nodes(other._skip_nodes), _skip_edges(other._skip_edges) {
1.236 +
1.237 + other._os = 0;
1.238 + other.local_os = false;
1.239 +
1.240 + _node_index.swap(other._node_index);
1.241 + _edge_index.swap(other._edge_index);
1.242 +
1.243 + _node_maps.swap(other._node_maps);
1.244 + _edge_maps.swap(other._edge_maps);
1.245 + _attributes.swap(other._attributes);
1.246 +
1.247 + _nodes_caption = other._nodes_caption;
1.248 + _edges_caption = other._edges_caption;
1.249 + _attributes_caption = other._attributes_caption;
1.250 + }
1.251 +
1.252 GraphWriter& operator=(const GraphWriter&);
1.253
1.254 public:
1.255 @@ -1410,21 +1445,21 @@
1.256
1.257 /// \relates GraphWriter
1.258 template <typename Graph>
1.259 - GraphWriter<Graph> graphWriter(std::ostream& os, Graph& graph) {
1.260 + GraphWriter<Graph> graphWriter(std::ostream& os, const Graph& graph) {
1.261 GraphWriter<Graph> tmp(os, graph);
1.262 return tmp;
1.263 }
1.264
1.265 /// \relates GraphWriter
1.266 template <typename Graph>
1.267 - GraphWriter<Graph> graphWriter(const std::string& fn, Graph& graph) {
1.268 + GraphWriter<Graph> graphWriter(const std::string& fn, const Graph& graph) {
1.269 GraphWriter<Graph> tmp(fn, graph);
1.270 return tmp;
1.271 }
1.272
1.273 /// \relates GraphWriter
1.274 template <typename Graph>
1.275 - GraphWriter<Graph> graphWriter(const char* fn, Graph& graph) {
1.276 + GraphWriter<Graph> graphWriter(const char* fn, const Graph& graph) {
1.277 GraphWriter<Graph> tmp(fn, graph);
1.278 return tmp;
1.279 }