Skip to content
Snippets Groups Projects
Commit eb8b27e7 authored by Marco Clemencic's avatar Marco Clemencic
Browse files

Make EventContext formattable

parent 999a9a7f
No related branches found
No related tags found
1 merge request!1597Add fmtlib support to EventContext
Pipeline #7503242 failed
......@@ -13,6 +13,7 @@
#include <GaudiKernel/EventIDBase.h>
#include <any>
#include <cstddef>
#include <fmt/format.h>
#include <iostream>
#include <limits>
......@@ -137,20 +138,26 @@ private:
std::any m_extension;
};
inline std::ostream& operator<<( std::ostream& os, const EventContext& ctx ) {
if ( ctx.valid() ) {
os << "s: " << ctx.slot() << " e: " << ctx.evt();
if ( ctx.usesSubSlot() ) os << " sub: " << ctx.subSlot();
return os;
} else {
return os << "INVALID";
template <>
struct fmt::formatter<EventContext> : formatter<string_view> {
auto format( const EventContext& ec, format_context& ctx ) const {
if ( ec.valid() ) {
std::string out;
if ( ec.usesSubSlot() ) {
out = fmt::format( "s: {} e: {} sub: {}", ec.slot(), ec.evt(), ec.subSlot() );
} else {
out = fmt::format( "s: {} e: {}", ec.slot(), ec.evt() );
}
return formatter<string_view>::format( out, ctx );
} else {
return formatter<string_view>::format( "INVALID", ctx );
}
}
}
};
inline std::ostream& operator<<( std::ostream& os, const EventContext& ctx ) { return os << fmt::format( "{}", ctx ); }
inline std::ostream& operator<<( std::ostream& os, const EventContext* c ) {
if ( c ) {
return os << *c;
} else {
return os << "INVALID";
}
if ( c ) { return os << fmt::format( "{}", *c ); }
return os << "INVALID";
}
......@@ -9,13 +9,6 @@
* or submit itself to any jurisdiction. *
\***********************************************************************************/
#include <GaudiKernel/EventContext.h>
#include <fmt/ostream.h>
#if FMT_VERSION >= 90000
// make EventContext formattable via fmt
template <>
struct fmt::formatter<EventContext> : ostream_formatter {};
#endif
#if __has_include( <catch2/catch.hpp>)
// Catch2 v2
......
......@@ -18,7 +18,6 @@
#include <chrono>
#include <csignal>
#include <fmt/format.h>
#include <fmt/ostream.h>
#include <mutex>
#include <range/v3/range/conversion.hpp>
#include <range/v3/view/remove.hpp>
......@@ -41,12 +40,6 @@ namespace {
std::mutex s_watchdogReportMutex;
} // namespace
#if FMT_VERSION >= 90000
// make EventContext formattable via fmt
template <>
struct fmt::formatter<EventContext> : ostream_formatter {};
#endif
using Gaudi::Utils::PeriodicAction;
namespace Gaudi {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment