Go to the documentation of this file.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
00028
00029
00030
00031
00032
00033
00034
00035 #ifndef OPENMS_KERNEL_AREAITERATOR_H
00036 #define OPENMS_KERNEL_AREAITERATOR_H
00037
00038
00039 #include <OpenMS/CONCEPT/Types.h>
00040 #include <OpenMS/KERNEL/PeakIndex.h>
00041
00042
00043 #include <iterator>
00044
00045 namespace OpenMS
00046 {
00047 namespace Internal
00048 {
00057 template <class ValueT, class ReferenceT, class PointerT, class SpectrumIteratorT, class PeakIteratorT>
00058 class AreaIterator :
00059 public std::iterator<std::forward_iterator_tag, ValueT>
00060 {
00061 public:
00062 typedef DoubleReal CoordinateType;
00063 typedef ValueT PeakType;
00064 typedef SpectrumIteratorT SpectrumIteratorType;
00065 typedef PeakIteratorT PeakIteratorType;
00066
00070
00071 typedef ValueT value_type;
00073 typedef ReferenceT reference;
00075 typedef PointerT pointer;
00077 typedef unsigned int difference_type;
00079
00081 AreaIterator(SpectrumIteratorType first, SpectrumIteratorType begin, SpectrumIteratorType end, CoordinateType low_mz, CoordinateType high_mz) :
00082 first_(first),
00083 current_scan_(begin),
00084 end_scan_(end),
00085 low_mz_(low_mz),
00086 high_mz_(high_mz),
00087 is_end_(false)
00088 {
00089 nextScan_();
00090 }
00091
00093 AreaIterator() :
00094 first_(),
00095 current_scan_(),
00096 end_scan_(),
00097 current_peak_(),
00098 end_peak_(),
00099 low_mz_(0.0),
00100 high_mz_(0.0),
00101 is_end_(true)
00102 {}
00103
00105 ~AreaIterator()
00106 {}
00107
00109 AreaIterator(const AreaIterator & rhs) :
00110 first_(rhs.first_),
00111 current_scan_(rhs.current_scan_),
00112 end_scan_(rhs.end_scan_),
00113 current_peak_(rhs.current_peak_),
00114 end_peak_(rhs.end_peak_),
00115 low_mz_(rhs.low_mz_),
00116 high_mz_(rhs.high_mz_),
00117 is_end_(rhs.is_end_)
00118 {}
00119
00121 AreaIterator & operator=(const AreaIterator & rhs)
00122 {
00123 if (&rhs == this) return *this;
00124
00125 is_end_ = rhs.is_end_;
00126
00127 if (!is_end_)
00128 {
00129 first_ = rhs.first_;
00130 current_scan_ = rhs.current_scan_;
00131 end_scan_ = rhs.end_scan_;
00132 current_peak_ = rhs.current_peak_;
00133 end_peak_ = rhs.end_peak_;
00134 low_mz_ = rhs.low_mz_;
00135 high_mz_ = rhs.high_mz_;
00136 }
00137
00138 return *this;
00139 }
00140
00142 bool operator==(const AreaIterator & rhs) const
00143 {
00144
00145 if (is_end_ && rhs.is_end_) return true;
00146
00147
00148 if (!is_end_ && rhs.is_end_) return false;
00149
00150 if (is_end_ && !rhs.is_end_) return false;
00151
00152
00153 return &(*current_peak_) == &(*(rhs.current_peak_));
00154 }
00155
00157 bool operator!=(const AreaIterator & rhs) const
00158 {
00159 return !(*this == rhs);
00160 }
00161
00163 AreaIterator & operator++()
00164 {
00165
00166 if (is_end_) return *this;
00167
00168 ++current_peak_;
00169
00170 if (current_peak_ == end_peak_)
00171 {
00172 ++current_scan_;
00173 nextScan_();
00174 }
00175 return *this;
00176 }
00177
00179 AreaIterator operator++(int)
00180 {
00181 AreaIterator tmp(*this);
00182 ++(*this);
00183 return tmp;
00184 }
00185
00187 reference operator*() const
00188 {
00189 return current_peak_.operator*();
00190 }
00191
00193 pointer operator->() const
00194 {
00195 return current_peak_.operator->();
00196 }
00197
00199 CoordinateType getRT() const
00200 {
00201 return current_scan_->getRT();
00202 }
00203
00205 inline PeakIndex getPeakIndex() const
00206 {
00207 if (is_end_)
00208 {
00209 return PeakIndex();
00210 }
00211 else
00212 {
00213 return PeakIndex(current_scan_ - first_, current_peak_ - current_scan_->begin());
00214 }
00215 }
00216
00217 private:
00218
00219 void nextScan_()
00220 {
00221 while (true)
00222 {
00223
00224 while (current_scan_ != end_scan_ && current_scan_->getMSLevel() != 1)
00225 {
00226 ++current_scan_;
00227 }
00228 if (current_scan_ == end_scan_)
00229 {
00230 is_end_ = true;
00231 return;
00232 }
00233 current_peak_ = current_scan_->MZBegin(low_mz_);
00234 end_peak_ = current_scan_->MZEnd(high_mz_);
00235 if (current_peak_ != end_peak_)
00236 {
00237 return;
00238 }
00239 ++current_scan_;
00240 }
00241 }
00242
00244 SpectrumIteratorType first_;
00246 SpectrumIteratorType current_scan_;
00248 SpectrumIteratorType end_scan_;
00250 PeakIteratorType current_peak_;
00252 PeakIteratorType end_peak_;
00254 CoordinateType low_mz_;
00256 CoordinateType high_mz_;
00258 bool is_end_;
00259
00260 };
00261
00262 }
00263 }
00264
00265 #endif