CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
19  template <typename C, typename T = typename Ref<C>::value_type, typename F = typename Ref<C>::finder_type>
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  }
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:
59  };
60 
61  RefProxy operator->() const {
62  if(refVector_) return RefProxy(value_type((*refVector_)[iter_]));
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
bool operator>(iterator const &rhs) const
RefVector< RefVector< C, T, F >, T, typename refhelper::FindTrait< RefVector< C, T, F >, T >::value > const * nestedRefVector_
Association< C > operator+(const Association< C > &a1, const Association< C > &a2)
Definition: Association.h:121
RefVectorIterator(RefVector< C, T, F > const *refVector, typename RefVector< C, T, F >::size_type iter)
iterator & operator-=(difference n)
reference operator*() const
Ref< C, T, F > const const_reference
#define nullptr
RefProxy operator->() const
std::vector< void const * >::const_iterator MemberIter
KeyVec::size_type size_type
Definition: RefVector.h:49
RefVector< C, T, F > const * refVector_
iterator operator-(difference n) const
bool operator==(iterator const &rhs) const
iterator & operator+=(difference n)
int j
Definition: DBlmapReader.cc:9
RefVectorIterator< C, T, F > iterator
std::vector< key_type >::const_iterator keyIter
bool operator<(iterator const &rhs) const
RefVector< C, T, F >::size_type iter_
reference operator[](difference n) const
bool operator<=(iterator const &rhs) const
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
boost::remove_cv< typename boost::remove_reference< argument_type >::type >::type key_type
Definition: Ref.h:168
difference operator-(iterator const &rhs) const