Design Patterns
list_traverser.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_TRAVERSER_H_
7 #define OPERATIONAL_ITERATOR_LIST_TRAVERSER_H_
8 
9 #include "list.h"
10 #include "list_iterator.h"
11 
12 namespace operational
13 {
14 namespace iterator
15 {
16 template<class Item>
18 {
19  public:
20  explicit ListTraverser(List<Item>* list);
21  virtual ~ListTraverser();
22 
23  virtual bool Traverse();
24 
25  protected:
26  virtual bool ProcessItem(const Item&) = 0;
27 
28  private:
29  ListIterator<Item> iterator_;
30 };
31 
32 template<class Item>
33 ListTraverser<Item>::ListTraverser(List<Item>* list) : iterator_(list) { }
34 
35 template<class Item>
37 
38 template<class Item>
40 {
41  auto result = false;
42 
43  for (iterator_.First(); !iterator_.IsDone(); iterator_.Next())
44  {
45  result = ProcessItem(iterator_.CurrentItem());
46  if (result == false)
47  {
48  break;
49  }
50  }
51  return result;
52 }
53 }
54 }
55 
56 #endif
57 
Definition: application.cc:10
ListTraverser(List< Item > *list)
Definition: list_traverser.h:33
Definition: list.h:17
virtual bool Traverse()
Definition: list_traverser.h:39
Definition: list_traverser.h:17
virtual bool ProcessItem(const Item &)=0
virtual ~ListTraverser()
Definition: list_traverser.h:36
Definition: list_iterator.h:17