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 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
|
// -*- 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_MESHDATABASEITERATORS
#define H_MESHDATABASEITERATORS
#include <stdio.h>
namespace MAd {
template <class CONTAINER, class DATA, class CLASSIF>
class MDB_Iter
{
public:
CONTAINER *l;
CLASSIF g;
int closure;
typename CONTAINER::iterator current;
typename CONTAINER::iterator end;
MDB_Iter (CONTAINER *_l):l(_l),g(NULL),closure(0)
{
reset();
}
MDB_Iter (CONTAINER *_l,CLASSIF _g):l(_l),g((CLASSIF) _g),closure(0) {
reset();
}
MDB_Iter (CONTAINER *_l,CLASSIF _g,int _c):l(_l),g((CLASSIF) _g),closure(_c) {
/* if ((DATA::getDim() == 3) && (_c == 1)) { */
/* printf("Closure iterator not allowed for regions\n"); */
/* exit(1); */
/* } */
if (_c == 1) {
printf("Closure iterator not yet implemented \n");
exit(1);
}
reset();
}
virtual ~MDB_Iter() {}
inline void reset()
{
end = l->end();
current = l->begin();
if (!g) {
while(current != end && (*current)->deleted)
{
typename CONTAINER::iterator currentb = current;
current++;
delete *currentb;
l->erase(currentb);
}
}
else {
while(current != end && ((*current)->deleted || (*current)->g != g))
{
typename CONTAINER::iterator currentb = current;
current++;
if ((*currentb)->deleted) {
delete *currentb;
l->erase(currentb);
}
}
}
// if (!g && current!= end && (*current)->deleted)next();
// if (g && current!= end && ((*current)->deleted || (*current)->g != g)) next();
}
inline void cleanup()
{
current = l->begin();
while(next()){}
}
inline virtual DATA * next ()
{
if (current == end) return 0;
DATA *r = *current;
++ current;
if (!g) {
while(current != end && (*current)->deleted)
{
typename CONTAINER::iterator currentb = current;
current++;
delete *currentb;
l->erase(currentb);
}
}
else {
while(current != end && ((*current)->deleted || (*current)->g != g))
{
typename CONTAINER::iterator currentb = current;
current++;
if ((*currentb)->deleted) {
delete *currentb;
l->erase(currentb);
}
}
}
// if the result data was marked for deletion
// after previous call to next() look for the next one
if (r->deleted) {
if (current == end) return 0;
r = *current;
++ current;
if (!g) {
while(current != end && (*current)->deleted)
{
typename CONTAINER::iterator currentb = current;
current++;
delete *currentb;
l->erase(currentb);
}
}
else {
while(current != end && ((*current)->deleted || (*current)->g != g))
{
typename CONTAINER::iterator currentb = current;
current++;
if ((*currentb)->deleted) {
delete *currentb;
l->erase(currentb);
}
}
}
}
return r;
}
};
template <class CONTAINER, class DATA, class CLASSIF>
int countClassifiedElements (CONTAINER* c,CLASSIF g) {
MDB_Iter<CONTAINER,DATA,CLASSIF>* iter = new MDB_Iter<CONTAINER,DATA,CLASSIF>(c,g);
DATA* el = NULL;
int count = 0;
while ( (el = iter->next()) ) count++;
delete iter;
return count;
}
}
/* //report errors to koen.hillewaert@cenaero.be */
/* template <class CONTAINER, class DATA> */
/* class MDB_CIter: public MDB_Iter <CONTAINER,DATA> */
/* { */
/* public: */
/* pGEntity ge; */
/* MDB_CIter (CONTAINER *_l,pGEntity _g):MDB_Iter<CONTAINER,DATA>(_l),ge(_g) */
/* { */
/* reset(); */
/* } */
/* inline DATA * next () */
/* { */
/* if (current == end)return 0; */
/* DATA *r = *current; */
/* ++ current; */
/* while(current != end && */
/* (*current)->deleted && */
/* EN_whatIn(current) != ge) */
/* { */
/* typename CONTAINER::iterator currentb = current; */
/* current++; */
/* delete *currentb; */
/* l->erase(currentb); */
/* } */
/* return r; */
/* } */
/* }; */
#endif
|