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

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

new class CigarIterator? that can be used to (surprise) iterate over a CIGAR.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.4 KB
Line 
1#ifndef theplu_yat_omic_cigar_iterator
2#define theplu_yat_omic_cigar_iterator
3
4// $Id: CigarIterator.h 3329 2014-10-12 08:25:00Z 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  private:
66    friend class boost::iterator_core_access;
67
68    const uint32_t* base_;
69    size_t index_;
70
71    void decrement(void);
72    reference dereference(void) const;
73    bool equal(const CigarIterator& other) const;
74    void increment(void);
75
76    // using compiler generated copy
77    //CigarIterator(const CigarIterator& other);
78    //CigarIterator& operator=(const CigarIterator&);
79  };
80
81}}}
82#endif
Note: See TracBrowser for help on using the repository browser.