OpenStructure
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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-2020 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 
30 
31  using iterator_category = std::forward_iterator_tag;
32  using value_type = AlignedColumn;
33  using difference_type = std::ptrdiff_t;
34  using pointer = AlignedColumn*;
35  using reference = AlignedColumn&;
36 
37 private:
38  void UpdateVal()
39  {
40  if (curr_<end_) {
41  val_=AlignedColumn(aln_, curr_);
42  }
43  }
44 public:
45  AlignedColumnIterator(const AlignmentHandle& aln, int start, int end):
46  aln_(aln), curr_(start), end_(end)
47  {
48  this->UpdateVal();
49  }
50 
52  {
53  ++curr_;
54  this->UpdateVal();
55  return *this;
56  }
57 
59  {
60  --curr_;
61  this->UpdateVal();
62  return *this;
63  }
64 
66  {
67  AlignedColumnIterator ans(*this);
68  ++(*this);
69  return ans;
70  }
71 
73  {
74  return &val_;
75  }
76 
78  {
79  return val_;
80  }
81 
82  bool operator==(const AlignedColumnIterator& rhs) const
83  {
84  return aln_==rhs.aln_ && rhs.curr_==curr_;
85  }
86 
87  bool operator!=(const AlignedColumnIterator& rhs) const
88  {
89  return !(*this==rhs);
90  }
91 private:
92  AlignmentHandle aln_;
93  int curr_;
94  int end_;
95  AlignedColumn val_;
96 };
97 }}
98 
99 #endif
AlignedColumnIterator(const AlignmentHandle &aln, int start, int end)
bool operator!=(const AlignedColumnIterator &rhs) const
AlignedColumnIterator & operator++()
AlignedColumnIterator & operator--()
bool operator==(const AlignedColumnIterator &rhs) const
pointer_it< T > end(const std::vector< T > &values)
Provides access to a column in a aligned region or a sequence alignment.
AlignedColumnIterator operator++(int)
representation of a multiple sequence alignemnt consisting of two or more sequences ...