yat  0.21pre
CigarIterator.h
1 #ifndef theplu_yat_utility_cigar_iterator
2 #define theplu_yat_utility_cigar_iterator
3 
4 // $Id: CigarIterator.h 3792 2019-04-12 07:15:09Z peter $
5 
6 /*
7  Copyright (C) 2014, 2015, 2016, 2018 Peter Johansson
8 
9  This file is part of the yat library, http://dev.thep.lu.se/yat
10 
11  The yat library is free software; you can redistribute it and/or
12  modify it under the terms of the GNU General Public License as
13  published by the Free Software Foundation; either version 3 of the
14  License, or (at your option) any later version.
15 
16  The yat library is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  General Public License for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with yat. If not, see <http://www.gnu.org/licenses/>.
23 */
24 
25 #include "Cigar.h"
26 
27 #include <boost/concept_check.hpp>
28 #include <boost/cstdint.hpp>
29 #include <boost/iterator/iterator_facade.hpp>
30 #include <boost/iterator/iterator_categories.hpp>
31 #include <boost/iterator/iterator_concepts.hpp>
32 
33 #include <cstddef> // for size_t
34 
35 namespace theplu {
36 namespace yat {
37 namespace utility {
38 
59  template<typename BASE>
61  : public boost::iterator_facade<
62  CigarIterator<BASE>, uint8_t
63  , boost::bidirectional_traversal_tag, const uint8_t>
64  {
65  public:
69  CigarIterator(void);
70 
76  explicit CigarIterator(BASE p, size_t offset=0);
77 
81  BASE base(void) const;
82  private:
83  friend class boost::iterator_core_access;
84 
85  BASE base_;
86  size_t index_;
87 
88  void decrement(void);
89  uint8_t dereference(void) const;
90  bool equal(const CigarIterator& other) const;
91  void increment(void);
92 
93  // using compiler generated copy
94  //CigarIterator(const CigarIterator& other);
95  //CigarIterator& operator=(const CigarIterator&);
96  };
97 
98 
100 
101  template<typename BASE>
103  {
104  BOOST_CONCEPT_ASSERT((boost_concepts::ReadableIterator<BASE>));
105  BOOST_CONCEPT_ASSERT((boost_concepts::BidirectionalTraversal<BASE>));
106  }
107 
108 
109  template<typename BASE>
111  : base_(b), index_(x)
112  {
113  BOOST_CONCEPT_ASSERT((boost_concepts::ReadableIterator<BASE>));
114  BOOST_CONCEPT_ASSERT((boost_concepts::BidirectionalTraversal<BASE>));
115  }
116 
117 
118  template<typename BASE>
119  BASE CigarIterator<BASE>::base(void) const
120  {
121  return base_;
122  }
123 
124 
125  template<typename BASE>
127  {
128  if (index_)
129  --index_;
130  else {
131  --base_;
132  index_ = bam_cigar_oplen(*base_)-1;
133  }
134  }
135 
136 
137  template<typename BASE>
138  uint8_t CigarIterator<BASE>::dereference(void) const
139  {
140  return bam_cigar_op(*base_);
141  }
142 
143 
144  template<typename BASE>
145  bool CigarIterator<BASE>::equal(const CigarIterator& other) const
146  {
147  return base_==other.base_ && index_==other.index_;
148  }
149 
150 
151  template<typename BASE>
152  void CigarIterator<BASE>::increment(void)
153  {
154  if (++index_ == bam_cigar_oplen(*base_)) {
155  index_=0;
156  ++base_;
157  }
158  }
159 
160 }}}
161 #endif
The Department of Theoretical Physics namespace as we define it.
Iterator over a CIGAR.
Definition: CigarIterator.h:60
CigarIterator(void)
Default constructor.
Definition: CigarIterator.h:102
BASE base(void) const
Definition: CigarIterator.h:119

Generated on Wed Jan 25 2023 03:34:29 for yat by  doxygen 1.8.14