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>
15 
16 namespace edm {
17 
18  template <typename C, typename T = typename Ref<C>::value_type, typename F = typename Ref<C>::finder_type>
19  class RefVectorIterator : public std::iterator <std::random_access_iterator_tag, Ref<C, T, F> > {
20  public:
22  typedef Ref<C, T, F> const const_reference; // Otherwise boost::iterator_reference assumes '*it' returns 'Ref &'
23  typedef const_reference reference; // This to prevent compilation of code that tries to modify the RefVector
24  // through this iterator
25  typedef typename value_type::key_type key_type;
26 
28  typedef std::ptrdiff_t difference;
29  typedef typename std::vector<key_type>::const_iterator keyIter;
31  explicit RefVectorIterator(RefCore const& product, keyIter const& it) :
32  product_(product), iter_(it) {}
33  reference operator*() const {
34  key_type const& key = *iter_;
35  return value_type(product_, key);
36  }
38  key_type const& key = iter_[n];
39  return value_type(product_, key);
40  }
41 
42  class RefProxy {
43  public:
44  RefProxy(value_type const& ref) : ref_(ref) { }
45  value_type const* operator->() const { return &ref_; }
46  private:
48  };
49 
50  RefProxy operator->() const {
51  key_type const& key = *iter_;
52  return RefProxy(value_type(product_, key));
53  }
54  iterator & operator++() {++iter_; return *this;}
55  iterator & operator--() {--iter_; return *this;}
56  iterator & operator+=(difference n) {iter_ += n; return *this;}
57  iterator & operator-=(difference n) {iter_ -= n; return *this;}
58 
59  iterator operator++(int) {iterator it(*this); ++iter_; return it;}
60  iterator operator--(int) {iterator it(*this); --iter_; return it;}
61  iterator operator+(difference n) const {iterator it(*this); it.iter_+=n; return it;}
62  iterator operator-(difference n) const {iterator it(*this); it.iter_-=n; return it;}
63 
64  difference operator-(iterator const& rhs) const {return this->iter_ - rhs.iter_;}
65 
66  bool operator==(iterator const& rhs) const {return this->iter_ == rhs.iter_;}
67  bool operator!=(iterator const& rhs) const {return this->iter_ != rhs.iter_;}
68  bool operator<(iterator const& rhs) const {return this->iter_ < rhs.iter_;}
69  bool operator>(iterator const& rhs) const {return this->iter_ > rhs.iter_;}
70  bool operator<=(iterator const& rhs) const {return this->iter_ <= rhs.iter_;}
71  bool operator>=(iterator const& rhs) const {return this->iter_ >= rhs.iter_;}
72 
73  key_type key() const { return *iter_;}
74 
75  private:
78  };
79 
80  template <typename C, typename T, typename F>
81  inline
83  return iter + n;
84  }
85 }
86 #endif
value_type const * operator->() const
bool operator>(iterator const &rhs) const
RefVectorIterator(RefCore const &product, keyIter const &it)
Association< C > operator+(const Association< C > &a1, const Association< C > &a2)
Definition: Association.h:121
iterator & operator-=(difference n)
reference operator*() const
Ref< C, T, F > const const_reference
RefProxy operator->() const
iterator operator-(difference n) const
bool operator==(iterator const &rhs) const
iterator & operator+=(difference n)
RefVectorIterator< C, T, F > iterator
Container::value_type value_type
std::vector< key_type >::const_iterator keyIter
bool operator<(iterator const &rhs) const
reference operator[](difference n) const
bool operator<=(iterator const &rhs) const
bool operator>=(iterator const &rhs) const
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
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:170
difference operator-(iterator const &rhs) const