27#if !defined(DIMVAL_WITH_PARCEL)
28#if __has_include(<parcel/parcel.h>)
29#define DIMVAL_WITH_PARCEL 1
31#define DIMVAL_WITH_PARCEL 0
48#include <parcel/parcel.h>
52template <UnitLike U, NumericValue T =
double>
53class UnitValueCell :
public ::parcel::BaseCell<UnitValueCell<U, T>, UnitValue<U, T>> {
54 using base_t = ::parcel::BaseCell<UnitValueCell<U, T>, UnitValue<U, T>>;
58 using base_t::operator=;
60 static constexpr std::string_view kind_id =
"uv";
62 [[nodiscard]] std::string to_string()
const override {
63 return this->value.to_string();
66 [[nodiscard]] std::string to_formatted_string()
const override {
67 return this->value.to_formatted_string();
70 static ::parcel::cell_t from_json(::parcel::json_t
const& j, ::parcel::ParcelRegistry
const&) {
71 auto v = base_t::template cell_from_json<UnitValue<U, T>>(j, kind_id);
72 auto cell = std::make_shared<UnitValueCell>(v);
73 base_t::absorb_display_info(j, cell);
77 static ::parcel::cell_type_descriptor_t descriptor() {
78 static const auto d = std::make_shared<::parcel::SimpleCellTypeDescriptor<UnitValueCell>>(
79 ::parcel::DisplayInfo{.name =
"dimval::UnitValue"});
84template <MeasureLike M, NumericValue T =
double>
85class MeasureValueCell :
public ::parcel::BaseCell<MeasureValueCell<M, T>, MeasureValue<M, T>> {
86 using base_t = ::parcel::BaseCell<MeasureValueCell<M, T>, MeasureValue<M, T>>;
90 using base_t::operator=;
92 static constexpr std::string_view kind_id =
"mv";
94 [[nodiscard]] std::string to_string()
const override {
95 return this->value.to_string();
98 [[nodiscard]] std::string to_formatted_string()
const override {
99 return this->value.to_formatted_string();
102 static ::parcel::cell_t from_json(::parcel::json_t
const& j, ::parcel::ParcelRegistry
const&) {
103 auto v = base_t::template cell_from_json<MeasureValue<M, T>>(j, kind_id);
104 auto cell = std::make_shared<MeasureValueCell>(v);
105 base_t::absorb_display_info(j, cell);
109 static ::parcel::cell_type_descriptor_t descriptor() {
110 static const auto d =
111 std::make_shared<::parcel::SimpleCellTypeDescriptor<MeasureValueCell>>(
112 ::parcel::DisplayInfo{.name =
"dimval::MeasureValue"});
117template <UnitLike U, NumericValue T =
double>
118class UnitRangeValueCell
119 :
public ::parcel::BaseCell<UnitRangeValueCell<U, T>, UnitRangeValue<U, T>> {
120 using base_t = ::parcel::BaseCell<UnitRangeValueCell<U, T>, UnitRangeValue<U, T>>;
123 using base_t::base_t;
124 using base_t::operator=;
126 static constexpr std::string_view kind_id =
"urv";
128 [[nodiscard]] std::string to_string()
const override {
129 return this->value.to_string();
132 [[nodiscard]] std::string to_formatted_string()
const override {
133 return this->value.to_formatted_string();
136 static ::parcel::cell_t from_json(::parcel::json_t
const& j, ::parcel::ParcelRegistry
const&) {
137 auto v = base_t::template cell_from_json<UnitRangeValue<U, T>>(j, kind_id);
138 auto cell = std::make_shared<UnitRangeValueCell>(v);
139 base_t::absorb_display_info(j, cell);
143 static ::parcel::cell_type_descriptor_t descriptor() {
144 static const auto d =
145 std::make_shared<::parcel::SimpleCellTypeDescriptor<UnitRangeValueCell>>(
146 ::parcel::DisplayInfo{.name =
"dimval::UnitRangeValue"});
151template <MeasureLike M, NumericValue T =
double>
152class MeasureRangeValueCell
153 :
public ::parcel::BaseCell<MeasureRangeValueCell<M, T>, MeasureRangeValue<M, T>> {
154 using base_t = ::parcel::BaseCell<MeasureRangeValueCell<M, T>, MeasureRangeValue<M, T>>;
157 using base_t::base_t;
158 using base_t::operator=;
160 static constexpr std::string_view kind_id =
"mrv";
162 [[nodiscard]] std::string to_string()
const override {
163 return this->value.to_string();
166 [[nodiscard]] std::string to_formatted_string()
const override {
167 return this->value.to_formatted_string();
170 static ::parcel::cell_t from_json(::parcel::json_t
const& j, ::parcel::ParcelRegistry
const&) {
171 auto v = base_t::template cell_from_json<MeasureRangeValue<M, T>>(j, kind_id);
172 auto cell = std::make_shared<MeasureRangeValueCell>(v);
173 base_t::absorb_display_info(j, cell);
177 static ::parcel::cell_type_descriptor_t descriptor() {
178 static const auto d =
179 std::make_shared<::parcel::SimpleCellTypeDescriptor<MeasureRangeValueCell>>(
180 ::parcel::DisplayInfo{.name =
"dimval::MeasureRangeValue"});
Optional nlohmann::json integration.
MeasureValue<M,T>: a UnitValue tagged with an additional semantic measure.
UnitRangeValue and MeasureRangeValue — closed/open intervals of dimensional values.
Concepts and helper accessors that drive the static side of dimval.
UnitValue<U,T>: a strongly-typed value carrying a compile-time unit tag.