OpenMS  2.7.0
FeatureHandle.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: $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
37 #include <OpenMS/CONCEPT/Types.h>
39 #include <OpenMS/KERNEL/Peak2D.h>
40 #include <OpenMS/OpenMSConfig.h>
41 
42 #include <iosfwd>
43 #include <vector>
44 
45 namespace OpenMS
46 {
47  class BaseFeature;
48 
57  class OPENMS_DLLAPI FeatureHandle :
58  public Peak2D,
59  public UniqueIdInterface
60  {
61 
62 public:
64 
66 
67  typedef Int ChargeType;
70  typedef float WidthType;
72 
74 
75  FeatureHandle();
77 
79  FeatureHandle(UInt64 map_index, const Peak2D& point, UInt64 element_index);
80 
82  FeatureHandle(UInt64 map_index, const BaseFeature& feature);
83 
86 
89 
91  ~FeatureHandle() override;
92 
108  FeatureHandleMutable_& asMutable() const;
110 
112 
113  UInt64 getMapIndex() const;
115 
118 
120  void setCharge(ChargeType charge);
121 
124 
126  void setWidth(WidthType width);
127 
130 
132 
134  bool operator==(const FeatureHandle& i) const;
135 
137  bool operator!=(const FeatureHandle& i) const;
138 
140  struct IndexLess
141  {
142  bool operator()(FeatureHandle const& left, FeatureHandle const& right) const;
143  };
144 
145 protected:
146 
152  float width_;
153  };
154 
162  class OPENMS_DLLAPI FeatureHandle::FeatureHandleMutable_ :
163  public FeatureHandle
164  {
165 private:
170  };
171 
173  {
174  // the const cast is to remove constness, but note that FeatureHandleMutable_ lacks some mutators
175  // TODO use const_cast
176  return static_cast<FeatureHandleMutable_&>(const_cast<FeatureHandle&>(*this));
177  }
178 
179  inline bool FeatureHandle::IndexLess::operator()(FeatureHandle const& left, FeatureHandle const& right) const
180  {
181  // if map indices are equal, use unique ids
182  if (left.map_index_ == right.map_index_)
183  {
184  return left.getUniqueId() < right.getUniqueId();
185  }
186  //else use map indices
187  return left.map_index_ < right.map_index_;
188  }
189 
191  OPENMS_DLLAPI std::ostream& operator<<(std::ostream& os, const FeatureHandle& cons);
192 } // namespace OpenMS
193 
A basic LC-MS feature.
Definition: BaseFeature.h:58
Helper class returned by FeatureHandle::asMutable(), which see.
Definition: FeatureHandle.h:164
FeatureHandleMutable_(const FeatureHandleMutable_ &)
Representation of a Peak2D, RichPeak2D or Feature .
Definition: FeatureHandle.h:60
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:148
FeatureHandleMutable_ & asMutable() const
Override (most of all) constness.
Definition: FeatureHandle.h:172
float WidthType
Feature width type.
Definition: FeatureHandle.h:70
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:68
~FeatureHandle() override
Destructor.
ChargeType getCharge() const
Returns the charge.
float width_
Width of the feature (FWHM)
Definition: FeatureHandle.h:152
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:150
A 2-dimensional raw data point or peak.
Definition: Peak2D.h:55
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:52
UInt64 getUniqueId() const
Non-mutable access to unique id - returns the unique id.
Definition: UniqueIdInterface.h:105
Size setUniqueId()
Assigns a new, valid unique id. Always returns 1.
Definition: UniqueIdInterface.h:146
OPENMS_UINT64_TYPE UInt64
Unsigned integer type (64bit)
Definition: Types.h:77
int Int
Signed integer type.
Definition: Types.h:102
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
Comparator by map and unique id.
Definition: FeatureHandle.h:141
bool operator()(FeatureHandle const &left, FeatureHandle const &right) const
Definition: FeatureHandle.h:179