The Gaudi Framework  master (37c0b60a)
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 
54 #include <Gaudi/Property.h>
55 #include <fmt/format.h>
56 #include <iomanip>
57 #include <sstream>
58 
59 template <typename T, typename V, typename H>
60 struct 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> ) {
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 };
Gaudi::Details::PropertyBase::name
const std::string name() const
property name
Definition: PropertyBase.h:39
gaudirun.s
string s
Definition: gaudirun.py:346
std::stringstream
STL class.
fmt::formatter< Gaudi::Property< T, V, H > >::format
auto format(const Gaudi::Property< T, V, H > &p, format_context &ctx) const
Definition: PropertyFmt.h:77
GaudiPython.Pythonizations.ctx
ctx
Definition: Pythonizations.py:578
Gaudi::Property::value
const ValueType & value() const
Definition: Property.h:237
fmt::formatter< Gaudi::Property< T, V, H > >::parse
constexpr auto parse(format_parse_context &ctx) -> format_parse_context::iterator
Definition: PropertyFmt.h:62
format
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:119
Gaudi
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
Definition: __init__.py:1
parse
StatusCode parse(DataObjID &dest, std::string_view src)
Definition: DataObjID.cpp:57
IOTest.end
end
Definition: IOTest.py:125
Gaudi::Property
Implementation of property with value of concrete type.
Definition: Property.h:37
Property.h