1.1 --- a/lemon/lgf_reader.h Fri Jul 04 15:21:48 2008 +0200
1.2 +++ b/lemon/lgf_reader.h Fri Jul 04 16:12:31 2008 +0200
1.3 @@ -386,6 +386,18 @@
1.4
1.5 }
1.6
1.7 + template <typename Digraph>
1.8 + class DigraphReader;
1.9 +
1.10 + template <typename Digraph>
1.11 + DigraphReader<Digraph> digraphReader(std::istream& is, Digraph& digraph);
1.12 +
1.13 + template <typename Digraph>
1.14 + DigraphReader<Digraph> digraphReader(const std::string& fn, Digraph& digraph);
1.15 +
1.16 + template <typename Digraph>
1.17 + DigraphReader<Digraph> digraphReader(const char *fn, Digraph& digraph);
1.18 +
1.19 /// \ingroup lemon_io
1.20 ///
1.21 /// \brief LGF reader for directed graphs
1.22 @@ -509,31 +521,6 @@
1.23 _use_nodes(false), _use_arcs(false),
1.24 _skip_nodes(false), _skip_arcs(false) {}
1.25
1.26 - /// \brief Copy constructor
1.27 - ///
1.28 - /// The copy constructor transfers all data from the other reader,
1.29 - /// therefore the copied reader will not be usable more.
1.30 - DigraphReader(DigraphReader& other)
1.31 - : _is(other._is), local_is(other.local_is), _digraph(other._digraph),
1.32 - _use_nodes(other._use_nodes), _use_arcs(other._use_arcs),
1.33 - _skip_nodes(other._skip_nodes), _skip_arcs(other._skip_arcs) {
1.34 -
1.35 - other._is = 0;
1.36 - other.local_is = false;
1.37 -
1.38 - _node_index.swap(other._node_index);
1.39 - _arc_index.swap(other._arc_index);
1.40 -
1.41 - _node_maps.swap(other._node_maps);
1.42 - _arc_maps.swap(other._arc_maps);
1.43 - _attributes.swap(other._attributes);
1.44 -
1.45 - _nodes_caption = other._nodes_caption;
1.46 - _arcs_caption = other._arcs_caption;
1.47 - _attributes_caption = other._attributes_caption;
1.48 -
1.49 - }
1.50 -
1.51 /// \brief Destructor
1.52 ~DigraphReader() {
1.53 for (typename NodeMaps::iterator it = _node_maps.begin();
1.54 @@ -558,7 +545,35 @@
1.55 }
1.56
1.57 private:
1.58 -
1.59 +
1.60 + friend DigraphReader<Digraph> digraphReader<>(std::istream& is,
1.61 + Digraph& digraph);
1.62 + friend DigraphReader<Digraph> digraphReader<>(const std::string& fn,
1.63 + Digraph& digraph);
1.64 + friend DigraphReader<Digraph> digraphReader<>(const char *fn,
1.65 + Digraph& digraph);
1.66 +
1.67 + DigraphReader(DigraphReader& other)
1.68 + : _is(other._is), local_is(other.local_is), _digraph(other._digraph),
1.69 + _use_nodes(other._use_nodes), _use_arcs(other._use_arcs),
1.70 + _skip_nodes(other._skip_nodes), _skip_arcs(other._skip_arcs) {
1.71 +
1.72 + other._is = 0;
1.73 + other.local_is = false;
1.74 +
1.75 + _node_index.swap(other._node_index);
1.76 + _arc_index.swap(other._arc_index);
1.77 +
1.78 + _node_maps.swap(other._node_maps);
1.79 + _arc_maps.swap(other._arc_maps);
1.80 + _attributes.swap(other._attributes);
1.81 +
1.82 + _nodes_caption = other._nodes_caption;
1.83 + _arcs_caption = other._arcs_caption;
1.84 + _attributes_caption = other._attributes_caption;
1.85 +
1.86 + }
1.87 +
1.88 DigraphReader& operator=(const DigraphReader&);
1.89
1.90 public:
1.91 @@ -1182,6 +1197,18 @@
1.92 return tmp;
1.93 }
1.94
1.95 + template <typename Graph>
1.96 + class GraphReader;
1.97 +
1.98 + template <typename Graph>
1.99 + GraphReader<Graph> graphReader(std::istream& is, Graph& graph);
1.100 +
1.101 + template <typename Graph>
1.102 + GraphReader<Graph> graphReader(const std::string& fn, Graph& graph);
1.103 +
1.104 + template <typename Graph>
1.105 + GraphReader<Graph> graphReader(const char *fn, Graph& graph);
1.106 +
1.107 /// \ingroup lemon_io
1.108 ///
1.109 /// \brief LGF reader for undirected graphs
1.110 @@ -1260,31 +1287,6 @@
1.111 _use_nodes(false), _use_edges(false),
1.112 _skip_nodes(false), _skip_edges(false) {}
1.113
1.114 - /// \brief Copy constructor
1.115 - ///
1.116 - /// The copy constructor transfers all data from the other reader,
1.117 - /// therefore the copied reader will not be usable more.
1.118 - GraphReader(GraphReader& other)
1.119 - : _is(other._is), local_is(other.local_is), _graph(other._graph),
1.120 - _use_nodes(other._use_nodes), _use_edges(other._use_edges),
1.121 - _skip_nodes(other._skip_nodes), _skip_edges(other._skip_edges) {
1.122 -
1.123 - other._is = 0;
1.124 - other.local_is = false;
1.125 -
1.126 - _node_index.swap(other._node_index);
1.127 - _edge_index.swap(other._edge_index);
1.128 -
1.129 - _node_maps.swap(other._node_maps);
1.130 - _edge_maps.swap(other._edge_maps);
1.131 - _attributes.swap(other._attributes);
1.132 -
1.133 - _nodes_caption = other._nodes_caption;
1.134 - _edges_caption = other._edges_caption;
1.135 - _attributes_caption = other._attributes_caption;
1.136 -
1.137 - }
1.138 -
1.139 /// \brief Destructor
1.140 ~GraphReader() {
1.141 for (typename NodeMaps::iterator it = _node_maps.begin();
1.142 @@ -1309,7 +1311,32 @@
1.143 }
1.144
1.145 private:
1.146 -
1.147 + friend GraphReader<Graph> graphReader<>(std::istream& is, Graph& graph);
1.148 + friend GraphReader<Graph> graphReader<>(const std::string& fn,
1.149 + Graph& graph);
1.150 + friend GraphReader<Graph> graphReader<>(const char *fn, Graph& graph);
1.151 +
1.152 + GraphReader(GraphReader& other)
1.153 + : _is(other._is), local_is(other.local_is), _graph(other._graph),
1.154 + _use_nodes(other._use_nodes), _use_edges(other._use_edges),
1.155 + _skip_nodes(other._skip_nodes), _skip_edges(other._skip_edges) {
1.156 +
1.157 + other._is = 0;
1.158 + other.local_is = false;
1.159 +
1.160 + _node_index.swap(other._node_index);
1.161 + _edge_index.swap(other._edge_index);
1.162 +
1.163 + _node_maps.swap(other._node_maps);
1.164 + _edge_maps.swap(other._edge_maps);
1.165 + _attributes.swap(other._attributes);
1.166 +
1.167 + _nodes_caption = other._nodes_caption;
1.168 + _edges_caption = other._edges_caption;
1.169 + _attributes_caption = other._attributes_caption;
1.170 +
1.171 + }
1.172 +
1.173 GraphReader& operator=(const GraphReader&);
1.174
1.175 public:
1.176 @@ -1977,6 +2004,12 @@
1.177 return tmp;
1.178 }
1.179
1.180 + class SectionReader;
1.181 +
1.182 + SectionReader sectionReader(std::istream& is);
1.183 + SectionReader sectionReader(const std::string& fn);
1.184 + SectionReader sectionReader(const char* fn);
1.185 +
1.186 /// \brief Section reader class
1.187 ///
1.188 /// In the \e LGF file extra sections can be placed, which contain
1.189 @@ -2019,19 +2052,6 @@
1.190 SectionReader(const char* fn)
1.191 : _is(new std::ifstream(fn)), local_is(true) {}
1.192
1.193 - /// \brief Copy constructor
1.194 - ///
1.195 - /// The copy constructor transfers all data from the other reader,
1.196 - /// therefore the copied reader will not be usable more.
1.197 - SectionReader(SectionReader& other)
1.198 - : _is(other._is), local_is(other.local_is) {
1.199 -
1.200 - other._is = 0;
1.201 - other.local_is = false;
1.202 -
1.203 - _sections.swap(other._sections);
1.204 - }
1.205 -
1.206 /// \brief Destructor
1.207 ~SectionReader() {
1.208 for (Sections::iterator it = _sections.begin();
1.209 @@ -2046,6 +2066,19 @@
1.210 }
1.211
1.212 private:
1.213 +
1.214 + friend SectionReader sectionReader(std::istream& is);
1.215 + friend SectionReader sectionReader(const std::string& fn);
1.216 + friend SectionReader sectionReader(const char* fn);
1.217 +
1.218 + SectionReader(SectionReader& other)
1.219 + : _is(other._is), local_is(other.local_is) {
1.220 +
1.221 + other._is = 0;
1.222 + other.local_is = false;
1.223 +
1.224 + _sections.swap(other._sections);
1.225 + }
1.226
1.227 SectionReader& operator=(const SectionReader&);
1.228
1.229 @@ -2295,34 +2328,19 @@
1.230 /// file.
1.231 LgfContents(const char* fn)
1.232 : _is(new std::ifstream(fn)), local_is(true) {}
1.233 -
1.234 - /// \brief Copy constructor
1.235 - ///
1.236 - /// The copy constructor transfers all data from the other reader,
1.237 - /// therefore the copied reader will not be usable more.
1.238 - LgfContents(LgfContents& other)
1.239 - : _is(other._is), local_is(other.local_is) {
1.240 -
1.241 - other._is = 0;
1.242 - other.local_is = false;
1.243 -
1.244 - _node_sections.swap(other._node_sections);
1.245 - _edge_sections.swap(other._edge_sections);
1.246 - _attribute_sections.swap(other._attribute_sections);
1.247 - _extra_sections.swap(other._extra_sections);
1.248 -
1.249 - _arc_sections.swap(other._arc_sections);
1.250 -
1.251 - _node_maps.swap(other._node_maps);
1.252 - _edge_maps.swap(other._edge_maps);
1.253 - _attributes.swap(other._attributes);
1.254 - }
1.255
1.256 /// \brief Destructor
1.257 ~LgfContents() {
1.258 if (local_is) delete _is;
1.259 }
1.260
1.261 + private:
1.262 +
1.263 + LgfContents(const LgfContents&);
1.264 + LgfContents& operator=(const LgfContents&);
1.265 +
1.266 + public:
1.267 +
1.268
1.269 /// \name Node sections
1.270 /// @{
2.1 --- a/lemon/lgf_writer.h Fri Jul 04 15:21:48 2008 +0200
2.2 +++ b/lemon/lgf_writer.h Fri Jul 04 16:12:31 2008 +0200
2.3 @@ -304,6 +304,21 @@
2.4 }
2.5
2.6 }
2.7 +
2.8 + template <typename Digraph>
2.9 + class DigraphWriter;
2.10 +
2.11 + template <typename Digraph>
2.12 + DigraphWriter<Digraph> digraphWriter(std::ostream& os,
2.13 + const Digraph& digraph);
2.14 +
2.15 + template <typename Digraph>
2.16 + DigraphWriter<Digraph> digraphWriter(const std::string& fn,
2.17 + const Digraph& digraph);
2.18 +
2.19 + template <typename Digraph>
2.20 + DigraphWriter<Digraph> digraphWriter(const char *fn,
2.21 + const Digraph& digraph);
2.22
2.23 /// \ingroup lemon_io
2.24 ///
2.25 @@ -362,7 +377,7 @@
2.26 std::ostream* _os;
2.27 bool local_os;
2.28
2.29 - Digraph& _digraph;
2.30 + const Digraph& _digraph;
2.31
2.32 std::string _nodes_caption;
2.33 std::string _arcs_caption;
2.34 @@ -394,7 +409,7 @@
2.35 ///
2.36 /// Construct a directed graph writer, which writes to the given
2.37 /// output stream.
2.38 - DigraphWriter(std::ostream& is, Digraph& digraph)
2.39 + DigraphWriter(std::ostream& is, const Digraph& digraph)
2.40 : _os(&is), local_os(false), _digraph(digraph),
2.41 _skip_nodes(false), _skip_arcs(false) {}
2.42
2.43 @@ -402,7 +417,7 @@
2.44 ///
2.45 /// Construct a directed graph writer, which writes to the given
2.46 /// output file.
2.47 - DigraphWriter(const std::string& fn, Digraph& digraph)
2.48 + DigraphWriter(const std::string& fn, const Digraph& digraph)
2.49 : _os(new std::ofstream(fn.c_str())), local_os(true), _digraph(digraph),
2.50 _skip_nodes(false), _skip_arcs(false) {}
2.51
2.52 @@ -410,33 +425,10 @@
2.53 ///
2.54 /// Construct a directed graph writer, which writes to the given
2.55 /// output file.
2.56 - DigraphWriter(const char* fn, Digraph& digraph)
2.57 + DigraphWriter(const char* fn, const Digraph& digraph)
2.58 : _os(new std::ofstream(fn)), local_os(true), _digraph(digraph),
2.59 _skip_nodes(false), _skip_arcs(false) {}
2.60
2.61 - /// \brief Copy constructor
2.62 - ///
2.63 - /// The copy constructor transfers all data from the other writer,
2.64 - /// therefore the copied writer will not be usable more.
2.65 - DigraphWriter(DigraphWriter& other)
2.66 - : _os(other._os), local_os(other.local_os), _digraph(other._digraph),
2.67 - _skip_nodes(other._skip_nodes), _skip_arcs(other._skip_arcs) {
2.68 -
2.69 - other._os = 0;
2.70 - other.local_os = false;
2.71 -
2.72 - _node_index.swap(other._node_index);
2.73 - _arc_index.swap(other._arc_index);
2.74 -
2.75 - _node_maps.swap(other._node_maps);
2.76 - _arc_maps.swap(other._arc_maps);
2.77 - _attributes.swap(other._attributes);
2.78 -
2.79 - _nodes_caption = other._nodes_caption;
2.80 - _arcs_caption = other._arcs_caption;
2.81 - _attributes_caption = other._attributes_caption;
2.82 - }
2.83 -
2.84 /// \brief Destructor
2.85 ~DigraphWriter() {
2.86 for (typename NodeMaps::iterator it = _node_maps.begin();
2.87 @@ -460,6 +452,32 @@
2.88 }
2.89
2.90 private:
2.91 +
2.92 + friend DigraphWriter<Digraph> digraphWriter<>(std::ostream& os,
2.93 + const Digraph& digraph);
2.94 + friend DigraphWriter<Digraph> digraphWriter<>(const std::string& fn,
2.95 + const Digraph& digraph);
2.96 + friend DigraphWriter<Digraph> digraphWriter<>(const char *fn,
2.97 + const Digraph& digraph);
2.98 +
2.99 + DigraphWriter(DigraphWriter& other)
2.100 + : _os(other._os), local_os(other.local_os), _digraph(other._digraph),
2.101 + _skip_nodes(other._skip_nodes), _skip_arcs(other._skip_arcs) {
2.102 +
2.103 + other._os = 0;
2.104 + other.local_os = false;
2.105 +
2.106 + _node_index.swap(other._node_index);
2.107 + _arc_index.swap(other._arc_index);
2.108 +
2.109 + _node_maps.swap(other._node_maps);
2.110 + _arc_maps.swap(other._arc_maps);
2.111 + _attributes.swap(other._attributes);
2.112 +
2.113 + _nodes_caption = other._nodes_caption;
2.114 + _arcs_caption = other._arcs_caption;
2.115 + _attributes_caption = other._attributes_caption;
2.116 + }
2.117
2.118 DigraphWriter& operator=(const DigraphWriter&);
2.119
2.120 @@ -844,7 +862,8 @@
2.121
2.122 /// \relates DigraphWriter
2.123 template <typename Digraph>
2.124 - DigraphWriter<Digraph> digraphWriter(std::ostream& os, Digraph& digraph) {
2.125 + DigraphWriter<Digraph> digraphWriter(std::ostream& os,
2.126 + const Digraph& digraph) {
2.127 DigraphWriter<Digraph> tmp(os, digraph);
2.128 return tmp;
2.129 }
2.130 @@ -852,18 +871,31 @@
2.131 /// \relates DigraphWriter
2.132 template <typename Digraph>
2.133 DigraphWriter<Digraph> digraphWriter(const std::string& fn,
2.134 - Digraph& digraph) {
2.135 + const Digraph& digraph) {
2.136 DigraphWriter<Digraph> tmp(fn, digraph);
2.137 return tmp;
2.138 }
2.139
2.140 /// \relates DigraphWriter
2.141 template <typename Digraph>
2.142 - DigraphWriter<Digraph> digraphWriter(const char* fn, Digraph& digraph) {
2.143 + DigraphWriter<Digraph> digraphWriter(const char* fn,
2.144 + const Digraph& digraph) {
2.145 DigraphWriter<Digraph> tmp(fn, digraph);
2.146 return tmp;
2.147 }
2.148
2.149 + template <typename Graph>
2.150 + class GraphWriter;
2.151 +
2.152 + template <typename Graph>
2.153 + GraphWriter<Graph> graphWriter(std::ostream& os, const Graph& graph);
2.154 +
2.155 + template <typename Graph>
2.156 + GraphWriter<Graph> graphWriter(const std::string& fn, const Graph& graph);
2.157 +
2.158 + template <typename Graph>
2.159 + GraphWriter<Graph> graphWriter(const char *fn, const Graph& graph);
2.160 +
2.161 /// \ingroup lemon_io
2.162 ///
2.163 /// \brief LGF writer for directed graphs
2.164 @@ -914,7 +946,7 @@
2.165 ///
2.166 /// Construct a directed graph writer, which writes to the given
2.167 /// output stream.
2.168 - GraphWriter(std::ostream& is, Graph& graph)
2.169 + GraphWriter(std::ostream& is, const Graph& graph)
2.170 : _os(&is), local_os(false), _graph(graph),
2.171 _skip_nodes(false), _skip_edges(false) {}
2.172
2.173 @@ -922,7 +954,7 @@
2.174 ///
2.175 /// Construct a directed graph writer, which writes to the given
2.176 /// output file.
2.177 - GraphWriter(const std::string& fn, Graph& graph)
2.178 + GraphWriter(const std::string& fn, const Graph& graph)
2.179 : _os(new std::ofstream(fn.c_str())), local_os(true), _graph(graph),
2.180 _skip_nodes(false), _skip_edges(false) {}
2.181
2.182 @@ -930,33 +962,10 @@
2.183 ///
2.184 /// Construct a directed graph writer, which writes to the given
2.185 /// output file.
2.186 - GraphWriter(const char* fn, Graph& graph)
2.187 + GraphWriter(const char* fn, const Graph& graph)
2.188 : _os(new std::ofstream(fn)), local_os(true), _graph(graph),
2.189 _skip_nodes(false), _skip_edges(false) {}
2.190
2.191 - /// \brief Copy constructor
2.192 - ///
2.193 - /// The copy constructor transfers all data from the other writer,
2.194 - /// therefore the copied writer will not be usable more.
2.195 - GraphWriter(GraphWriter& other)
2.196 - : _os(other._os), local_os(other.local_os), _graph(other._graph),
2.197 - _skip_nodes(other._skip_nodes), _skip_edges(other._skip_edges) {
2.198 -
2.199 - other._os = 0;
2.200 - other.local_os = false;
2.201 -
2.202 - _node_index.swap(other._node_index);
2.203 - _edge_index.swap(other._edge_index);
2.204 -
2.205 - _node_maps.swap(other._node_maps);
2.206 - _edge_maps.swap(other._edge_maps);
2.207 - _attributes.swap(other._attributes);
2.208 -
2.209 - _nodes_caption = other._nodes_caption;
2.210 - _edges_caption = other._edges_caption;
2.211 - _attributes_caption = other._attributes_caption;
2.212 - }
2.213 -
2.214 /// \brief Destructor
2.215 ~GraphWriter() {
2.216 for (typename NodeMaps::iterator it = _node_maps.begin();
2.217 @@ -978,9 +987,35 @@
2.218 delete _os;
2.219 }
2.220 }
2.221 +
2.222 + private:
2.223
2.224 - private:
2.225 -
2.226 + friend GraphWriter<Graph> graphWriter<>(std::ostream& os,
2.227 + const Graph& graph);
2.228 + friend GraphWriter<Graph> graphWriter<>(const std::string& fn,
2.229 + const Graph& graph);
2.230 + friend GraphWriter<Graph> graphWriter<>(const char *fn,
2.231 + const Graph& graph);
2.232 +
2.233 + GraphWriter(GraphWriter& other)
2.234 + : _os(other._os), local_os(other.local_os), _graph(other._graph),
2.235 + _skip_nodes(other._skip_nodes), _skip_edges(other._skip_edges) {
2.236 +
2.237 + other._os = 0;
2.238 + other.local_os = false;
2.239 +
2.240 + _node_index.swap(other._node_index);
2.241 + _edge_index.swap(other._edge_index);
2.242 +
2.243 + _node_maps.swap(other._node_maps);
2.244 + _edge_maps.swap(other._edge_maps);
2.245 + _attributes.swap(other._attributes);
2.246 +
2.247 + _nodes_caption = other._nodes_caption;
2.248 + _edges_caption = other._edges_caption;
2.249 + _attributes_caption = other._attributes_caption;
2.250 + }
2.251 +
2.252 GraphWriter& operator=(const GraphWriter&);
2.253
2.254 public:
2.255 @@ -1410,21 +1445,21 @@
2.256
2.257 /// \relates GraphWriter
2.258 template <typename Graph>
2.259 - GraphWriter<Graph> graphWriter(std::ostream& os, Graph& graph) {
2.260 + GraphWriter<Graph> graphWriter(std::ostream& os, const Graph& graph) {
2.261 GraphWriter<Graph> tmp(os, graph);
2.262 return tmp;
2.263 }
2.264
2.265 /// \relates GraphWriter
2.266 template <typename Graph>
2.267 - GraphWriter<Graph> graphWriter(const std::string& fn, Graph& graph) {
2.268 + GraphWriter<Graph> graphWriter(const std::string& fn, const Graph& graph) {
2.269 GraphWriter<Graph> tmp(fn, graph);
2.270 return tmp;
2.271 }
2.272
2.273 /// \relates GraphWriter
2.274 template <typename Graph>
2.275 - GraphWriter<Graph> graphWriter(const char* fn, Graph& graph) {
2.276 + GraphWriter<Graph> graphWriter(const char* fn, const Graph& graph) {
2.277 GraphWriter<Graph> tmp(fn, graph);
2.278 return tmp;
2.279 }