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
6namespace R3B
7{
8 template <typename DataType>
10 {
11 MinMaxValue() = default;
12 constexpr MinMaxValue(DataType min_val, DataType max_val)
13 : min{ min_val }
14 , max{ max_val }
15 {
16 }
17
18 DataType min{};
19 DataType max{};
20 };
21
25
26 template <typename DataType>
27 void to_json(nlohmann::ordered_json& json_obj, const MinMaxValue<DataType>& value)
28 {
29 json_obj = nlohmann::ordered_json{ { "min", value.min }, { "max", value.max } };
30 }
31
32 template <typename DataType>
33 void from_json(const nlohmann::ordered_json& json_obj, MinMaxValue<DataType>& value)
34 {
35 json_obj.at("min").get_to(value.min);
36 json_obj.at("max").get_to(value.max);
37 }
38
39} // namespace R3B
40
41template <typename DataType>
42class fmt::formatter<R3B::MinMaxValue<DataType>>
43{
44 public:
45 static constexpr auto parse(format_parse_context& ctx) { return ctx.end(); }
46 template <typename FmtContent>
47 constexpr auto format(const R3B::MinMaxValue<DataType>& value, FmtContent& ctn) const
48 {
49 return format_to(ctn.out(), "{{min: {}, max: {}}}", value.min, value.max);
50 }
51};
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