# HG changeset patch # User Balazs Dezso # Date 2008-07-04 16:12:31 # Node ID 1e6af6f0843c373a0579fc699ac4a83bb4f5948a # Parent a63ed81c57babfd26265bcf154436fb8600c13c3 Move to private copy constrcutors diff --git a/lemon/lgf_reader.h b/lemon/lgf_reader.h --- a/lemon/lgf_reader.h +++ b/lemon/lgf_reader.h @@ -386,6 +386,18 @@ } + template + class DigraphReader; + + template + DigraphReader digraphReader(std::istream& is, Digraph& digraph); + + template + DigraphReader digraphReader(const std::string& fn, Digraph& digraph); + + template + DigraphReader digraphReader(const char *fn, Digraph& digraph); + /// \ingroup lemon_io /// /// \brief LGF reader for directed graphs @@ -509,31 +521,6 @@ _use_nodes(false), _use_arcs(false), _skip_nodes(false), _skip_arcs(false) {} - /// \brief Copy constructor - /// - /// The copy constructor transfers all data from the other reader, - /// therefore the copied reader will not be usable more. - DigraphReader(DigraphReader& other) - : _is(other._is), local_is(other.local_is), _digraph(other._digraph), - _use_nodes(other._use_nodes), _use_arcs(other._use_arcs), - _skip_nodes(other._skip_nodes), _skip_arcs(other._skip_arcs) { - - other._is = 0; - other.local_is = false; - - _node_index.swap(other._node_index); - _arc_index.swap(other._arc_index); - - _node_maps.swap(other._node_maps); - _arc_maps.swap(other._arc_maps); - _attributes.swap(other._attributes); - - _nodes_caption = other._nodes_caption; - _arcs_caption = other._arcs_caption; - _attributes_caption = other._attributes_caption; - - } - /// \brief Destructor ~DigraphReader() { for (typename NodeMaps::iterator it = _node_maps.begin(); @@ -558,7 +545,35 @@ } private: - + + friend DigraphReader digraphReader<>(std::istream& is, + Digraph& digraph); + friend DigraphReader digraphReader<>(const std::string& fn, + Digraph& digraph); + friend DigraphReader digraphReader<>(const char *fn, + Digraph& digraph); + + DigraphReader(DigraphReader& other) + : _is(other._is), local_is(other.local_is), _digraph(other._digraph), + _use_nodes(other._use_nodes), _use_arcs(other._use_arcs), + _skip_nodes(other._skip_nodes), _skip_arcs(other._skip_arcs) { + + other._is = 0; + other.local_is = false; + + _node_index.swap(other._node_index); + _arc_index.swap(other._arc_index); + + _node_maps.swap(other._node_maps); + _arc_maps.swap(other._arc_maps); + _attributes.swap(other._attributes); + + _nodes_caption = other._nodes_caption; + _arcs_caption = other._arcs_caption; + _attributes_caption = other._attributes_caption; + + } + DigraphReader& operator=(const DigraphReader&); public: @@ -1182,6 +1197,18 @@ return tmp; } + template + class GraphReader; + + template + GraphReader graphReader(std::istream& is, Graph& graph); + + template + GraphReader graphReader(const std::string& fn, Graph& graph); + + template + GraphReader graphReader(const char *fn, Graph& graph); + /// \ingroup lemon_io /// /// \brief LGF reader for undirected graphs @@ -1260,31 +1287,6 @@ _use_nodes(false), _use_edges(false), _skip_nodes(false), _skip_edges(false) {} - /// \brief Copy constructor - /// - /// The copy constructor transfers all data from the other reader, - /// therefore the copied reader will not be usable more. - GraphReader(GraphReader& other) - : _is(other._is), local_is(other.local_is), _graph(other._graph), - _use_nodes(other._use_nodes), _use_edges(other._use_edges), - _skip_nodes(other._skip_nodes), _skip_edges(other._skip_edges) { - - other._is = 0; - other.local_is = false; - - _node_index.swap(other._node_index); - _edge_index.swap(other._edge_index); - - _node_maps.swap(other._node_maps); - _edge_maps.swap(other._edge_maps); - _attributes.swap(other._attributes); - - _nodes_caption = other._nodes_caption; - _edges_caption = other._edges_caption; - _attributes_caption = other._attributes_caption; - - } - /// \brief Destructor ~GraphReader() { for (typename NodeMaps::iterator it = _node_maps.begin(); @@ -1309,7 +1311,32 @@ } private: - + friend GraphReader graphReader<>(std::istream& is, Graph& graph); + friend GraphReader graphReader<>(const std::string& fn, + Graph& graph); + friend GraphReader graphReader<>(const char *fn, Graph& graph); + + GraphReader(GraphReader& other) + : _is(other._is), local_is(other.local_is), _graph(other._graph), + _use_nodes(other._use_nodes), _use_edges(other._use_edges), + _skip_nodes(other._skip_nodes), _skip_edges(other._skip_edges) { + + other._is = 0; + other.local_is = false; + + _node_index.swap(other._node_index); + _edge_index.swap(other._edge_index); + + _node_maps.swap(other._node_maps); + _edge_maps.swap(other._edge_maps); + _attributes.swap(other._attributes); + + _nodes_caption = other._nodes_caption; + _edges_caption = other._edges_caption; + _attributes_caption = other._attributes_caption; + + } + GraphReader& operator=(const GraphReader&); public: @@ -1977,6 +2004,12 @@ return tmp; } + class SectionReader; + + SectionReader sectionReader(std::istream& is); + SectionReader sectionReader(const std::string& fn); + SectionReader sectionReader(const char* fn); + /// \brief Section reader class /// /// In the \e LGF file extra sections can be placed, which contain @@ -2019,19 +2052,6 @@ SectionReader(const char* fn) : _is(new std::ifstream(fn)), local_is(true) {} - /// \brief Copy constructor - /// - /// The copy constructor transfers all data from the other reader, - /// therefore the copied reader will not be usable more. - SectionReader(SectionReader& other) - : _is(other._is), local_is(other.local_is) { - - other._is = 0; - other.local_is = false; - - _sections.swap(other._sections); - } - /// \brief Destructor ~SectionReader() { for (Sections::iterator it = _sections.begin(); @@ -2046,6 +2066,19 @@ } private: + + friend SectionReader sectionReader(std::istream& is); + friend SectionReader sectionReader(const std::string& fn); + friend SectionReader sectionReader(const char* fn); + + SectionReader(SectionReader& other) + : _is(other._is), local_is(other.local_is) { + + other._is = 0; + other.local_is = false; + + _sections.swap(other._sections); + } SectionReader& operator=(const SectionReader&); @@ -2295,34 +2328,19 @@ /// file. LgfContents(const char* fn) : _is(new std::ifstream(fn)), local_is(true) {} - - /// \brief Copy constructor - /// - /// The copy constructor transfers all data from the other reader, - /// therefore the copied reader will not be usable more. - LgfContents(LgfContents& other) - : _is(other._is), local_is(other.local_is) { - - other._is = 0; - other.local_is = false; - - _node_sections.swap(other._node_sections); - _edge_sections.swap(other._edge_sections); - _attribute_sections.swap(other._attribute_sections); - _extra_sections.swap(other._extra_sections); - - _arc_sections.swap(other._arc_sections); - - _node_maps.swap(other._node_maps); - _edge_maps.swap(other._edge_maps); - _attributes.swap(other._attributes); - } /// \brief Destructor ~LgfContents() { if (local_is) delete _is; } + private: + + LgfContents(const LgfContents&); + LgfContents& operator=(const LgfContents&); + + public: + /// \name Node sections /// @{ diff --git a/lemon/lgf_writer.h b/lemon/lgf_writer.h --- a/lemon/lgf_writer.h +++ b/lemon/lgf_writer.h @@ -304,6 +304,21 @@ } } + + template + class DigraphWriter; + + template + DigraphWriter digraphWriter(std::ostream& os, + const Digraph& digraph); + + template + DigraphWriter digraphWriter(const std::string& fn, + const Digraph& digraph); + + template + DigraphWriter digraphWriter(const char *fn, + const Digraph& digraph); /// \ingroup lemon_io /// @@ -362,7 +377,7 @@ std::ostream* _os; bool local_os; - Digraph& _digraph; + const Digraph& _digraph; std::string _nodes_caption; std::string _arcs_caption; @@ -394,7 +409,7 @@ /// /// Construct a directed graph writer, which writes to the given /// output stream. - DigraphWriter(std::ostream& is, Digraph& digraph) + DigraphWriter(std::ostream& is, const Digraph& digraph) : _os(&is), local_os(false), _digraph(digraph), _skip_nodes(false), _skip_arcs(false) {} @@ -402,7 +417,7 @@ /// /// Construct a directed graph writer, which writes to the given /// output file. - DigraphWriter(const std::string& fn, Digraph& digraph) + DigraphWriter(const std::string& fn, const Digraph& digraph) : _os(new std::ofstream(fn.c_str())), local_os(true), _digraph(digraph), _skip_nodes(false), _skip_arcs(false) {} @@ -410,33 +425,10 @@ /// /// Construct a directed graph writer, which writes to the given /// output file. - DigraphWriter(const char* fn, Digraph& digraph) + DigraphWriter(const char* fn, const Digraph& digraph) : _os(new std::ofstream(fn)), local_os(true), _digraph(digraph), _skip_nodes(false), _skip_arcs(false) {} - /// \brief Copy constructor - /// - /// The copy constructor transfers all data from the other writer, - /// therefore the copied writer will not be usable more. - DigraphWriter(DigraphWriter& other) - : _os(other._os), local_os(other.local_os), _digraph(other._digraph), - _skip_nodes(other._skip_nodes), _skip_arcs(other._skip_arcs) { - - other._os = 0; - other.local_os = false; - - _node_index.swap(other._node_index); - _arc_index.swap(other._arc_index); - - _node_maps.swap(other._node_maps); - _arc_maps.swap(other._arc_maps); - _attributes.swap(other._attributes); - - _nodes_caption = other._nodes_caption; - _arcs_caption = other._arcs_caption; - _attributes_caption = other._attributes_caption; - } - /// \brief Destructor ~DigraphWriter() { for (typename NodeMaps::iterator it = _node_maps.begin(); @@ -460,6 +452,32 @@ } private: + + friend DigraphWriter digraphWriter<>(std::ostream& os, + const Digraph& digraph); + friend DigraphWriter digraphWriter<>(const std::string& fn, + const Digraph& digraph); + friend DigraphWriter digraphWriter<>(const char *fn, + const Digraph& digraph); + + DigraphWriter(DigraphWriter& other) + : _os(other._os), local_os(other.local_os), _digraph(other._digraph), + _skip_nodes(other._skip_nodes), _skip_arcs(other._skip_arcs) { + + other._os = 0; + other.local_os = false; + + _node_index.swap(other._node_index); + _arc_index.swap(other._arc_index); + + _node_maps.swap(other._node_maps); + _arc_maps.swap(other._arc_maps); + _attributes.swap(other._attributes); + + _nodes_caption = other._nodes_caption; + _arcs_caption = other._arcs_caption; + _attributes_caption = other._attributes_caption; + } DigraphWriter& operator=(const DigraphWriter&); @@ -844,7 +862,8 @@ /// \relates DigraphWriter template - DigraphWriter digraphWriter(std::ostream& os, Digraph& digraph) { + DigraphWriter digraphWriter(std::ostream& os, + const Digraph& digraph) { DigraphWriter tmp(os, digraph); return tmp; } @@ -852,18 +871,31 @@ /// \relates DigraphWriter template DigraphWriter digraphWriter(const std::string& fn, - Digraph& digraph) { + const Digraph& digraph) { DigraphWriter tmp(fn, digraph); return tmp; } /// \relates DigraphWriter template - DigraphWriter digraphWriter(const char* fn, Digraph& digraph) { + DigraphWriter digraphWriter(const char* fn, + const Digraph& digraph) { DigraphWriter tmp(fn, digraph); return tmp; } + template + class GraphWriter; + + template + GraphWriter graphWriter(std::ostream& os, const Graph& graph); + + template + GraphWriter graphWriter(const std::string& fn, const Graph& graph); + + template + GraphWriter graphWriter(const char *fn, const Graph& graph); + /// \ingroup lemon_io /// /// \brief LGF writer for directed graphs @@ -914,7 +946,7 @@ /// /// Construct a directed graph writer, which writes to the given /// output stream. - GraphWriter(std::ostream& is, Graph& graph) + GraphWriter(std::ostream& is, const Graph& graph) : _os(&is), local_os(false), _graph(graph), _skip_nodes(false), _skip_edges(false) {} @@ -922,7 +954,7 @@ /// /// Construct a directed graph writer, which writes to the given /// output file. - GraphWriter(const std::string& fn, Graph& graph) + GraphWriter(const std::string& fn, const Graph& graph) : _os(new std::ofstream(fn.c_str())), local_os(true), _graph(graph), _skip_nodes(false), _skip_edges(false) {} @@ -930,33 +962,10 @@ /// /// Construct a directed graph writer, which writes to the given /// output file. - GraphWriter(const char* fn, Graph& graph) + GraphWriter(const char* fn, const Graph& graph) : _os(new std::ofstream(fn)), local_os(true), _graph(graph), _skip_nodes(false), _skip_edges(false) {} - /// \brief Copy constructor - /// - /// The copy constructor transfers all data from the other writer, - /// therefore the copied writer will not be usable more. - GraphWriter(GraphWriter& other) - : _os(other._os), local_os(other.local_os), _graph(other._graph), - _skip_nodes(other._skip_nodes), _skip_edges(other._skip_edges) { - - other._os = 0; - other.local_os = false; - - _node_index.swap(other._node_index); - _edge_index.swap(other._edge_index); - - _node_maps.swap(other._node_maps); - _edge_maps.swap(other._edge_maps); - _attributes.swap(other._attributes); - - _nodes_caption = other._nodes_caption; - _edges_caption = other._edges_caption; - _attributes_caption = other._attributes_caption; - } - /// \brief Destructor ~GraphWriter() { for (typename NodeMaps::iterator it = _node_maps.begin(); @@ -978,9 +987,35 @@ delete _os; } } + + private: - private: - + friend GraphWriter graphWriter<>(std::ostream& os, + const Graph& graph); + friend GraphWriter graphWriter<>(const std::string& fn, + const Graph& graph); + friend GraphWriter graphWriter<>(const char *fn, + const Graph& graph); + + GraphWriter(GraphWriter& other) + : _os(other._os), local_os(other.local_os), _graph(other._graph), + _skip_nodes(other._skip_nodes), _skip_edges(other._skip_edges) { + + other._os = 0; + other.local_os = false; + + _node_index.swap(other._node_index); + _edge_index.swap(other._edge_index); + + _node_maps.swap(other._node_maps); + _edge_maps.swap(other._edge_maps); + _attributes.swap(other._attributes); + + _nodes_caption = other._nodes_caption; + _edges_caption = other._edges_caption; + _attributes_caption = other._attributes_caption; + } + GraphWriter& operator=(const GraphWriter&); public: @@ -1410,21 +1445,21 @@ /// \relates GraphWriter template - GraphWriter graphWriter(std::ostream& os, Graph& graph) { + GraphWriter graphWriter(std::ostream& os, const Graph& graph) { GraphWriter tmp(os, graph); return tmp; } /// \relates GraphWriter template - GraphWriter graphWriter(const std::string& fn, Graph& graph) { + GraphWriter graphWriter(const std::string& fn, const Graph& graph) { GraphWriter tmp(fn, graph); return tmp; } /// \relates GraphWriter template - GraphWriter graphWriter(const char* fn, Graph& graph) { + GraphWriter graphWriter(const char* fn, const Graph& graph) { GraphWriter tmp(fn, graph); return tmp; }