ATLAS Offline Software
Loading...
Searching...
No Matches
combined_ordered_iterator.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef combined_ordered_iterator_H
6#define combined_ordered_iterator_H
7
14
15namespace LArBadChanImpl {
16
17 template <class Iter, class CMP>
19 public:
20
21 typedef typename Iter::value_type value_type;
22
23 combined_ordered_iterator( const Iter& b1, const Iter& e1,
24 const Iter& b2, const Iter& e2, const CMP& cmp) :
25 m_b1(b1), m_e1(e1), m_b2(b2), m_e2(e2), m_cmp(cmp)
26 {
27 m_first = m_cmp( *m_b1, *m_b2);
28 }
29
30 combined_ordered_iterator() : m_b1(Iter()), m_e1(Iter()),
31 m_b2(Iter()), m_e2(Iter()), m_cmp(CMP()),
32 m_first(false){}
33
35 advance();
37 else if ( !other_at_the_end()) {
38 if (m_cmp(other(), current())) switch_to_other(); // we must switch to the other container
39 }
40 return *this;
41 }
42
45 operator++();
46 return tmp;
47 }
48
50 return current();
51 }
52
53 operator bool() const {return m_b1 != m_e1 || m_b2 != m_e2;}
54
56 if (at_the_end()) return ! other.at_the_end();
57 else if (other.at_the_end()) return true;
58 else return current_iter() != other.current_iter();
59 }
60
62 return !operator!=(other);
63 }
64
65 private:
66
67 Iter m_b1;
68 Iter m_e1;
69 Iter m_b2;
70 Iter m_e2;
71 CMP m_cmp;
72 bool m_first;
73
74 const value_type& other() const {return m_first ? *m_b2 : *m_b1;}
75
76 const value_type& current() const {return m_first ? *m_b1 : *m_b2;}
77
78 const Iter& current_iter() const {return m_first ? m_b1 : m_b2;}
79
80 const value_type& next_in_same() const {
81 Iter tmp = (m_first? m_b1 : m_b2);
82 return *(++tmp);
83 }
84
85 void advance() {
86 if (m_first) {
87 if (m_b1 != m_e1) ++m_b1;
88 }
89 else {
90 if (m_b2 != m_e2) ++m_b2;
91 }
92 }
93
94 bool at_the_end() const {
95 return m_first ? (m_b1 == m_e1) : (m_b2 == m_e2);
96 }
97
98 bool other_at_the_end() const {
99 return m_first ? (m_b2 == m_e2) : (m_b1 == m_e1);
100 }
101
103
104 };
105
106}
107
108#endif
combined_ordered_iterator(const Iter &b1, const Iter &e1, const Iter &b2, const Iter &e2, const CMP &cmp)
bool operator==(const combined_ordered_iterator &other) const
bool operator!=(const combined_ordered_iterator &other) const
A helper class that provides iterators over elements in two separate ordered containers as if the ele...