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  std::auto_ptr<value_type> operator->() const {
42  key_type const& key = *iter_;
43  return std::auto_ptr<value_type>(new value_type(product_, key));
44  }
45  iterator & operator++() {++iter_; return *this;}
46  iterator & operator--() {--iter_; return *this;}
47  iterator & operator+=(difference n) {iter_ += n; return *this;}
48  iterator & operator-=(difference n) {iter_ -= n; return *this;}
49 
50  iterator operator++(int) {iterator it(*this); ++iter_; return it;}
51  iterator operator--(int) {iterator it(*this); --iter_; return it;}
52  iterator operator+(difference n) const {iterator it(*this); it.iter_+=n; return it;}
53  iterator operator-(difference n) const {iterator it(*this); it.iter_-=n; return it;}
54 
55  difference operator-(iterator const& rhs) const {return this->iter_ - rhs.iter_;}
56 
57  bool operator==(iterator const& rhs) const {return this->iter_ == rhs.iter_;}
58  bool operator!=(iterator const& rhs) const {return this->iter_ != rhs.iter_;}
59  bool operator<(iterator const& rhs) const {return this->iter_ < rhs.iter_;}
60  bool operator>(iterator const& rhs) const {return this->iter_ > rhs.iter_;}
61  bool operator<=(iterator const& rhs) const {return this->iter_ <= rhs.iter_;}
62  bool operator>=(iterator const& rhs) const {return this->iter_ >= rhs.iter_;}
63 
64  private:
67  };
68 
69  template <typename C, typename T, typename F>
70  inline
72  return iter + n;
73  }
74 }
75 #endif
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
std::auto_ptr< value_type > operator->() const
iterator & operator-=(difference n)
reference operator*() const
Ref< C, T, F > const const_reference
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
list key
Definition: combine.py:13
bool operator>=(iterator const &rhs) const
const_reference reference
bool operator!=(iterator const &rhs) const
boost::remove_cv< typename boost::remove_reference< argument_type >::type >::type key_type
Definition: Ref.h:170
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:281
iterator operator+(difference n) const
value_type::key_type key_type
difference operator-(iterator const &rhs) const