Health-GPS  1.2.2.0
Global Health Policy Simulation model (Health-GPS)
mapping.h
Go to the documentation of this file.
1 #pragma once
3 
4 #include <stdexcept>
5 #include <string>
6 #include <unordered_map>
7 #include <vector>
8 
9 namespace hgps {
10 
12 inline const core::Identifier InterceptKey = core::Identifier{"intercept"};
13 
18 struct FactorRange {
20  FactorRange() = default;
21 
26  FactorRange(double min_value, double max_value)
27  : empty{false}, minimum{min_value}, maximum{max_value} {
28  if (min_value > max_value) {
29  throw std::invalid_argument("Factor range minimum must not be greater than maximum.");
30  }
31  }
32 
34  bool empty{true};
35 
37  double minimum{};
38 
40  double maximum{};
41 };
42 
47 class MappingEntry {
48  public:
49  MappingEntry() = delete;
50 
58  bool dynamic_factor);
59 
65  MappingEntry(std::string name, short level, core::Identifier entity_key, bool dynamic_factor);
66 
73 
78  MappingEntry(std::string name, short level, core::Identifier entity_key);
79 
83  MappingEntry(std::string name, short level);
84 
87  const std::string &name() const noexcept;
88 
91  short level() const noexcept;
92 
95  const core::Identifier &key() const noexcept;
96 
99  const core::Identifier &entity_key() const noexcept;
100 
103  bool is_entity() const noexcept;
104 
107  bool is_dynamic_factor() const noexcept;
108 
111  const FactorRange &range() const noexcept;
112 
116  double get_bounded_value(const double &value) const noexcept;
117 
118  private:
119  std::string name_;
120  core::Identifier name_key_;
121  short level_{};
122  core::Identifier entity_key_;
123  FactorRange range_;
124  bool dynamic_factor_;
125 };
126 
129  public:
131  using IteratorType = std::vector<MappingEntry>::iterator;
133  using ConstIteratorType = std::vector<MappingEntry>::const_iterator;
134 
136 
139  HierarchicalMapping(std::vector<MappingEntry> &&mapping);
140 
143  const std::vector<MappingEntry> &entries() const noexcept;
144 
147  std::vector<MappingEntry> entries_without_dynamic() const noexcept;
148 
151  std::size_t size() const noexcept;
152 
155  int max_level() const noexcept;
156 
161  MappingEntry at(const core::Identifier &key) const;
162 
166  std::vector<MappingEntry> at_level(int level) const noexcept;
167 
171  std::vector<MappingEntry> at_level_without_dynamic(int level) const noexcept;
172 
175  IteratorType begin() noexcept { return mapping_.begin(); }
176 
179  IteratorType end() noexcept { return mapping_.end(); }
180 
183  ConstIteratorType begin() const noexcept { return mapping_.cbegin(); }
184 
187  ConstIteratorType end() const noexcept { return mapping_.cend(); }
188 
191  ConstIteratorType cbegin() const noexcept { return mapping_.cbegin(); }
192 
195  ConstIteratorType cend() const noexcept { return mapping_.cend(); }
196 
197  private:
198  std::vector<MappingEntry> mapping_;
199 };
200 } // namespace hgps
Defines the hierarchical model mapping data type.
Definition: mapping.h:128
IteratorType end() noexcept
Gets an iterator to the element following the last mapping.
Definition: mapping.h:179
ConstIteratorType cend() const noexcept
Gets a read-only iterator to the element following the last mapping.
Definition: mapping.h:195
std::vector< MappingEntry >::iterator IteratorType
Hierarchical mappings iterator.
Definition: mapping.h:131
ConstIteratorType end() const noexcept
Gets a read-only iterator to the element following the last mapping.
Definition: mapping.h:187
std::vector< MappingEntry > entries_without_dynamic() const noexcept
Gets the collection of mapping entries without the dynamic factor.
Definition: mapping.cpp:71
std::vector< MappingEntry >::const_iterator ConstIteratorType
read-only hierarchical mappings iterator
Definition: mapping.h:133
IteratorType begin() noexcept
Gets an iterator to the beginning of the mappings.
Definition: mapping.h:175
const std::vector< MappingEntry > & entries() const noexcept
Gets the collection of mapping entries.
Definition: mapping.cpp:69
std::vector< MappingEntry > at_level_without_dynamic(int level) const noexcept
Gets the mapping entries at a given hierarchical level without the dynamic factor.
Definition: mapping.cpp:108
int max_level() const noexcept
Gets the maximum hierarchical level.
Definition: mapping.cpp:81
std::size_t size() const noexcept
Gets the size of the mappings collection.
Definition: mapping.cpp:79
ConstIteratorType cbegin() const noexcept
Gets an read-only iterator to the beginning of the mappings.
Definition: mapping.h:191
ConstIteratorType begin() const noexcept
Gets an read-only iterator to the beginning of the mappings.
Definition: mapping.h:183
std::vector< MappingEntry > at_level(int level) const noexcept
Gets the mapping entries at a given hierarchical level.
Definition: mapping.cpp:100
MappingEntry at(const core::Identifier &key) const
Gets a mapping entry by identifier.
Definition: mapping.cpp:89
Defines risk factor mapping entry data type.
Definition: mapping.h:47
bool is_entity() const noexcept
Determine whether this factor has an associated Person property, e.g. age.
Definition: mapping.cpp:37
const core::Identifier & key() const noexcept
Gets the factor unique identification.
Definition: mapping.cpp:41
double get_bounded_value(const double &value) const noexcept
Adjusts a value to the factor range, if provided.
Definition: mapping.cpp:45
short level() const noexcept
Gets the factor hierarchical level.
Definition: mapping.cpp:31
const std::string & name() const noexcept
Gets the factor name.
Definition: mapping.cpp:29
const core::Identifier & entity_key() const noexcept
Gets the factor's associated Person property identifier.
Definition: mapping.cpp:33
const FactorRange & range() const noexcept
Gets the factor allowed values range.
Definition: mapping.cpp:43
bool is_dynamic_factor() const noexcept
Determine whether this instance is a dynamic factor.
Definition: mapping.cpp:39
Top-level namespace for Health-GPS C++ API.
Definition: analysis_definition.h:8
const core::Identifier InterceptKey
The constant in the regression model presentation identifier.
Definition: mapping.h:12
Global namespace.
Definition: jsonparser.h:88
Defines the risk factor allowed range data type.
Definition: mapping.h:18
bool empty
Gets a value indicating whether the range is empty, no limits.
Definition: mapping.h:34
FactorRange(double min_value, double max_value)
Initialises a new instance of the FactorRange structure.
Definition: mapping.h:26
double minimum
The range minimum value.
Definition: mapping.h:37
double maximum
The range maximum value.
Definition: mapping.h:40
FactorRange()=default
Initialises a new instance of the FactorRange structure.
Entity unique identifier data type.
Definition: identifier.h:17