ATLAS Offline Software
RangedItr.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef DERIVATIONFRAMEWORKTRIGGER_RANGEDITR_H
6 #define DERIVATIONFRAMEWORKTRIGGER_RANGEDITR_H
7 
8 
9 #include <iterator> //std::distance, iterator_traits
10 #include <type_traits>
11 
12 namespace DerivationFramework { namespace TriggerMatchingUtils {
17 template <typename T>
18  class RangedItr {
19  protected:
20  using tr = std::iterator_traits<T>;
21  static_assert(std::is_base_of<std::bidirectional_iterator_tag, typename tr::iterator_category>::value, "Templated type must be a random access iterator");
22  public:
23  // A full implementation of this idea would allow for any input
24  // iterator type. For this version, just require at least bidirectional
25 
26  using iterator_category = std::bidirectional_iterator_tag;
27  using value_type = typename tr::value_type;
28  using reference = typename tr::reference;
29  using pointer = typename tr::pointer;
30  using difference_type = typename tr::difference_type;
31 
33  RangedItr() = default;
34 
36  RangedItr(const T& begin, const T& end) :
37  RangedItr(begin, end, begin) {}
38 
40  RangedItr(const T& begin, const T& end, const T& position) :
41  m_begin(begin), m_end(end), m_position(position) {}
42 
44  reference operator*() { return m_position.operator*(); }
45  pointer operator->() { return m_position.operator->(); }
46 
48  ++m_position;
49  return *this;
50  }
52  RangedItr ret = *this;
53  ++m_position;
54  return ret;
55  }
56 
58  --m_position;
59  return *this;
60  }
62  RangedItr ret = *this;
63  --m_position;
64  return ret;
65  }
66 
67  bool operator==(const RangedItr& other) {
68  return m_begin == other.m_begin &&
69  m_end == other.m_end &&
70  m_position == other.m_position;
71  }
72 
73  bool operator!=(const RangedItr& other) {
74  return !(*this == other);
75  }
76 
78  bool exhausted() const { return m_position == m_end; }
79 
81  void restart() { m_position = m_begin; }
82 
84  RangedItr begin() const { return RangedItr(m_begin, m_end, m_begin); }
85  RangedItr end() const { return RangedItr(m_begin, m_end, m_end); }
87 
89  operator T() const { return m_position; }
90  private:
92  T m_end;
94 
95  }; //> end class RangedItr
96 } } //> end namespace DerivationFramework::TriggerMatchingUtils
97 #endif //> !DERIVATIONFRAMEWORKTRIGGER_RANGEDITR_H
DerivationFramework::TriggerMatchingUtils::RangedItr::operator--
RangedItr & operator--()
Definition: RangedItr.h:57
DerivationFramework::TriggerMatchingUtils::RangedItr::operator++
RangedItr & operator++()
Definition: RangedItr.h:47
DerivationFramework::TriggerMatchingUtils::RangedItr::difference_type
typename tr::difference_type difference_type
Definition: RangedItr.h:30
DerivationFramework::TriggerMatchingUtils::RangedItr::iterator_category
std::bidirectional_iterator_tag iterator_category
Definition: RangedItr.h:26
DerivationFramework::TriggerMatchingUtils::RangedItr::RangedItr
RangedItr(const T &begin, const T &end, const T &position)
Construct from a beginning, an end and a starting position.
Definition: RangedItr.h:40
athena.value
value
Definition: athena.py:122
DerivationFramework::TriggerMatchingUtils::RangedItr::operator->
pointer operator->()
Definition: RangedItr.h:45
reference
Definition: hcg.cxx:437
DerivationFramework::TriggerMatchingUtils::RangedItr::operator*
reference operator*()
Iterator interface.
Definition: RangedItr.h:44
DerivationFramework::TriggerMatchingUtils::RangedItr::size
difference_type size() const
Definition: RangedItr.h:86
ret
T ret(T t)
Definition: rootspy.cxx:260
DerivationFramework::TriggerMatchingUtils::RangedItr::operator!=
bool operator!=(const RangedItr &other)
Definition: RangedItr.h:73
DerivationFramework::TriggerMatchingUtils::RangedItr
utility class that acts wraps a bidirectional iterator.
Definition: RangedItr.h:18
DerivationFramework::TriggerMatchingUtils::RangedItr::m_end
T m_end
Definition: RangedItr.h:92
DerivationFramework
THE reconstruction tool.
Definition: ParticleSortingAlg.h:24
DerivationFramework::TriggerMatchingUtils::RangedItr::operator--
RangedItr operator--(int)
Definition: RangedItr.h:61
DerivationFramework::TriggerMatchingUtils::RangedItr::begin
RangedItr begin() const
Make this act as a range.
Definition: RangedItr.h:84
DerivationFramework::TriggerMatchingUtils::RangedItr::operator==
bool operator==(const RangedItr &other)
Definition: RangedItr.h:67
DerivationFramework::TriggerMatchingUtils::RangedItr::m_begin
T m_begin
Definition: RangedItr.h:91
DerivationFramework::TriggerMatchingUtils::RangedItr::restart
void restart()
Reset this iterator to its start.
Definition: RangedItr.h:81
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
DerivationFramework::TriggerMatchingUtils::RangedItr::end
RangedItr end() const
Definition: RangedItr.h:85
DerivationFramework::TriggerMatchingUtils::RangedItr::tr
std::iterator_traits< T > tr
Definition: RangedItr.h:20
dq_make_web_display.reference
reference
Definition: dq_make_web_display.py:44
DerivationFramework::TriggerMatchingUtils::RangedItr::pointer
typename tr::pointer pointer
Definition: RangedItr.h:29
DerivationFramework::TriggerMatchingUtils::RangedItr::RangedItr
RangedItr(const T &begin, const T &end)
Construct from a beginning and an end.
Definition: RangedItr.h:36
DerivationFramework::TriggerMatchingUtils::RangedItr::operator++
RangedItr operator++(int)
Definition: RangedItr.h:51
value_type
Definition: EDM_MasterSearch.h:11
DerivationFramework::TriggerMatchingUtils::RangedItr::exhausted
bool exhausted() const
Is this iterator exhausted?
Definition: RangedItr.h:78
Amg::distance
float distance(const Amg::Vector3D &p1, const Amg::Vector3D &p2)
calculates the distance between two point in 3D space
Definition: GeoPrimitivesHelpers.h:54
DerivationFramework::TriggerMatchingUtils::RangedItr::m_position
T m_position
Definition: RangedItr.h:93
DerivationFramework::TriggerMatchingUtils::RangedItr::RangedItr
RangedItr()=default
Default Constructor.