Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v38r0 (2143aa4c)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 != '}' ) detail::error_handler().on_error( "invalid format" );
68  return it;
69  }
70  return formatter<T>::parse( ctx );
71  }
72  auto format( const Gaudi::Property<T, V, H>& p, format_context& ctx )
73 #if FMT_VERSION >= 90000
74  const
75 #endif
76  {
77  if ( debug ) {
78  if constexpr ( std::is_same_v<T, std::string> ) {
80  s << std::quoted( p.value(), '\'' );
81  return fmt::format_to( ctx.out(), " '{}':{}", p.name(), s.str() );
82  } else {
83  return fmt::format_to( ctx.out(), " '{}':{}", p.name(), p.value() );
84  }
85  } else {
86  return formatter<T>::format( static_cast<const T&>( p ), ctx );
87  }
88  }
89 };
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.
GaudiPython.Pythonizations.ctx
ctx
Definition: Pythonizations.py:578
Gaudi::Property::value
const ValueType & value() const
Definition: Property.h:239
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
Header file for std:chrono::duration-based Counters.
Definition: __init__.py:1
fmt::formatter< Gaudi::Property< T, V, H > >::format
auto format(const Gaudi::Property< T, V, H > &p, format_context &ctx)
Definition: PropertyFmt.h:72
parse
StatusCode parse(DataObjID &dest, const std::string &src)
Definition: DataObjID.cpp:57
IOTest.end
end
Definition: IOTest.py:123
Gaudi::Property
Implementation of property with value of concrete type.
Definition: Property.h:39
Property.h