Health-GPS 3.0.0.0
Global Health Policy Simulation model (Health-GPS)
Loading...
Searching...
No Matches
datatable.h
Go to the documentation of this file.
1#pragma once
2
3#include <algorithm>
4#include <memory>
5#include <mutex>
6#include <optional>
7#include <ostream>
8#include <unordered_map>
9#include <vector>
10
11#include "column.h"
12
13namespace hgps::core {
14
16class DataTable {
17 public:
19 using IteratorType = std::vector<std::unique_ptr<DataTableColumn>>::const_iterator;
20
23 std::size_t num_columns() const noexcept;
24
27 std::size_t num_rows() const noexcept;
28
31 std::vector<std::string> names() const;
32
36 void add(std::unique_ptr<DataTableColumn> column);
37
42 const DataTableColumn &column(std::size_t index) const;
43
48 const DataTableColumn &column(const std::string &name) const;
49
53 std::optional<std::reference_wrapper<const DataTableColumn>>
54 column_if_exists(const std::string &name) const;
55
58 IteratorType cbegin() const noexcept { return columns_.cbegin(); }
59
62 IteratorType cend() const noexcept { return columns_.cend(); }
63
66 std::string to_string() const noexcept;
67
68 private:
69 std::unique_ptr<std::mutex> sync_mtx_{std::make_unique<std::mutex>()};
70 std::vector<std::string> names_{};
71 std::unordered_map<std::string, std::size_t> index_{};
72 std::vector<std::unique_ptr<DataTableColumn>> columns_{};
73 size_t rows_count_ = 0;
74};
75
76} // namespace hgps::core
77
82std::ostream &operator<<(std::ostream &stream, const hgps::core::DataTable &table);
DataTable columns interface data type.
Definition column.h:11
Defines a Datatable for in memory data class.
Definition datatable.h:16
IteratorType cbegin() const noexcept
Gets the iterator to the first column of the table.
Definition datatable.h:58
IteratorType cend() const noexcept
Gets the iterator element following the last column of the table.
Definition datatable.h:62
std::size_t num_columns() const noexcept
Gets the number of columns.
Definition datatable.cpp:10
std::size_t num_rows() const noexcept
Gets the number of rows.
Definition datatable.cpp:12
std::optional< std::reference_wrapper< const DataTableColumn > > column_if_exists(const std::string &name) const
Gets the column by name, also checking if the column exists.
Definition datatable.cpp:51
std::vector< std::string > names() const
Gets the collection of columns name.
Definition datatable.cpp:14
std::string to_string() const noexcept
Creates a string representation of the DataTable structure.
Definition datatable.cpp:59
void add(std::unique_ptr< DataTableColumn > column)
Adds a new column to the table.
Definition datatable.cpp:16
std::vector< std::unique_ptr< DataTableColumn > >::const_iterator IteratorType
DataTable columns iterator type.
Definition datatable.h:19
const DataTableColumn & column(std::size_t index) const
Gets the column at a given index.
Definition datatable.cpp:38
std::ostream & operator<<(std::ostream &stream, const hgps::core::DataTable &table)
Output streams operator for DataTable type.
Definition datatable.cpp:85
Top-level namespace for Health-GPS Core C++ API.
Definition analysis.h:7
Global namespace.
Definition column_iterator.h:123