Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages

FeatureHandle.h

Go to the documentation of this file.
00001 // --------------------------------------------------------------------------
00002 //                   OpenMS -- Open-Source Mass Spectrometry
00003 // --------------------------------------------------------------------------
00004 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
00005 // ETH Zurich, and Freie Universitaet Berlin 2002-2012.
00006 //
00007 // This software is released under a three-clause BSD license:
00008 //  * Redistributions of source code must retain the above copyright
00009 //    notice, this list of conditions and the following disclaimer.
00010 //  * Redistributions in binary form must reproduce the above copyright
00011 //    notice, this list of conditions and the following disclaimer in the
00012 //    documentation and/or other materials provided with the distribution.
00013 //  * Neither the name of any author or any participating institution
00014 //    may be used to endorse or promote products derived from this software
00015 //    without specific prior written permission.
00016 // For a full list of authors, refer to the file AUTHORS.
00017 // --------------------------------------------------------------------------
00018 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00019 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00020 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00021 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
00022 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00023 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00024 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
00025 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
00026 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
00027 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
00028 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029 //
00030 // --------------------------------------------------------------------------
00031 // $Maintainer: Erhan Kenar $
00032 // $Authors: $
00033 // --------------------------------------------------------------------------
00034 
00035 #ifndef OPENMS_KERNEL_FEATUREHANDLE_H
00036 #define OPENMS_KERNEL_FEATUREHANDLE_H
00037 
00038 #include <iostream>
00039 #include <vector>
00040 
00041 #include <OpenMS/KERNEL/Feature.h>
00042 
00043 namespace OpenMS
00044 {
00045   class ConsensusFeature;
00054   class OPENMS_DLLAPI FeatureHandle :
00055     public Peak2D,
00056     public UniqueIdInterface
00057   {
00058 
00059 public:
00060     class FeatureHandleMutable_;
00061 
00063 
00064 
00065     typedef Int ChargeType;
00067     typedef Real WidthType;
00069 
00071 
00072 
00073     FeatureHandle() :
00074       Peak2D(),
00075       UniqueIdInterface(),
00076       map_index_(0),
00077       charge_(0),
00078       width_(0)
00079     {}
00080 
00082     FeatureHandle(UInt64 map_index, const Peak2D & point, UInt64 element_index) :
00083       Peak2D(point),
00084       map_index_(map_index),
00085       charge_(0),
00086       width_(0)
00087     {
00088       setUniqueId(element_index);
00089     }
00090 
00092     FeatureHandle(UInt64 map_index, const BaseFeature & feature) :
00093       Peak2D(feature),
00094       UniqueIdInterface(feature),
00095       map_index_(map_index),
00096       charge_(feature.getCharge()),
00097       width_(feature.getWidth())
00098     {}
00099 
00101     FeatureHandle(const FeatureHandle & rhs) :
00102       Peak2D(rhs),
00103       UniqueIdInterface(rhs),
00104       map_index_(rhs.map_index_),
00105       charge_(rhs.charge_),
00106       width_(rhs.width_)
00107     {}
00108 
00110     FeatureHandle & operator=(const FeatureHandle & rhs)
00111     {
00112       Peak2D::operator=(rhs);
00113       UniqueIdInterface::operator=(rhs);
00114       map_index_ = rhs.map_index_;
00115       charge_ = rhs.charge_;
00116       width_ = rhs.width_;
00117 
00118       return *this;
00119     }
00120 
00122     virtual ~FeatureHandle()
00123     {}
00124 
00140     FeatureHandleMutable_ & asMutable() const;
00142 
00144 
00145 
00146     UInt64 getMapIndex() const
00147     {
00148       return map_index_;
00149     }
00150 
00152     void setMapIndex(UInt64 i)
00153     {
00154       map_index_ = i;
00155     }
00156 
00158     void setCharge(ChargeType charge)
00159     {
00160       charge_ = charge;
00161     }
00162 
00164     ChargeType getCharge() const
00165     {
00166       return charge_;
00167     }
00168 
00170     void setWidth(WidthType width)
00171     {
00172       width_ = width;
00173     }
00174 
00176     WidthType getWidth() const
00177     {
00178       return width_;
00179     }
00180 
00182 
00184     bool operator==(const FeatureHandle & i) const
00185     {
00186       return (Peak2D::operator==(i))
00187              && (UniqueIdInterface::operator==(i))
00188              && (map_index_ == i.map_index_)
00189              && (charge_ == i.charge_)
00190              && (width_ == i.width_);
00191     }
00192 
00194     bool operator!=(const FeatureHandle & i) const
00195     {
00196       return !(operator==(i));
00197     }
00198 
00200     struct IndexLess :
00201       std::binary_function<FeatureHandle, FeatureHandle, bool>
00202     {
00203       bool operator()(FeatureHandle const & left, FeatureHandle const & right) const
00204       {
00205         // if map indices are equal, use unique ids
00206         if (left.map_index_ == right.map_index_)
00207         {
00208           return left.getUniqueId() < right.getUniqueId();
00209         }
00210         //else use map indices
00211         return left.map_index_ < right.map_index_;
00212       }
00213 
00214     };
00215 
00216 protected:
00217 
00219     UInt64 map_index_;
00221     Int charge_;
00223     Real width_;
00224   };
00225 
00233   class OPENMS_DLLAPI FeatureHandle::FeatureHandleMutable_ :
00234     public FeatureHandle
00235   {
00236 private:
00237     using FeatureHandle::setUniqueId;
00238     using FeatureHandle::setMapIndex;
00239     FeatureHandleMutable_();
00240     FeatureHandleMutable_(const FeatureHandleMutable_ &);
00241   };
00242 
00243   inline FeatureHandle::FeatureHandleMutable_ & FeatureHandle::asMutable() const
00244   {
00245     // the const cast is to remove constness, but note that FeatureHandleMutable_ lacks some mutators
00246     return static_cast<FeatureHandleMutable_ &>(const_cast<FeatureHandle &>(*this));
00247   }
00248 
00250   OPENMS_DLLAPI std::ostream & operator<<(std::ostream & os, const FeatureHandle & cons);
00251 } // namespace OpenMS
00252 
00253 #endif // OPENMS_KERNEL_FEATUREHANDLE_H

OpenMS / TOPP release 1.10.0 Documentation generated on Thu Mar 7 2013 09:42:39 using doxygen 1.7.1