R3BROOT
R3B analysis software
Loading...
Searching...
No Matches
R3BFormatters.h
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (C) 2019 GSI Helmholtzzentrum für Schwerionenforschung GmbH *
3 * Copyright (C) 2019-2023 Members of R3B Collaboration *
4 * *
5 * This software is distributed under the terms of the *
6 * GNU General Public Licence (GPL) version 3, *
7 * copied verbatim in the file "LICENSE". *
8 * *
9 * In applying this license GSI does not waive the privileges and immunities *
10 * granted to it by virtue of its status as an Intergovernmental Organization *
11 * or submit itself to any jurisdiction. *
12 ******************************************************************************/
13
14#pragma once
15
16#include "R3BShared.h"
17#include "R3BValueError.h"
18#include <TVector3.h>
19#include <fmt/core.h>
20#include <fmt/format.h>
21
22template <>
23class fmt::formatter<TVector3>
24{
25 public:
26 static constexpr auto parse(format_parse_context& ctx) { return ctx.end(); }
27 template <typename FmtContent>
28 constexpr auto format(const TVector3& vec, FmtContent& ctn) const
29 {
30 return format_to(ctn.out(), "[x: {}, y: {}, z: {}]", vec.X(), vec.Y(), vec.Z());
31 }
32};
33
34template <typename DataType>
35class fmt::formatter<R3B::ValueError<DataType>>
36{
37 public:
38 // TODO: add more options
39 static constexpr auto parse(format_parse_context& ctx) { return ctx.end(); }
40 template <typename FmtContent>
41 constexpr auto format(const R3B::ValueError<DataType>& value_error, FmtContent& ctn) const
42 {
43 return format_to(ctn.out(), "{}+/-{}", value_error.value, value_error.error);
44 }
45};
46
47template <typename DataType>
48class fmt::formatter<R3B::LRPair<DataType>>
49{
50 public:
51 static constexpr auto parse(format_parse_context& ctx) { return ctx.end(); }
52 template <typename FmtContent>
53 constexpr auto format(const R3B::LRPair<DataType>& data_pair, FmtContent& ctn) const
54 {
55 return format_to(ctn.out(), "[left: {}, right: {}]", data_pair.left(), data_pair.right());
56 }
57};
58
59template <>
60class fmt::formatter<R3B::Side>
61{
62 public:
63 static constexpr auto parse(format_parse_context& ctx) { return ctx.end(); }
64 template <typename FmtContent>
65 constexpr auto format(const R3B::Side& side, FmtContent& ctn) const
66 {
67 if (side == R3B::Side::left)
68 {
69 return format_to(ctn.out(), "{}", "left");
70 }
71 return format_to(ctn.out(), "{}", "right");
72 }
73};
Side
Definition R3BShared.h:113
auto left() -> DataType &
Definition R3BShared.h:150
auto right() -> DataType &
Definition R3BShared.h:151
constexpr auto format(const R3B::LRPair< DataType > &data_pair, FmtContent &ctn) const
static constexpr auto parse(format_parse_context &ctx)
constexpr auto format(const R3B::Side &side, FmtContent &ctn) const
static constexpr auto parse(format_parse_context &ctx)
constexpr auto format(const R3B::ValueError< DataType > &value_error, FmtContent &ctn) const
static constexpr auto parse(format_parse_context &ctx)
constexpr auto format(const TVector3 &vec, FmtContent &ctn) const
static constexpr auto parse(format_parse_context &ctx)