aboutsummaryrefslogtreecommitdiff
path: root/Src/Wasabi/bfc/foreach.h
blob: 1ba538014f089189c20892adf84bda69d01bb47a (plain) (blame)
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
#ifndef _FOREACH_H
#define _FOREACH_H

#include "memblock.h"
#include "ptrlist.h"


// foreach stuff
/* use like this:
  PtrList<blah> list;
  foreach(list)
    list.getfor()->booga();
    something(list.getfor());
  endfor
*/

// foreach stuff
class __foreach 
{
public:
  __foreach(const PtrListRoot &ptrlist, int reverse=FALSE);
  __foreach(const PtrListRoot *ptrlist, int reverse=FALSE);

  int done() const;
  void *next(int advance = TRUE);
  void *getPtr() const;

  int getPos() const;

private:
  MemBlock<void *> list;
  int pos;
};

#define foreach(x) \
{ \
  void *__fe_void; \
  __foreach ___f(x); \
  for (__fe_void = ___f.getPtr(); !___f.done(); __fe_void = ___f.next()) {
#define getfor() castFor(__fe_void)
#define endfor \
  } \
}
#define foreach_reverse(x) \
{ \
  void *__fe_void; \
  __foreach ___f(x, TRUE); \
  for (__fe_void = ___f.getPtr(); !___f.done(); __fe_void = ___f.next()) {
#define getfor() castFor(__fe_void)
#define endfor \
  } \
}
#define foreach_index (___f.getPos())

#endif