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