Health-GPS 3.0.0.0
Global Health Policy Simulation model (Health-GPS)
Loading...
Searching...
No Matches
two_step_value.h
Go to the documentation of this file.
1#pragma once
2#include <utility>
3
4namespace hgps {
5
9template <typename TYPE> struct TwoStepValue {
11 TwoStepValue() = default;
12
15 TwoStepValue(TYPE value) : value_{value}, old_value_{} {}
16
19 TYPE value() const { return value_; }
20
23 TYPE old_value() const { return old_value_; }
24
28 value_ = new_value;
29 old_value_ = new_value;
30 }
31
34 void set_value(TYPE new_value) { old_value_ = std::exchange(value_, new_value); }
35
38 TYPE operator()() const { return value_; }
39
43
48 clone = value();
49 return clone;
50 }
51
52 private:
53 TYPE value_{};
54 TYPE old_value_{};
55};
56} // namespace hgps
Top-level namespace for Health-GPS Console host application.
Definition command_options.cpp:8
Defines a two step value data type.
Definition two_step_value.h:9
void operator=(TYPE new_value)
Sets the current value.
Definition two_step_value.h:42
TwoStepValue< TYPE > clone()
Creates a new instance from this contents.
Definition two_step_value.h:46
TYPE value() const
Gets the current value.
Definition two_step_value.h:19
TwoStepValue(TYPE value)
Initialise a new instance of the TwoStepValue type.
Definition two_step_value.h:15
void set_value(TYPE new_value)
Sets the current value.
Definition two_step_value.h:34
TwoStepValue()=default
Initialise a new instance of the TwoStepValue type.
TYPE old_value() const
Gets the previous value.
Definition two_step_value.h:23
TYPE operator()() const
Gets the current value.
Definition two_step_value.h:38
void set_both_values(TYPE new_value)
Sets both current and previous values to the same value.
Definition two_step_value.h:27