00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef OPENMS_KERNEL_AREAITERATOR_H
00028 #define OPENMS_KERNEL_AREAITERATOR_H
00029
00030
00031 #include <OpenMS/CONCEPT/Types.h>
00032
00033
00034 #include <iterator>
00035
00036 namespace OpenMS
00037 {
00038 namespace Internal
00039 {
00048 template<class ValueT, class ReferenceT, class PointerT, class SpectrumIteratorT, class PeakIteratorT>
00049 class AreaIterator : public std::iterator<std::forward_iterator_tag, ValueT>
00050 {
00051 public:
00052 typedef DoubleReal CoordinateType;
00053 typedef ValueT PeakType;
00054 typedef SpectrumIteratorT SpectrumIteratorType;
00055 typedef PeakIteratorT PeakIteratorType;
00056
00060
00061 typedef ValueT value_type;
00063 typedef ReferenceT reference;
00065 typedef PointerT pointer;
00067 typedef unsigned int difference_type;
00069
00071 AreaIterator(SpectrumIteratorType begin, SpectrumIteratorType end, CoordinateType low_mz, CoordinateType high_mz)
00072 : current_scan_(begin),
00073 end_scan_(end),
00074 low_mz_(low_mz),
00075 high_mz_(high_mz)
00076 {
00077 nextScan_();
00078 }
00079
00081 AreaIterator( SpectrumIteratorType spectrum_end, PeakIteratorType peak_end )
00082 : current_scan_(spectrum_end),
00083 end_scan_(spectrum_end),
00084 current_peak_(peak_end),
00085 end_peak_(peak_end)
00086 {
00087 }
00088
00090 ~AreaIterator()
00091 {
00092 }
00093
00095 AreaIterator(const AreaIterator& rhs)
00096 : current_scan_(rhs.current_scan_),
00097 end_scan_(rhs.end_scan_),
00098 current_peak_(rhs.current_peak_),
00099 end_peak_(rhs.end_peak_),
00100 low_mz_(rhs.low_mz_),
00101 high_mz_(rhs.high_mz_)
00102 {
00103 }
00104
00106 AreaIterator& operator=(const AreaIterator& rhs)
00107 {
00108 if (&rhs == this) return *this;
00109
00110 current_scan_ = rhs.current_scan_;
00111 end_scan_ = rhs.end_scan_;
00112 current_peak_ = rhs.current_peak_;
00113 end_peak_ = rhs.end_peak_;
00114 low_mz_ = rhs.low_mz_;
00115 high_mz_ = rhs.high_mz_;
00116
00117 return *this;
00118 }
00119
00121 bool operator==(const AreaIterator& rhs) const
00122 {
00123 return ( &(*current_peak_) == &(*(rhs.current_peak_)))
00124 ||
00125 ( current_peak_ == end_peak_ &&
00126 current_scan_ == end_scan_ &&
00127 rhs.current_scan_ == rhs.end_scan_ &&
00128 rhs.current_peak_ == rhs.end_peak_ ) ;
00129 }
00130
00132 bool operator!=(const AreaIterator& rhs) const
00133 {
00134 return !(*this == rhs);
00135 }
00136
00138 AreaIterator& operator++()
00139 {
00140 ++current_peak_;
00141
00142 if (current_peak_ == end_peak_)
00143 {
00144 ++current_scan_;
00145 nextScan_();
00146 }
00147 return (*this);
00148 }
00149
00151 AreaIterator operator++(int)
00152 {
00153 AreaIterator tmp(*this);
00154 ++(*this);
00155 return tmp;
00156 }
00157
00159 reference operator*() const
00160 {
00161 return current_peak_.operator*();
00162 }
00163
00165 pointer operator->() const
00166 {
00167 return current_peak_.operator->();
00168 }
00169
00171 CoordinateType getRT() const
00172 {
00173 return current_scan_->getRT();
00174 }
00175
00176 private:
00177
00178 void nextScan_()
00179 {
00180 while (true)
00181 {
00182
00183 while (current_scan_ != end_scan_ && current_scan_->getMSLevel()!=1)
00184 {
00185 ++current_scan_;
00186 }
00187 if (current_scan_ == end_scan_)
00188 {
00189 current_peak_ = end_peak_ = PeakIteratorType();
00190 return;
00191 }
00192 current_peak_ = current_scan_->MZBegin(low_mz_);
00193 end_peak_ = current_scan_->MZEnd(high_mz_);
00194 if (current_peak_!=end_peak_)
00195 {
00196 return;
00197 }
00198 ++current_scan_;
00199 }
00200 }
00201
00203 SpectrumIteratorType current_scan_;
00205 SpectrumIteratorType end_scan_;
00207 PeakIteratorType current_peak_;
00209 PeakIteratorType end_peak_;
00211 CoordinateType low_mz_;
00213 CoordinateType high_mz_;
00214
00215 private:
00216
00217 AreaIterator();
00218 };
00219
00220 }
00221 }
00222
00223 #endif