OpenStructure
aligned_column_iterator.hh
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // This file is part of the OpenStructure project <www.openstructure.org>
3 //
4 // Copyright (C) 2008-2011 by the OpenStructure authors
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License as published by the Free
8 // Software Foundation; either version 3.0 of the License, or (at your option)
9 // any later version.
10 // This library is distributed in the hope that it will be useful, but WITHOUT
11 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13 // details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with this library; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 //------------------------------------------------------------------------------
19 #ifndef OST_SEQ_ALIGNED_COLUMN_ITERATOR_HH
20 #define OST_SEQ_ALIGNED_COLUMN_ITERATOR_HH
21 
23 
24 /*
25  Author: Marco Biasini
26  */
27 namespace ost { namespace seq {
28 
29 class AlignedColumnIterator : public std::iterator<std::forward_iterator_tag,
30  AlignedColumn> {
31 private:
32  void UpdateVal()
33  {
34  if (curr_<end_) {
35  val_=AlignedColumn(aln_, curr_);
36  }
37  }
38 public:
39  AlignedColumnIterator(const AlignmentHandle& aln, int start, int end):
40  aln_(aln), curr_(start), end_(end)
41  {
42  this->UpdateVal();
43  }
44 
46  {
47  ++curr_;
48  this->UpdateVal();
49  return *this;
50  }
51 
53  {
54  --curr_;
55  this->UpdateVal();
56  return *this;
57  }
58 
60  {
61  AlignedColumnIterator ans(*this);
62  ++(*this);
63  return ans;
64  }
65 
67  {
68  return &val_;
69  }
70 
72  {
73  return val_;
74  }
75 
76  bool operator==(const AlignedColumnIterator& rhs) const
77  {
78  return aln_==rhs.aln_ && rhs.curr_==curr_;
79  }
80 
81  bool operator!=(const AlignedColumnIterator& rhs) const
82  {
83  return !(*this==rhs);
84  }
85 private:
86  AlignmentHandle aln_;
87  int curr_;
88  int end_;
89  AlignedColumn val_;
90 };
91 }}
92 
93 #endif