15 template <core::Numerical ROW, core::Numerical TYPE>
class GenderTable {
27 : table_{
std::move(values)}, rows_index_{}, cols_index_{} {
28 if (
rows.size() != table_.rows() || cols.size() != table_.columns()) {
29 throw std::invalid_argument(
"Lookup breakpoints and values size mismatch.");
32 auto rows_count =
static_cast<int>(
rows.size());
33 for (
auto index = 0; index < rows_count; index++) {
34 rows_index_.emplace(
rows[index], index);
37 auto cols_count =
static_cast<int>(cols.size());
38 for (
auto index = 0; index < cols_count; index++) {
39 cols_index_.emplace(cols[index], index);
45 std::size_t
size() const noexcept {
return table_.size(); }
49 std::size_t
rows() const noexcept {
return table_.rows(); }
53 std::size_t
columns() const noexcept {
return table_.columns(); }
57 bool empty() const noexcept {
return rows_index_.empty() || cols_index_.empty(); }
65 return table_(rows_index_.at(row), cols_index_.at(gender));
74 return table_(rows_index_.at(row), cols_index_.at(gender));
83 return table_(rows_index_.at(row), cols_index_.at(gender));
92 return table_(rows_index_.at(row), cols_index_.at(gender));
98 bool contains(
const ROW row)
const noexcept {
return rows_index_.contains(row); }
105 if (rows_index_.contains(row)) {
106 return cols_index_.contains(gender);
114 std::map<ROW, int> rows_index_{};
115 std::map<core::Gender, int> cols_index_{};
141 template <core::Numerical TYPE>
143 if (rows_range.
lower() < 0 || rows_range.
lower() >= rows_range.
upper()) {
144 throw std::out_of_range(
"The 'range lower' value must be greater than zero and less than "
145 "the 'range upper' value.");
148 auto rows = std::vector<int>(
static_cast<size_t>(rows_range.
length()) + 1);
149 std::iota(rows.begin(), rows.end(), rows_range.
lower());
161 template <core::Numerical TYPE>
164 throw std::invalid_argument(
165 "The 'age lower' value must be greater than zero and less than the 'age upper' value.");
168 auto rows = std::vector<int>(
static_cast<std::size_t
>(age_range.
length()) + 1);
169 std::iota(rows.begin(), rows.end(), age_range.
lower());
Defines the age and gender lookup table data type.
Definition: gender_table.h:120
AgeGenderTable(const MonotonicVector< int > &rows, const std::vector< core::Gender > &cols, core::Array2D< TYPE > &&values)
Initialises a new instance of the AgeGenderTable class.
Definition: gender_table.h:130
AgeGenderTable()=default
Initialises a new instance of the AgeGenderTable class.
Defines the gender column lookup table data type.
Definition: gender_table.h:15
bool empty() const noexcept
Determine whether the lookup table is empty.
Definition: gender_table.h:57
std::size_t rows() const noexcept
Get the number of rows lookup breakpoints.
Definition: gender_table.h:49
const TYPE & at(const ROW row, const core::Gender gender) const
Gets a read-only value at a given row and column intersection.
Definition: gender_table.h:73
GenderTable()=default
Initialises a new instance of the GenderTable class.
bool contains(const ROW row, const core::Gender gender) const noexcept
Determines whether the lookup contains a value.
Definition: gender_table.h:104
std::size_t size() const noexcept
Gets the lookup table size.
Definition: gender_table.h:45
std::size_t columns() const noexcept
Get the number of columns lookup breakpoints.
Definition: gender_table.h:53
GenderTable(const MonotonicVector< ROW > &rows, const std::vector< core::Gender > &cols, core::Array2D< TYPE > &&values)
Initialises a new instance of the GenderTable class.
Definition: gender_table.h:25
bool contains(const ROW row) const noexcept
Determines whether the lookup contains a row.
Definition: gender_table.h:98
TYPE & operator()(const ROW row, const core::Gender gender)
Gets a value at a given row and column intersection.
Definition: gender_table.h:82
const TYPE & operator()(const ROW row, const core::Gender gender) const
Gets a read-only value at a given row and column intersection.
Definition: gender_table.h:91
TYPE & at(const ROW row, const core::Gender gender)
Gets a value at a given row and column intersection.
Definition: gender_table.h:64
Defines a monotonic vector container type.
Definition: monotonic_vector.h:42
Defines a contiguous storage for two-dimensional numerical data in row-major format.
Definition: array2d.h:15
Numeric interval representation data type.
Definition: interval.h:10
TYPE upper() const noexcept
Gets the interval upper bound.
Definition: interval.h:27
TYPE length() const noexcept
Gets the interval length.
Definition: interval.h:31
TYPE lower() const noexcept
Gets the interval lower bound.
Definition: interval.h:23
Gender
Enumerates gender types.
Definition: forward_type.h:18
Top-level namespace for Health-GPS C++ API.
Definition: analysis_definition.h:8
GenderTable< int, TYPE > create_integer_gender_table(const core::IntegerInterval &rows_range)
Creates an instance of the gender lookup table for integer rows breakpoints value.
Definition: gender_table.h:142
AgeGenderTable< TYPE > create_age_gender_table(const core::IntegerInterval &age_range)
Creates an instance of the age and gender lookup table.
Definition: gender_table.h:162
Global namespace.
Definition: jsonparser.h:88