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 
33  RefVectorIterator() : refVector_(nullptr), nestedRefVector_(nullptr), iter_(0) {}
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  }
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:
62  };
63 
64  RefProxy operator->() const {
65  if (refVector_)
66  return RefProxy(value_type((*refVector_)[iter_]));
68  }
70  ++iter_;
71  return *this;
72  }
74  --iter_;
75  return *this;
76  }
78  iter_ += n;
79  return *this;
80  }
82  iter_ -= n;
83  return *this;
84  }
85 
87  iterator it(*this);
88  ++iter_;
89  return it;
90  }
92  iterator it(*this);
93  --iter_;
94  return it;
95  }
97  iterator it(*this);
98  it.iter_ += n;
99  return it;
100  }
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
edm::RefVectorIterator::operator>
bool operator>(iterator const &rhs) const
Definition: RefVectorIterator.h:112
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
edm::RefVectorIterator::RefProxy::RefProxy
RefProxy(value_type const &ref)
Definition: RefVectorIterator.h:57
edm::RefVectorIterator::operator--
iterator & operator--()
Definition: RefVectorIterator.h:73
edm::RefVector::size_type
KeyVec::size_type size_type
Definition: RefVector.h:48
edm::RefVectorIterator::operator++
iterator & operator++()
Definition: RefVectorIterator.h:69
edm::RefVectorIterator::value_type
Ref< C, T, F > value_type
Definition: RefVectorIterator.h:22
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::RefVectorIterator::RefProxy::operator->
value_type const * operator->() const
Definition: RefVectorIterator.h:58
edm::RefVectorIterator::nestedRefVector_
RefVector< RefVector< C, T, F >, T, typename refhelper::FindTrait< RefVector< C, T, F >, T >::value > const * nestedRefVector_
Definition: RefVectorIterator.h:125
edm::RefVectorIterator::operator<=
bool operator<=(iterator const &rhs) const
Definition: RefVectorIterator.h:113
edm::RefVectorIterator::RefProxy
Definition: RefVectorIterator.h:55
RefTraits.h
edm::RefVectorIterator::operator->
RefProxy operator->() const
Definition: RefVectorIterator.h:64
edm::RefVector
Definition: EDProductfwd.h:27
edm::Ref::finder_type
F finder_type
Definition: Ref.h:162
edm::Ref
Definition: AssociativeIterator.h:58
edm::RefVectorIterator::operator[]
reference operator[](difference n) const
Definition: RefVectorIterator.h:48
edm::RefVectorIterator::operator+=
iterator & operator+=(difference n)
Definition: RefVectorIterator.h:77
F
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:163
edm::RefVectorIterator::operator-=
iterator & operator-=(difference n)
Definition: RefVectorIterator.h:81
edm::RefVectorIterator::RefVectorIterator
RefVectorIterator(RefVector< C, T, F > const *refVector, typename RefVector< C, T, F >::size_type iter)
Definition: RefVectorIterator.h:35
edm::RefVectorIterator::operator<
bool operator<(iterator const &rhs) const
Definition: RefVectorIterator.h:111
edm::RefVectorIterator::const_reference
const Ref< C, T, F > const_reference
Definition: RefVectorIterator.h:23
edm::RefVectorIterator::keyIter
std::vector< key_type >::const_iterator keyIter
Definition: RefVectorIterator.h:30
edm::RefVectorIterator::operator++
iterator operator++(int)
Definition: RefVectorIterator.h:86
edm::RefVectorIterator::RefVectorIterator
RefVectorIterator()
Definition: RefVectorIterator.h:33
edm::RefVectorIterator::MemberIter
std::vector< void const * >::const_iterator MemberIter
Definition: RefVectorIterator.h:31
RefVector.h
edm::RefVectorIterator::key
key_type key() const
Definition: RefVectorIterator.h:116
edm::RefVectorIterator::iter_
RefVector< C, T, F >::size_type iter_
Definition: RefVectorIterator.h:126
edm::RefVectorIterator::operator--
iterator operator--(int)
Definition: RefVectorIterator.h:91
value
Definition: value.py:1
edm::RefVectorIterator::operator-
iterator operator-(difference n) const
Definition: RefVectorIterator.h:101
edm::RefVectorIterator::reference
const_reference reference
Definition: RefVectorIterator.h:24
reco::JetExtendedAssociation::value_type
Container::value_type value_type
Definition: JetExtendedAssociation.h:30
edm::RefVectorIterator::refVector_
RefVector< C, T, F > const * refVector_
Definition: RefVectorIterator.h:123
edm::RefVectorIterator::RefVectorIterator
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)
Definition: RefVectorIterator.h:38
edm::RefVectorIterator::RefProxy::ref_
value_type ref_
Definition: RefVectorIterator.h:61
edm::Ref::key_type
std::remove_cv< typename std::remove_reference< argument_type >::type >::type key_type
Definition: Ref.h:164
edm::RefVectorIterator::operator==
bool operator==(iterator const &rhs) const
Definition: RefVectorIterator.h:109
edm::RefVectorIterator::iterator
RefVectorIterator< C, T, F > iterator
Definition: RefVectorIterator.h:28
Ref.h
edm::RefVectorIterator::difference
std::ptrdiff_t difference
Definition: RefVectorIterator.h:29
T
long double T
Definition: Basic3DVectorLD.h:48
relativeConstraints.value
value
Definition: relativeConstraints.py:53
edm::RefVectorIterator
Definition: EDProductfwd.h:33
edm::RefVectorIterator::operator!=
bool operator!=(iterator const &rhs) const
Definition: RefVectorIterator.h:110
edm::RefVectorIterator::operator-
difference operator-(iterator const &rhs) const
Definition: RefVectorIterator.h:107
edm::RefVectorIterator::key_type
value_type::key_type key_type
Definition: RefVectorIterator.h:26
edm::refhelper::FindTrait
Definition: RefTraits.h:41
edm::RefVectorIterator::operator*
reference operator*() const
Definition: RefVectorIterator.h:43
edm::operator+
Association< C > operator+(const Association< C > &a1, const Association< C > &a2)
Definition: Association.h:122
edm::RefVectorIterator::operator>=
bool operator>=(iterator const &rhs) const
Definition: RefVectorIterator.h:114
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
edm::RefVectorIterator::operator+
iterator operator+(difference n) const
Definition: RefVectorIterator.h:96