source: trunk/yat/omic/CigarIterator.h @ 3332

Last change on this file since 3332 was 3332, checked in by Peter, 7 years ago

In Pileup store reads in a std::list (rather than std::deque) to allow
easy erase as soon as we are one passed last base. Erasing reads
immediately implies we don't need a filter_iterator, but can use
list::const_iterator directly.

Fix a bug in Pileup::Entry, which held a BamRead? and CigarIterator? and
the latter is essentially a uint32_t* that is returned from
BamRead::cigar(). This caused problems in copy/assignment since the
BamRead? was copied by value and the CigarIterator? didn't point to
BamRead? in this class but to BamRead? in rhs. The problem was solved by
replacing the BamRead? by a shared_ptr<BamRead?>.

refs #806

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.5 KB
Line 
1#ifndef theplu_yat_omic_cigar_iterator
2#define theplu_yat_omic_cigar_iterator
3
4// $Id: CigarIterator.h 3332 2014-10-23 11:18:15Z peter $
5
6/*
7  Copyright (C) 2014 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 <boost/cstdint.hpp>
26#include <boost/iterator/iterator_facade.hpp>
27#include <boost/iterator/iterator_categories.hpp>
28
29namespace theplu {
30namespace yat {
31namespace omic {
32
33  /**
34     \brief Iterator over a CIGAR
35
36     A CIGAR string is typically represented as a compact array, i.e.,
37     an array \c MMMMMMDDMMMM is represented as \c 6M2D4M. This class
38     is a proxy that allows iterating over a CIGAR as though the array
39     was \c MMMMMMDDMMMM.
40
41     CigarIterator is a \readable_iterator (not mutable) and and
42     models a \bidirectional_traversal_iterator. Its value_type is \c
43     uint8_t. Since no \c uint8_t is stored in CIGAR, the dereference
44     operator calculates the CIGAR element to return and returns by
45     value. CigarIterator is therefore an \input_iterator.
46
47     \since New in yat 0.13
48   */
49  class CigarIterator
50    : public boost::iterator_facade<
51    CigarIterator, uint8_t, boost::bidirectional_traversal_tag, const uint8_t>
52  {
53  public:
54    /**
55       \brief Default constructor
56     */
57    CigarIterator(void);
58
59    /**
60       Construct an iterator that points to element offset in \a p. If
61       \a p corresponds to \c 5M and offset is 2, the iterator points to
62       the third \c M.
63     */
64    explicit CigarIterator(const uint32_t* p, size_t offset=0);
65
66    /**
67       \return underlying iterator
68     */
69    const uint32_t* base(void) const;
70  private:
71    friend class boost::iterator_core_access;
72
73    const uint32_t* base_;
74    size_t index_;
75
76    void decrement(void);
77    reference dereference(void) const;
78    bool equal(const CigarIterator& other) const;
79    void increment(void);
80
81    // using compiler generated copy
82    //CigarIterator(const CigarIterator& other);
83    //CigarIterator& operator=(const CigarIterator&);
84  };
85
86}}}
87#endif
Note: See TracBrowser for help on using the repository browser.