00001 // -*- C++ -*- 00002 // 00003 // DIterator.h is a part of ThePEG - Toolkit for HEP Event Generation 00004 // Copyright (C) 1999-2007 Leif Lonnblad 00005 // 00006 // ThePEG is licenced under version 2 of the GPL, see COPYING for details. 00007 // Please respect the MCnet academic guidelines, see GUIDELINES for details. 00008 // 00009 #ifndef ThePEG_DIterator_H 00010 #define ThePEG_DIterator_H 00011 // This is the declaration of the DIterator class. 00012 00013 #include <iterator> 00014 00015 namespace ThePEG { 00016 00017 template <typename BaseIterator> 00029 class DIterator { 00030 00031 public: 00032 00034 typedef std::iterator_traits<BaseIterator> Traits; 00036 typedef typename Traits::iterator_category iterator_category; 00038 typedef typename Traits::difference_type difference_type; 00040 typedef typename Traits::value_type PtrType; 00042 typedef std::iterator_traits<PtrType> PtrTraits; 00044 typedef typename PtrTraits::value_type value_type; 00046 typedef typename PtrTraits::pointer pointer; 00048 typedef typename PtrTraits::reference reference; 00049 00050 public: 00051 00055 DIterator(const BaseIterator & in): i(in) {} 00056 00060 DIterator(const DIterator & pi): i(pi.i) {} 00061 00062 public: 00063 00067 reference operator*() const { return **i; } 00068 00072 pointer operator->() const { return *i; } 00073 00077 DIterator & operator=(const DIterator & pi) { i = pi.i; return *this; } 00078 00082 DIterator & operator=(const BaseIterator & pi) { i = pi; return *this; } 00083 00087 DIterator & operator++() { ++i; return *this; } 00089 DIterator operator++(int) { DIterator tmp(*this); ++i; return tmp; } 00091 DIterator & operator--() { --i; return *this; } 00093 DIterator operator--(int) { DIterator tmp(*this); --i; return tmp; } 00095 DIterator & operator+=(int n) { i += n; return *this; } 00097 DIterator operator+(int n) { return DIterator(i + n); } 00099 DIterator & operator-=(int n) { i -= n; return *this; } 00101 DIterator operator-(int n) { return DIterator(i - n); } 00103 00108 reference operator[](difference_type n) { return *(i[n]); } 00109 00113 difference_type operator-(const DIterator & pi) { return i - pi.i; } 00114 00118 bool operator==(const DIterator & pi) { return i == pi.i; } 00120 bool operator!=(const DIterator & pi) { return i != pi.i; } 00122 bool operator<(const DIterator & pi) { return i < pi.i; } 00124 bool operator>(const DIterator & pi) { return i > pi.i; } 00126 bool operator<=(const DIterator & pi) { return i <= pi.i; } 00128 bool operator>=(const DIterator & pi) { return i >= pi.i; } 00130 bool operator==(const BaseIterator & bi) { return i == bi; } 00132 bool operator!=(const BaseIterator & bi) { return i != bi; } 00134 bool operator<(const BaseIterator & bi) { return i < bi; } 00136 bool operator>(const BaseIterator & bi) { return i > bi; } 00138 bool operator<=(const BaseIterator & bi) { return i <= bi; } 00140 bool operator>=(const BaseIterator & bi) { return i >= bi; } 00142 00143 private: 00144 00148 BaseIterator i; 00149 00150 private: 00151 00155 DIterator() {} 00156 00157 }; 00158 00159 } 00160 00161 #endif /* ThePEG_DIterator_H */