The Gaudi Framework  master (3415b466)
Loading...
Searching...
No Matches
PropertyFmt.h File Reference
#include <Gaudi/Property.h>
#include <fmt/format.h>
#include <fmt/ranges.h>
#include <format>
#include <iomanip>
#include <sstream>
Include dependency graph for PropertyFmt.h:

Go to the source code of this file.

Classes

struct  fmt::is_range< Gaudi::Property< T, V, H >, Char >
 Definitions to allow use of Gaudi::Property<T> with fmtlib. More...
 

Macros

#define GAUDI_PROPERTY_FORMATTING_IMPL(ns, assert_for_ranges)
 
#define assert_for_ranges
 

Macro Definition Documentation

◆ assert_for_ranges

#define assert_for_ranges
Value:
static_assert( !std::ranges::range<T> || std::is_same_v<T, std::string>, \
"Range-valued Property formatting is not supported with std::format in C++20" )

Definition at line 99 of file PropertyFmt.h.

99# define assert_for_ranges \
100 static_assert( !std::ranges::range<T> || std::is_same_v<T, std::string>, \
101 "Range-valued Property formatting is not supported with std::format in C++20" )

◆ GAUDI_PROPERTY_FORMATTING_IMPL

#define GAUDI_PROPERTY_FORMATTING_IMPL ( ns,
assert_for_ranges )
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)
Definition DataObjID.cpp:58
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition MsgStream.cpp:93
#define assert_for_ranges
Definition PropertyFmt.h:99
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
Definition __init__.py:1

Definition at line 66 of file PropertyFmt.h.

66#define GAUDI_PROPERTY_FORMATTING_IMPL( ns, assert_for_ranges ) \
67 template <typename T, typename V, typename H> \
68 struct ns::formatter<Gaudi::Property<T, V, H>> : ns::formatter<T> { \
69 assert_for_ranges; \
70 bool debug = false; \
71 constexpr auto parse( ns::format_parse_context& ctx ) { \
72 auto it = ctx.begin(), end = ctx.end(); \
73 if ( it != end && *it == '?' ) { \
74 debug = true; \
75 ++it; \
76 if ( it != end && *it != '}' ) throw ns::format_error( "invalid format" ); \
77 return it; \
78 } \
79 return ns::formatter<T>::parse( ctx ); \
80 } \
81 auto format( const Gaudi::Property<T, V, H>& p, ns::format_context& ctx ) const { \
82 if ( debug ) { \
83 if constexpr ( std::is_same_v<T, std::string> ) { \
84 std::stringstream s; \
85 s << std::quoted( p.value(), '\'' ); \
86 return ns::format_to( ctx.out(), " '{}':{}", p.name(), s.str() ); \
87 } else { \
88 return ns::format_to( ctx.out(), " '{}':{}", p.name(), p.value() ); \
89 } \
90 } else { \
91 return ns::formatter<T>::format( static_cast<const T&>( p ), ctx ); \
92 } \
93 } \
94 };