Iterator.cpp 463 B

1234567891011121314151617181920212223242526272829303132
  1. #include "Iterator.h"
  2. Iterator::Iterator() {
  3. }
  4. Iterator::~Iterator() {
  5. }
  6. ConcreteIterator::ConcreteIterator(Aggregate *ag, int idx = 0) {
  7. _ag = ag;
  8. _idx = idx;
  9. }
  10. Object ConcreteIterator::CurrentItem() {
  11. return _ag->GetItem(_idx);
  12. }
  13. void ConcreteIterator::First() {
  14. _idx = 0;
  15. }
  16. void ConcreteIterator::Next() {
  17. if (_idx < _ag->GetSize()) {
  18. _idx++;
  19. }
  20. }
  21. bool ConcreteIterator::IsDone() {
  22. return (_idx == _ag->GetSize());
  23. }