22 explicit Interval(TYPE lower_value, TYPE upper_value)
23 : lower_{lower_value}, upper_{upper_value} {
24 if (lower_ > upper_) {
25 throw HgpsException(fmt::format(
"Invalid interval: {}-{}", lower_, upper_));
31 TYPE
lower() const noexcept {
return lower_; }
35 TYPE
upper() const noexcept {
return upper_; }
39 TYPE
length() const noexcept {
return upper_ - lower_; }
44 bool contains(TYPE value)
const noexcept {
return lower_ <= value && value <= upper_; }
56 TYPE
clamp(TYPE value)
const noexcept {
return std::clamp(value, lower_, upper_); }
60 std::string
to_string() const noexcept {
return fmt::format(
"{}-{}", lower_, upper_); }
87 const std::string_view delims =
"-");
95 const std::string_view delims =
"-");
103 const std::string_view delims =
"-");
HealthGPS base exception class, with source location information.
Definition exception.h:19
Numeric interval representation data type.
Definition interval.h:14
auto operator<=>(const Interval< TYPE > &rhs) const =default
Compare two Interval instances.
bool contains(Interval< TYPE > &other) const noexcept
Determines whether an Interval is inside this instance interval.
Definition interval.h:49
std::string to_string() const noexcept
Convert this instance to a string representation.
Definition interval.h:60
TYPE upper() const noexcept
Gets the interval upper bound.
Definition interval.h:35
TYPE clamp(TYPE value) const noexcept
Clamp a given value to the interval boundaries.
Definition interval.h:56
TYPE length() const noexcept
Gets the interval length.
Definition interval.h:39
Interval()=default
Initialises a new instance of the Interval class.
TYPE lower() const noexcept
Gets the interval lower bound.
Definition interval.h:31
Interval(TYPE lower_value, TYPE upper_value)
Initialises a new instance of the Interval class.
Definition interval.h:22
bool contains(TYPE value) const noexcept
Determines whether a value is in the Interval.
Definition interval.h:44
Top-level namespace for Health-GPS Core C++ API.
Definition analysis.h:7
FloatInterval parse_float_interval(const std::string_view &value, const std::string_view delims)
Converts the string representation to its FloatInterval equivalent.
Definition interval.cpp:16
DoubleInterval parse_double_interval(const std::string_view &value, const std::string_view delims)
Converts the string representation to its DoubleInterval equivalent.
Definition interval.cpp:26
@ other
Common diseases excluding cancers.
IntegerInterval parse_integer_interval(const std::string_view &value, const std::string_view delims)
Converts the string representation to its IntegerInterval equivalent.
Definition interval.cpp:5