COIN-OR::LEMON - Graph Library

Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • lemon/path.h

    r1270 r1336  
    3131#include <lemon/core.h>
    3232#include <lemon/concepts/path.h>
     33#include <lemon/bits/stl_iterators.h>
    3334
    3435namespace lemon {
     
    140141      int idx;
    141142    };
     143
     144    /// \brief Gets the collection of the arcs of the path.
     145    ///
     146    /// This function can be used for iterating on the
     147    /// arcs of the path. It returns a wrapped
     148    /// ArcIt, which looks like an STL container
     149    /// (by having begin() and end()) which you can use in range-based
     150    /// for loops, STL algorithms, etc.
     151    /// For example you can write:
     152    ///\code
     153    /// for(auto a: p.arcs())
     154    ///   doSomething(a);
     155    ///\endcode
     156    LemonRangeWrapper1<ArcIt, Path> arcs() const {
     157      return LemonRangeWrapper1<ArcIt, Path>(*this);
     158    }
     159
    142160
    143161    /// \brief Length of the path.
     
    346364    };
    347365
     366    /// \brief Gets the collection of the arcs of the path.
     367    ///
     368    /// This function can be used for iterating on the
     369    /// arcs of the path. It returns a wrapped
     370    /// ArcIt, which looks like an STL container
     371    /// (by having begin() and end()) which you can use in range-based
     372    /// for loops, STL algorithms, etc.
     373    /// For example you can write:
     374    ///\code
     375    /// for(auto a: p.arcs())
     376    ///   doSomething(a);
     377    ///\endcode
     378    LemonRangeWrapper1<ArcIt, SimplePath> arcs() const {
     379      return LemonRangeWrapper1<ArcIt, SimplePath>(*this);
     380    }
     381
     382
    348383    /// \brief Length of the path.
    349384    int length() const { return data.size(); }
     
    543578      Node *node;
    544579    };
     580
     581    /// \brief Gets the collection of the arcs of the path.
     582    ///
     583    /// This function can be used for iterating on the
     584    /// arcs of the path. It returns a wrapped
     585    /// ArcIt, which looks like an STL container
     586    /// (by having begin() and end()) which you can use in range-based
     587    /// for loops, STL algorithms, etc.
     588    /// For example you can write:
     589    ///\code
     590    /// for(auto a: p.arcs())
     591    ///   doSomething(a);
     592    ///\endcode
     593    LemonRangeWrapper1<ArcIt, ListPath> arcs() const {
     594      return LemonRangeWrapper1<ArcIt, ListPath>(*this);
     595    }
     596
    545597
    546598    /// \brief The n-th arc.
     
    796848    ///
    797849    /// Default constructor
    798     StaticPath() : len(0), arcs(0) {}
     850    StaticPath() : len(0), _arcs(0) {}
    799851
    800852    /// \brief Copy constructor
    801853    ///
    802     StaticPath(const StaticPath& cpath) : arcs(0) {
     854    StaticPath(const StaticPath& cpath) : _arcs(0) {
    803855      pathCopy(cpath, *this);
    804856    }
     
    808860    /// This path can be initialized from any other path type.
    809861    template <typename CPath>
    810     StaticPath(const CPath& cpath) : arcs(0) {
     862    StaticPath(const CPath& cpath) : _arcs(0) {
    811863      pathCopy(cpath, *this);
    812864    }
     
    816868    /// Destructor of the path
    817869    ~StaticPath() {
    818       if (arcs) delete[] arcs;
     870      if (_arcs) delete[] _arcs;
    819871    }
    820872
     
    883935      int idx;
    884936    };
     937   
     938    /// \brief Gets the collection of the arcs of the path.
     939    ///
     940    /// This function can be used for iterating on the
     941    /// arcs of the path. It returns a wrapped
     942    /// ArcIt, which looks like an STL container
     943    /// (by having begin() and end()) which you can use in range-based
     944    /// for loops, STL algorithms, etc.
     945    /// For example you can write:
     946    ///\code
     947    /// for(auto a: p.arcs())
     948    ///   doSomething(a);
     949    ///\endcode
     950    LemonRangeWrapper1<ArcIt, StaticPath> arcs() const {
     951      return LemonRangeWrapper1<ArcIt, StaticPath>(*this);
     952    }
     953   
    885954
    886955    /// \brief The n-th arc.
     
    888957    /// \pre \c n is in the <tt>[0..length() - 1]</tt> range.
    889958    const Arc& nth(int n) const {
    890       return arcs[n];
     959      return _arcs[n];
    891960    }
    892961
     
    905974    void clear() {
    906975      len = 0;
    907       if (arcs) delete[] arcs;
    908       arcs = 0;
     976      if (_arcs) delete[] _arcs;
     977      _arcs = 0;
    909978    }
    910979
    911980    /// \brief The first arc of the path.
    912981    const Arc& front() const {
    913       return arcs[0];
     982      return _arcs[0];
    914983    }
    915984
    916985    /// \brief The last arc of the path.
    917986    const Arc& back() const {
    918       return arcs[len - 1];
     987      return _arcs[len - 1];
    919988    }
    920989
     
    925994    void build(const CPath& path) {
    926995      len = path.length();
    927       arcs = new Arc[len];
     996      _arcs = new Arc[len];
    928997      int index = 0;
    929998      for (typename CPath::ArcIt it(path); it != INVALID; ++it) {
    930         arcs[index] = it;
     999        _arcs[index] = it;
    9311000        ++index;
    9321001      }
     
    9361005    void buildRev(const CPath& path) {
    9371006      len = path.length();
    938       arcs = new Arc[len];
     1007      _arcs = new Arc[len];
    9391008      int index = len;
    9401009      for (typename CPath::RevArcIt it(path); it != INVALID; ++it) {
    9411010        --index;
    942         arcs[index] = it;
     1011        _arcs[index] = it;
    9431012      }
    9441013    }
     
    9461015  private:
    9471016    int len;
    948     Arc* arcs;
     1017    Arc* _arcs;
    9491018  };
    9501019
     
    11581227  };
    11591228
     1229  /// \brief Gets the collection of the nodes of the path.
     1230  ///
     1231  /// This function can be used for iterating on the
     1232  /// nodes of the path. It returns a wrapped
     1233  /// PathNodeIt, which looks like an STL container
     1234  /// (by having begin() and end()) which you can use in range-based
     1235  /// for loops, STL algorithms, etc.
     1236  /// For example you can write:
     1237  ///\code
     1238  /// for(auto u: pathNodes(g,p))
     1239  ///   doSomething(u);
     1240  ///\endcode
     1241  template<typename Path>
     1242  LemonRangeWrapper2<PathNodeIt<Path>, typename Path::Digraph, Path>
     1243      pathNodes(const typename Path::Digraph &g, const Path &p) {
     1244    return
     1245        LemonRangeWrapper2<PathNodeIt<Path>, typename Path::Digraph, Path>(g,p);
     1246  }
     1247
    11601248  ///@}
    11611249
Note: See TracChangeset for help on using the changeset viewer.