OpenMS  2.5.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-2020.
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 
85  FeatureHandle(const FeatureHandle& rhs);
86 
88  FeatureHandle& operator=(const FeatureHandle& rhs);
89 
91  ~FeatureHandle() override;
92 
108  FeatureHandleMutable_& asMutable() const;
110 
112 
113  UInt64 getMapIndex() const;
115 
117  void setMapIndex(UInt64 i);
118 
120  void setCharge(ChargeType charge);
121 
123  ChargeType getCharge() const;
124 
126  void setWidth(WidthType width);
127 
129  WidthType getWidth() const;
130 
132 
134  bool operator==(const FeatureHandle& i) const;
135 
137  bool operator!=(const FeatureHandle& i) const;
138 
140  struct IndexLess :
141  std::binary_function<FeatureHandle, FeatureHandle, bool>
142  {
143  bool operator()(FeatureHandle const& left, FeatureHandle const& right) const;
144  };
145 
146 protected:
147 
153  float width_;
154  };
155 
163  class OPENMS_DLLAPI FeatureHandle::FeatureHandleMutable_ :
164  public FeatureHandle
165  {
166 private:
171  };
172 
174  {
175  // the const cast is to remove constness, but note that FeatureHandleMutable_ lacks some mutators
176  // TODO use const_cast
177  return static_cast<FeatureHandleMutable_&>(const_cast<FeatureHandle&>(*this));
178  }
179 
180  inline bool FeatureHandle::IndexLess::operator()(FeatureHandle const& left, FeatureHandle const& right) const
181  {
182  // if map indices are equal, use unique ids
183  if (left.map_index_ == right.map_index_)
184  {
185  return left.getUniqueId() < right.getUniqueId();
186  }
187  //else use map indices
188  return left.map_index_ < right.map_index_;
189  }
190 
192  OPENMS_DLLAPI std::ostream& operator<<(std::ostream& os, const FeatureHandle& cons);
193 } // namespace OpenMS
194 
UniqueIdInterface.h
OpenMS::UInt64
OPENMS_UINT64_TYPE UInt64
Unsigned integer type (64bit)
Definition: Types.h:77
Types.h
OpenMS::Peak2D
A 2-dimensional raw data point or peak.
Definition: Peak2D.h:54
OpenMS::BaseFeature
A basic LC-MS feature.
Definition: BaseFeature.h:56
KDTree::operator!=
bool operator!=(_Iterator< _Val, _Ref, _Ptr > const &, _Iterator< _Val, _Ref, _Ptr > const &)
Definition: KDTree.h:824
OpenMS::FeatureHandle::width_
float width_
Width of the feature (FWHM)
Definition: FeatureHandle.h:153
OpenMS::UniqueIdInterface
A base class defining a common interface for all classes having a unique id.
Definition: UniqueIdInterface.h:51
OpenMS::FeatureHandle::FeatureHandleMutable_
Helper class returned by FeatureHandle::asMutable(), which see.
Definition: FeatureHandle.h:163
OpenMS::FeatureHandle::IndexLess
Comparator by map and unique id.
Definition: FeatureHandle.h:140
OpenMS::FeatureHandle::setMapIndex
void setMapIndex(UInt64 i)
Set the map index.
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
Peak2D.h
OpenMS::Peak2D::operator<<
friend std::ostream & operator<<(std::ostream &os, const Peak2D &point)
Print the contents to a stream.
OpenMS::FeatureHandle::charge_
Int charge_
Charge of the feature.
Definition: FeatureHandle.h:151
int
OpenMS::UniqueIdInterface::setUniqueId
Size setUniqueId()
Assigns a new, valid unique id. Always returns 1.
Definition: UniqueIdInterface.h:146
OpenMS::FeatureHandle::map_index_
UInt64 map_index_
Index of the element's container.
Definition: FeatureHandle.h:149
OpenMS::FeatureHandle::IndexLess::operator()
bool operator()(FeatureHandle const &left, FeatureHandle const &right) const
Definition: FeatureHandle.h:180
OpenMS::FeatureHandle::WidthType
float WidthType
Feature width type.
Definition: FeatureHandle.h:70
KDTree::operator==
bool operator==(_Iterator< _Val, _Ref, _Ptr > const &, _Iterator< _Val, _Ref, _Ptr > const &)
Definition: KDTree.h:806
OpenMS::FeatureHandle
Representation of a Peak2D, RichPeak2D or Feature .
Definition: FeatureHandle.h:57
float
OpenMS::FeatureHandle::asMutable
FeatureHandleMutable_ & asMutable() const
Override (most of all) constness.
Definition: FeatureHandle.h:173
OpenMS::UniqueIdInterface::getUniqueId
UInt64 getUniqueId() const
Non-mutable access to unique id - returns the unique id.
Definition: UniqueIdInterface.h:105