Go to the documentation of this file.00001 #ifndef DataFormats_Common_RefVectorIterator_h
00002 #define DataFormats_Common_RefVectorIterator_h
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include <memory>
00014 #include "DataFormats/Common/interface/RefCore.h"
00015 #include "DataFormats/Common/interface/Ref.h"
00016
00017 namespace edm {
00018
00019 template <typename C, typename T = typename Ref<C>::value_type, typename F = typename Ref<C>::finder_type>
00020 class RefVectorIterator : public std::iterator <std::random_access_iterator_tag, Ref<C, T, F> > {
00021 public:
00022 typedef Ref<C, T, F> value_type;
00023 typedef Ref<C, T, F> const const_reference;
00024 typedef const_reference reference;
00025
00026 typedef typename value_type::key_type key_type;
00027
00028 typedef RefVectorIterator<C, T, F> iterator;
00029 typedef std::ptrdiff_t difference;
00030 typedef typename std::vector<key_type>::const_iterator keyIter;
00031 RefVectorIterator() : product_(), iter_() {}
00032 explicit RefVectorIterator(RefCore const& product, keyIter const& it) :
00033 product_(product), iter_(it) {}
00034 reference operator*() const {
00035 key_type const& key = *iter_;
00036 return value_type(product_, key);
00037 }
00038 reference operator[](difference n) const {
00039 key_type const& key = iter_[n];
00040 return value_type(product_, key);
00041 }
00042 std::auto_ptr<value_type> operator->() const {
00043 key_type const& key = *iter_;
00044 return std::auto_ptr<value_type>(new value_type(product_, key));
00045 }
00046 iterator & operator++() {++iter_; return *this;}
00047 iterator & operator--() {--iter_; return *this;}
00048 iterator & operator+=(difference n) {iter_ += n; return *this;}
00049 iterator & operator-=(difference n) {iter_ -= n; return *this;}
00050
00051 iterator operator++(int) {iterator it(*this); ++iter_; return it;}
00052 iterator operator--(int) {iterator it(*this); --iter_; return it;}
00053 iterator operator+(difference n) const {iterator it(*this); it.iter_+=n; return it;}
00054 iterator operator-(difference n) const {iterator it(*this); it.iter_-=n; return it;}
00055
00056 difference operator-(iterator const& rhs) const {return this->iter_ - rhs.iter_;}
00057
00058 bool operator==(iterator const& rhs) const {return this->iter_ == rhs.iter_;}
00059 bool operator!=(iterator const& rhs) const {return this->iter_ != rhs.iter_;}
00060 bool operator<(iterator const& rhs) const {return this->iter_ < rhs.iter_;}
00061 bool operator>(iterator const& rhs) const {return this->iter_ > rhs.iter_;}
00062 bool operator<=(iterator const& rhs) const {return this->iter_ <= rhs.iter_;}
00063 bool operator>=(iterator const& rhs) const {return this->iter_ >= rhs.iter_;}
00064
00065 private:
00066 RefCore product_;
00067 keyIter iter_;
00068 };
00069
00070 template <typename C, typename T, typename F>
00071 inline
00072 RefVectorIterator<C, T, F> operator+(typename RefVectorIterator<C, T, F>::difference n, RefVectorIterator<C, T, F> const& iter) {
00073 return iter + n;
00074 }
00075 }
00076 #endif