Gamgee
You miserable little maggot. I'll stove your head in!
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
variant_filters_iterator.h
Go to the documentation of this file.
1 #ifndef gamgee__variant_filters_iterator__guard
2 #define gamgee__variant_filters_iterator__guard
3 
4 #include "variant_filters.h"
5 
6 #include "../utils/hts_memory.h"
7 
8 #include "htslib/vcf.h"
9 
10 #include <string>
11 #include <memory>
12 
13 namespace gamgee {
14 
18 class VariantFiltersIterator : public std::iterator<std::random_access_iterator_tag, std::string> {
19  public:
20 
27  VariantFiltersIterator(const std::shared_ptr<bcf_hdr_t>& header, const std::shared_ptr<bcf1_t>& body, const uint32_t position) :
28  m_header {header},
29  m_body {body},
30  m_position {position}
31  {}
32 
33  std::string operator[](int index) const { return utils::htslib_filter_name(m_header.get(), m_body.get(), index); }
34  std::string operator*() const { return utils::htslib_filter_name(m_header.get(), m_body.get(), m_position); }
35  VariantFiltersIterator operator++() { m_position++; return *this; }
36  VariantFiltersIterator operator--() { m_position--; return *this; }
37  VariantFiltersIterator operator+=(const int n) { m_position += n; return *this; }
38  VariantFiltersIterator operator-=(const int n) { m_position -= n; return *this; }
39  bool operator!=(const VariantFiltersIterator& other) { return m_position != other.m_position || m_body != other.m_body || m_header != other.m_header; }
40  bool operator==(const VariantFiltersIterator& other) { return m_position == other.m_position && m_body == other.m_body && m_header == other.m_header; }
41  bool operator<=(const VariantFiltersIterator& other) { return m_position <= other.m_position && m_body == other.m_body && m_header == other.m_header; }
42  bool operator>=(const VariantFiltersIterator& other) { return m_position >= other.m_position && m_body == other.m_body && m_header == other.m_header; }
43  bool operator< (const VariantFiltersIterator& other) { return m_position < other.m_position && m_body == other.m_body && m_header == other.m_header; }
44  bool operator> (const VariantFiltersIterator& other) { return m_position > other.m_position && m_body == other.m_body && m_header == other.m_header; }
45 
46  uint32_t size() const { return uint32_t(m_body->d.n_flt); }
47 
48  private:
49  std::shared_ptr<bcf_hdr_t> m_header;
50  std::shared_ptr<bcf1_t> m_body;
51  uint32_t m_position;
52 };
53 
54 }
55 
56 #endif // gamgee__variant_filters_iterator__guard
VariantFiltersIterator operator-=(const int n)
rewinds the iterator by n positions
Definition: variant_filters_iterator.h:38
bool operator<(const VariantFiltersIterator &other)
Can be compared with inequality relational operators (<, >, <= and >=).
Definition: variant_filters_iterator.h:43
VariantFiltersIterator(const std::shared_ptr< bcf_hdr_t > &header, const std::shared_ptr< bcf1_t > &body, const uint32_t position)
simple constructor used by the VariantFilters begin/end member functions
Definition: variant_filters_iterator.h:27
simple random-access iterator class for VariantFilters objects
Definition: variant_filters_iterator.h:18
bool operator>(const VariantFiltersIterator &other)
Can be compared with inequality relational operators (<, >, <= and >=).
Definition: variant_filters_iterator.h:44
bool operator>=(const VariantFiltersIterator &other)
Can be compared with inequality relational operators (<, >, <= and >=).
Definition: variant_filters_iterator.h:42
uint32_t size() const
returns the number of filters in this object
Definition: variant_filters_iterator.h:46
bool operator!=(const VariantFiltersIterator &other)
can be compared for equivalence using the equality/inequality operators
Definition: variant_filters_iterator.h:39
void iterator(const char *fname)
Definition: test-vcf-api.c:248
bool operator==(const VariantFiltersIterator &other)
can be compared for equivalence using the equality/inequality operators
Definition: variant_filters_iterator.h:40
VariantFiltersIterator operator--()
rewinds the iterator by one position
Definition: variant_filters_iterator.h:36
Definition: exceptions.h:9
std::string operator[](int index) const
returns a new string for the element at position 'index'
Definition: variant_filters_iterator.h:33
VariantFiltersIterator operator+=(const int n)
advances the iterator by n positions
Definition: variant_filters_iterator.h:37
bool operator<=(const VariantFiltersIterator &other)
Can be compared with inequality relational operators (<, >, <= and >=).
Definition: variant_filters_iterator.h:41
std::string htslib_filter_name(bcf_hdr_t *header, bcf1_t *body, int index)
helper function to translate an index into a string in the filter list
Definition: hts_memory.cpp:144
std::string operator*() const
returns a new string for the element at the current position
Definition: variant_filters_iterator.h:34
VariantFiltersIterator operator++()
advances the iterator by one position
Definition: variant_filters_iterator.h:35