[Lemon-commits] Alpar Juttner: Merge bugfix #444 to branch 1.1
Lemon HG
hg at lemon.cs.elte.hu
Fri Jun 22 16:45:20 CEST 2012
details: http://lemon.cs.elte.hu/hg/lemon/rev/98b306776b25
changeset: 1145:98b306776b25
user: Alpar Juttner <alpar [at] cs.elte.hu>
date: Fri Jun 22 16:31:05 2012 +0200
description:
Merge bugfix #444 to branch 1.1
diffstat:
lemon/path.h | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
test/path_test.cc | 29 +++++++++++++++++++++++++++++
2 files changed, 81 insertions(+), 0 deletions(-)
diffs (151 lines):
diff --git a/lemon/path.h b/lemon/path.h
--- a/lemon/path.h
+++ b/lemon/path.h
@@ -64,6 +64,12 @@
/// Default constructor
Path() {}
+ /// \brief Copy constructor
+ ///
+ Path(const Path& cpath) {
+ pathCopy(cpath, *this);
+ }
+
/// \brief Template copy constructor
///
/// This constuctor initializes the path from any other path type.
@@ -73,6 +79,13 @@
pathCopy(cpath, *this);
}
+ /// \brief Copy assignment
+ ///
+ Path& operator=(const Path& cpath) {
+ pathCopy(cpath, *this);
+ return *this;
+ }
+
/// \brief Template copy assignment
///
/// This operator makes a copy of a path of any other type.
@@ -252,6 +265,12 @@
/// Default constructor
SimplePath() {}
+ /// \brief Copy constructor
+ ///
+ SimplePath(const SimplePath& cpath) {
+ pathCopy(cpath, *this);
+ }
+
/// \brief Template copy constructor
///
/// This path can be initialized with any other path type. It just
@@ -261,6 +280,13 @@
pathCopy(cpath, *this);
}
+ /// \brief Copy assignment
+ ///
+ SimplePath& operator=(const SimplePath& cpath) {
+ pathCopy(cpath, *this);
+ return *this;
+ }
+
/// \brief Template copy assignment
///
/// This path can be initialized with any other path type. It just
@@ -431,6 +457,12 @@
/// Default constructor
ListPath() : first(0), last(0) {}
+ /// \brief Copy constructor
+ ///
+ ListPath(const ListPath& cpath) : first(0), last(0) {
+ pathCopy(cpath, *this);
+ }
+
/// \brief Template copy constructor
///
/// This path can be initialized with any other path type. It just
@@ -447,6 +479,13 @@
clear();
}
+ /// \brief Copy assignment
+ ///
+ ListPath& operator=(const ListPath& cpath) {
+ pathCopy(cpath, *this);
+ return *this;
+ }
+
/// \brief Template copy assignment
///
/// This path can be initialized with any other path type. It just
@@ -758,6 +797,12 @@
/// Default constructor
StaticPath() : len(0), arcs(0) {}
+ /// \brief Copy constructor
+ ///
+ StaticPath(const StaticPath& cpath) : arcs(0) {
+ pathCopy(cpath, *this);
+ }
+
/// \brief Template copy constructor
///
/// This path can be initialized from any other path type.
@@ -773,6 +818,13 @@
if (arcs) delete[] arcs;
}
+ /// \brief Copy assignment
+ ///
+ StaticPath& operator=(const StaticPath& cpath) {
+ pathCopy(cpath, *this);
+ return *this;
+ }
+
/// \brief Template copy assignment
///
/// This path can be made equal to any other path type. It simply
diff --git a/test/path_test.cc b/test/path_test.cc
--- a/test/path_test.cc
+++ b/test/path_test.cc
@@ -38,7 +38,36 @@
checkConcept<concepts::Path<ListDigraph>, ListPath<ListDigraph> >();
}
+// Check if proper copy consructor is called (use valgrind for testing)
+template<class _Path>
+void checkCopy()
+{
+ ListDigraph g;
+ ListDigraph::Arc a = g.addArc(g.addNode(), g.addNode());
+
+ _Path p,q;
+ p.addBack(a);
+ q=p;
+ _Path r(p);
+ StaticPath<ListDigraph> s(r);
+}
+
int main() {
check_concepts();
+
+ checkCopy<Path<ListDigraph> >();
+ checkCopy<SimplePath<ListDigraph> >();
+ checkCopy<ListPath<ListDigraph> >();
+
+ ListDigraph g;
+ ListDigraph::Arc a = g.addArc(g.addNode(), g.addNode());
+
+ Path<ListDigraph> p;
+ StaticPath<ListDigraph> q,r;
+ p.addBack(a);
+ q=p;
+ r=q;
+ StaticPath<ListDigraph> s(q);
+
return 0;
}
More information about the Lemon-commits
mailing list