1 #ifndef gamgee__shared_field_iterator__guard
2 #define gamgee__shared_field_iterator__guard
4 #include "../utils/variant_field_type.h"
27 template<
class VALUE_TYPE>
37 m_current_data_ptr {
nullptr},
38 m_original_data_ptr{
nullptr},
39 m_end_data_ptr{
nullptr},
42 m_is_current_pointee_cached{
false}
56 m_current_data_ptr {data_ptr},
57 m_original_data_ptr {data_ptr},
58 m_end_data_ptr {end_ptr},
59 m_bytes_per_value {bytes_per_value},
61 m_is_current_pointee_cached{
false}
88 if(m_is_current_pointee_cached)
89 return m_current_data_value;
91 return convert_from_byte_array(m_current_data_ptr, 0);
98 m_current_data_value = *(*this);
99 m_is_current_pointee_cached =
true;
100 return m_current_data_value;
105 m_current_data_ptr += n * m_bytes_per_value;
106 m_is_current_pointee_cached =
false;
113 m_current_data_ptr -= n * m_bytes_per_value;
114 m_is_current_pointee_cached =
false;
125 m_current_data_ptr += m_bytes_per_value;
126 m_is_current_pointee_cached =
false;
151 m_current_data_ptr -= m_bytes_per_value;
152 m_is_current_pointee_cached =
false;
173 return static_cast<int32_t
>(m_current_data_ptr - first.m_current_data_ptr)/m_bytes_per_value;
184 return (index == 0 ? *(*
this) : convert_from_byte_array(m_current_data_ptr, index));
188 std::shared_ptr<bcf1_t> m_body;
189 const uint8_t* m_current_data_ptr;
190 const uint8_t* m_original_data_ptr;
191 const uint8_t* m_end_data_ptr;
192 uint8_t m_bytes_per_value;
194 VALUE_TYPE m_current_data_value;
195 bool m_is_current_pointee_cached;
197 VALUE_TYPE convert_from_byte_array(
const uint8_t* data_ptr,
int index)
const;
204 int32_t SharedFieldIterator<int32_t>::convert_from_byte_array(
const uint8_t* data_ptr,
int index)
const {
212 float SharedFieldIterator<float>::convert_from_byte_array(
const uint8_t* data_ptr,
int index)
const {
220 std::string SharedFieldIterator<std::string>::convert_from_byte_array(
const uint8_t* data_ptr,
int index)
const {
226 #endif // gamgee__shared_field_iterator__guard
bool operator<=(const SharedFieldIterator &other)
not greater than other
Definition: shared_field_iterator.h:84
VariantFieldType
an enumeration of the types in htslib for the format field values
Definition: variant_field_type.h:16
bool operator==(const SharedFieldIterator &other)
Definition: shared_field_iterator.h:80
int32_t operator-(const SharedFieldIterator &first) const
difference between two iterators as an integer.
Definition: shared_field_iterator.h:172
SharedFieldIterator()
default constructor of an empty iterator
Definition: shared_field_iterator.h:35
SharedFieldIterator operator--(int) noexcept
Postfix decrement. Move back to the previous sample.
Definition: shared_field_iterator.h:162
SharedFieldIterator(const std::shared_ptr< bcf1_t > &body, uint8_t *data_ptr, const uint8_t bytes_per_value, const utils::VariantFieldType &type)
Constructor with bcf1_t structure and start pointer of the vector/array.
Definition: shared_field_iterator.h:72
SharedFieldIterator operator++(int) noexcept
Postfix increment. Advances to the next sample.
Definition: shared_field_iterator.h:137
std::string convert_data_to_string(const uint8_t *data_ptr, const int index, const uint8_t num_bytes_per_value, const VariantFieldType &type)
converts the value in an index from the byte array into string
Definition: variant_field_type.cpp:77
SharedFieldIterator & operator--()
advances to the previous value
Definition: shared_field_iterator.h:150
SharedFieldIterator & operator=(const SharedFieldIterator &other)=default
standard copy assignment operator creates a new iterator pointing to the same underlying data ...
bool operator>=(const SharedFieldIterator &other)
not smaller than other
Definition: shared_field_iterator.h:85
SharedFieldIterator & operator+=(const int n)
Definition: shared_field_iterator.h:104
bool operator>(const SharedFieldIterator &other)
not smaller than other neither equal to other
Definition: shared_field_iterator.h:83
SharedFieldIterator & operator-=(const int n)
Definition: shared_field_iterator.h:112
VALUE_TYPE operator*() const noexcept
Definition: shared_field_iterator.h:87
bool operator<(const SharedFieldIterator &other)
an operator is greater/less than another iterator if it is pointing to a previous element in the Shar...
Definition: shared_field_iterator.h:82
void iterator(const char *fname)
Definition: test-vcf-api.c:248
const uint8_t * cache_and_advance_to_end_if_necessary(const uint8_t *current_ptr, const uint8_t *end_ptr, ITER &it)
advances current ptr to end of the vector if the current element is bcf_*_vector_end ...
Definition: utils.h:130
VALUE_TYPE operator[](const uint32_t index) const
random access to the value of a given index for reading or writing
Definition: shared_field_iterator.h:183
Definition: exceptions.h:9
VALUE_TYPE read_and_cache_current_pointee() noexcept
Definition: shared_field_iterator.h:97
bool operator!=(const SharedFieldIterator &other)
the negation of SharedFieldIterator::operator==()
Definition: shared_field_iterator.h:81
SharedFieldIterator & operator++() noexcept
advances to the next value
Definition: shared_field_iterator.h:124
int32_t convert_data_to_integer(const uint8_t *data_ptr, const int index, const uint8_t num_bytes_per_value, const VariantFieldType &type)
converts the value in an index from the byte array into int32_t
Definition: variant_field_type.cpp:11
iterator for SharedField objects.
Definition: shared_field_iterator.h:28
float convert_data_to_float(const uint8_t *data_ptr, const int index, const uint8_t num_bytes_per_value, const VariantFieldType &type)
converts the value in an index from the byte array into float
Definition: variant_field_type.cpp:41
SharedFieldIterator(const std::shared_ptr< bcf1_t > &body, uint8_t *data_ptr, uint8_t *end_ptr, const uint8_t bytes_per_value, const utils::VariantFieldType &type)
Constructor with bcf1_t structure and start and end pointers of the vector/array. ...
Definition: shared_field_iterator.h:54