1 #ifndef gamgee__individual_field_value_iterator__guard
2 #define gamgee__individual_field_value_iterator__guard
4 #include "../utils/variant_field_type.h"
30 template<
class VALUE_TYPE>
46 m_current_data_ptr {data_ptr},
47 m_original_data_ptr {data_ptr},
48 m_end_data_ptr {end_ptr},
49 m_num_bytes {num_bytes},
51 m_is_current_pointee_cached {
false}
70 m_body {other.m_body},
71 m_current_data_ptr {other.m_current_data_ptr},
72 m_original_data_ptr {other.m_original_data_ptr},
73 m_end_data_ptr {other.m_end_data_ptr},
74 m_num_bytes {other.m_num_bytes},
75 m_type {other.m_type},
76 m_current_data_value {other.m_current_data_value},
77 m_is_current_pointee_cached {other.m_is_current_pointee_cached}
84 m_body {std::move(other.m_body)},
85 m_current_data_ptr {other.m_current_data_ptr},
86 m_original_data_ptr {other.m_original_data_ptr},
87 m_end_data_ptr {other.m_end_data_ptr},
88 m_num_bytes {other.m_num_bytes},
89 m_type {other.m_type},
90 m_current_data_value {other.m_current_data_value},
91 m_is_current_pointee_cached {other.m_is_current_pointee_cached}
100 m_body = std::move(other.m_body);
101 m_current_data_ptr = other.m_current_data_ptr;
102 m_original_data_ptr = other.m_original_data_ptr;
103 m_end_data_ptr = other.m_end_data_ptr;
104 m_num_bytes = other.m_num_bytes;
105 m_type = other.m_type;
106 m_current_data_value = other.m_current_data_value;
107 m_is_current_pointee_cached = other.m_is_current_pointee_cached;
118 m_body = std::move(other.m_body);
119 m_current_data_ptr = other.m_current_data_ptr;
120 m_original_data_ptr = other.m_original_data_ptr;
121 m_end_data_ptr = other.m_end_data_ptr;
122 m_num_bytes = other.m_num_bytes;
123 m_type = other.m_type;
124 m_current_data_value = other.m_current_data_value;
125 m_is_current_pointee_cached = other.m_is_current_pointee_cached;
133 m_current_data_ptr += n * m_num_bytes;
134 m_is_current_pointee_cached =
false;
143 m_current_data_ptr -= n * m_num_bytes;
144 m_is_current_pointee_cached =
false;
157 return !(*
this == other);
165 return m_body == other.m_body && m_current_data_ptr < other.m_current_data_ptr;
172 return m_body == other.m_body && m_current_data_ptr > other.m_current_data_ptr;
179 return m_body == other.m_body && m_current_data_ptr <= other.m_current_data_ptr;
186 return m_body == other.m_body && m_current_data_ptr >= other.m_current_data_ptr;
194 if(m_is_current_pointee_cached)
195 return m_current_data_value;
197 return convert_from_byte_array(m_current_data_ptr, 0);
204 m_current_data_value = *(*this);
205 m_is_current_pointee_cached =
true;
206 return m_current_data_value;
215 m_current_data_ptr += m_num_bytes;
216 m_is_current_pointee_cached =
false;
239 m_current_data_ptr -= m_num_bytes;
240 m_is_current_pointee_cached =
false;
264 return (index == 0 ? *(*
this) : convert_from_byte_array(m_current_data_ptr, index));
268 std::shared_ptr<bcf1_t> m_body;
269 const uint8_t* m_current_data_ptr;
270 const uint8_t* m_original_data_ptr;
271 const uint8_t* m_end_data_ptr;
274 VALUE_TYPE m_current_data_value;
275 bool m_is_current_pointee_cached;
277 VALUE_TYPE convert_from_byte_array(
const uint8_t* data_ptr,
int index)
const;
284 int32_t IndividualFieldValueIterator<int32_t>::convert_from_byte_array(
const uint8_t* data_ptr,
int index)
const {
292 float IndividualFieldValueIterator<float>::convert_from_byte_array(
const uint8_t* data_ptr,
int index)
const {
300 std::string IndividualFieldValueIterator<std::string>::convert_from_byte_array(
const uint8_t* data_ptr,
int index)
const {
306 #endif // gamgee__individual_field_value_iterator__guard
VariantFieldType
an enumeration of the types in htslib for the format field values
Definition: variant_field_type.h:16
IndividualFieldValueIterator operator++(int) noexcept
postfix operator to advance iterator to the next position
Definition: individual_field_value_iterator.h:227
bool operator==(const IndividualFieldValueIterator &other)
two iterators are equal if they are in exactly the same state (pointing at the same location in memor...
Definition: individual_field_value_iterator.h:151
IndividualFieldValueIterator(IndividualFieldValueIterator &&other) noexcept
copy constructor is only meant for internal STL functions use. It makes a shallow copy of the underly...
Definition: individual_field_value_iterator.h:83
IndividualFieldValueIterator operator--(int) noexcept
postfix operator to retreat iterator to the previous position
Definition: individual_field_value_iterator.h:250
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
IndividualFieldValueIterator & operator=(IndividualFieldValueIterator &&other) noexcept
safely moves the data from one VariantField to a new one without making any copies ...
Definition: individual_field_value_iterator.h:115
IndividualFieldValueIterator & operator+=(const int n)
simple compound assignment operation for random advances (back/forward) to the iterator ...
Definition: individual_field_value_iterator.h:132
IndividualFieldValueIterator & operator--()
advances to the previous sample
Definition: individual_field_value_iterator.h:238
IndividualFieldValueIterator(const std::shared_ptr< bcf1_t > &body, uint8_t *data_ptr, uint8_t *end_ptr, const uint8_t num_bytes, const utils::VariantFieldType &type)
Constructor with bcf1_t structure and start and end pointers of the array/vector. ...
Definition: individual_field_value_iterator.h:44
bool operator>(const IndividualFieldValueIterator &other)
an operator is greater/less than another iterator if it is pointing to a previous element (sample) in...
Definition: individual_field_value_iterator.h:171
IndividualFieldValueIterator & operator++() noexcept
advances to the next sample
Definition: individual_field_value_iterator.h:214
VALUE_TYPE operator[](const uint32_t index) const
random access to the value of a given index for reading or writing
Definition: individual_field_value_iterator.h:262
void iterator(const char *fname)
Definition: test-vcf-api.c:248
IndividualFieldValueIterator(const IndividualFieldValueIterator &other)
copy constructor is only meant for internal STL functions use. It makes a shallow copy of the underly...
Definition: individual_field_value_iterator.h:69
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
IndividualFieldValueIterator & operator-=(const int n)
simple compound assignment operation for random advances (back/forward) to the iterator ...
Definition: individual_field_value_iterator.h:142
Definition: exceptions.h:9
IndividualFieldValueIterator & operator=(const IndividualFieldValueIterator &other)
copy constructor is only meant for internal STL functions use. It makes a shallow copy of the underly...
Definition: individual_field_value_iterator.h:97
bool operator>=(const IndividualFieldValueIterator &other)
an operator is greater/less than another iterator if it is pointing to a previous element (sample) in...
Definition: individual_field_value_iterator.h:185
VALUE_TYPE read_and_cache_current_pointee() noexcept
Definition: individual_field_value_iterator.h:203
iterator for FormatFieldGenericValue objects.
Definition: individual_field_value_iterator.h:31
bool operator<=(const IndividualFieldValueIterator &other)
an operator is greater/less than another iterator if it is pointing to a previous element (sample) in...
Definition: individual_field_value_iterator.h:178
IndividualFieldValueIterator(const std::shared_ptr< bcf1_t > &body, uint8_t *data_ptr, const uint8_t num_bytes, const utils::VariantFieldType &type)
Constructor with bcf1_t structure and start pointer of the array/vector.
Definition: individual_field_value_iterator.h:63
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
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
bool operator!=(const IndividualFieldValueIterator &other)
the oposite check of IndividualFieldValueIterator::operator==()
Definition: individual_field_value_iterator.h:156
bool operator<(const IndividualFieldValueIterator &other)
an operator is greater/less than another iterator if it is pointing to a previous element (sample) in...
Definition: individual_field_value_iterator.h:164
VALUE_TYPE operator*() const noexcept
direct access to the value of the current sample
Definition: individual_field_value_iterator.h:193