The Gaudi Framework  master (594c33fa)
fmt::formatter< Gaudi::Property< T, V, H > > Struct Template Reference

Definitions to allow use of Gaudi::Property<T> with fmtlib. More...

#include </builds/gaudi/Gaudi/GaudiKernel/include/Gaudi/PropertyFmt.h>

Inheritance diagram for fmt::formatter< Gaudi::Property< T, V, H > >:
Collaboration diagram for fmt::formatter< Gaudi::Property< T, V, H > >:

Public Member Functions

constexpr auto parse (format_parse_context &ctx) -> format_parse_context::iterator
 
auto format (const Gaudi::Property< T, V, H > &p, format_context &ctx)
 

Public Attributes

bool debug = false
 

Detailed Description

template<typename T, typename V, typename H>
struct fmt::formatter< Gaudi::Property< T, V, H > >

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 <Gaudi/Property.h>
#include <fmt/format.h>
int main() {
Gaudi::Property<int> p{ "MyProp", 20 };
fmt::print( "property {} has value {}\n", p.name(), p );
}

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 <Gaudi/Property.h>
#include <fmt/format.h>
#include <iostream>
int main() {
Gaudi::Property<int> p{ "MyProp", 20 };
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.

Member Function Documentation

◆ format()

template<typename T , typename V , typename H >
auto fmt::formatter< Gaudi::Property< T, V, H > >::format ( const Gaudi::Property< T, V, H > &  p,
format_context &  ctx 
)
inline

Definition at line 72 of file PropertyFmt.h.

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  }

◆ parse()

template<typename T , typename V , typename H >
constexpr auto fmt::formatter< Gaudi::Property< T, V, H > >::parse ( format_parse_context &  ctx) -> format_parse_context::iterator
inlineconstexpr

Definition at line 62 of file PropertyFmt.h.

62  {
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  }

Member Data Documentation

◆ debug

template<typename T , typename V , typename H >
bool fmt::formatter< Gaudi::Property< T, V, H > >::debug = false

Definition at line 61 of file PropertyFmt.h.


The documentation for this struct was generated from the following file:
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 > >::debug
bool debug
Definition: PropertyFmt.h:61
GaudiPython.Pythonizations.ctx
ctx
Definition: Pythonizations.py:578
std::cout
Gaudi::Property::value
const ValueType & value() const
Definition: Property.h:239
format
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:119
parse
StatusCode parse(DataObjID &dest, std::string_view src)
Definition: DataObjID.cpp:57
fmt
Definition: MessageSvcSink.cpp:26
PropertyFmt.h
IOTest.end
end
Definition: IOTest.py:125
main
int main(int argc, char *argv[])
Definition: main.cpp:14
Gaudi::Property< int >
Property.h