Merge bugfix #444
authorAlpar Juttner <alpar@cs.elte.hu>
Fri, 22 Jun 2012 16:42:05 +0200
changeset 991a10624ed1997
parent 989 38e1d4383262
parent 990 7440937d154b
child 992 78434a448b5e
Merge bugfix #444
lemon/path.h
     1.1 --- a/lemon/path.h	Sun May 06 17:18:39 2012 +0200
     1.2 +++ b/lemon/path.h	Fri Jun 22 16:42:05 2012 +0200
     1.3 @@ -64,6 +64,12 @@
     1.4      /// Default constructor
     1.5      Path() {}
     1.6  
     1.7 +    /// \brief Copy constructor
     1.8 +    ///
     1.9 +    Path(const Path& cpath) {
    1.10 +      pathCopy(cpath, *this);
    1.11 +    }
    1.12 +
    1.13      /// \brief Template copy constructor
    1.14      ///
    1.15      /// This constuctor initializes the path from any other path type.
    1.16 @@ -73,6 +79,13 @@
    1.17        pathCopy(cpath, *this);
    1.18      }
    1.19  
    1.20 +    /// \brief Copy assignment
    1.21 +    ///
    1.22 +    Path& operator=(const Path& cpath) {
    1.23 +      pathCopy(cpath, *this);
    1.24 +      return *this;
    1.25 +    }
    1.26 +
    1.27      /// \brief Template copy assignment
    1.28      ///
    1.29      /// This operator makes a copy of a path of any other type.
    1.30 @@ -252,6 +265,12 @@
    1.31      /// Default constructor
    1.32      SimplePath() {}
    1.33  
    1.34 +    /// \brief Copy constructor
    1.35 +    ///
    1.36 +    SimplePath(const SimplePath& cpath) {
    1.37 +      pathCopy(cpath, *this);
    1.38 +    }
    1.39 +
    1.40      /// \brief Template copy constructor
    1.41      ///
    1.42      /// This path can be initialized with any other path type. It just
    1.43 @@ -261,6 +280,13 @@
    1.44        pathCopy(cpath, *this);
    1.45      }
    1.46  
    1.47 +    /// \brief Copy assignment
    1.48 +    ///
    1.49 +    SimplePath& operator=(const SimplePath& cpath) {
    1.50 +      pathCopy(cpath, *this);
    1.51 +      return *this;
    1.52 +    }
    1.53 +
    1.54      /// \brief Template copy assignment
    1.55      ///
    1.56      /// This path can be initialized with any other path type. It just
    1.57 @@ -431,6 +457,12 @@
    1.58      /// Default constructor
    1.59      ListPath() : first(0), last(0) {}
    1.60  
    1.61 +    /// \brief Copy constructor
    1.62 +    ///
    1.63 +    ListPath(const ListPath& cpath) : first(0), last(0) {
    1.64 +      pathCopy(cpath, *this);
    1.65 +    }
    1.66 +
    1.67      /// \brief Template copy constructor
    1.68      ///
    1.69      /// This path can be initialized with any other path type. It just
    1.70 @@ -447,6 +479,13 @@
    1.71        clear();
    1.72      }
    1.73  
    1.74 +    /// \brief Copy assignment
    1.75 +    ///
    1.76 +    ListPath& operator=(const ListPath& cpath) {
    1.77 +      pathCopy(cpath, *this);
    1.78 +      return *this;
    1.79 +    }
    1.80 +
    1.81      /// \brief Template copy assignment
    1.82      ///
    1.83      /// This path can be initialized with any other path type. It just
    1.84 @@ -758,6 +797,12 @@
    1.85      /// Default constructor
    1.86      StaticPath() : len(0), arcs(0) {}
    1.87  
    1.88 +    /// \brief Copy constructor
    1.89 +    ///
    1.90 +    StaticPath(const StaticPath& cpath) : arcs(0) {
    1.91 +      pathCopy(cpath, *this);
    1.92 +    }
    1.93 +
    1.94      /// \brief Template copy constructor
    1.95      ///
    1.96      /// This path can be initialized from any other path type.
    1.97 @@ -773,6 +818,13 @@
    1.98        if (arcs) delete[] arcs;
    1.99      }
   1.100  
   1.101 +    /// \brief Copy assignment
   1.102 +    ///
   1.103 +    StaticPath& operator=(const StaticPath& cpath) {
   1.104 +      pathCopy(cpath, *this);
   1.105 +      return *this;
   1.106 +    }
   1.107 +
   1.108      /// \brief Template copy assignment
   1.109      ///
   1.110      /// This path can be made equal to any other path type. It simply
     2.1 --- a/test/path_test.cc	Sun May 06 17:18:39 2012 +0200
     2.2 +++ b/test/path_test.cc	Fri Jun 22 16:42:05 2012 +0200
     2.3 @@ -38,7 +38,36 @@
     2.4    checkConcept<concepts::Path<ListDigraph>, ListPath<ListDigraph> >();
     2.5  }
     2.6  
     2.7 +// Check if proper copy consructor is called (use valgrind for testing)
     2.8 +template<class _Path>
     2.9 +void checkCopy()
    2.10 +{
    2.11 +  ListDigraph g;
    2.12 +  ListDigraph::Arc a  = g.addArc(g.addNode(), g.addNode());
    2.13 +  
    2.14 +  _Path p,q;
    2.15 +  p.addBack(a);
    2.16 +  q=p;
    2.17 +  _Path r(p);
    2.18 +  StaticPath<ListDigraph> s(r);
    2.19 +}
    2.20 +  
    2.21  int main() {
    2.22    check_concepts();
    2.23 +
    2.24 +  checkCopy<Path<ListDigraph> >();
    2.25 +  checkCopy<SimplePath<ListDigraph> >();
    2.26 +  checkCopy<ListPath<ListDigraph> >();
    2.27 +
    2.28 +  ListDigraph g;
    2.29 +  ListDigraph::Arc a  = g.addArc(g.addNode(), g.addNode());
    2.30 +  
    2.31 +  Path<ListDigraph> p;
    2.32 +  StaticPath<ListDigraph> q,r;
    2.33 +  p.addBack(a);
    2.34 +  q=p;
    2.35 +  r=q;
    2.36 +  StaticPath<ListDigraph> s(q);
    2.37 +
    2.38    return 0;
    2.39  }