src/work/alpar/gwrapper.h
author deba
Wed, 08 Sep 2004 12:06:45 +0000
changeset 822 88226d9fe821
parent 145 07c32a103bbb
child 921 818510fa3d99
permissions -rw-r--r--
The MapFactories have been removed from the code because
if we use macros then they increases only the complexity.

The pair iterators of the maps are separeted from the maps.

Some macros and comments has been changed.
     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 RevGraphExt : public G
   121 {
   122 public:
   123   //  typedef G BaseGraph;
   124 
   125   typedef typename G::EdgeIt EdgeIt;
   126   
   127   typedef typename G::InEdgeIt OutEdgeIt;
   128   typedef typename G::OutEdgeIt InEdgeIt;
   129   typedef typename G::SymEdgeIt SymEdgeIt;
   130   typedef typename G::EachEdgeIt EachEdgeIt;
   131 
   132   typedef typename G::NodeIt NodeIt;
   133     
   134 //   template<typename I> I &getFirst(I &i); { return graph->getFirst(i); }
   135 //   template<typename I,typename P> I &getFirst(I &i,const P &p);
   136 //   { return graph->getFirst(i,p); }
   137 //   template<typename I> I next(const I i); { return graph->goNext(i); }
   138 //   template<typename I> I &goNext(I &i); { return graph->goNext(i); }
   139 
   140   NodeIt head(const EdgeIt &e);
   141   { return G::tail(e); }
   142   NodeIt tail(const EdgeIt &e);
   143   { return G::head(e); }
   144   
   145 //   template<typename I> NodeIt aNode(const I e);
   146 //   { return graph->aNode(e); }
   147 //   template<typename I> NodeIt bNode(const I e);
   148 //   { return graph->bNode(e); }
   149   
   150 //   template<typename I> bool valid(const I i);
   151 //   { return graph->valid(i); }
   152   
   153 //   template<typename I> void setInvalid(const I &i);
   154 //   { return graph->setInvalid(i); }
   155   
   156 //   NodeIt addNode(); { return graph->addNode(); }
   157 
   158   EdgeIt addEdge(const NodeIt from,const NodeIt to);
   159   { return G::addEdge(to,from); }
   160   
   161 //   template<I> void delete(I i); { graph->delete(i); }
   162   
   163 //   void clean();  { graph->clean(); }
   164   
   165 //   template<class T> class NodeMap : public typename G::NodeMap<T>;
   166 //   template<class T> class EdgeMap : public typename G::EdgeMap<T>;
   167   
   168 //   void SetG(G &g) {graph = &g;}
   169   
   170 //   RevGraphWrapper() {graph = NULL;}
   171 //   RevGraphWrapper(G &g) {graph = &g;}
   172 };
   173 
   174 template<typename G>
   175 class SymGraphWrapper
   176 {
   177   G *graph;
   178   
   179 public:
   180   typedef G BaseGraph;
   181 
   182   typedef typename G::EdgeIt EdgeIt;
   183   
   184   typedef typename G::SymEdgeIt InEdgeIt;
   185   typedef typename G::SymEdgeIt OutEdgeIt;
   186   typedef typename G::SymEdgeIt SymEdgeIt;
   187   typedef typename G::EachEdgeIt EachEdgeIt;
   188 
   189   typedef typename G::NodeIt NodeIt;
   190     
   191   template<typename I> I &getFirst(I &i); { return graph->getFirst(i); }
   192   template<typename I,typename P> I &getFirst(I &i,const P &p);
   193   { return graph->getFirst(i,p); }
   194   template<typename I> I next(const I i); { return graph->goNext(i); }
   195   template<typename I> I &goNext(I &i); { return graph->goNext(i); }
   196 
   197   NodeIt head(const EdgeIt &e);
   198   { return graph->head(e); }
   199   NodeIt tail(const EdgeIt &e);
   200   { return graph->tail(e); }
   201   
   202   template<typename I> NodeIt aNode(const I e);
   203   { return graph->aNode(e); }
   204   template<typename I> NodeIt bNode(const I e);
   205   { return graph->bNode(e); }
   206   
   207   template<typename I> bool valid(const I i);
   208   { return graph->valid(i); }
   209   
   210   template<typename I> void setInvalid(const I &i);
   211   { return graph->setInvalid(i); }
   212   
   213   NodeIt addNode(); { return graph->addNode(); }
   214   EdgeIt addEdge(const NodeIt from,const NodeIt to);
   215   { return graph->addEdge(to,from); }
   216   
   217   template<I> void delete(I i); { graph->delete(i); }
   218   
   219   void clean();  { graph->clean(); }
   220   
   221   template<class T> class NodeMap : public typename G::NodeMap<T>;
   222   template<class T> class EdgeMap : public typename G::EdgeMap<T>;
   223   
   224   void SetG(G &g) {graph = &g;}
   225   
   226   RevGraphWrapper() {graph = NULL;}
   227   RevGraphWrapper(G &g) {graph = &g;}
   228 };
   229 
   230 
   231 
   232 
   233 
   234 
   235 
   236 
   237 
   238 
   239 
   240 
   241 
   242 
   243 
   244 
   245 
   246 
   247 
   248 // FIXME: comparison should be made better!!!
   249 template<typename G, typename lomap, typename fmap, typename himap>
   250 class ResGraphWrapper
   251 {
   252   G *graph;
   253   
   254 public:
   255   typedef G BaseGraph;
   256 
   257   typedef typename G::EdgeIt EdgeIt;
   258   
   259   class InEdgeIt 
   260   {
   261   public:
   262     G::NodeIt n;
   263     G::InEdgeIt i;   
   264     G::OutEdgeIt o;
   265   }
   266   class OutEdgeIt 
   267   {
   268   public:
   269     G::NodeIt n;
   270     G::InEdgeIt i;   
   271     G::OutEdgeIt o;
   272   }
   273   typedef typename G::SymEdgeIt SymEdgeIt;
   274   typedef typename G::EachEdgeIt EachEdgeIt;
   275 
   276   typedef typename G::NodeIt NodeIt;
   277     
   278   NodeIt &getFirst(NodeIt &n); { return graph->getFirst(n); }
   279 
   280   // EachEdge and SymEdge  is missing!!!!
   281   // EdgeIt <-> In/OutEdgeIt conversion is missing!!!!
   282 
   283   InEdgeIt &getFirst(InEdgeIt &e,const NodeIt &n)
   284   {
   285     e.n=n;
   286     graph->getFirst(e.i,n);
   287     while(graph->valid(e.i) && fmap.get(e.i)>=himap.get(e.i))
   288       graph->goNext(e.i);
   289     if(!graph->valid(e.i)) {
   290       graph->getFirst(e.o,n);
   291       while(graph->valid(e.o) && fmap.get(e.o)<=lomap.get(e.o))
   292 	graph->goNext(e.o);
   293     }
   294     return e;
   295   }
   296   InEdgeIt &goNext(InEdgeIt &e)
   297   {
   298     if(graph->valid(e.i)) {
   299       while(graph->valid(e.i) && fmap.get(e.i)>=himap.get(e.i))
   300 	graph->goNext(e.i);
   301       if(graph->valid(e.i)) return e;
   302       else graph->getFirst(e.o,e.n);
   303     }
   304     else {
   305       while(graph->valid(e.o) && fmap.get(e.o)<=lomap.get(e.o))
   306 	graph->goNext(e.o);
   307       return e;
   308     }
   309   }
   310   InEdgeIt Next(const InEdgeIt &e) {InEdgeIt t(e); return goNext(t);}
   311   bool valid(const InEdgeIt e) { return graph->valid(e.i)||graph->valid(e.o);}
   312 
   313   OutEdgeIt &getFirst(OutEdgeIt &e,const NodeIt &n)
   314   {
   315     e.n=n;
   316     graph->getFirst(e.o,n);
   317     while(graph->valid(e.o) && fmap.get(e.o)>=himap.get(e.o))
   318       graph->goNext(e.o);
   319     if(!graph->valid(e.o)) {
   320       graph->getFirst(e.i,n);
   321       while(graph->valid(e.i) && fmap.get(e.i)<=lomap.get(e.i))
   322 	graph->goNext(e.i);
   323     }
   324     return e;
   325   }
   326   OutEdgeIt &goNext(OutEdgeIt &e)
   327   {
   328     if(graph->valid(e.o)) {
   329       while(graph->valid(e.o) && fmap.get(e.o)>=himap.get(e.o))
   330 	graph->goNext(e.o);
   331       if(graph->valid(e.o)) return e;
   332       else graph->getFirst(e.i,e.n);
   333     }
   334     else {
   335       while(graph->valid(e.i) && fmap.get(e.i)<=lomap.get(e.i))
   336 	graph->goNext(e.i);
   337       return e;
   338     }
   339   }
   340   OutEdgeIt Next(const OutEdgeIt &e) {OutEdgeIt t(e); return goNext(t);}
   341   bool valid(const OutEdgeIt e) { return graph->valid(e.o)||graph->valid(e.i);}
   342 
   343   template<typename I> I &goNext(I &i); { return graph->goNext(i); }
   344   template<typename I> I next(const I i); { return graph->goNext(i); }
   345 
   346   NodeIt head(const EdgeIt &e);
   347   { return graph->head(e); }
   348   NodeIt tail(const EdgeIt &e);
   349   { return graph->tail(e); }
   350   
   351   template<typename I> NodeIt aNode(const I e);
   352   { return graph->aNode(e); }
   353   template<typename I> NodeIt bNode(const I e);
   354   { return graph->bNode(e); }
   355   
   356   template<typename I> bool valid(const I i);
   357   { return graph->valid(i); }
   358   
   359   template<typename I> void setInvalid(const I &i);
   360   { return graph->setInvalid(i); }
   361   
   362   NodeIt addNode(); { return graph->addNode(); }
   363   EdgeIt addEdge(const NodeIt from,const NodeIt to);
   364   { return graph->addEdge(to,from); }
   365   
   366   template<I> void delete(I i); { graph->delete(i); }
   367   
   368   void clean();  { graph->clean(); }
   369   
   370   template<class T> class NodeMap : public typename G::NodeMap<T>;
   371   template<class T> class EdgeMap : public typename G::EdgeMap<T>;
   372   
   373   void SetG(G &g) {graph = &g;}
   374   
   375   RevGraphWrapper() {graph = NULL;}
   376   RevGraphWrapper(G &g) {graph = &g;}
   377 };
   378 
   379 
   380 
   381 //   NodeIt &getFirst(NodeIt &n) { return graph->getFirst(n); }
   382 //   InEdgeIt &getFirst(InEdgeIt &e,const NodeIt &n);
   383 //   { return graph->getFirst(e,n); }
   384 //   OutEdgeIt &getFirst(OutEdgeIt &e,const NodeIt &n);
   385 //   { return graph->getFirst(e,n); }
   386 //   SymEdgeIt &getFirst(SymEdgeIt &e,const NodeIt &n);
   387 //   { return graph->getFirst(e,n); }
   388 //   EachEdgeIt &getFirst(EachEdgeIt &e);
   389 //   { return graph->getFirst(e); }
   390    
   391 //   NodeIt next(const NodeIt &n);
   392 //   { return graph->next(n); }
   393 //   InEdgeIt next(const InEdgeIt &e);
   394 //   { return graph->next(e); }
   395 //   OutEdgeIt next(const OutEdgeIt &e);
   396 //   { return graph->next(e); }
   397 //   SymEdgeIt next(const SymEdgeIt &e);
   398 //   { return graph->next(e); }
   399 //   EachEdgeIt next(const EachEdgeIt &e);
   400 //   { return graph->next(e); }
   401  
   402 //   NodeIt &goNext(NodeIt &n);
   403 //   { return graph->goNext(n); }
   404 //   InEdgeIt &goNext(InEdgeIt &e);
   405 //   { return graph->goNext(e); }
   406 //   OutEdgeIt &goNext(OutEdgeIt &e);
   407 //   { return graph->goNext(e); }
   408 //   SymEdgeIt &goNext(SymEdgeIt &e);
   409 //   { return graph->goNext(e); }
   410 //   EachEdgeIt &goNext(EachEdgeIt &e);
   411 //   { return graph->goNext(e); }
   412