OpenMS
FeatureHandle.h
Go to the documentation of this file.
1 // Copyright (c) 2002-present, The OpenMS Team -- EKU Tuebingen, ETH Zurich, and FU Berlin
2 // SPDX-License-Identifier: BSD-3-Clause
3 //
4 // --------------------------------------------------------------------------
5 // $Maintainer: Timo Sachsenberg $
6 // $Authors: $
7 // --------------------------------------------------------------------------
8 
9 #pragma once
10 
11 #include <OpenMS/CONCEPT/Types.h>
13 #include <OpenMS/KERNEL/Peak2D.h>
14 #include <OpenMS/OpenMSConfig.h>
15 
16 #include <iosfwd>
17 #include <vector>
18 
19 namespace OpenMS
20 {
21  class BaseFeature;
22 
31  class OPENMS_DLLAPI FeatureHandle :
32  public Peak2D,
33  public UniqueIdInterface
34  {
35 
36 public:
38 
40 
41  typedef Int ChargeType;
44  typedef float WidthType;
46 
48 
49  FeatureHandle();
51 
53  FeatureHandle(UInt64 map_index, const Peak2D& point, UInt64 element_index);
54 
56  FeatureHandle(UInt64 map_index, const BaseFeature& feature);
57 
60 
63 
65  ~FeatureHandle() override;
66 
82  FeatureHandleMutable_& asMutable() const;
84 
86 
87  UInt64 getMapIndex() const;
89 
92 
94  void setCharge(ChargeType charge);
95 
98 
100  void setWidth(WidthType width);
101 
104 
106 
108  bool operator==(const FeatureHandle& i) const;
109 
111  bool operator!=(const FeatureHandle& i) const;
112 
114  struct IndexLess
115  {
116  bool operator()(FeatureHandle const& left, FeatureHandle const& right) const;
117  };
118 
119 protected:
120 
126  float width_;
127  };
128 
136  class OPENMS_DLLAPI FeatureHandle::FeatureHandleMutable_ :
137  public FeatureHandle
138  {
139 private:
144  };
145 
147  {
148  // the const cast is to remove constness, but note that FeatureHandleMutable_ lacks some mutators
149  // TODO use const_cast
150  return static_cast<FeatureHandleMutable_&>(const_cast<FeatureHandle&>(*this));
151  }
152 
153  inline bool FeatureHandle::IndexLess::operator()(FeatureHandle const& left, FeatureHandle const& right) const
154  {
155  // if map indices are equal, use unique ids
156  if (left.map_index_ == right.map_index_)
157  {
158  return left.getUniqueId() < right.getUniqueId();
159  }
160  //else use map indices
161  return left.map_index_ < right.map_index_;
162  }
163 
165  OPENMS_DLLAPI std::ostream& operator<<(std::ostream& os, const FeatureHandle& cons);
166 } // namespace OpenMS
167 
A basic LC-MS feature.
Definition: BaseFeature.h:33
Helper class returned by FeatureHandle::asMutable(), which see.
Definition: FeatureHandle.h:138
FeatureHandleMutable_(const FeatureHandleMutable_ &)
Representation of a Peak2D, RichPeak2D or Feature .
Definition: FeatureHandle.h:34
FeatureHandle(UInt64 map_index, const BaseFeature &feature)
Constructor from map index and basic feature.
bool operator!=(const FeatureHandle &i) const
Equality operator.
bool operator==(const FeatureHandle &i) const
Equality operator.
UInt64 map_index_
Index of the element's container.
Definition: FeatureHandle.h:122
FeatureHandleMutable_ & asMutable() const
Override (most of all) constness.
Definition: FeatureHandle.h:146
float WidthType
Feature width type.
Definition: FeatureHandle.h:44
void setMapIndex(UInt64 i)
Set the map index.
FeatureHandle & operator=(const FeatureHandle &rhs)
Assignment operator.
void setWidth(WidthType width)
Sets the width (FWHM)
FeatureHandle(const FeatureHandle &rhs)
Copy constructor.
WidthType getWidth() const
Returns the width (FWHM)
Int ChargeType
Charge type.
Definition: FeatureHandle.h:42
~FeatureHandle() override
Destructor.
ChargeType getCharge() const
Returns the charge.
float width_
Width of the feature (FWHM)
Definition: FeatureHandle.h:126
FeatureHandle(UInt64 map_index, const Peak2D &point, UInt64 element_index)
Constructor with map index, element index and position.
void setCharge(ChargeType charge)
Sets the charge.
Int charge_
Charge of the feature.
Definition: FeatureHandle.h:124
A 2-dimensional raw data point or peak.
Definition: Peak2D.h:29
friend std::ostream & operator<<(std::ostream &os, const Peak2D &point)
Print the contents to a stream.
A base class defining a common interface for all classes having a unique id.
Definition: UniqueIdInterface.h:25
UInt64 getUniqueId() const
Non-mutable access to unique id - returns the unique id.
Definition: UniqueIdInterface.h:78
Size setUniqueId()
Assigns a new, valid unique id. Always returns 1.
int Int
Signed integer type.
Definition: Types.h:72
uint64_t UInt64
Unsigned integer type (64bit)
Definition: Types.h:47
Main OpenMS namespace.
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
Comparator by map and unique id.
Definition: FeatureHandle.h:115
bool operator()(FeatureHandle const &left, FeatureHandle const &right) const
Definition: FeatureHandle.h:153