Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages
AreaIterator.h
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
2 // OpenMS -- Open-Source Mass Spectrometry
3 // --------------------------------------------------------------------------
4 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
5 // ETH Zurich, and Freie Universitaet Berlin 2002-2017.
6 //
7 // This software is released under a three-clause BSD license:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of any author or any participating institution
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
16 // For a full list of authors, refer to the file AUTHORS.
17 // --------------------------------------------------------------------------
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
22 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // --------------------------------------------------------------------------
31 // $Maintainer: Timo Sachsenberg$
32 // $Authors: Marc Sturm $
33 // --------------------------------------------------------------------------
34 
35 #ifndef OPENMS_KERNEL_AREAITERATOR_H
36 #define OPENMS_KERNEL_AREAITERATOR_H
37 
38 // OpenMS includes
39 #include <OpenMS/CONCEPT/Types.h>
41 
42 // STL includes
43 #include <iterator>
44 
45 namespace OpenMS
46 {
47  namespace Internal
48  {
57  template <class ValueT, class ReferenceT, class PointerT, class SpectrumIteratorT, class PeakIteratorT>
58  class AreaIterator :
59  public std::iterator<std::forward_iterator_tag, ValueT>
60  {
61 public:
62  typedef double CoordinateType;
63  typedef ValueT PeakType;
64  typedef SpectrumIteratorT SpectrumIteratorType;
65  typedef PeakIteratorT PeakIteratorType;
66 
70  typedef ValueT value_type;
73  typedef ReferenceT reference;
75  typedef PointerT pointer;
77  typedef unsigned int difference_type;
79 
81  AreaIterator(SpectrumIteratorType first, SpectrumIteratorType begin, SpectrumIteratorType end, CoordinateType low_mz, CoordinateType high_mz) :
82  first_(first),
83  current_scan_(begin),
84  end_scan_(end),
85  low_mz_(low_mz),
86  high_mz_(high_mz),
87  is_end_(false)
88  {
89  nextScan_();
90  }
91 
94  first_(),
95  current_scan_(),
96  end_scan_(),
97  current_peak_(),
98  end_peak_(),
99  low_mz_(0.0),
100  high_mz_(0.0),
101  is_end_(true)
102  {}
103 
106  {}
107 
109  AreaIterator(const AreaIterator & rhs) :
110  first_(rhs.first_),
112  end_scan_(rhs.end_scan_),
114  end_peak_(rhs.end_peak_),
115  low_mz_(rhs.low_mz_),
116  high_mz_(rhs.high_mz_),
117  is_end_(rhs.is_end_)
118  {}
119 
122  {
123  if (&rhs == this) return *this;
124 
125  is_end_ = rhs.is_end_;
126  //only copy iterators, if the assigned iterator is not the end iterator
127  if (!is_end_)
128  {
129  first_ = rhs.first_;
131  end_scan_ = rhs.end_scan_;
133  end_peak_ = rhs.end_peak_;
134  low_mz_ = rhs.low_mz_;
135  high_mz_ = rhs.high_mz_;
136  }
137 
138  return *this;
139  }
140 
142  bool operator==(const AreaIterator & rhs) const
143  {
144  //Both end iterators => equal
145  if (is_end_ && rhs.is_end_) return true;
146 
147  //Normal and end iterator => not equal
148  if (!is_end_ && rhs.is_end_) return false;
149 
150  if (is_end_ && !rhs.is_end_) return false;
151 
152  //Equality of pointed to peak addresses
153  return &(*current_peak_) == &(*(rhs.current_peak_));
154  }
155 
157  bool operator!=(const AreaIterator & rhs) const
158  {
159  return !(*this == rhs);
160  }
161 
164  {
165  //no increment if this is the end iterator
166  if (is_end_) return *this;
167 
168  ++current_peak_;
169  // test whether we arrived at the end of the current scan
170  if (current_peak_ == end_peak_)
171  {
172  ++current_scan_;
173  nextScan_();
174  }
175  return *this;
176  }
177 
180  {
181  AreaIterator tmp(*this);
182  ++(*this);
183  return tmp;
184  }
185 
187  reference operator*() const
188  {
189  return current_peak_.operator*();
190  }
191 
193  pointer operator->() const
194  {
195  return current_peak_.operator->();
196  }
197 
199  CoordinateType getRT() const
200  {
201  return current_scan_->getRT();
202  }
203 
205  inline PeakIndex getPeakIndex() const
206  {
207  if (is_end_)
208  {
209  return PeakIndex();
210  }
211  else
212  {
214  }
215  }
216 
217 private:
218  //Advances to the iterator to the next valid peak in the next valid spectrum
219  void nextScan_()
220  {
221  while (true)
222  {
223  //if (current_scan_ != end_scan_) std::cout << "RT: " << current_scan_->getRT() << std::endl;
224  while (current_scan_ != end_scan_ && current_scan_->getMSLevel() != 1)
225  {
226  ++current_scan_;
227  }
228  if (current_scan_ == end_scan_)
229  {
230  is_end_ = true;
231  return;
232  }
233  current_peak_ = current_scan_->MZBegin(low_mz_);
234  end_peak_ = current_scan_->MZEnd(high_mz_);
235  if (current_peak_ != end_peak_)
236  {
237  return;
238  }
239  ++current_scan_;
240  }
241  }
242 
244  SpectrumIteratorType first_;
246  SpectrumIteratorType current_scan_;
248  SpectrumIteratorType end_scan_;
250  PeakIteratorType current_peak_;
252  PeakIteratorType end_peak_;
254  CoordinateType low_mz_;
256  CoordinateType high_mz_;
258  bool is_end_;
259 
260  };
261 
262  }
263 }
264 
265 #endif
PeakIteratorT PeakIteratorType
Definition: AreaIterator.h:65
ValueT PeakType
Definition: AreaIterator.h:63
SpectrumIteratorType end_scan_
Past-the-end iterator of spectra.
Definition: AreaIterator.h:248
AreaIterator & operator=(const AreaIterator &rhs)
Assignment operator.
Definition: AreaIterator.h:121
double CoordinateType
Definition: AreaIterator.h:62
AreaIterator(const AreaIterator &rhs)
Copy constructor.
Definition: AreaIterator.h:109
void nextScan_()
Definition: AreaIterator.h:219
Forward iterator for an area of peaks in an experiment.
Definition: AreaIterator.h:58
unsigned int difference_type
The difference type.
Definition: AreaIterator.h:77
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
CoordinateType low_mz_
low m/z boundary
Definition: AreaIterator.h:254
CoordinateType high_mz_
high m/z boundary
Definition: AreaIterator.h:256
PeakIteratorType end_peak_
Past-the-end iterator of peaks in the current spectrum.
Definition: AreaIterator.h:252
AreaIterator operator++(int)
Step forward by one (postfix operator)
Definition: AreaIterator.h:179
AreaIterator()
Default constructor (for the end iterator)
Definition: AreaIterator.h:93
~AreaIterator()
Destructor.
Definition: AreaIterator.h:105
SpectrumIteratorT SpectrumIteratorType
Definition: AreaIterator.h:64
PeakIteratorType current_peak_
Iterator to the current peak.
Definition: AreaIterator.h:250
ReferenceT reference
The reference type as returned by operator*()
Definition: AreaIterator.h:73
pointer operator->() const
Dereferencing of this pointer yields the underlying peak.
Definition: AreaIterator.h:193
SpectrumIteratorType current_scan_
Iterator to the current spectrum.
Definition: AreaIterator.h:246
CoordinateType getRT() const
returns the retention time of the current scan
Definition: AreaIterator.h:199
reference operator*() const
Dereferencing of this pointer yields the underlying peak.
Definition: AreaIterator.h:187
bool operator==(const AreaIterator &rhs) const
Test for equality.
Definition: AreaIterator.h:142
PointerT pointer
The pointer type as returned by operator->()
Definition: AreaIterator.h:75
SpectrumIteratorType first_
Iterator to the first scan of the map (needed to calculate the index)
Definition: AreaIterator.h:244
ValueT value_type
The iterator&#39;s value type.
Definition: AreaIterator.h:71
bool is_end_
Flag that indicates that this iterator is the end iterator.
Definition: AreaIterator.h:258
AreaIterator(SpectrumIteratorType first, SpectrumIteratorType begin, SpectrumIteratorType end, CoordinateType low_mz, CoordinateType high_mz)
Constructor for the begin iterator.
Definition: AreaIterator.h:81
bool operator!=(const AreaIterator &rhs) const
Test for inequality.
Definition: AreaIterator.h:157
PeakIndex getPeakIndex() const
returns the PeakIndex corresponding to the current iterator position
Definition: AreaIterator.h:205
AreaIterator & operator++()
Step forward by one (prefix operator)
Definition: AreaIterator.h:163
Index of a peak or feature.
Definition: PeakIndex.h:51

OpenMS / TOPP release 2.3.0 Documentation generated on Tue Jan 9 2018 18:21:59 using doxygen 1.8.13