The Gaudi Framework  master (181af51f)
Loading...
Searching...
No Matches
PropertyFmt.h
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 2023 CERN for the benefit of the LHCb and ATLAS collaborations *
3* *
4* This software is distributed under the terms of the Apache version 2 licence, *
5* copied verbatim in the file "LICENSE". *
6* *
7* In applying this licence, CERN does not waive the privileges and immunities *
8* granted to it by virtue of its status as an Intergovernmental Organization *
9* or submit itself to any jurisdiction. *
10\***********************************************************************************/
11#pragma once
12
53
54#include <Gaudi/Property.h>
55#include <fmt/format.h>
56#include <iomanip>
57#include <sstream>
58
59template <typename T, typename V, typename H>
60struct fmt::formatter<Gaudi::Property<T, V, H>> : formatter<T> {
61 bool debug = false;
62 constexpr auto parse( format_parse_context& ctx ) -> format_parse_context::iterator {
63 auto it = ctx.begin(), end = ctx.end();
64 if ( it != end && *it == '?' ) {
65 debug = true;
66 ++it;
67 if ( it != end && *it != '}' )
68#if FMT_VERSION >= 110000
69 report_error( "invalid format" );
70#else
71 detail::throw_format_error( "invalid format" );
72#endif
73 return it;
74 }
75 return formatter<T>::parse( ctx );
76 }
77 auto format( const Gaudi::Property<T, V, H>& p, format_context& ctx ) const {
78 if ( debug ) {
79 if constexpr ( std::is_same_v<T, std::string> ) {
80 std::stringstream s;
81 s << std::quoted( p.value(), '\'' );
82 return fmt::format_to( ctx.out(), " '{}':{}", p.name(), s.str() );
83 } else {
84 return fmt::format_to( ctx.out(), " '{}':{}", p.name(), p.value() );
85 }
86 } else {
87 return formatter<T>::format( static_cast<const T&>( p ), ctx );
88 }
89 }
90};
const std::string name() const
property name
Implementation of property with value of concrete type.
Definition PropertyFwd.h:27
const ValueType & value() const
Definition Property.h:229
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
Definition __init__.py:1
auto format(const Gaudi::Property< T, V, H > &p, format_context &ctx) const
Definition PropertyFmt.h:77
constexpr auto parse(format_parse_context &ctx) -> format_parse_context::iterator
Definition PropertyFmt.h:62