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 $Id: RefVectorIterator.h,v 1.8 2007/12/21 22:42:30 wmtan Exp $
10 
11 ----------------------------------------------------------------------*/
12 
13 #include <memory>
17 
18 namespace edm {
19 
20  template <typename C, typename T = typename Ref<C>::value_type, typename F = typename Ref<C>::finder_type>
21  class RefVectorIterator : public std::iterator <std::random_access_iterator_tag, Ref<C, T, F> > {
22  public:
24  typedef Ref<C, T, F> const const_reference; // Otherwise boost::iterator_reference assumes '*it' returns 'Ref &'
25  typedef const_reference reference; // This to prevent compilation of code that tries to modify the RefVector
26  // through this iterator
27  typedef typename value_type::key_type key_type;
28 
30  typedef std::ptrdiff_t difference;
31  typedef typename std::vector<RefItem<key_type> >::const_iterator itemIter;
33  explicit RefVectorIterator(RefCore const& product, itemIter const& it) :
34  product_(product), iter_(it) {}
35  reference operator*() const {
36  RefItem<key_type> const& item = *iter_;
37  return value_type(product_, item);
38  }
40  RefItem<key_type> const& item = iter_[n];
41  return value_type(product_, item);
42  }
43  std::auto_ptr<value_type> operator->() const {
44  RefItem<key_type> const& item = *iter_;
45  return std::auto_ptr<value_type>(new value_type(product_, item));
46  }
47  iterator & operator++() {++iter_; return *this;}
48  iterator & operator--() {--iter_; return *this;}
49  iterator & operator+=(difference n) {iter_ += n; return *this;}
50  iterator & operator-=(difference n) {iter_ -= n; return *this;}
51 
52  iterator operator++(int) {iterator it(*this); ++iter_; return it;}
53  iterator operator--(int) {iterator it(*this); --iter_; return it;}
54  iterator operator+(difference n) const {iterator it(*this); it.iter_+=n; return it;}
55  iterator operator-(difference n) const {iterator it(*this); it.iter_-=n; return it;}
56 
57  difference operator-(iterator const& rhs) const {return this->iter_ - rhs.iter_;}
58 
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  bool operator<=(iterator const& rhs) const {return this->iter_ <= rhs.iter_;}
64  bool operator>=(iterator const& rhs) const {return this->iter_ >= rhs.iter_;}
65 
66  private:
69  };
70 
71  template <typename C, typename T, typename F>
72  inline
74  return iter + n;
75  }
76 }
77 #endif
bool operator>(iterator const &rhs) const
Association< C > operator+(const Association< C > &a1, const Association< C > &a2)
Definition: Association.h:117
std::auto_ptr< value_type > operator->() const
iterator & operator-=(difference n)
Container::value_type value_type
reference operator*() const
Ref< C, T, F > const const_reference
RefVectorIterator(RefCore const &product, itemIter const &it)
iterator operator-(difference n) const
bool operator==(iterator const &rhs) const
iterator & operator+=(difference n)
RefVectorIterator< C, T, F > iterator
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
bool operator!=(iterator const &rhs) const
std::vector< RefItem< key_type > >::const_iterator itemIter
boost::remove_cv< typename boost::remove_reference< argument_type >::type >::type key_type
Definition: Ref.h:167
iterator operator+(difference n) const
value_type::key_type key_type
difference operator-(iterator const &rhs) const