Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages
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-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_PEAKINDEX_H
36 #define OPENMS_KERNEL_PEAKINDEX_H
37 
38 
39 #include <OpenMS/CONCEPT/Types.h>
41 #include <OpenMS/CONCEPT/Macros.h>
42 #include <limits>
43 
44 namespace OpenMS
45 {
51  struct PeakIndex
52  {
54  inline PeakIndex() :
55  peak((std::numeric_limits<Size>::max)()),
56  spectrum((std::numeric_limits<Size>::max)())
57  {}
58 
60  explicit inline PeakIndex(Size lpeak) :
61  peak(lpeak),
62  spectrum((std::numeric_limits<Size>::max)())
63  {}
64 
66  inline PeakIndex(Size lspectrum, Size lpeak) :
67  peak(lpeak),
68  spectrum(lspectrum)
69  {}
70 
72  inline bool isValid() const
73  {
74  return peak != (std::numeric_limits<Size>::max)();
75  }
76 
78  inline void clear()
79  {
80  peak = (std::numeric_limits<Size>::max)();
81  spectrum = (std::numeric_limits<Size>::max)();
82  }
83 
95  template <typename FeatureMapType>
96  const typename FeatureMapType::value_type & getFeature(const FeatureMapType & map) const
97  {
98  OPENMS_PRECONDITION(peak < map.size(), "Feature index exceeds map size");
99  return map[peak];
100  }
101 
113  template <typename PeakMapType>
114  const typename PeakMapType::PeakType & getPeak(const PeakMapType & map) const
115  {
116  OPENMS_PRECONDITION(spectrum < map.size(), "Spectrum index exceeds map size");
117  OPENMS_PRECONDITION(peak < map[spectrum].size(), "Peak index exceeds spectrum size");
118  return map[spectrum][peak];
119  }
120 
132  template <typename PeakMapType>
133  const typename PeakMapType::SpectrumType & getSpectrum(const PeakMapType & map) const
134  {
135  OPENMS_PRECONDITION(spectrum < map.size(), "Spectrum index exceeds map size");
136  return map[spectrum];
137  }
138 
140  inline bool operator==(const PeakIndex & rhs) const
141  {
142  return peak == rhs.peak && spectrum == rhs.spectrum;
143  }
144 
146  inline bool operator!=(const PeakIndex & rhs) const
147  {
148  return peak != rhs.peak || spectrum != rhs.spectrum;
149  }
150 
155  };
156 
157 } // namespace OpenMS
158 
159 #endif // OPENMS_KERNEL_PEAKINDEX_H
bool operator!=(const PeakIndex &rhs) const
Inequality operator.
Definition: PeakIndex.h:146
#define OPENMS_PRECONDITION(condition, message)
Precondition macro.
Definition: openms/include/OpenMS/CONCEPT/Macros.h:107
bool operator==(const PeakIndex &rhs) const
Equality operator.
Definition: PeakIndex.h:140
Peak2D PeakType
Definition: MassTrace.h:48
STL namespace.
void clear()
Invalidates the current index.
Definition: PeakIndex.h:78
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
Size peak
Peak or feature index.
Definition: PeakIndex.h:152
Size spectrum
Spectrum index.
Definition: PeakIndex.h:154
const PeakMapType::PeakType & getPeak(const PeakMapType &map) const
Access to a peak corresponding to this index.
Definition: PeakIndex.h:114
PeakIndex(Size lspectrum, Size lpeak)
Constructor that sets the peak and spectrum index (for peak maps)
Definition: PeakIndex.h:66
bool isValid() const
returns if the current peak ref is valid
Definition: PeakIndex.h:72
const PeakMapType::SpectrumType & getSpectrum(const PeakMapType &map) const
Access to a spectrum corresponding to this index.
Definition: PeakIndex.h:133
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:128
const FeatureMapType::value_type & getFeature(const FeatureMapType &map) const
Access to the feature (or consensus feature) corresponding to this index.
Definition: PeakIndex.h:96
PeakIndex(Size lpeak)
Constructor that sets the peak index (for feature maps)
Definition: PeakIndex.h:60
PeakIndex()
Default constructor. Creates an invalid peak reference.
Definition: PeakIndex.h:54
Index of a peak or feature.
Definition: PeakIndex.h:51
MSSpectrum SpectrumType
Definition: MzDataHandler.h:62

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