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.10 2011/02/24 20:20:48 wmtan Exp $
10 
11 ----------------------------------------------------------------------*/
12 
13 #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;
32  explicit RefVectorIterator(RefCore const& product, keyIter const& it) :
33  product_(product), iter_(it) {}
34  reference operator*() const {
35  key_type const& key = *iter_;
36  return value_type(product_, key);
37  }
39  key_type const& key = iter_[n];
40  return value_type(product_, key);
41  }
42  std::auto_ptr<value_type> operator->() const {
43  key_type const& key = *iter_;
44  return std::auto_ptr<value_type>(new value_type(product_, key));
45  }
46  iterator & operator++() {++iter_; return *this;}
47  iterator & operator--() {--iter_; return *this;}
48  iterator & operator+=(difference n) {iter_ += n; return *this;}
49  iterator & operator-=(difference n) {iter_ -= n; return *this;}
50 
51  iterator operator++(int) {iterator it(*this); ++iter_; return it;}
52  iterator operator--(int) {iterator it(*this); --iter_; return it;}
53  iterator operator+(difference n) const {iterator it(*this); it.iter_+=n; return it;}
54  iterator operator-(difference n) const {iterator it(*this); it.iter_-=n; return it;}
55 
56  difference operator-(iterator const& rhs) const {return this->iter_ - rhs.iter_;}
57 
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  bool operator>=(iterator const& rhs) const {return this->iter_ >= rhs.iter_;}
64 
65  private:
68  };
69 
70  template <typename C, typename T, typename F>
71  inline
73  return iter + n;
74  }
75 }
76 #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:122
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