dimval 0.2.0
Modern C++23 header-only library of dimensional values (units, measures, ranges)
Loading...
Searching...
No Matches
json_nlohmann.hpp File Reference

Optional nlohmann::json integration. More...

#include <dimval/measure.hpp>
#include <dimval/range.hpp>
#include <dimval/traits.hpp>
#include <dimval/unit.hpp>
#include <nlohmann/json.hpp>
#include <commons/json.hpp>
#include <string>
Include dependency graph for json_nlohmann.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Detailed Description

Optional nlohmann::json integration.

Define DIMVAL_WITH_NLOHMANN_JSON or simply have <nlohmann/json.hpp> available on the include path; both paths enable this header.

Schema (compact field names):

UnitValue           {"u":"m","v":42.5}
MeasureValue        {"m":"distance","u":"m","v":42.5}
UnitRangeValue      {"u":"m","min":0,"max":10,"mi":true,"xi":true}
MeasureRangeValue   {"m":"distance","u":"m","min":0,"max":10,
                     "mi":true,"xi":true}

Field-name legend: u = unit id, m = measure id, v = value, mi = min_inclusive, xi = max_inclusive (x = max convention).

On parse, the u / m fields are validated against the tag's descriptor; mismatch throws nlohmann::json::other_error so the failure shows up at the ADL boundary like any other from_json mismatch.