Iterator.h
Go to the documentation of this file.
1 #ifndef WIRECELL_IWIREDATABASE
2 #define WIRECELL_IWIREDATABASE
3 
4 
6 #include <iterator>
7 
8 namespace WireCell {
9 
10  /** This iterator provides a facade over a WireCell::IteratorBase<ValueType>.
11  *
12  * This facade can be passed by value without slicing the abstract
13  * base iterator.
14  */
15  template <typename ValueType>
16  class Iterator : public std::iterator<std::forward_iterator_tag, ValueType> {
17  public:
19 
20  // Produce an empty/invalid iterator.
21  Iterator() : base_itr(0) { }
22 
23 
25  if (other.base_itr) {
26  base_itr = other.base_itr->clone();
27  }
28  }
29  Iterator(const BaseIteratorType& base_other) : base_itr(0) {
30  base_itr = base_other.clone();
31  }
33  if (base_itr) {
34  delete base_itr;
35  }
36  base_itr = 0;
37  }
38 
39  bool operator==(const Iterator& rhs) const {
40  if (base_itr == rhs.base_itr) return true;
41  if (!base_itr || !rhs.base_itr) return false;
42  return *base_itr == *rhs.base_itr;
43  }
44  bool operator!=(const Iterator& rhs) const {
45  if (base_itr && rhs.base_itr) {
46  return *base_itr != *rhs.base_itr;
47  }
48  return base_itr != rhs.base_itr;
49  }
50 
52  ++(*base_itr);
53  return *this;
54  }
55 
56  ValueType operator*() const {
57  return *(*base_itr);
58  }
59 
60  Iterator& operator=(const Iterator& rhs) {
61  if (base_itr) {
62  delete base_itr;
63  }
64  base_itr = rhs.base_itr->clone();
65  return *this;
66  }
67 
68  private:
69  BaseIteratorType* base_itr;
70  };
71 
72 }
73 
74 
75 #endif
intermediate_table::iterator iterator
Iterator & operator=(const Iterator &rhs)
Definition: Iterator.h:60
ValueType operator*() const
Definition: Iterator.h:56
bool operator==(const Iterator &rhs) const
Definition: Iterator.h:39
Iterator & operator++()
Definition: Iterator.h:51
virtual IteratorBase * clone() const =0
WireCell::IteratorBase< ValueType > BaseIteratorType
Definition: Iterator.h:18
Definition: Main.h:22
Iterator(const BaseIteratorType &base_other)
Definition: Iterator.h:29
Iterator(const Iterator &other)
Definition: Iterator.h:24
BaseIteratorType * base_itr
Definition: Iterator.h:69
bool operator!=(const Iterator &rhs) const
Definition: Iterator.h:44