CMS 3D CMS Logo

RefVectorIterator.h
Go to the documentation of this file.
1 #ifndef DataFormats_Common_RefVectorIterator_h
2 #define DataFormats_Common_RefVectorIterator_h
3 
4 /*----------------------------------------------------------------------
5 
6 RefVectorIterator: An iterator for a RefVector
7 Note: this is actually a *const_iterator*
8 
9 
10 ----------------------------------------------------------------------*/
11 
12 #include <memory>
16 
17 namespace edm {
18 
20  class RefVectorIterator {
21  public:
22  using iterator_category = std::random_access_iterator_tag;
24  using const_reference = Ref<C, T, F> const; // Otherwise boost::iterator_reference assumes '*it' returns 'Ref &'
25  using reference = const_reference; // This to prevent compilation of code that tries to modify the RefVector
26  // through this iterator
27  using pointer = Ref<C, T, F> const*;
28  using key_type = typename value_type::key_type;
29 
31  using difference = std::ptrdiff_t;
33  using keyIter = typename std::vector<key_type>::const_iterator;
34  using MemberIter = typename std::vector<void const*>::const_iterator;
35 
36  RefVectorIterator() : refVector_(nullptr), nestedRefVector_(nullptr), iter_(0) {}
37 
38  explicit RefVectorIterator(RefVector<C, T, F> const* refVector, typename RefVector<C, T, F>::size_type iter)
39  : refVector_(refVector), nestedRefVector_(nullptr), iter_(iter) {}
40 
43  typename RefVector<C, T, F>::size_type iter)
44  : refVector_(nullptr), nestedRefVector_(refVector), iter_(iter) {}
45 
46  reference operator*() const {
47  if (refVector_)
48  return (*refVector_)[iter_];
49  return (*nestedRefVector_)[iter_];
50  }
53  if (refVector_)
54  return (*refVector_)[j];
55  return (*nestedRefVector_)[j];
56  }
57 
58  class RefProxy {
59  public:
60  RefProxy(value_type const& ref) : ref_(ref) {}
61  value_type const* operator->() const { return &ref_; }
62 
63  private:
65  };
66 
67  RefProxy operator->() const {
68  if (refVector_)
69  return RefProxy(value_type((*refVector_)[iter_]));
71  }
73  ++iter_;
74  return *this;
75  }
77  --iter_;
78  return *this;
79  }
81  iter_ += n;
82  return *this;
83  }
85  iter_ -= n;
86  return *this;
87  }
88 
90  iterator it(*this);
91  ++iter_;
92  return it;
93  }
95  iterator it(*this);
96  --iter_;
97  return it;
98  }
100  iterator it(*this);
101  it.iter_ += n;
102  return it;
103  }
105  iterator it(*this);
106  it.iter_ -= n;
107  return it;
108  }
109 
110  difference operator-(iterator const& rhs) const { return this->iter_ - rhs.iter_; }
111 
112  bool operator==(iterator const& rhs) const { return this->iter_ == rhs.iter_; }
113  bool operator!=(iterator const& rhs) const { return this->iter_ != rhs.iter_; }
114  bool operator<(iterator const& rhs) const { return this->iter_ < rhs.iter_; }
115  bool operator>(iterator const& rhs) const { return this->iter_ > rhs.iter_; }
116  bool operator<=(iterator const& rhs) const { return this->iter_ <= rhs.iter_; }
117  bool operator>=(iterator const& rhs) const { return this->iter_ >= rhs.iter_; }
118 
119  key_type key() const {
120  if (refVector_)
121  return (*refVector_)[iter_].key();
122  return (*nestedRefVector_)[iter_].key();
123  }
124 
125  private:
130  };
131 
132  template <typename C, typename T, typename F>
134  RefVectorIterator<C, T, F> const& iter) {
135  return iter + n;
136  }
137 } // namespace edm
138 #endif
RefVector< RefVector< C, T, F >, T, typename refhelper::FindTrait< RefVector< C, T, F >, T >::value > const * nestedRefVector_
reference operator*() const
std::remove_cv< typename std::remove_reference< argument_type >::type >::type key_type
Definition: Ref.h:164
typename value_type::key_type key_type
bool operator>=(iterator const &rhs) const
Association< C > operator+(const Association< C > &a1, const Association< C > &a2)
Definition: Association.h:117
reference operator[](difference n) const
RefVectorIterator(RefVector< C, T, F > const *refVector, typename RefVector< C, T, F >::size_type iter)
bool operator<(iterator const &rhs) const
iterator & operator-=(difference n)
typename std::vector< void const * >::const_iterator MemberIter
Ref< C, T, F > const const_reference
KeyVec::size_type size_type
Definition: RefVector.h:48
bool operator<=(iterator const &rhs) const
RefProxy operator->() const
iterator operator-(difference n) const
RefVector< C, T, F > const * refVector_
iterator & operator+=(difference n)
Definition: value.py:1
bool operator!=(iterator const &rhs) const
typename std::vector< key_type >::const_iterator keyIter
RefVector< C, T, F >::size_type iter_
value_type const * operator->() const
F finder_type
Definition: Ref.h:162
std::random_access_iterator_tag iterator_category
HLT enums.
iterator operator+(difference n) const
RefVectorIterator(RefVector< RefVector< C, T, F >, T, typename refhelper::FindTrait< RefVector< C, T, F >, T >::value > const *refVector, typename RefVector< C, T, F >::size_type iter)
bool operator>(iterator const &rhs) const
bool operator==(iterator const &rhs) const
RefProxy(value_type const &ref)
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:163
long double T
difference operator-(iterator const &rhs) const