alpar@65: // -*-mode: c++; -*-
alpar@103: #ifndef GRAPH_WRAPPER_H
alpar@103: #define GRAPH_WRAPPER_H
alpar@103: 
alpar@921: namespace lemon {
alpar@65: 
alpar@65: template<typename G>
alpar@65: class TrivGraphWrapper
alpar@65: {
alpar@65:   G *graph;
alpar@65:   
alpar@65: public:
alpar@65:   typedef G BaseGraph;
alpar@65: 
alpar@65:   typedef typename G::EdgeIt EdgeIt;
alpar@65:   
alpar@65:   typedef typename G::InEdgeIt InEdgeIt;
alpar@65:   typedef typename G::OutEdgeIt OutEdgeIt;
alpar@65:   typedef typename G::SymEdgeIt SymEdgeIt;
alpar@65:   typedef typename G::EachEdgeIt EachEdgeIt;
alpar@65: 
alpar@65:   typedef typename G::NodeIt NodeIt;
alpar@65:     
alpar@65:   template<typename I> I &getFirst(I &i); { return graph->getFirst(i); }
alpar@65:   template<typename I,typename P> I &getFirst(I &i,const P &p);
alpar@65:   { return graph->getFirst(i,p); }
alpar@65:   template<typename I> I next(const I i); { return graph->goNext(i); }
alpar@65:   template<typename I> I &goNext(I &i); { return graph->goNext(i); }
alpar@65: 
alpar@986:   NodeIt target(const EdgeIt &e);
alpar@986:   { return graph->target(e); }
alpar@986:   NodeIt source(const EdgeIt &e);
alpar@986:   { return graph->source(e); }
alpar@65:   
alpar@65:   template<typename I> NodeIt aNode(const I e);
alpar@65:   { return graph->aNode(e); }
alpar@65:   template<typename I> NodeIt bNode(const I e);
alpar@65:   { return graph->bNode(e); }
alpar@65:   
alpar@65:   template<typename I> bool valid(const I i);
alpar@65:   { return graph->valid(i); }
alpar@65:   
alpar@65:   template<typename I> void setInvalid(const I &i);
alpar@65:   { return graph->setInvalid(i); }
alpar@65:   
alpar@65:   NodeIt addNode(); { return graph->addNode(); }
alpar@65:   EdgeIt addEdge(const NodeIt from,const NodeIt to);
alpar@65:   { return graph->addEdge(ftom,to); }
alpar@65:   
alpar@65:   template<I> void delete(I i); { graph->delete(i); }
alpar@65:   
alpar@65:   void clean();  { graph->clean(); }
alpar@65:   
alpar@65:   template<class T> class NodeMap : public typename G::NodeMap<T>;
alpar@65:   template<class T> class EdgeMap : public typename G::EdgeMap<T>;
alpar@65:   
alpar@65:   void SetG(G &g) {graph = &g;}
alpar@65:   
alpar@65:   TrivGraphWrapper() {graph = NULL;}
alpar@65:   TrivGraphWrapper(G &g) {graph = &g;}
alpar@65: };
alpar@65: 
alpar@65: template<typename G>
alpar@65: class RevGraphWrapper
alpar@65: {
alpar@65:   G *graph;
alpar@65:   
alpar@65: public:
alpar@65:   typedef G BaseGraph;
alpar@65: 
alpar@65:   typedef typename G::EdgeIt EdgeIt;
alpar@65:   
alpar@65:   typedef typename G::InEdgeIt OutEdgeIt;
alpar@65:   typedef typename G::OutEdgeIt InEdgeIt;
alpar@65:   typedef typename G::SymEdgeIt SymEdgeIt;
alpar@65:   typedef typename G::EachEdgeIt EachEdgeIt;
alpar@65: 
alpar@65:   typedef typename G::NodeIt NodeIt;
alpar@65:     
alpar@65:   template<typename I> I &getFirst(I &i); { return graph->getFirst(i); }
alpar@65:   template<typename I,typename P> I &getFirst(I &i,const P &p);
alpar@65:   { return graph->getFirst(i,p); }
alpar@65:   template<typename I> I next(const I i); { return graph->goNext(i); }
alpar@65:   template<typename I> I &goNext(I &i); { return graph->goNext(i); }
alpar@65: 
alpar@986:   NodeIt target(const EdgeIt &e);
alpar@986:   { return graph->source(e); }
alpar@986:   NodeIt source(const EdgeIt &e);
alpar@986:   { return graph->target(e); }
alpar@65:   
alpar@65:   template<typename I> NodeIt aNode(const I e);
alpar@65:   { return graph->aNode(e); }
alpar@65:   template<typename I> NodeIt bNode(const I e);
alpar@65:   { return graph->bNode(e); }
alpar@65:   
alpar@65:   template<typename I> bool valid(const I i);
alpar@65:   { return graph->valid(i); }
alpar@65:   
alpar@65:   template<typename I> void setInvalid(const I &i);
alpar@65:   { return graph->setInvalid(i); }
alpar@65:   
alpar@65:   NodeIt addNode(); { return graph->addNode(); }
alpar@65:   EdgeIt addEdge(const NodeIt from,const NodeIt to);
alpar@65:   { return graph->addEdge(to,from); }
alpar@65:   
alpar@65:   template<I> void delete(I i); { graph->delete(i); }
alpar@65:   
alpar@65:   void clean();  { graph->clean(); }
alpar@65:   
alpar@65:   template<class T> class NodeMap : public typename G::NodeMap<T>;
alpar@65:   template<class T> class EdgeMap : public typename G::EdgeMap<T>;
alpar@65:   
alpar@65:   void SetG(G &g) {graph = &g;}
alpar@65:   
alpar@65:   RevGraphWrapper() {graph = NULL;}
alpar@65:   RevGraphWrapper(G &g) {graph = &g;}
alpar@65: };
alpar@65: 
alpar@70: template<typename G>
alpar@145: class RevGraphExt : public G
alpar@145: {
alpar@145: public:
alpar@145:   //  typedef G BaseGraph;
alpar@145: 
alpar@145:   typedef typename G::EdgeIt EdgeIt;
alpar@145:   
alpar@145:   typedef typename G::InEdgeIt OutEdgeIt;
alpar@145:   typedef typename G::OutEdgeIt InEdgeIt;
alpar@145:   typedef typename G::SymEdgeIt SymEdgeIt;
alpar@145:   typedef typename G::EachEdgeIt EachEdgeIt;
alpar@145: 
alpar@145:   typedef typename G::NodeIt NodeIt;
alpar@145:     
alpar@145: //   template<typename I> I &getFirst(I &i); { return graph->getFirst(i); }
alpar@145: //   template<typename I,typename P> I &getFirst(I &i,const P &p);
alpar@145: //   { return graph->getFirst(i,p); }
alpar@145: //   template<typename I> I next(const I i); { return graph->goNext(i); }
alpar@145: //   template<typename I> I &goNext(I &i); { return graph->goNext(i); }
alpar@145: 
alpar@986:   NodeIt target(const EdgeIt &e);
alpar@986:   { return G::source(e); }
alpar@986:   NodeIt source(const EdgeIt &e);
alpar@986:   { return G::target(e); }
alpar@145:   
alpar@145: //   template<typename I> NodeIt aNode(const I e);
alpar@145: //   { return graph->aNode(e); }
alpar@145: //   template<typename I> NodeIt bNode(const I e);
alpar@145: //   { return graph->bNode(e); }
alpar@145:   
alpar@145: //   template<typename I> bool valid(const I i);
alpar@145: //   { return graph->valid(i); }
alpar@145:   
alpar@145: //   template<typename I> void setInvalid(const I &i);
alpar@145: //   { return graph->setInvalid(i); }
alpar@145:   
alpar@145: //   NodeIt addNode(); { return graph->addNode(); }
alpar@145: 
alpar@145:   EdgeIt addEdge(const NodeIt from,const NodeIt to);
alpar@145:   { return G::addEdge(to,from); }
alpar@145:   
alpar@145: //   template<I> void delete(I i); { graph->delete(i); }
alpar@145:   
alpar@145: //   void clean();  { graph->clean(); }
alpar@145:   
alpar@145: //   template<class T> class NodeMap : public typename G::NodeMap<T>;
alpar@145: //   template<class T> class EdgeMap : public typename G::EdgeMap<T>;
alpar@145:   
alpar@145: //   void SetG(G &g) {graph = &g;}
alpar@145:   
alpar@145: //   RevGraphWrapper() {graph = NULL;}
alpar@145: //   RevGraphWrapper(G &g) {graph = &g;}
alpar@145: };
alpar@145: 
alpar@145: template<typename G>
alpar@70: class SymGraphWrapper
alpar@70: {
alpar@70:   G *graph;
alpar@70:   
alpar@70: public:
alpar@70:   typedef G BaseGraph;
alpar@70: 
alpar@70:   typedef typename G::EdgeIt EdgeIt;
alpar@70:   
alpar@147:   typedef typename G::SymEdgeIt InEdgeIt;
alpar@147:   typedef typename G::SymEdgeIt OutEdgeIt;
alpar@70:   typedef typename G::SymEdgeIt SymEdgeIt;
alpar@70:   typedef typename G::EachEdgeIt EachEdgeIt;
alpar@70: 
alpar@70:   typedef typename G::NodeIt NodeIt;
alpar@70:     
alpar@70:   template<typename I> I &getFirst(I &i); { return graph->getFirst(i); }
alpar@70:   template<typename I,typename P> I &getFirst(I &i,const P &p);
alpar@70:   { return graph->getFirst(i,p); }
alpar@70:   template<typename I> I next(const I i); { return graph->goNext(i); }
alpar@70:   template<typename I> I &goNext(I &i); { return graph->goNext(i); }
alpar@70: 
alpar@986:   NodeIt target(const EdgeIt &e);
alpar@986:   { return graph->target(e); }
alpar@986:   NodeIt source(const EdgeIt &e);
alpar@986:   { return graph->source(e); }
alpar@70:   
alpar@70:   template<typename I> NodeIt aNode(const I e);
alpar@70:   { return graph->aNode(e); }
alpar@70:   template<typename I> NodeIt bNode(const I e);
alpar@70:   { return graph->bNode(e); }
alpar@70:   
alpar@70:   template<typename I> bool valid(const I i);
alpar@70:   { return graph->valid(i); }
alpar@70:   
alpar@70:   template<typename I> void setInvalid(const I &i);
alpar@70:   { return graph->setInvalid(i); }
alpar@70:   
alpar@70:   NodeIt addNode(); { return graph->addNode(); }
alpar@70:   EdgeIt addEdge(const NodeIt from,const NodeIt to);
alpar@70:   { return graph->addEdge(to,from); }
alpar@70:   
alpar@70:   template<I> void delete(I i); { graph->delete(i); }
alpar@70:   
alpar@70:   void clean();  { graph->clean(); }
alpar@70:   
alpar@70:   template<class T> class NodeMap : public typename G::NodeMap<T>;
alpar@70:   template<class T> class EdgeMap : public typename G::EdgeMap<T>;
alpar@70:   
alpar@70:   void SetG(G &g) {graph = &g;}
alpar@70:   
alpar@70:   RevGraphWrapper() {graph = NULL;}
alpar@70:   RevGraphWrapper(G &g) {graph = &g;}
alpar@70: };
alpar@70: 
alpar@70: 
alpar@145: 
alpar@145: 
alpar@145: 
alpar@145: 
alpar@145: 
alpar@145: 
alpar@145: 
alpar@145: 
alpar@145: 
alpar@145: 
alpar@145: 
alpar@145: 
alpar@145: 
alpar@145: 
alpar@145: 
alpar@145: 
alpar@145: 
alpar@70: // FIXME: comparison should be made better!!!
alpar@70: template<typename G, typename lomap, typename fmap, typename himap>
alpar@70: class ResGraphWrapper
alpar@70: {
alpar@70:   G *graph;
alpar@70:   
alpar@70: public:
alpar@70:   typedef G BaseGraph;
alpar@70: 
alpar@70:   typedef typename G::EdgeIt EdgeIt;
alpar@70:   
alpar@70:   class InEdgeIt 
alpar@70:   {
alpar@70:   public:
alpar@70:     G::NodeIt n;
alpar@70:     G::InEdgeIt i;   
alpar@70:     G::OutEdgeIt o;
alpar@70:   }
alpar@70:   class OutEdgeIt 
alpar@70:   {
alpar@70:   public:
alpar@70:     G::NodeIt n;
alpar@70:     G::InEdgeIt i;   
alpar@70:     G::OutEdgeIt o;
alpar@70:   }
alpar@70:   typedef typename G::SymEdgeIt SymEdgeIt;
alpar@70:   typedef typename G::EachEdgeIt EachEdgeIt;
alpar@70: 
alpar@70:   typedef typename G::NodeIt NodeIt;
alpar@70:     
alpar@70:   NodeIt &getFirst(NodeIt &n); { return graph->getFirst(n); }
alpar@70: 
alpar@70:   // EachEdge and SymEdge  is missing!!!!
alpar@70:   // EdgeIt <-> In/OutEdgeIt conversion is missing!!!!
alpar@70: 
alpar@70:   InEdgeIt &getFirst(InEdgeIt &e,const NodeIt &n)
alpar@70:   {
alpar@70:     e.n=n;
alpar@70:     graph->getFirst(e.i,n);
alpar@70:     while(graph->valid(e.i) && fmap.get(e.i)>=himap.get(e.i))
alpar@70:       graph->goNext(e.i);
alpar@70:     if(!graph->valid(e.i)) {
alpar@70:       graph->getFirst(e.o,n);
alpar@70:       while(graph->valid(e.o) && fmap.get(e.o)<=lomap.get(e.o))
alpar@70: 	graph->goNext(e.o);
alpar@70:     }
alpar@70:     return e;
alpar@70:   }
alpar@70:   InEdgeIt &goNext(InEdgeIt &e)
alpar@70:   {
alpar@70:     if(graph->valid(e.i)) {
alpar@70:       while(graph->valid(e.i) && fmap.get(e.i)>=himap.get(e.i))
alpar@70: 	graph->goNext(e.i);
alpar@70:       if(graph->valid(e.i)) return e;
alpar@70:       else graph->getFirst(e.o,e.n);
alpar@70:     }
alpar@70:     else {
alpar@70:       while(graph->valid(e.o) && fmap.get(e.o)<=lomap.get(e.o))
alpar@70: 	graph->goNext(e.o);
alpar@70:       return e;
alpar@70:     }
alpar@70:   }
alpar@70:   InEdgeIt Next(const InEdgeIt &e) {InEdgeIt t(e); return goNext(t);}
alpar@70:   bool valid(const InEdgeIt e) { return graph->valid(e.i)||graph->valid(e.o);}
alpar@70: 
alpar@70:   OutEdgeIt &getFirst(OutEdgeIt &e,const NodeIt &n)
alpar@70:   {
alpar@70:     e.n=n;
alpar@70:     graph->getFirst(e.o,n);
alpar@70:     while(graph->valid(e.o) && fmap.get(e.o)>=himap.get(e.o))
alpar@70:       graph->goNext(e.o);
alpar@70:     if(!graph->valid(e.o)) {
alpar@70:       graph->getFirst(e.i,n);
alpar@70:       while(graph->valid(e.i) && fmap.get(e.i)<=lomap.get(e.i))
alpar@70: 	graph->goNext(e.i);
alpar@70:     }
alpar@70:     return e;
alpar@70:   }
alpar@70:   OutEdgeIt &goNext(OutEdgeIt &e)
alpar@70:   {
alpar@70:     if(graph->valid(e.o)) {
alpar@70:       while(graph->valid(e.o) && fmap.get(e.o)>=himap.get(e.o))
alpar@70: 	graph->goNext(e.o);
alpar@70:       if(graph->valid(e.o)) return e;
alpar@70:       else graph->getFirst(e.i,e.n);
alpar@70:     }
alpar@70:     else {
alpar@70:       while(graph->valid(e.i) && fmap.get(e.i)<=lomap.get(e.i))
alpar@70: 	graph->goNext(e.i);
alpar@70:       return e;
alpar@70:     }
alpar@70:   }
alpar@70:   OutEdgeIt Next(const OutEdgeIt &e) {OutEdgeIt t(e); return goNext(t);}
alpar@70:   bool valid(const OutEdgeIt e) { return graph->valid(e.o)||graph->valid(e.i);}
alpar@70: 
alpar@70:   template<typename I> I &goNext(I &i); { return graph->goNext(i); }
alpar@70:   template<typename I> I next(const I i); { return graph->goNext(i); }
alpar@70: 
alpar@986:   NodeIt target(const EdgeIt &e);
alpar@986:   { return graph->target(e); }
alpar@986:   NodeIt source(const EdgeIt &e);
alpar@986:   { return graph->source(e); }
alpar@70:   
alpar@70:   template<typename I> NodeIt aNode(const I e);
alpar@70:   { return graph->aNode(e); }
alpar@70:   template<typename I> NodeIt bNode(const I e);
alpar@70:   { return graph->bNode(e); }
alpar@70:   
alpar@70:   template<typename I> bool valid(const I i);
alpar@70:   { return graph->valid(i); }
alpar@70:   
alpar@70:   template<typename I> void setInvalid(const I &i);
alpar@70:   { return graph->setInvalid(i); }
alpar@70:   
alpar@70:   NodeIt addNode(); { return graph->addNode(); }
alpar@70:   EdgeIt addEdge(const NodeIt from,const NodeIt to);
alpar@70:   { return graph->addEdge(to,from); }
alpar@70:   
alpar@70:   template<I> void delete(I i); { graph->delete(i); }
alpar@70:   
alpar@70:   void clean();  { graph->clean(); }
alpar@70:   
alpar@70:   template<class T> class NodeMap : public typename G::NodeMap<T>;
alpar@70:   template<class T> class EdgeMap : public typename G::EdgeMap<T>;
alpar@70:   
alpar@70:   void SetG(G &g) {graph = &g;}
alpar@70:   
alpar@70:   RevGraphWrapper() {graph = NULL;}
alpar@70:   RevGraphWrapper(G &g) {graph = &g;}
alpar@70: };
alpar@70: 
alpar@65: 
alpar@65: 
alpar@65: //   NodeIt &getFirst(NodeIt &n) { return graph->getFirst(n); }
alpar@65: //   InEdgeIt &getFirst(InEdgeIt &e,const NodeIt &n);
alpar@65: //   { return graph->getFirst(e,n); }
alpar@65: //   OutEdgeIt &getFirst(OutEdgeIt &e,const NodeIt &n);
alpar@65: //   { return graph->getFirst(e,n); }
alpar@65: //   SymEdgeIt &getFirst(SymEdgeIt &e,const NodeIt &n);
alpar@65: //   { return graph->getFirst(e,n); }
alpar@65: //   EachEdgeIt &getFirst(EachEdgeIt &e);
alpar@65: //   { return graph->getFirst(e); }
alpar@65:    
alpar@65: //   NodeIt next(const NodeIt &n);
alpar@65: //   { return graph->next(n); }
alpar@65: //   InEdgeIt next(const InEdgeIt &e);
alpar@65: //   { return graph->next(e); }
alpar@65: //   OutEdgeIt next(const OutEdgeIt &e);
alpar@65: //   { return graph->next(e); }
alpar@65: //   SymEdgeIt next(const SymEdgeIt &e);
alpar@65: //   { return graph->next(e); }
alpar@65: //   EachEdgeIt next(const EachEdgeIt &e);
alpar@65: //   { return graph->next(e); }
alpar@65:  
alpar@65: //   NodeIt &goNext(NodeIt &n);
alpar@65: //   { return graph->goNext(n); }
alpar@65: //   InEdgeIt &goNext(InEdgeIt &e);
alpar@65: //   { return graph->goNext(e); }
alpar@65: //   OutEdgeIt &goNext(OutEdgeIt &e);
alpar@65: //   { return graph->goNext(e); }
alpar@65: //   SymEdgeIt &goNext(SymEdgeIt &e);
alpar@65: //   { return graph->goNext(e); }
alpar@65: //   EachEdgeIt &goNext(EachEdgeIt &e);
alpar@65: //   { return graph->goNext(e); }
alpar@65: