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