Health-GPS  1.2.2.0
Global Health Policy Simulation model (Health-GPS)
weight_model.h
Go to the documentation of this file.
1 #pragma once
3 #include "person.h"
4 #include "weight_category.h"
5 
6 #include <memory>
7 #include <string>
8 
9 namespace hgps {
10 
12 class WeightModel {
13  public:
17  template <typename T> WeightModel(T &&value) : pimpl_{new Model<T>(std::forward<T>(value))} {}
18 
21  WeightModel(const WeightModel &other) : pimpl_{other.pimpl_->clone()} {}
22 
27  this->pimpl_ = other.pimpl_->clone();
28  return *this;
29  }
30 
33  WeightModel(WeightModel &&other) = default;
34 
38  WeightModel &operator=(WeightModel &&other) = default;
39 
42  unsigned int child_cutoff_age() const noexcept { return pimpl_->child_cutoff_age(); }
43 
47  WeightCategory classify_weight(const Person &person) const {
48  return pimpl_->classify_weight(person);
49  }
50 
57  double adjust_risk_factor_value(const Person &entity, const core::Identifier &risk_factor_key,
58  double value) const {
59  return pimpl_->adjust_risk_factor_value(entity, risk_factor_key, value);
60  }
61 
62  private:
63  struct Concept {
64  virtual ~Concept() {}
65  virtual std::unique_ptr<Concept> clone() const = 0;
66  virtual unsigned int child_cutoff_age() const noexcept = 0;
67  virtual WeightCategory classify_weight(const Person &entity) const = 0;
68  virtual double adjust_risk_factor_value(const Person &entity,
69  const core::Identifier &risk_factor_key,
70  double value) const = 0;
71  };
72 
73  template <typename T> struct Model : Concept {
74  Model(T &&value) : object_{std::forward<T>(value)} {}
75 
76  std::unique_ptr<Concept> clone() const override { return std::make_unique<Model>(*this); }
77 
78  unsigned int child_cutoff_age() const noexcept override {
79  return object_.child_cutoff_age();
80  }
81 
82  WeightCategory classify_weight(const Person &entity) const override {
83  return object_.classify_weight(entity);
84  }
85 
86  double adjust_risk_factor_value(const Person &entity,
87  const core::Identifier &risk_factor_key,
88  double value) const override {
89  return object_.adjust_risk_factor_value(entity, risk_factor_key, value);
90  }
91 
92  T object_;
93  };
94 
95  std::unique_ptr<Concept> pimpl_;
96 };
97 
102 std::string weight_category_to_string(WeightCategory value);
103 } // namespace hgps
Weight classification model polymorphic wrapper class.
Definition: weight_model.h:12
double adjust_risk_factor_value(const Person &entity, const core::Identifier &risk_factor_key, double value) const
Adjust a Person risk factor value.
Definition: weight_model.h:57
WeightModel & operator=(const WeightModel &other)
Replaces the WeightModel with a copy of the other's contents.
Definition: weight_model.h:26
WeightModel(WeightModel &&other)=default
Constructs the WeightModel with the contents of other using move semantics.
WeightModel & operator=(WeightModel &&other)=default
Replaces the WeightModel contents with the other using move semantics.
unsigned int child_cutoff_age() const noexcept
Gets the children cut-off age (before adult)
Definition: weight_model.h:42
WeightModel(const WeightModel &other)
Constructs the WeightModel with the copy of the other's contents.
Definition: weight_model.h:21
WeightModel(T &&value)
Initialises a new instance of the WeightModel class.
Definition: weight_model.h:17
WeightCategory classify_weight(const Person &person) const
Classify a person weight according with the predefined categories.
Definition: weight_model.h:47
Top-level namespace for Health-GPS C++ API.
Definition: analysis_definition.h:8
std::string weight_category_to_string(WeightCategory value)
Converts a WeightCategory to a string representation.
Definition: weight_model.cpp:4
WeightCategory
Enumerates the Person weight categories.
Definition: weight_category.h:7
Global namespace.
Definition: jsonparser.h:88
Defines a virtual population person data type.
Definition: person.h:40
Entity unique identifier data type.
Definition: identifier.h:17