yat  0.10.4pre
BamReadIterator.h
1 #ifndef theplu_yat_omic_bam_read_iterator
2 #define theplu_yat_omic_bam_read_iterator
3 
4 // $Id: BamReadIterator.h 3014 2013-04-04 02:43:32Z peter $
5 //
6 // Copyright (C) 2012, 2013 Peter Johansson
7 //
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 3 of the License, or
11 // (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful, but
14 // WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 
21 #include "BamFile.h"
22 #include "BamRead.h"
23 #include "config_bam.h"
24 
25 #include YAT_SAM_HEADER
26 
27 #include <boost/iterator/iterator_facade.hpp>
28 #include <boost/shared_ptr.hpp>
29 
30 #include <iterator>
31 
32 namespace theplu {
33 namespace yat {
34 namespace omic {
35 
36  // forward declaration
37  class InBamFile;
38 
57  : public boost::iterator_facade<
58  BamReadIterator, const BamRead, std::input_iterator_tag
59  >
60  {
61  public:
65  BamReadIterator(void);
66 
73  explicit BamReadIterator(InBamFile& in);
74 
92  BamReadIterator(InBamFile& in, int32_t tid, int32_t start, int32_t end);
93  private:
94  friend class boost::iterator_core_access;
95  BamReadIterator::reference dereference(void) const;
96  bool equal(const BamReadIterator& other) const;
97  void increment(void);
98 
99  /*
100  Interface class for the actor that handles difference between
101  an iterator that iterates the entire file and one that uses
102  index to iterate over a specific region.
103  */
104  class Actor
105  {
106  public:
107  explicit Actor(InBamFile*);
108  virtual ~Actor(void);
109  virtual void increment(void)=0;
110  InBamFile* in_;
111  BamRead read_;
112  };
113 
114  // class used when region is entire file
115  class AllActor : public Actor
116  {
117  public:
118  AllActor(void);
119  explicit AllActor(InBamFile&);
120  void increment(void);
121  };
122 
123  // class used when iterating over a sub-region of the bam file
124  class IndexActor : public Actor
125  {
126  public:
127  IndexActor(InBamFile& bf, int32_t tid, int32_t begin, int32_t end);
128  void increment(void);
129  private:
130  boost::shared_ptr<__bam_iter_t> iter_;
131  };
132 
133  boost::shared_ptr<Actor> actor_;
134 
135  struct IndexDestroyer
136  {
137  void operator()(bam_iter_t i) const
138  {
139  bam_iter_destroy(i);
140  }
141  };
142  };
143 }}}
144 #endif

Generated on Mon Nov 11 2013 09:41:44 for yat by  doxygen 1.8.1