File: GM_Iterators.h

package info (click to toggle)
madlib 1.3.0-2.2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 6,912 kB
  • sloc: cpp: 39,850; sh: 10,088; makefile: 476
file content (125 lines) | stat: -rw-r--r-- 3,081 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// -*- C++ -*-
// -------------------------------------------------------------------
// MAdLib - Copyright (C) 2008-2009 Universite catholique de Louvain
//
// See the Copyright.txt and License.txt files for license information. 
// You should have received a copy of these files along with MAdLib. 
// If not, see <http://www.madlib.be/license/>
//
// Please report all bugs and problems to <contrib@madlib.be>
//
// Authors: Jean-Francois Remacle, Gaetan Compere
// -------------------------------------------------------------------

#ifndef _H_GM_ITERATORS
#define _H_GM_ITERATORS

#include "ModelInterface.h"

namespace MAd {

  // -------------------------------------------------------------------
  class GM_RegionIterator {

  private:
    MAdModel * model;
    MAdModel::riter iter;

  public:
    GM_RegionIterator(MAdModel * _model):
      model(_model)
    { iter = model->firstRegion(); }
    GM_RegionIterator(const GM_RegionIterator& it):
      model(it.model),iter(it.iter) {}
    ~GM_RegionIterator() {}

    void reset() { iter = model->firstRegion(); }
    MAdGRegion * next()
    {
      if ( iter == model->lastRegion() ) return NULL;
      MAdGRegion * res = *iter;
      iter++;
      return res;
    }
  };

  // -------------------------------------------------------------------
  class GM_FaceIterator {

  private:
    MAdModel * model;
    MAdModel::fiter iter;

  public:
    GM_FaceIterator(MAdModel * _model):
      model(_model)
    { iter = model->firstFace(); }
    GM_FaceIterator(const GM_FaceIterator& it):
      model(it.model),iter(it.iter) {}
    ~GM_FaceIterator() {}

    void reset() { iter = model->firstFace(); }
    MAdGFace * next()
    {
      if ( iter == model->lastFace() ) return NULL;
      MAdGFace * res = *iter;
      iter++;
      return res;
    }
  };

  // -------------------------------------------------------------------
  class GM_EdgeIterator {

  private:
    MAdModel * model;
    MAdModel::eiter iter;

  public:
    GM_EdgeIterator(MAdModel * _model):
      model(_model)
    { iter = model->firstEdge(); }
    GM_EdgeIterator(const GM_EdgeIterator& it):
      model(it.model),iter(it.iter) {}
    ~GM_EdgeIterator() {}

    void reset() { iter = model->firstEdge(); }
    MAdGEdge * next()
    {
      if ( iter == model->lastEdge() ) return NULL;
      MAdGEdge * res = *iter;
      iter++;
      return res;
    }
  };

  // -------------------------------------------------------------------
  class GM_VertexIterator {

  private:
    MAdModel * model;
    MAdModel::viter iter;

  public:
    GM_VertexIterator(MAdModel * _model):
      model(_model)
    { iter = model->firstVertex(); }
    GM_VertexIterator(const GM_VertexIterator& it):
      model(it.model),iter(it.iter) {}
    ~GM_VertexIterator() {}

    void reset() { iter = model->firstVertex(); }
    MAdGVertex * next()
    {
      if ( iter == model->lastVertex() ) return NULL;
      MAdGVertex * res = *iter;
      iter++;
      return res;
    }
  };

  // -------------------------------------------------------------------

}

#endif