10 template <
class TROW,
class TCOL,
class TCell>
class Map2d {
13 using IteratorType =
typename std::map<TROW, std::map<TCOL, TCell>>::iterator;
23 Map2d(std::map<TROW, std::map<TCOL, TCell>> &&data) noexcept : table_{std::move(data)} {}
27 bool empty() const noexcept {
return table_.empty(); }
35 std::size_t
rows() const noexcept {
return table_.size(); }
40 if (table_.size() > 0) {
43 return table_.begin()->second.size();
52 bool contains(
const TROW &row_key)
const {
return table_.contains(row_key); }
58 bool contains(
const TROW &row_key,
const TCOL &col_key)
const {
59 if (table_.contains(row_key)) {
60 return table_.at(row_key).contains(col_key);
69 std::map<TCOL, TCell> &
row(
const TROW &row_key) {
return table_.at(row_key); }
74 const std::map<TCOL, TCell> &
row(
const TROW &row_key)
const {
return table_.at(row_key); }
80 TCell &
at(
const TROW &row_key,
const TCOL &col_key) {
return table_.at(row_key).at(col_key); }
86 const TCell &
at(
const TROW &row_key,
const TCOL &col_key)
const {
87 return table_.at(row_key).at(col_key);
115 std::map<TROW, std::map<TCOL, TCell>> table_;
Defines the two-dimensional map (lookup table) data type.
Definition: map2d.h:10
typename std::map< TROW, std::map< TCOL, TCell > >::iterator IteratorType
Map row iterator.
Definition: map2d.h:13
std::size_t size() const noexcept
Gets the total size of the container dataset.
Definition: map2d.h:31
Map2d()=default
Initialises a new instance of the Map2d class.
const std::map< TCOL, TCell > & row(const TROW &row_key) const
Gets a read-row dataset.
Definition: map2d.h:74
bool contains(const TROW &row_key) const
Determines whether the container contains a row.
Definition: map2d.h:52
bool empty() const noexcept
Determine whether the container is empty.
Definition: map2d.h:27
IteratorType begin() noexcept
Gets an iterator to the beginning of the map.
Definition: map2d.h:92
TCell & at(const TROW &row_key, const TCOL &col_key)
Gets a value at a cell by row and column with bounds checking.
Definition: map2d.h:80
bool contains(const TROW &row_key, const TCOL &col_key) const
Determines whether the container contains a value.
Definition: map2d.h:58
ConstIteratorType end() const noexcept
Gets an read-only iterator to the element following the element of the map.
Definition: map2d.h:104
typename std::map< TROW, std::map< TCOL, TCell > >::const_iterator ConstIteratorType
Read-only map iterator.
Definition: map2d.h:16
ConstIteratorType cbegin() const noexcept
Gets an read-only iterator to the beginning of the map.
Definition: map2d.h:108
Map2d(std::map< TROW, std::map< TCOL, TCell >> &&data) noexcept
Initialises a new instance of the Map2d class.
Definition: map2d.h:23
std::map< TCOL, TCell > & row(const TROW &row_key)
Gets a row dataset.
Definition: map2d.h:69
std::size_t rows() const noexcept
Gets the number of rows.
Definition: map2d.h:35
ConstIteratorType begin() const noexcept
Gets an read-only iterator to the beginning of the map.
Definition: map2d.h:100
std::size_t columns() const noexcept
Gets the number of columns.
Definition: map2d.h:39
ConstIteratorType cend() const noexcept
Gets an read-only iterator to the element following the element of the map.
Definition: map2d.h:112
const TCell & at(const TROW &row_key, const TCOL &col_key) const
Gets a read-only value at a cell by row and column with bounds checking.
Definition: map2d.h:86
IteratorType end() noexcept
Gets an iterator to the element following the element of the map.
Definition: map2d.h:96
Top-level namespace for Health-GPS C++ API.
Definition: analysis_definition.h:8