diff --git a/lemon/path.h b/lemon/path.h --- a/lemon/path.h +++ b/lemon/path.h @@ -70,7 +70,7 @@ /// It simply makes a copy of the given path. template Path(const CPath& cpath) { - copyPath(*this, cpath); + pathCopy(cpath, *this); } /// \brief Template copy assignment @@ -78,7 +78,7 @@ /// This operator makes a copy of a path of any other type. template Path& operator=(const CPath& cpath) { - copyPath(*this, cpath); + pathCopy(cpath, *this); return *this; } @@ -258,7 +258,7 @@ /// makes a copy of the given path. template SimplePath(const CPath& cpath) { - copyPath(*this, cpath); + pathCopy(cpath, *this); } /// \brief Template copy assignment @@ -267,7 +267,7 @@ /// makes a copy of the given path. template SimplePath& operator=(const CPath& cpath) { - copyPath(*this, cpath); + pathCopy(cpath, *this); return *this; } @@ -437,7 +437,7 @@ /// makes a copy of the given path. template ListPath(const CPath& cpath) : first(0), last(0) { - copyPath(*this, cpath); + pathCopy(cpath, *this); } /// \brief Destructor of the path @@ -453,7 +453,7 @@ /// makes a copy of the given path. template ListPath& operator=(const CPath& cpath) { - copyPath(*this, cpath); + pathCopy(cpath, *this); return *this; } @@ -763,7 +763,7 @@ /// This path can be initialized from any other path type. template StaticPath(const CPath& cpath) : arcs(0) { - copyPath(*this, cpath); + pathCopy(cpath, *this); } /// \brief Destructor of the path @@ -779,7 +779,7 @@ /// makes a copy of the given path. template StaticPath& operator=(const CPath& cpath) { - copyPath(*this, cpath); + pathCopy(cpath, *this); return *this; } @@ -928,57 +928,57 @@ static const bool value = true; }; - template ::value> + template ::value> struct PathCopySelectorForward { - static void copy(Target& target, const Source& source) { - target.clear(); - for (typename Source::ArcIt it(source); it != INVALID; ++it) { - target.addBack(it); + static void copy(const From& from, To& to) { + to.clear(); + for (typename From::ArcIt it(from); it != INVALID; ++it) { + to.addBack(it); } } }; - template - struct PathCopySelectorForward { - static void copy(Target& target, const Source& source) { - target.clear(); - target.build(source); + template + struct PathCopySelectorForward { + static void copy(const From& from, To& to) { + to.clear(); + to.build(from); } }; - template ::value> + template ::value> struct PathCopySelectorBackward { - static void copy(Target& target, const Source& source) { - target.clear(); - for (typename Source::RevArcIt it(source); it != INVALID; ++it) { - target.addFront(it); + static void copy(const From& from, To& to) { + to.clear(); + for (typename From::RevArcIt it(from); it != INVALID; ++it) { + to.addFront(it); } } }; - template - struct PathCopySelectorBackward { - static void copy(Target& target, const Source& source) { - target.clear(); - target.buildRev(source); + template + struct PathCopySelectorBackward { + static void copy(const From& from, To& to) { + to.clear(); + to.buildRev(from); } }; - template ::value> + template ::value> struct PathCopySelector { - static void copy(Target& target, const Source& source) { - PathCopySelectorForward::copy(target, source); + static void copy(const From& from, To& to) { + PathCopySelectorForward::copy(from, to); } }; - template - struct PathCopySelector { - static void copy(Target& target, const Source& source) { - PathCopySelectorBackward::copy(target, source); + template + struct PathCopySelector { + static void copy(const From& from, To& to) { + PathCopySelectorBackward::copy(from, to); } }; @@ -987,11 +987,19 @@ /// \brief Make a copy of a path. /// - /// This function makes a copy of a path. - template - void copyPath(Target& target, const Source& source) { - checkConcept, Source>(); - _path_bits::PathCopySelector::copy(target, source); + /// This function makes a copy of a path. + template + void pathCopy(const From& from, To& to) { + checkConcept, From>(); + _path_bits::PathCopySelector::copy(from, to); + } + + /// \brief Deprecated version of \ref pathCopy(). + /// + /// Deprecated version of \ref pathCopy() (only for reverse compatibility). + template + void copyPath(To& to, const From& from) { + pathCopy(from, to); } /// \brief Check the consistency of a path. @@ -1015,18 +1023,20 @@ /// \brief The source of a path /// - /// This function returns the source of the given path. + /// This function returns the source node of the given path. + /// If the path is empty, then it returns \c INVALID. template typename Digraph::Node pathSource(const Digraph& digraph, const Path& path) { - return digraph.source(path.front()); + return path.empty() ? INVALID : digraph.source(path.front()); } /// \brief The target of a path /// - /// This function returns the target of the given path. + /// This function returns the target node of the given path. + /// If the path is empty, then it returns \c INVALID. template typename Digraph::Node pathTarget(const Digraph& digraph, const Path& path) { - return digraph.target(path.back()); + return path.empty() ? INVALID : digraph.target(path.back()); } /// \brief Class which helps to iterate through the nodes of a path