Gamgee
You miserable little maggot. I'll stove your head in!
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
variant_builder_multi_sample_vector.h
Go to the documentation of this file.
1 #ifndef gamgee__variant_builder_multi_sample_vector__guard
2 #define gamgee__variant_builder_multi_sample_vector__guard
3 
4 #include <vector>
5 #include <string>
6 #include <cassert>
7 
8 namespace gamgee {
9 
39 template<class ELEMENT_TYPE>
41  public:
42 
53  VariantBuilderMultiSampleVector(const uint32_t num_samples, const uint32_t max_values_per_sample, const ELEMENT_TYPE missing_value, const ELEMENT_TYPE end_of_vector_value) :
54  m_multi_sample_values(num_samples * max_values_per_sample, end_of_vector_value), // Fill with end_of_vector_value
55  m_num_samples{num_samples},
56  m_max_values_per_sample{max_values_per_sample}
57  {
58  // Place a single missing value at the start of each sample's values (the rest of the vector has already
59  // been padded with vector end values)
60  for ( auto sample_start = 0u; sample_start < m_multi_sample_values.size(); sample_start += m_max_values_per_sample ) {
61  m_multi_sample_values[sample_start] = missing_value;
62  }
63  }
64 
65  // Both copyable and moveable, with default destruction
71 
85  inline void set_sample_value(const uint32_t sample_index, const uint32_t value_index, const ELEMENT_TYPE value) {
86  assert(sample_index < m_num_samples);
87  assert(value_index < m_max_values_per_sample);
88 
89  m_multi_sample_values[sample_index * m_max_values_per_sample + value_index] = value;
90  }
91 
104  inline void set_sample_values(const uint32_t sample_index, const std::vector<ELEMENT_TYPE>& values) {
105  assert(sample_index < m_num_samples);
106  assert(values.size() <= m_max_values_per_sample);
107 
108  const auto sample_start = sample_index * m_max_values_per_sample;
109  for ( auto value_index = 0u; value_index < values.size(); ++value_index ) {
110  m_multi_sample_values[sample_start + value_index] = values[value_index];
111  }
112  }
113 
117  const std::vector<ELEMENT_TYPE>& get_vector() const { return m_multi_sample_values; }
118 
122  uint32_t num_samples() const { return m_num_samples; }
123 
127  uint32_t max_values_per_sample() const { return m_max_values_per_sample; }
128 
129  private:
130  std::vector<ELEMENT_TYPE> m_multi_sample_values;
131  uint32_t m_num_samples;
132  uint32_t m_max_values_per_sample;
133 
134  friend class VariantBuilder; // VariantBuilder needs access to internals in order to build efficiently
135 };
136 
137 }
138 
139 #endif /* gamgee__variant_builder_multi_sample_vector__guard */
uint32_t num_samples() const
Return the number of samples whose values we are storing.
Definition: variant_builder_multi_sample_vector.h:122
void set_sample_value(const uint32_t sample_index, const uint32_t value_index, const ELEMENT_TYPE value)
Set a single value for one sample.
Definition: variant_builder_multi_sample_vector.h:85
uint32_t max_values_per_sample() const
Return the maximum number of values across all samples.
Definition: variant_builder_multi_sample_vector.h:127
VariantBuilderMultiSampleVector(const uint32_t num_samples, const uint32_t max_values_per_sample, const ELEMENT_TYPE missing_value, const ELEMENT_TYPE end_of_vector_value)
Construct a VariantBuilderMultiSampleVector.
Definition: variant_builder_multi_sample_vector.h:53
Class that allows you to efficiently prepare multi-sample data for setting individual fields in Varia...
Definition: variant_builder_multi_sample_vector.h:40
VariantBuilder: construct Variant records from scratch (and, coming soon, from existing Variant recor...
Definition: variant_builder.h:164
Definition: exceptions.h:9
const std::vector< ELEMENT_TYPE > & get_vector() const
Get a reference to the internal one-dimensional vector used for value storage.
Definition: variant_builder_multi_sample_vector.h:117
VariantBuilderMultiSampleVector & operator=(const VariantBuilderMultiSampleVector &other)=default
void set_sample_values(const uint32_t sample_index, const std::vector< ELEMENT_TYPE > &values)
Set all values for one sample at once.
Definition: variant_builder_multi_sample_vector.h:104