yat  0.13.2pre
CigarIterator.h
1 #ifndef theplu_yat_utility_cigar_iterator
2 #define theplu_yat_utility_cigar_iterator
3 
4 // $Id: CigarIterator.h 3385 2015-03-13 07:55:49Z peter $
5 
6 /*
7  Copyright (C) 2014, 2015 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 this program. 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 
55  template<typename BASE>
57  : public boost::iterator_facade<
58  CigarIterator<BASE>, uint8_t
59  , boost::bidirectional_traversal_tag, const uint8_t>
60  {
61  public:
65  CigarIterator(void);
66 
72  explicit CigarIterator(BASE p, size_t offset=0);
73 
77  BASE base(void) const;
78  private:
79  friend class boost::iterator_core_access;
80 
81  BASE base_;
82  size_t index_;
83 
84  void decrement(void);
85  uint8_t dereference(void) const;
86  bool equal(const CigarIterator& other) const;
87  void increment(void);
88 
89  // using compiler generated copy
90  //CigarIterator(const CigarIterator& other);
91  //CigarIterator& operator=(const CigarIterator&);
92  };
93 
94 
96 
97  template<typename BASE>
99  {
100  BOOST_CONCEPT_ASSERT((boost_concepts::ReadableIterator<BASE>));
101  BOOST_CONCEPT_ASSERT((boost_concepts::BidirectionalTraversal<BASE>));
102  }
103 
104 
105  template<typename BASE>
107  : base_(b), index_(x)
108  {
109  BOOST_CONCEPT_ASSERT((boost_concepts::ReadableIterator<BASE>));
110  BOOST_CONCEPT_ASSERT((boost_concepts::BidirectionalTraversal<BASE>));
111  }
112 
113 
114  template<typename BASE>
115  BASE CigarIterator<BASE>::base(void) const
116  {
117  return base_;
118  }
119 
120 
121  template<typename BASE>
123  {
124  if (index_)
125  --index_;
126  else {
127  --base_;
128  index_ = bam_cigar_oplen(*base_)-1;
129  }
130  }
131 
132 
133  template<typename BASE>
134  uint8_t CigarIterator<BASE>::dereference(void) const
135  {
136  return bam_cigar_op(*base_);
137  }
138 
139 
140  template<typename BASE>
141  bool CigarIterator<BASE>::equal(const CigarIterator& other) const
142  {
143  return base_==other.base_ && index_==other.index_;
144  }
145 
146 
147  template<typename BASE>
148  void CigarIterator<BASE>::increment(void)
149  {
150  if (++index_ == bam_cigar_oplen(*base_)) {
151  index_=0;
152  ++base_;
153  }
154  }
155 
156 }}}
157 #endif
Iterator over a CIGAR.
Definition: CigarIterator.h:56
BASE base(void) const
Definition: CigarIterator.h:115
CigarIterator(void)
Default constructor.
Definition: CigarIterator.h:98

Generated on Wed Jan 4 2017 02:23:07 for yat by  doxygen 1.8.5