Health-GPS  1.2.2.0
Global Health Policy Simulation model (Health-GPS)
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 
13 namespace hgps::core {
14 
16 class 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 
52  IteratorType cbegin() const noexcept { return columns_.cbegin(); }
53 
56  IteratorType cend() const noexcept { return columns_.cend(); }
57 
60  std::string to_string() const noexcept;
61 
62  private:
63  std::vector<std::string> names_{};
64  std::unordered_map<std::string, std::size_t> index_{};
65  std::vector<std::unique_ptr<DataTableColumn>> columns_{};
66  size_t rows_count_ = 0;
67  std::mutex sync_mtx_{};
68 };
69 } // namespace hgps::core
70 
75 std::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:52
IteratorType cend() const noexcept
Gets the iterator element following the last column of the table.
Definition: datatable.h:56
std::size_t num_columns() const noexcept
Gets the number of columns.
Definition: datatable.cpp:9
std::size_t num_rows() const noexcept
Gets the number of rows.
Definition: datatable.cpp:11
std::vector< std::string > names() const
Gets the collection of columns name.
Definition: datatable.cpp:13
std::string to_string() const noexcept
Creates a string representation of the DataTable structure.
Definition: datatable.cpp:49
void add(std::unique_ptr< DataTableColumn > column)
Adds a new column to the table.
Definition: datatable.cpp:15
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:37
std::ostream & operator<<(std::ostream &stream, const hgps::core::DataTable &table)
Output streams operator for DataTable type.
Definition: datatable.cpp:74
Top-level namespace for Health-GPS Core C++ API.
Definition: analysis.h:7
Global namespace.
Definition: jsonparser.h:88