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

AreaIterator.h (Maintainer: Marc Sturm)

Go to the documentation of this file.
00001 // -*- Mode: C++; tab-width: 2; -*-
00002 // vi: set ts=2:
00003 //
00004 // --------------------------------------------------------------------------
00005 //                   OpenMS Mass Spectrometry Framework
00006 // --------------------------------------------------------------------------
00007 //  Copyright (C) 2003-2008 -- Oliver Kohlbacher, Knut Reinert
00008 //
00009 //  This library is free software; you can redistribute it and/or
00010 //  modify it under the terms of the GNU Lesser General Public
00011 //  License as published by the Free Software Foundation; either
00012 //  version 2.1 of the License, or (at your option) any later version.
00013 //
00014 //  This library is distributed in the hope that it will be useful,
00015 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017 //  Lesser General Public License for more details.
00018 //
00019 //  You should have received a copy of the GNU Lesser General Public
00020 //  License along with this library; if not, write to the Free Software
00021 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 //
00023 // --------------------------------------------------------------------------
00024 // $Maintainer: Marc Sturm $
00025 // --------------------------------------------------------------------------
00026 
00027 #ifndef OPENMS_KERNEL_AREAITERATOR_H
00028 #define OPENMS_KERNEL_AREAITERATOR_H
00029 
00030 // OpenMS includes
00031 #include <OpenMS/CONCEPT/Types.h>
00032 
00033 // STL includes
00034 #include <iterator>
00035 
00036 namespace OpenMS
00037 {
00038   namespace Internal
00039   {
00048     template<class ValueT, class ReferenceT, class PointerT, class SpectrumIteratorT, class PeakIteratorT>
00049     class AreaIterator : public std::iterator<std::forward_iterator_tag, ValueT>
00050     {
00051       public:
00052         typedef DoubleReal CoordinateType;
00053         typedef ValueT PeakType;
00054         typedef SpectrumIteratorT SpectrumIteratorType;
00055         typedef PeakIteratorT PeakIteratorType;
00056         
00060 
00061         typedef ValueT value_type;
00063         typedef ReferenceT reference;
00065         typedef PointerT pointer;
00067         typedef unsigned int difference_type;
00069     
00071         AreaIterator(SpectrumIteratorType begin, SpectrumIteratorType end, CoordinateType low_mz, CoordinateType high_mz)
00072           : current_scan_(begin), 
00073             end_scan_(end), 
00074             low_mz_(low_mz), 
00075             high_mz_(high_mz)
00076         {
00077           nextScan_();
00078         }
00079     
00081         AreaIterator( SpectrumIteratorType spectrum_end, PeakIteratorType peak_end )
00082           : current_scan_(spectrum_end), 
00083             end_scan_(spectrum_end), 
00084             current_peak_(peak_end), 
00085             end_peak_(peak_end)
00086         {
00087         }
00088     
00090         ~AreaIterator()
00091         {
00092         }
00093     
00095         AreaIterator(const AreaIterator& rhs)
00096           : current_scan_(rhs.current_scan_),
00097             end_scan_(rhs.end_scan_),
00098             current_peak_(rhs.current_peak_),
00099             end_peak_(rhs.end_peak_),
00100             low_mz_(rhs.low_mz_),
00101             high_mz_(rhs.high_mz_)
00102         {
00103         }
00104     
00106         AreaIterator& operator=(const AreaIterator& rhs)
00107         {
00108           if (&rhs == this) return *this;
00109     
00110           current_scan_ = rhs.current_scan_;
00111           end_scan_ = rhs.end_scan_;
00112           current_peak_ = rhs.current_peak_;
00113           end_peak_ = rhs.end_peak_;
00114           low_mz_ = rhs.low_mz_;
00115           high_mz_ = rhs.high_mz_;
00116     
00117           return *this;
00118         }
00119     
00121         bool operator==(const AreaIterator& rhs) const
00122         {
00123           return ( &(*current_peak_) == &(*(rhs.current_peak_))) //Equality of pointed to peak adresses
00124                  ||
00125                  ( current_peak_ == end_peak_ && //Equality to the end iterator
00126                    current_scan_ == end_scan_ &&
00127                    rhs.current_scan_ == rhs.end_scan_ &&  
00128                    rhs.current_peak_ == rhs.end_peak_ ) ;
00129         }
00130     
00132         bool operator!=(const AreaIterator& rhs) const
00133         {
00134           return !(*this == rhs);
00135         }
00136     
00138         AreaIterator& operator++()
00139         {
00140           ++current_peak_;
00141           // test whether we arrived at the end of the current scan
00142           if (current_peak_ == end_peak_)
00143           {
00144             ++current_scan_;
00145             nextScan_();
00146           }
00147           return (*this);
00148         }
00149     
00151         AreaIterator operator++(int)
00152         {
00153           AreaIterator tmp(*this);
00154           ++(*this);
00155           return tmp;
00156         }
00157     
00159         reference operator*() const
00160         {
00161           return current_peak_.operator*();
00162         }
00163     
00165         pointer operator->() const
00166         {
00167           return current_peak_.operator->();
00168         }
00169   
00171         CoordinateType getRT() const
00172         {
00173           return current_scan_->getRT();
00174         }
00175         
00176       private:
00177         //Advances to the iterator to the next valid peak in the next valid spectrum
00178         void nextScan_()
00179         {
00180           while (true)
00181           {
00182             //if (current_scan_ != end_scan_) std::cout << "RT: " << current_scan_->getRT() << std::endl;
00183             while (current_scan_ != end_scan_ && current_scan_->getMSLevel()!=1)
00184             {
00185               ++current_scan_;
00186             }
00187             if (current_scan_ == end_scan_)
00188             {
00189               current_peak_ = end_peak_ = PeakIteratorType();
00190               return;
00191             }
00192             current_peak_ = current_scan_->MZBegin(low_mz_);
00193             end_peak_ = current_scan_->MZEnd(high_mz_);
00194             if (current_peak_!=end_peak_)
00195             {
00196               return;
00197             }
00198             ++current_scan_;
00199           }
00200         }
00201       
00203         SpectrumIteratorType current_scan_;
00205         SpectrumIteratorType end_scan_;
00207         PeakIteratorType current_peak_;
00209         PeakIteratorType end_peak_;
00211         CoordinateType low_mz_;
00213         CoordinateType high_mz_;
00214       
00215       private:
00216         //Hidden default constructor
00217         AreaIterator();
00218     };
00219 
00220   }
00221 }
00222 
00223 #endif

Generated Tue Apr 1 15:36:32 2008 -- using doxygen 1.5.4 OpenMS / TOPP 1.1