00001 //------------------------------------------------------------------------------ 00002 // This file is part of the OpenStructure project <www.openstructure.org> 00003 // 00004 // Copyright (C) 2008-2011 by the OpenStructure authors 00005 // 00006 // This library is free software; you can redistribute it and/or modify it under 00007 // the terms of the GNU Lesser General Public License as published by the Free 00008 // Software Foundation; either version 3.0 of the License, or (at your option) 00009 // any later version. 00010 // This library is distributed in the hope that it will be useful, but WITHOUT 00011 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00012 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 00013 // details. 00014 // 00015 // You should have received a copy of the GNU Lesser General Public License 00016 // along with this library; if not, write to the Free Software Foundation, Inc., 00017 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00018 //------------------------------------------------------------------------------ 00019 #ifndef OST_SEQ_ALIGNED_COLUMN_ITERATOR_HH 00020 #define OST_SEQ_ALIGNED_COLUMN_ITERATOR_HH 00021 00022 #include <ost/seq/aligned_column.hh> 00023 00024 /* 00025 Author: Marco Biasini 00026 */ 00027 namespace ost { namespace seq { 00028 00029 class AlignedColumnIterator : public std::iterator<std::forward_iterator_tag, 00030 AlignedColumn> { 00031 private: 00032 void UpdateVal() 00033 { 00034 if (curr_<end_) { 00035 val_=AlignedColumn(aln_, curr_); 00036 } 00037 } 00038 public: 00039 AlignedColumnIterator(const AlignmentHandle& aln, int start, int end): 00040 aln_(aln), curr_(start), end_(end) 00041 { 00042 this->UpdateVal(); 00043 } 00044 00045 AlignedColumnIterator& operator++() 00046 { 00047 ++curr_; 00048 this->UpdateVal(); 00049 return *this; 00050 } 00051 00052 AlignedColumnIterator& operator--() 00053 { 00054 --curr_; 00055 this->UpdateVal(); 00056 return *this; 00057 } 00058 00059 AlignedColumnIterator operator++(int) 00060 { 00061 AlignedColumnIterator ans(*this); 00062 ++(*this); 00063 return ans; 00064 } 00065 00066 AlignedColumn* operator->() 00067 { 00068 return &val_; 00069 } 00070 00071 AlignedColumn& operator*() 00072 { 00073 return val_; 00074 } 00075 00076 bool operator==(const AlignedColumnIterator& rhs) const 00077 { 00078 return aln_==rhs.aln_ && rhs.curr_==curr_; 00079 } 00080 00081 bool operator!=(const AlignedColumnIterator& rhs) const 00082 { 00083 return !(*this==rhs); 00084 } 00085 private: 00086 AlignmentHandle aln_; 00087 int curr_; 00088 int end_; 00089 AlignedColumn val_; 00090 }; 00091 }} 00092 00093 #endif