Design Patterns
list_iterator.h
Go to the documentation of this file.
1 // Based on "Design Patterns: Elements of Reusable Object-Oriented Software"
2 // book by Erich Gamma, John Vlissides, Ralph Johnson, and Richard Helm
3 //
4 // Created by Bartosz Rachwal. The National Institute of Advanced Industrial Science and Technology, Japan.
5 
6 #ifndef OPERATIONAL_ITERATOR_LIST_ITERATOR_H_
7 #define OPERATIONAL_ITERATOR_LIST_ITERATOR_H_
8 
9 #include "iterator_interface.h"
10 #include "list_interface.h"
11 
12 namespace operational
13 {
14 namespace iterator
15 {
16 template<class Item>
17 class ListIterator : public IteratorInterface<Item>
18 {
19  public:
20  explicit ListIterator(const ListInterface<Item>* list);
21  virtual ~ListIterator() override;
22 
23  virtual void First() override;
24  virtual void Next() override;
25  virtual bool IsDone() const override;
26  virtual Item CurrentItem() const override;
27 
28  private:
29  const ListInterface<Item>* list_;
30  long current_;
31 };
32 
33 template<class Item>
34 ListIterator<Item>::ListIterator(const ListInterface<Item>* list) : list_(list), current_(0) { }
35 
36 template<class Item>
38 
39 template<class Item>
41 {
42  current_ = 0;
43 }
44 
45 template<class Item>
47 {
48  current_++;
49 }
50 
51 template<class Item>
53 {
54  return current_ >= list_->Count();
55 }
56 
57 template<class Item>
59 {
60  if (IsDone())
61  {
62  return nullptr;
63  }
64  return list_->Get(current_);
65 }
66 }
67 }
68 
69 #endif
70 
ListIterator(const ListInterface< Item > *list)
Definition: list_iterator.h:34
Definition: application.cc:10
virtual void First() override
Definition: list_iterator.h:40
Definition: list_interface.h:14
virtual ~ListIterator() override
Definition: list_iterator.h:37
virtual bool IsDone() const override
Definition: list_iterator.h:52
Definition: iterator_interface.h:14
virtual void Next() override
Definition: list_iterator.h:46
Definition: list_iterator.h:17
virtual Item CurrentItem() const override
Definition: list_iterator.h:58