OpenMS
PeakIndex.h
Go to the documentation of this file.
1 // Copyright (c) 2002-present, OpenMS Inc. -- EKU Tuebingen, ETH Zurich, and FU Berlin
2 // SPDX-License-Identifier: BSD-3-Clause
3 //
4 // --------------------------------------------------------------------------
5 // $Maintainer: Timo Sachsenberg$
6 // $Authors: Marc Sturm $
7 // --------------------------------------------------------------------------
8 
9 #pragma once
10 
11 
12 #include <OpenMS/CONCEPT/Types.h>
14 #include <OpenMS/CONCEPT/Macros.h>
15 #include <limits>
16 
17 namespace OpenMS
18 {
24  struct PeakIndex
25  {
27  inline PeakIndex() :
28  peak((std::numeric_limits<Size>::max)()),
29  spectrum((std::numeric_limits<Size>::max)())
30  {}
31 
33  explicit inline PeakIndex(Size lpeak) :
34  peak(lpeak),
35  spectrum((std::numeric_limits<Size>::max)())
36  {}
37 
39  inline PeakIndex(Size lspectrum, Size lpeak) :
40  peak(lpeak),
41  spectrum(lspectrum)
42  {}
43 
45  inline bool isValid() const
46  {
47  return peak != (std::numeric_limits<Size>::max)();
48  }
49 
51  inline void clear()
52  {
53  peak = (std::numeric_limits<Size>::max)();
54  spectrum = (std::numeric_limits<Size>::max)();
55  }
56 
68  template <typename FeatureMapType>
69  const typename FeatureMapType::value_type & getFeature(const FeatureMapType & map) const
70  {
71  OPENMS_PRECONDITION(peak < map.size(), "Feature index exceeds map size");
72  return map[peak];
73  }
74 
86  template <typename PeakMapType>
87  const typename PeakMapType::PeakType & getPeak(const PeakMapType & map) const
88  {
89  OPENMS_PRECONDITION(spectrum < map.size(), "Spectrum index exceeds map size");
90  OPENMS_PRECONDITION(peak < map[spectrum].size(), "Peak index exceeds spectrum size");
91  return map[spectrum][peak];
92  }
93 
105  template <typename PeakMapType>
106  const typename PeakMapType::SpectrumType & getSpectrum(const PeakMapType & map) const
107  {
108  OPENMS_PRECONDITION(spectrum < map.size(), "Spectrum index exceeds map size");
109  return map[spectrum];
110  }
111 
113  inline bool operator==(const PeakIndex & rhs) const
114  {
115  return peak == rhs.peak && spectrum == rhs.spectrum;
116  }
117 
119  inline bool operator!=(const PeakIndex & rhs) const
120  {
121  return peak != rhs.peak || spectrum != rhs.spectrum;
122  }
123 
128  };
129 
130 } // namespace OpenMS
131 
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:97
#define OPENMS_PRECONDITION(condition, message)
Precondition macro.
Definition: openms/include/OpenMS/CONCEPT/Macros.h:94
MSSpectrum SpectrumType
Definition: MzDataHandler.h:34
Main OpenMS namespace.
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
Peak2D PeakType
Definition: MassTrace.h:21
Index of a peak or feature.
Definition: PeakIndex.h:25
const FeatureMapType::value_type & getFeature(const FeatureMapType &map) const
Access to the feature (or consensus feature) corresponding to this index.
Definition: PeakIndex.h:69
bool isValid() const
returns if the current peak ref is valid
Definition: PeakIndex.h:45
const PeakMapType::PeakType & getPeak(const PeakMapType &map) const
Access to a peak corresponding to this index.
Definition: PeakIndex.h:87
PeakIndex(Size lpeak)
Constructor that sets the peak index (for feature maps)
Definition: PeakIndex.h:33
bool operator!=(const PeakIndex &rhs) const
Inequality operator.
Definition: PeakIndex.h:119
PeakIndex()
Default constructor. Creates an invalid peak reference.
Definition: PeakIndex.h:27
void clear()
Invalidates the current index.
Definition: PeakIndex.h:51
bool operator==(const PeakIndex &rhs) const
Equality operator.
Definition: PeakIndex.h:113
PeakIndex(Size lspectrum, Size lpeak)
Constructor that sets the peak and spectrum index (for peak maps)
Definition: PeakIndex.h:39
Size spectrum
Spectrum index.
Definition: PeakIndex.h:127
Size peak
Peak or feature index.
Definition: PeakIndex.h:125
const PeakMapType::SpectrumType & getSpectrum(const PeakMapType &map) const
Access to a spectrum corresponding to this index.
Definition: PeakIndex.h:106