OpenMS  2.7.0
PeakIndex.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-2021.
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 #pragma once
36 
37 
38 #include <OpenMS/CONCEPT/Types.h>
40 #include <OpenMS/CONCEPT/Macros.h>
41 #include <limits>
42 
43 namespace OpenMS
44 {
50  struct PeakIndex
51  {
53  inline PeakIndex() :
54  peak((std::numeric_limits<Size>::max)()),
55  spectrum((std::numeric_limits<Size>::max)())
56  {}
57 
59  explicit inline PeakIndex(Size lpeak) :
60  peak(lpeak),
61  spectrum((std::numeric_limits<Size>::max)())
62  {}
63 
65  inline PeakIndex(Size lspectrum, Size lpeak) :
66  peak(lpeak),
67  spectrum(lspectrum)
68  {}
69 
71  inline bool isValid() const
72  {
73  return peak != (std::numeric_limits<Size>::max)();
74  }
75 
77  inline void clear()
78  {
79  peak = (std::numeric_limits<Size>::max)();
80  spectrum = (std::numeric_limits<Size>::max)();
81  }
82 
94  template <typename FeatureMapType>
95  const typename FeatureMapType::value_type & getFeature(const FeatureMapType & map) const
96  {
97  OPENMS_PRECONDITION(peak < map.size(), "Feature index exceeds map size");
98  return map[peak];
99  }
100 
112  template <typename PeakMapType>
113  const typename PeakMapType::PeakType & getPeak(const PeakMapType & map) const
114  {
115  OPENMS_PRECONDITION(spectrum < map.size(), "Spectrum index exceeds map size");
116  OPENMS_PRECONDITION(peak < map[spectrum].size(), "Peak index exceeds spectrum size");
117  return map[spectrum][peak];
118  }
119 
131  template <typename PeakMapType>
132  const typename PeakMapType::SpectrumType & getSpectrum(const PeakMapType & map) const
133  {
134  OPENMS_PRECONDITION(spectrum < map.size(), "Spectrum index exceeds map size");
135  return map[spectrum];
136  }
137 
139  inline bool operator==(const PeakIndex & rhs) const
140  {
141  return peak == rhs.peak && spectrum == rhs.spectrum;
142  }
143 
145  inline bool operator!=(const PeakIndex & rhs) const
146  {
147  return peak != rhs.peak || spectrum != rhs.spectrum;
148  }
149 
154  };
155 
156 } // namespace OpenMS
157 
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
#define OPENMS_PRECONDITION(condition, message)
Precondition macro.
Definition: openms/include/OpenMS/CONCEPT/Macros.h:120
MSSpectrum SpectrumType
Definition: MzDataHandler.h:60
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
Peak2D PeakType
Definition: MassTrace.h:47
Index of a peak or feature.
Definition: PeakIndex.h:51
const FeatureMapType::value_type & getFeature(const FeatureMapType &map) const
Access to the feature (or consensus feature) corresponding to this index.
Definition: PeakIndex.h:95
bool isValid() const
returns if the current peak ref is valid
Definition: PeakIndex.h:71
const PeakMapType::PeakType & getPeak(const PeakMapType &map) const
Access to a peak corresponding to this index.
Definition: PeakIndex.h:113
PeakIndex(Size lpeak)
Constructor that sets the peak index (for feature maps)
Definition: PeakIndex.h:59
bool operator!=(const PeakIndex &rhs) const
Inequality operator.
Definition: PeakIndex.h:145
PeakIndex()
Default constructor. Creates an invalid peak reference.
Definition: PeakIndex.h:53
void clear()
Invalidates the current index.
Definition: PeakIndex.h:77
bool operator==(const PeakIndex &rhs) const
Equality operator.
Definition: PeakIndex.h:139
PeakIndex(Size lspectrum, Size lpeak)
Constructor that sets the peak and spectrum index (for peak maps)
Definition: PeakIndex.h:65
Size spectrum
Spectrum index.
Definition: PeakIndex.h:153
Size peak
Peak or feature index.
Definition: PeakIndex.h:151
const PeakMapType::SpectrumType & getSpectrum(const PeakMapType &map) const
Access to a spectrum corresponding to this index.
Definition: PeakIndex.h:132