R3BROOT
R3B analysis software
Loading...
Searching...
No Matches
R3BMinMaxValue.h
Go to the documentation of this file.
1#pragma once
2
3#include <fmt/core.h>
4#include <nlohmann/json.hpp>
5#include <nlohmann/json_fwd.hpp>
6
7namespace R3B
8{
9 template <typename DataType>
11 {
12 MinMaxValue() = default;
13 constexpr MinMaxValue(DataType min_val, DataType max_val)
14 : min{ min_val }
15 , max{ max_val }
16 {
17 }
18
19 DataType min{};
20 DataType max{};
21 };
22
26
27 template <typename DataType>
28 void to_json(nlohmann::ordered_json& json_obj, const MinMaxValue<DataType>& value)
29 {
30 json_obj = nlohmann::ordered_json{ { "min", value.min }, { "max", value.max } };
31 }
32
33 template <typename DataType>
34 void from_json(const nlohmann::ordered_json& json_obj, MinMaxValue<DataType>& value)
35 {
36 json_obj.at("min").get_to(value.min);
37 json_obj.at("max").get_to(value.max);
38 }
39
40} // namespace R3B
41
42template <typename DataType>
43class fmt::formatter<R3B::MinMaxValue<DataType>>
44{
45 public:
46 static constexpr auto parse(format_parse_context& ctx) { return ctx.end(); }
47 template <typename FmtContent>
48 constexpr auto format(const R3B::MinMaxValue<DataType>& value, FmtContent& ctn) const
49 {
50 return fmt::format_to(ctn.out(), "{{min: {}, max: {}}}", value.min, value.max);
51 }
52};
constexpr auto format(const R3B::MinMaxValue< DataType > &value, FmtContent &ctn) const
static constexpr auto parse(format_parse_context &ctx)
MinMaxValue< double > MinMaxValueD
MinMaxValue< float > MinMaxValueF
void from_json(const nlohmann::ordered_json &json_obj, MinMaxValue< DataType > &value)
MinMaxValue< int > MinMaxValueI
void to_json(nlohmann::ordered_json &json_obj, const MinMaxValue< DataType > &value)
constexpr MinMaxValue(DataType min_val, DataType max_val)
MinMaxValue()=default