Value: template <typename T, typename V, typename H> \
struct ns::formatter<
Gaudi::Property<T, V, H>> : ns::formatter<T> { \
bool debug = false; \
constexpr auto parse( ns::format_parse_context& ctx ) { \
auto it = ctx.begin(), end = ctx.end(); \
if ( it != end && *it == '?' ) { \
debug = true; \
++it; \
if ( it != end && *it != '}' ) throw ns::format_error( "invalid format" ); \
return it; \
} \
return ns::formatter<T>::
parse( ctx ); \
} \
auto
format( const
Gaudi::Property<T, V, H>& p, ns::format_context& ctx )
const { \
if ( debug ) { \
if constexpr ( std::is_same_v<T, std::string> ) { \
std::stringstream s; \
s << std::quoted( p.value(), '\'' ); \
return ns::format_to( ctx.out(), " '{}':{}", p.name(), s.str() ); \
} else { \
return ns::format_to( ctx.out(), " '{}':{}", p.name(), p.value() ); \
} \
} else { \
return ns::formatter<T>::format( static_cast<const T&>( p ), ctx ); \
} \
} \
};
StatusCode parse(DataObjID &dest, std::string_view src)
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
#define assert_for_ranges
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
Definitions to allow use of Gaudi::Property<T> with fmtlib.
When this header is included, one can pass a Gaudi::Property<T> instance as argument to fmt::format.
For example
#include <fmt/format.h>
fmt::print( "property {} has value {}\n", p.name(), p );
}
Implementation of property with value of concrete type.
will print
property MyProp has value 20
A special formatting option can be used to print the property name as well as the value, so
#include <fmt/format.h>
#include <iostream>
std::cout << "cout" << p << '\n';
fmt::print( "fmt {:?}\n", p );
}
will print
cout 'MyProp':20
fmt 'MyProp':20
Definition at line 60 of file PropertyFmt.h.
60#define GAUDI_PROPERTY_FORMATTING_IMPL( ns, assert_for_ranges ) \
61 template <typename T, typename V, typename H> \
62 struct ns::formatter<Gaudi::Property<T, V, H>> : ns::formatter<T> { \
63 assert_for_ranges; \
64 bool debug = false; \
65 constexpr auto parse( ns::format_parse_context& ctx ) { \
66 auto it = ctx.begin(), end = ctx.end(); \
67 if ( it != end && *it == '?' ) { \
68 debug = true; \
69 ++it; \
70 if ( it != end && *it != '}' ) throw ns::format_error( "invalid format" ); \
71 return it; \
72 } \
73 return ns::formatter<T>::parse( ctx ); \
74 } \
75 auto format( const Gaudi::Property<T, V, H>& p, ns::format_context& ctx ) const { \
76 if ( debug ) { \
77 if constexpr ( std::is_same_v<T, std::string> ) { \
78 std::stringstream s; \
79 s << std::quoted( p.value(), '\'' ); \
80 return ns::format_to( ctx.out(), " '{}':{}", p.name(), s.str() ); \
81 } else { \
82 return ns::format_to( ctx.out(), " '{}':{}", p.name(), p.value() ); \
83 } \
84 } else { \
85 return ns::formatter<T>::format( static_cast<const T&>( p ), ctx ); \
86 } \
87 } \
88 };