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
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
bool operator>=(iterator const &rhs) const
Association< C > operator+(const Association< C > &a1, const Association< C > &a2)
Definition: Association.h:122
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)
Ref< C, T, F > const const_reference
std::vector< void const * >::const_iterator MemberIter
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)
RefVectorIterator< C, T, F > iterator
Definition: value.py:1
bool operator!=(iterator const &rhs) const
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
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
const_reference reference
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
value_type::key_type key_type