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 : public std::iterator<std::random_access_iterator_tag, Ref<C, T, F> > {
21  public:
23  typedef Ref<C, T, F> const const_reference; // Otherwise boost::iterator_reference assumes '*it' returns 'Ref &'
24  typedef const_reference reference; // This to prevent compilation of code that tries to modify the RefVector
25  // through this iterator
26  typedef typename value_type::key_type key_type;
27 
29  typedef std::ptrdiff_t difference;
30  typedef typename std::vector<key_type>::const_iterator keyIter;
31  typedef typename std::vector<void const*>::const_iterator MemberIter;
32 
34 
35  explicit RefVectorIterator(RefVector<C, T, F> const* refVector, typename RefVector<C, T, F>::size_type iter)
36  : refVector_(refVector), nestedRefVector_(nullptr), iter_(iter) {}
37 
40  typename RefVector<C, T, F>::size_type iter)
41  : refVector_(nullptr), nestedRefVector_(refVector), iter_(iter) {}
42 
43  reference operator*() const {
44  if (refVector_)
45  return (*refVector_)[iter_];
46  return (*nestedRefVector_)[iter_];
47  }
48  reference operator[](difference n) const {
50  if (refVector_)
51  return (*refVector_)[j];
52  return (*nestedRefVector_)[j];
53  }
54 
55  class RefProxy {
56  public:
57  RefProxy(value_type const& ref) : ref_(ref) {}
58  value_type const* operator->() const { return &ref_; }
59 
60  private:
61  value_type ref_;
62  };
63 
64  RefProxy operator->() const {
65  if (refVector_)
66  return RefProxy(value_type((*refVector_)[iter_]));
67  return RefProxy(value_type((*nestedRefVector_)[iter_]));
68  }
69  iterator& operator++() {
70  ++iter_;
71  return *this;
72  }
73  iterator& operator--() {
74  --iter_;
75  return *this;
76  }
77  iterator& operator+=(difference n) {
78  iter_ += n;
79  return *this;
80  }
81  iterator& operator-=(difference n) {
82  iter_ -= n;
83  return *this;
84  }
85 
86  iterator operator++(int) {
87  iterator it(*this);
88  ++iter_;
89  return it;
90  }
91  iterator operator--(int) {
92  iterator it(*this);
93  --iter_;
94  return it;
95  }
96  iterator operator+(difference n) const {
97  iterator it(*this);
98  it.iter_ += n;
99  return it;
100  }
101  iterator operator-(difference n) const {
102  iterator it(*this);
103  it.iter_ -= n;
104  return it;
105  }
106 
107  difference operator-(iterator const& rhs) const { return this->iter_ - rhs.iter_; }
108 
109  bool operator==(iterator const& rhs) const { return this->iter_ == rhs.iter_; }
110  bool operator!=(iterator const& rhs) const { return this->iter_ != rhs.iter_; }
111  bool operator<(iterator const& rhs) const { return this->iter_ < rhs.iter_; }
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 
116  key_type key() const {
117  if (refVector_)
118  return (*refVector_)[iter_].key();
119  return (*nestedRefVector_)[iter_].key();
120  }
121 
122  private:
127  };
128 
129  template <typename C, typename T, typename F>
131  RefVectorIterator<C, T, F> const& iter) {
132  return iter + n;
133  }
134 } // namespace edm
135 #endif
value_type const * operator->() const
RefVector< RefVector< C, T, F >, T, typename refhelper::FindTrait< RefVector< C, T, F >, T >::value > const * nestedRefVector_
std::remove_cv< typename std::remove_reference< argument_type >::type >::type key_type
Definition: Ref.h:164
bool operator>(iterator const &rhs) const
RefVectorIterator(RefVector< C, T, F > const *refVector, typename RefVector< C, T, F >::size_type iter)
#define nullptr
iterator & operator-=(difference n)
reference operator*() const
Ref< C, T, F > const const_reference
RefProxy operator->() const
std::vector< void const * >::const_iterator MemberIter
KeyVec::size_type size_type
Definition: RefVector.h:48
RefVector< C, T, F > const * refVector_
iterator operator-(difference n) const
bool operator==(iterator const &rhs) const
iterator & operator+=(difference n)
RefVectorIterator< C, T, F > iterator
Definition: value.py:1
std::vector< key_type >::const_iterator keyIter
bool operator<(iterator const &rhs) const
RefVector< C, T, F >::size_type iter_
F finder_type
Definition: Ref.h:162
reference operator[](difference n) const
bool operator<=(iterator const &rhs) const
HLT enums.
bool operator>=(iterator const &rhs) 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)
const_reference reference
RefProxy(value_type const &ref)
bool operator!=(iterator const &rhs) const
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:163
long double T
iterator operator+(difference n) const
value_type::key_type key_type
difference operator-(iterator const &rhs) const