COIN-OR::LEMON - Graph Library

Changeset 1144:7440937d154b in lemon


Ignore:
Timestamp:
06/22/12 16:25:56 (12 years ago)
Author:
Alpar Juttner <alpar@…>
Branch:
default
Children:
1145:98b306776b25, 1146:a5810903ed28, 1147:a10624ed1997, 1149:157427808b40
Phase:
public
Message:

Bugfix in path copy constructors and assignment operators (#444)

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • lemon/path.h

    r867 r1144  
    6565    Path() {}
    6666
     67    /// \brief Copy constructor
     68    ///
     69    Path(const Path& cpath) {
     70      pathCopy(cpath, *this);
     71    }
     72
    6773    /// \brief Template copy constructor
    6874    ///
     
    7278    Path(const CPath& cpath) {
    7379      pathCopy(cpath, *this);
     80    }
     81
     82    /// \brief Copy assignment
     83    ///
     84    Path& operator=(const Path& cpath) {
     85      pathCopy(cpath, *this);
     86      return *this;
    7487    }
    7588
     
    253266    SimplePath() {}
    254267
     268    /// \brief Copy constructor
     269    ///
     270    SimplePath(const SimplePath& cpath) {
     271      pathCopy(cpath, *this);
     272    }
     273
    255274    /// \brief Template copy constructor
    256275    ///
     
    260279    SimplePath(const CPath& cpath) {
    261280      pathCopy(cpath, *this);
     281    }
     282
     283    /// \brief Copy assignment
     284    ///
     285    SimplePath& operator=(const SimplePath& cpath) {
     286      pathCopy(cpath, *this);
     287      return *this;
    262288    }
    263289
     
    432458    ListPath() : first(0), last(0) {}
    433459
     460    /// \brief Copy constructor
     461    ///
     462    ListPath(const ListPath& cpath) : first(0), last(0) {
     463      pathCopy(cpath, *this);
     464    }
     465
    434466    /// \brief Template copy constructor
    435467    ///
     
    446478    ~ListPath() {
    447479      clear();
     480    }
     481
     482    /// \brief Copy assignment
     483    ///
     484    ListPath& operator=(const ListPath& cpath) {
     485      pathCopy(cpath, *this);
     486      return *this;
    448487    }
    449488
     
    759798    StaticPath() : len(0), arcs(0) {}
    760799
     800    /// \brief Copy constructor
     801    ///
     802    StaticPath(const StaticPath& cpath) : arcs(0) {
     803      pathCopy(cpath, *this);
     804    }
     805
    761806    /// \brief Template copy constructor
    762807    ///
     
    772817    ~StaticPath() {
    773818      if (arcs) delete[] arcs;
     819    }
     820
     821    /// \brief Copy assignment
     822    ///
     823    StaticPath& operator=(const StaticPath& cpath) {
     824      pathCopy(cpath, *this);
     825      return *this;
    774826    }
    775827
  • test/path_test.cc

    r463 r1144  
    3939}
    4040
     41// Check if proper copy consructor is called (use valgrind for testing)
     42template<class _Path>
     43void checkCopy()
     44{
     45  ListDigraph g;
     46  ListDigraph::Arc a  = g.addArc(g.addNode(), g.addNode());
     47 
     48  _Path p,q;
     49  p.addBack(a);
     50  q=p;
     51  _Path r(p);
     52  StaticPath<ListDigraph> s(r);
     53}
     54 
    4155int main() {
    4256  check_concepts();
     57
     58  checkCopy<Path<ListDigraph> >();
     59  checkCopy<SimplePath<ListDigraph> >();
     60  checkCopy<ListPath<ListDigraph> >();
     61
     62  ListDigraph g;
     63  ListDigraph::Arc a  = g.addArc(g.addNode(), g.addNode());
     64 
     65  Path<ListDigraph> p;
     66  StaticPath<ListDigraph> q,r;
     67  p.addBack(a);
     68  q=p;
     69  r=q;
     70  StaticPath<ListDigraph> s(q);
     71
    4372  return 0;
    4473}
Note: See TracChangeset for help on using the changeset viewer.