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,
36  typename RefVector<C, T, F>::size_type iter) :
37  refVector_(refVector), nestedRefVector_(nullptr), iter_(iter) {}
38 
40  typename RefVector<C, T, F>::size_type iter) :
41  refVector_(nullptr), nestedRefVector_(refVector), iter_(iter) {}
42 
43  reference operator*() const {
44  if(refVector_) return (*refVector_)[iter_];
45  return (*nestedRefVector_)[iter_];
46  }
47  reference operator[](difference n) const {
48  typename RefVector<C, T, F>::size_type j = iter_ + n;
49  if(refVector_) return (*refVector_)[j];
50  return (*nestedRefVector_)[j];
51  }
52 
53  class RefProxy {
54  public:
55  RefProxy(value_type const& ref) : ref_(ref) { }
56  value_type const* operator->() const { return &ref_; }
57  private:
58  value_type ref_;
59  };
60 
61  RefProxy operator->() const {
63  return RefProxy(value_type((*nestedRefVector_)[iter_]));
64  }
65  iterator & operator++() {++iter_; return *this;}
66  iterator & operator--() {--iter_; return *this;}
67  iterator & operator+=(difference n) {iter_ += n; return *this;}
68  iterator & operator-=(difference n) {iter_ -= n; return *this;}
69 
70  iterator operator++(int) {iterator it(*this); ++iter_; return it;}
71  iterator operator--(int) {iterator it(*this); --iter_; return it;}
72  iterator operator+(difference n) const {iterator it(*this); it.iter_+=n; return it;}
73  iterator operator-(difference n) const {iterator it(*this); it.iter_-=n; return it;}
74 
75  difference operator-(iterator const& rhs) const {return this->iter_ - rhs.iter_;}
76 
77  bool operator==(iterator const& rhs) const {return this->iter_ == rhs.iter_;}
78  bool operator!=(iterator const& rhs) const {return this->iter_ != rhs.iter_;}
79  bool operator<(iterator const& rhs) const {return this->iter_ < rhs.iter_;}
80  bool operator>(iterator const& rhs) const {return this->iter_ > rhs.iter_;}
81  bool operator<=(iterator const& rhs) const {return this->iter_ <= rhs.iter_;}
82  bool operator>=(iterator const& rhs) const {return this->iter_ >= rhs.iter_;}
83 
84  key_type key() const {
85  if(refVector_) return (*refVector_)[iter_].key();
86  return (*nestedRefVector_)[iter_].key();
87  }
88 
89  private:
93  };
94 
95  template <typename C, typename T, typename F>
96  inline
98  return iter + n;
99  }
100 }
101 #endif
value_type const * operator->() const
std::remove_cv< typename std::remove_reference< argument_type >::type >::type key_type
Definition: Ref.h:167
bool operator>(iterator const &rhs) const
RefVector< RefVector< C, T, F >, T, typename refhelper::FindTrait< RefVector< C, T, F >, T >::value > const * nestedRefVector_
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:165
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
key_type key() const
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:281
long double T
iterator operator+(difference n) const
value_type::key_type key_type
difference operator-(iterator const &rhs) const