COIN-OR::LEMON - Graph Library

Ticket #325: stl-iterators-adaptors-72900babc6c2.patch

File stl-iterators-adaptors-72900babc6c2.patch, 3.9 KB (added by Gábor Gévay, 6 years ago)
  • contrib/stlit_test/stlit_test.cc

    # HG changeset patch
    # User Gabor Gevay <ggab90@gmail.com>
    # Date 1428763765 -7200
    #      Sat Apr 11 16:49:25 2015 +0200
    # Node ID 72900babc6c2f320c386d3bcb5d9c1d34521cdc6
    # Parent  d9521d1a0c08a1ba16af15be9307300c6a9693cc
    STL style iterators for the adaptors.
    
    diff -r d9521d1a0c08 -r 72900babc6c2 contrib/stlit_test/stlit_test.cc
    a b  
    1414#include <lemon/maps.h>
    1515//#include <lemon/matching.h>
    1616#include <lemon/glpk.h>
     17#include <lemon/adaptors.h>
    1718
    1819
    1920using namespace std;
     
    6970  for(auto u: g.nodes())
    7071    cout<<g.id(u)<<endl;
    7172
     73
    7274  /*//Test postincrement
    7375  for(auto it=g.nodes().begin(); it!=g.nodes().end(); it++) {
    7476    auto u=*it;
     
    9092
    9193  cout<<endl;
    9294
     95  ReverseDigraph<ListDigraph> gr(g);
     96  for(auto u: gr.nodes()) {
     97    //cout<<":"<<g.id(u)<<endl;
     98    for(auto v: gr.outArcs(u))
     99      cout<<g.id(u)<<":"<<g.id(v)<<endl;
     100  }
     101  cout<<endl;
     102
     103  Undirector<ListDigraph> gu(g);
     104  for(auto u: gu.nodes()) {
     105    //cout<<":"<<g.id(u)<<endl;
     106    for(auto v: gu.incEdges(u))
     107      cout<<g.id(u)<<"::"<<g.id(v)<<endl;
     108  }
     109  cout<<endl;
     110
    93111
    94112  LemonItWrapper<ListDigraph::NodeIt> st1 = g.nodes().begin();
    95113  //auto st1 = g.nodes().begin();
  • lemon/bits/graph_adaptor_extender.h

    diff -r d9521d1a0c08 -r 72900babc6c2 lemon/bits/graph_adaptor_extender.h
    a b  
    8585
    8686    };
    8787
     88    LemonRangeWrapper1<NodeIt, Adaptor> nodes() {
     89      return LemonRangeWrapper1<NodeIt, Adaptor>(*this);
     90    }
    8891
    8992    class ArcIt : public Arc {
    9093      const Adaptor* _adaptor;
     
    108111
    109112    };
    110113
     114    LemonRangeWrapper1<ArcIt, Adaptor> arcs() {
     115      return LemonRangeWrapper1<ArcIt, Adaptor>(*this);
     116    }
     117
    111118
    112119    class OutArcIt : public Arc {
    113120      const Adaptor* _adaptor;
     
    132139
    133140    };
    134141
     142    LemonRangeWrapper2<OutArcIt, Adaptor, Node> outArcs(const Node& u) const {
     143      return LemonRangeWrapper2<OutArcIt, Adaptor, Node>(*this, u);
     144    }
     145
    135146
    136147    class InArcIt : public Arc {
    137148      const Adaptor* _adaptor;
     
    156167
    157168    };
    158169
     170    LemonRangeWrapper2<InArcIt, Adaptor, Node> inArcs(const Node& u) const {
     171      return LemonRangeWrapper2<InArcIt, Adaptor, Node>(*this, u);
     172    }
     173
    159174    Node baseNode(const OutArcIt &e) const {
    160175      return Parent::source(e);
    161176    }
     
    254269
    255270    };
    256271
     272    LemonRangeWrapper1<NodeIt, Adaptor> nodes() {
     273      return LemonRangeWrapper1<NodeIt, Adaptor>(*this);
     274    }
     275
    257276
    258277    class ArcIt : public Arc {
    259278      const Adaptor* _adaptor;
     
    277296
    278297    };
    279298
     299    LemonRangeWrapper1<ArcIt, Adaptor> arcs() {
     300      return LemonRangeWrapper1<ArcIt, Adaptor>(*this);
     301    }
     302
    280303
    281304    class OutArcIt : public Arc {
    282305      const Adaptor* _adaptor;
     
    301324
    302325    };
    303326
     327    LemonRangeWrapper2<OutArcIt, Adaptor, Node> outArcs(const Node& u) const {
     328      return LemonRangeWrapper2<OutArcIt, Adaptor, Node>(*this, u);
     329    }
     330
    304331
    305332    class InArcIt : public Arc {
    306333      const Adaptor* _adaptor;
     
    325352
    326353    };
    327354
     355    LemonRangeWrapper2<InArcIt, Adaptor, Node> inArcs(const Node& u) const {
     356      return LemonRangeWrapper2<InArcIt, Adaptor, Node>(*this, u);
     357    }
     358
    328359    class EdgeIt : public Parent::Edge {
    329360      const Adaptor* _adaptor;
    330361    public:
     
    347378
    348379    };
    349380
     381    LemonRangeWrapper1<EdgeIt, Adaptor> edges() {
     382      return LemonRangeWrapper1<EdgeIt, Adaptor>(*this);
     383    }
     384
     385
    350386    class IncEdgeIt : public Edge {
    351387      friend class GraphAdaptorExtender;
    352388      const Adaptor* _adaptor;
     
    372408      }
    373409    };
    374410
     411    LemonRangeWrapper2<IncEdgeIt, Adaptor, Node> incEdges(const Node& u) const {
     412      return LemonRangeWrapper2<IncEdgeIt, Adaptor, Node>(*this, u);
     413    }
     414
     415
    375416    Node baseNode(const OutArcIt &a) const {
    376417      return Parent::source(a);
    377418    }