Health-GPS  1.2.2.0
Global Health Policy Simulation model (Health-GPS)
runtime_metric.h
Go to the documentation of this file.
1 #pragma once
2 #include <string>
3 #include <unordered_map>
4 
5 namespace hgps {
6 
13  public:
15  using IteratorType = std::unordered_map<std::string, double>::iterator;
16 
18  using ConstIteratorType = std::unordered_map<std::string, double>::const_iterator;
19 
22  std::size_t size() const noexcept;
23 
27  double &operator[](const std::string metric_key);
28 
34  double &at(const std::string metric_key);
35 
41  const double &at(const std::string metric_key) const;
42 
46  bool contains(const std::string metric_key) const noexcept;
47 
52  bool emplace(const std::string metric_key, const double value);
53 
57  bool erase(const std::string metric_key);
58 
60  void clear() noexcept;
61 
63  void reset() noexcept;
64 
67  bool empty() const noexcept;
68 
71  IteratorType begin() noexcept { return metrics_.begin(); }
72 
75  IteratorType end() noexcept { return metrics_.end(); }
76 
79  ConstIteratorType begin() const noexcept { return metrics_.cbegin(); }
80 
83  ConstIteratorType end() const noexcept { return metrics_.cend(); }
84 
87  ConstIteratorType cbegin() const noexcept { return metrics_.cbegin(); }
88 
91  ConstIteratorType cend() const noexcept { return metrics_.cend(); }
92 
93  private:
94  std::unordered_map<std::string, double> metrics_;
95 };
96 } // namespace hgps
Defines the Simulation run-time metrics container data type.
Definition: runtime_metric.h:12
std::unordered_map< std::string, double >::iterator IteratorType
Metric iterator.
Definition: runtime_metric.h:15
IteratorType end() noexcept
Gets an iterator to the element following the last metric.
Definition: runtime_metric.h:75
ConstIteratorType cbegin() const noexcept
Gets a read-only iterator to the beginning of the metrics.
Definition: runtime_metric.h:87
bool erase(const std::string metric_key)
Removes a specified metric from the container.
Definition: runtime_metric.cpp:24
std::size_t size() const noexcept
Gets the number of metrics in the container.
Definition: runtime_metric.cpp:5
ConstIteratorType cend() const noexcept
Gets a read-only iterator to the element following the last metric.
Definition: runtime_metric.h:91
std::unordered_map< std::string, double >::const_iterator ConstIteratorType
Read-only metric iterator.
Definition: runtime_metric.h:18
bool empty() const noexcept
Checks if the container has no metrics.
Definition: runtime_metric.cpp:37
bool emplace(const std::string metric_key, const double value)
Inserts a new metric into the container constructed in-place with arguments.
Definition: runtime_metric.cpp:19
bool contains(const std::string metric_key) const noexcept
Checks if the container contains a metric with specific identifier.
Definition: runtime_metric.cpp:15
void reset() noexcept
Resets the values of all metrics in the container to zero.
Definition: runtime_metric.cpp:31
void clear() noexcept
Erases all metrics from the container.
Definition: runtime_metric.cpp:29
double & at(const std::string metric_key)
Gets a reference to a metric value by identifier with bounds checking.
Definition: runtime_metric.cpp:9
ConstIteratorType end() const noexcept
Gets a read-only iterator to the element following the last metric.
Definition: runtime_metric.h:83
IteratorType begin() noexcept
Gets an iterator to the beginning of the metrics.
Definition: runtime_metric.h:71
ConstIteratorType begin() const noexcept
Gets a read-only iterator to the beginning of the metrics.
Definition: runtime_metric.h:79
Top-level namespace for Health-GPS C++ API.
Definition: analysis_definition.h:8
Global namespace.
Definition: jsonparser.h:88