src/work/alpar/gwrapper.h
author jacint
Sun, 22 Feb 2004 12:17:16 +0000
changeset 113 cf7b01232d86
parent 103 063de9e1be98
child 145 07c32a103bbb
permissions -rw-r--r--
*** empty log message ***
     1 // -*-mode: c++; -*-
     2 #ifndef GRAPH_WRAPPER_H
     3 #define GRAPH_WRAPPER_H
     4 
     5 namespace hugo {
     6 
     7 template<typename G>
     8 class TrivGraphWrapper
     9 {
    10   G *graph;
    11   
    12 public:
    13   typedef G BaseGraph;
    14 
    15   typedef typename G::EdgeIt EdgeIt;
    16   
    17   typedef typename G::InEdgeIt InEdgeIt;
    18   typedef typename G::OutEdgeIt OutEdgeIt;
    19   typedef typename G::SymEdgeIt SymEdgeIt;
    20   typedef typename G::EachEdgeIt EachEdgeIt;
    21 
    22   typedef typename G::NodeIt NodeIt;
    23     
    24   template<typename I> I &getFirst(I &i); { return graph->getFirst(i); }
    25   template<typename I,typename P> I &getFirst(I &i,const P &p);
    26   { return graph->getFirst(i,p); }
    27   template<typename I> I next(const I i); { return graph->goNext(i); }
    28   template<typename I> I &goNext(I &i); { return graph->goNext(i); }
    29 
    30   NodeIt head(const EdgeIt &e);
    31   { return graph->head(e); }
    32   NodeIt tail(const EdgeIt &e);
    33   { return graph->tail(e); }
    34   
    35   template<typename I> NodeIt aNode(const I e);
    36   { return graph->aNode(e); }
    37   template<typename I> NodeIt bNode(const I e);
    38   { return graph->bNode(e); }
    39   
    40   template<typename I> bool valid(const I i);
    41   { return graph->valid(i); }
    42   
    43   template<typename I> void setInvalid(const I &i);
    44   { return graph->setInvalid(i); }
    45   
    46   NodeIt addNode(); { return graph->addNode(); }
    47   EdgeIt addEdge(const NodeIt from,const NodeIt to);
    48   { return graph->addEdge(ftom,to); }
    49   
    50   template<I> void delete(I i); { graph->delete(i); }
    51   
    52   void clean();  { graph->clean(); }
    53   
    54   template<class T> class NodeMap : public typename G::NodeMap<T>;
    55   template<class T> class EdgeMap : public typename G::EdgeMap<T>;
    56   
    57   void SetG(G &g) {graph = &g;}
    58   
    59   TrivGraphWrapper() {graph = NULL;}
    60   TrivGraphWrapper(G &g) {graph = &g;}
    61 };
    62 
    63 template<typename G>
    64 class RevGraphWrapper
    65 {
    66   G *graph;
    67   
    68 public:
    69   typedef G BaseGraph;
    70 
    71   typedef typename G::EdgeIt EdgeIt;
    72   
    73   typedef typename G::InEdgeIt OutEdgeIt;
    74   typedef typename G::OutEdgeIt InEdgeIt;
    75   typedef typename G::SymEdgeIt SymEdgeIt;
    76   typedef typename G::EachEdgeIt EachEdgeIt;
    77 
    78   typedef typename G::NodeIt NodeIt;
    79     
    80   template<typename I> I &getFirst(I &i); { return graph->getFirst(i); }
    81   template<typename I,typename P> I &getFirst(I &i,const P &p);
    82   { return graph->getFirst(i,p); }
    83   template<typename I> I next(const I i); { return graph->goNext(i); }
    84   template<typename I> I &goNext(I &i); { return graph->goNext(i); }
    85 
    86   NodeIt head(const EdgeIt &e);
    87   { return graph->tail(e); }
    88   NodeIt tail(const EdgeIt &e);
    89   { return graph->head(e); }
    90   
    91   template<typename I> NodeIt aNode(const I e);
    92   { return graph->aNode(e); }
    93   template<typename I> NodeIt bNode(const I e);
    94   { return graph->bNode(e); }
    95   
    96   template<typename I> bool valid(const I i);
    97   { return graph->valid(i); }
    98   
    99   template<typename I> void setInvalid(const I &i);
   100   { return graph->setInvalid(i); }
   101   
   102   NodeIt addNode(); { return graph->addNode(); }
   103   EdgeIt addEdge(const NodeIt from,const NodeIt to);
   104   { return graph->addEdge(to,from); }
   105   
   106   template<I> void delete(I i); { graph->delete(i); }
   107   
   108   void clean();  { graph->clean(); }
   109   
   110   template<class T> class NodeMap : public typename G::NodeMap<T>;
   111   template<class T> class EdgeMap : public typename G::EdgeMap<T>;
   112   
   113   void SetG(G &g) {graph = &g;}
   114   
   115   RevGraphWrapper() {graph = NULL;}
   116   RevGraphWrapper(G &g) {graph = &g;}
   117 };
   118 
   119 template<typename G>
   120 class SymGraphWrapper
   121 {
   122   G *graph;
   123   
   124 public:
   125   typedef G BaseGraph;
   126 
   127   typedef typename G::EdgeIt EdgeIt;
   128   
   129   typedef typename G::InEdgeIt SymEdgeIt;
   130   typedef typename G::OutEdgeIt SymEdgeIt;
   131   typedef typename G::SymEdgeIt SymEdgeIt;
   132   typedef typename G::EachEdgeIt EachEdgeIt;
   133 
   134   typedef typename G::NodeIt NodeIt;
   135     
   136   template<typename I> I &getFirst(I &i); { return graph->getFirst(i); }
   137   template<typename I,typename P> I &getFirst(I &i,const P &p);
   138   { return graph->getFirst(i,p); }
   139   template<typename I> I next(const I i); { return graph->goNext(i); }
   140   template<typename I> I &goNext(I &i); { return graph->goNext(i); }
   141 
   142   NodeIt head(const EdgeIt &e);
   143   { return graph->head(e); }
   144   NodeIt tail(const EdgeIt &e);
   145   { return graph->tail(e); }
   146   
   147   template<typename I> NodeIt aNode(const I e);
   148   { return graph->aNode(e); }
   149   template<typename I> NodeIt bNode(const I e);
   150   { return graph->bNode(e); }
   151   
   152   template<typename I> bool valid(const I i);
   153   { return graph->valid(i); }
   154   
   155   template<typename I> void setInvalid(const I &i);
   156   { return graph->setInvalid(i); }
   157   
   158   NodeIt addNode(); { return graph->addNode(); }
   159   EdgeIt addEdge(const NodeIt from,const NodeIt to);
   160   { return graph->addEdge(to,from); }
   161   
   162   template<I> void delete(I i); { graph->delete(i); }
   163   
   164   void clean();  { graph->clean(); }
   165   
   166   template<class T> class NodeMap : public typename G::NodeMap<T>;
   167   template<class T> class EdgeMap : public typename G::EdgeMap<T>;
   168   
   169   void SetG(G &g) {graph = &g;}
   170   
   171   RevGraphWrapper() {graph = NULL;}
   172   RevGraphWrapper(G &g) {graph = &g;}
   173 };
   174 
   175 
   176 // FIXME: comparison should be made better!!!
   177 template<typename G, typename lomap, typename fmap, typename himap>
   178 class ResGraphWrapper
   179 {
   180   G *graph;
   181   
   182 public:
   183   typedef G BaseGraph;
   184 
   185   typedef typename G::EdgeIt EdgeIt;
   186   
   187   class InEdgeIt 
   188   {
   189   public:
   190     G::NodeIt n;
   191     G::InEdgeIt i;   
   192     G::OutEdgeIt o;
   193   }
   194   class OutEdgeIt 
   195   {
   196   public:
   197     G::NodeIt n;
   198     G::InEdgeIt i;   
   199     G::OutEdgeIt o;
   200   }
   201   typedef typename G::SymEdgeIt SymEdgeIt;
   202   typedef typename G::EachEdgeIt EachEdgeIt;
   203 
   204   typedef typename G::NodeIt NodeIt;
   205     
   206   NodeIt &getFirst(NodeIt &n); { return graph->getFirst(n); }
   207 
   208   // EachEdge and SymEdge  is missing!!!!
   209   // EdgeIt <-> In/OutEdgeIt conversion is missing!!!!
   210 
   211   InEdgeIt &getFirst(InEdgeIt &e,const NodeIt &n)
   212   {
   213     e.n=n;
   214     graph->getFirst(e.i,n);
   215     while(graph->valid(e.i) && fmap.get(e.i)>=himap.get(e.i))
   216       graph->goNext(e.i);
   217     if(!graph->valid(e.i)) {
   218       graph->getFirst(e.o,n);
   219       while(graph->valid(e.o) && fmap.get(e.o)<=lomap.get(e.o))
   220 	graph->goNext(e.o);
   221     }
   222     return e;
   223   }
   224   InEdgeIt &goNext(InEdgeIt &e)
   225   {
   226     if(graph->valid(e.i)) {
   227       while(graph->valid(e.i) && fmap.get(e.i)>=himap.get(e.i))
   228 	graph->goNext(e.i);
   229       if(graph->valid(e.i)) return e;
   230       else graph->getFirst(e.o,e.n);
   231     }
   232     else {
   233       while(graph->valid(e.o) && fmap.get(e.o)<=lomap.get(e.o))
   234 	graph->goNext(e.o);
   235       return e;
   236     }
   237   }
   238   InEdgeIt Next(const InEdgeIt &e) {InEdgeIt t(e); return goNext(t);}
   239   bool valid(const InEdgeIt e) { return graph->valid(e.i)||graph->valid(e.o);}
   240 
   241   OutEdgeIt &getFirst(OutEdgeIt &e,const NodeIt &n)
   242   {
   243     e.n=n;
   244     graph->getFirst(e.o,n);
   245     while(graph->valid(e.o) && fmap.get(e.o)>=himap.get(e.o))
   246       graph->goNext(e.o);
   247     if(!graph->valid(e.o)) {
   248       graph->getFirst(e.i,n);
   249       while(graph->valid(e.i) && fmap.get(e.i)<=lomap.get(e.i))
   250 	graph->goNext(e.i);
   251     }
   252     return e;
   253   }
   254   OutEdgeIt &goNext(OutEdgeIt &e)
   255   {
   256     if(graph->valid(e.o)) {
   257       while(graph->valid(e.o) && fmap.get(e.o)>=himap.get(e.o))
   258 	graph->goNext(e.o);
   259       if(graph->valid(e.o)) return e;
   260       else graph->getFirst(e.i,e.n);
   261     }
   262     else {
   263       while(graph->valid(e.i) && fmap.get(e.i)<=lomap.get(e.i))
   264 	graph->goNext(e.i);
   265       return e;
   266     }
   267   }
   268   OutEdgeIt Next(const OutEdgeIt &e) {OutEdgeIt t(e); return goNext(t);}
   269   bool valid(const OutEdgeIt e) { return graph->valid(e.o)||graph->valid(e.i);}
   270 
   271   template<typename I> I &goNext(I &i); { return graph->goNext(i); }
   272   template<typename I> I next(const I i); { return graph->goNext(i); }
   273 
   274   NodeIt head(const EdgeIt &e);
   275   { return graph->head(e); }
   276   NodeIt tail(const EdgeIt &e);
   277   { return graph->tail(e); }
   278   
   279   template<typename I> NodeIt aNode(const I e);
   280   { return graph->aNode(e); }
   281   template<typename I> NodeIt bNode(const I e);
   282   { return graph->bNode(e); }
   283   
   284   template<typename I> bool valid(const I i);
   285   { return graph->valid(i); }
   286   
   287   template<typename I> void setInvalid(const I &i);
   288   { return graph->setInvalid(i); }
   289   
   290   NodeIt addNode(); { return graph->addNode(); }
   291   EdgeIt addEdge(const NodeIt from,const NodeIt to);
   292   { return graph->addEdge(to,from); }
   293   
   294   template<I> void delete(I i); { graph->delete(i); }
   295   
   296   void clean();  { graph->clean(); }
   297   
   298   template<class T> class NodeMap : public typename G::NodeMap<T>;
   299   template<class T> class EdgeMap : public typename G::EdgeMap<T>;
   300   
   301   void SetG(G &g) {graph = &g;}
   302   
   303   RevGraphWrapper() {graph = NULL;}
   304   RevGraphWrapper(G &g) {graph = &g;}
   305 };
   306 
   307 
   308 
   309 //   NodeIt &getFirst(NodeIt &n) { return graph->getFirst(n); }
   310 //   InEdgeIt &getFirst(InEdgeIt &e,const NodeIt &n);
   311 //   { return graph->getFirst(e,n); }
   312 //   OutEdgeIt &getFirst(OutEdgeIt &e,const NodeIt &n);
   313 //   { return graph->getFirst(e,n); }
   314 //   SymEdgeIt &getFirst(SymEdgeIt &e,const NodeIt &n);
   315 //   { return graph->getFirst(e,n); }
   316 //   EachEdgeIt &getFirst(EachEdgeIt &e);
   317 //   { return graph->getFirst(e); }
   318    
   319 //   NodeIt next(const NodeIt &n);
   320 //   { return graph->next(n); }
   321 //   InEdgeIt next(const InEdgeIt &e);
   322 //   { return graph->next(e); }
   323 //   OutEdgeIt next(const OutEdgeIt &e);
   324 //   { return graph->next(e); }
   325 //   SymEdgeIt next(const SymEdgeIt &e);
   326 //   { return graph->next(e); }
   327 //   EachEdgeIt next(const EachEdgeIt &e);
   328 //   { return graph->next(e); }
   329  
   330 //   NodeIt &goNext(NodeIt &n);
   331 //   { return graph->goNext(n); }
   332 //   InEdgeIt &goNext(InEdgeIt &e);
   333 //   { return graph->goNext(e); }
   334 //   OutEdgeIt &goNext(OutEdgeIt &e);
   335 //   { return graph->goNext(e); }
   336 //   SymEdgeIt &goNext(SymEdgeIt &e);
   337 //   { return graph->goNext(e); }
   338 //   EachEdgeIt &goNext(EachEdgeIt &e);
   339 //   { return graph->goNext(e); }
   340