1
0

foreach.cpp 623 B

12345678910111213141516171819202122
  1. #include "foreach.h"
  2. __foreach::__foreach(const PtrListRoot &ptrlist, int reverse) :
  3. list(ptrlist.getNumItems(), ptrlist.getItemList()), pos(0)
  4. {
  5. if (reverse) list.reverse();
  6. }
  7. __foreach::__foreach(const PtrListRoot *ptrlist, int reverse) :
  8. list(ptrlist->getNumItems(), ptrlist->getItemList()), pos(0) {
  9. if (reverse) list.reverse();
  10. }
  11. int __foreach::done() const { return (pos >= list.getSize()); }
  12. void *__foreach::next(int advance) { if (advance) pos++; return getPtr(); }
  13. void *__foreach::getPtr() const { return (pos < list.getSize()) ? list[pos] : NULL; }
  14. int __foreach::getPos() const { return pos; }