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