Skip to content

Commit 8772bea

Browse files
committed
Add fmt compatibility for interface types
1 parent 36366cd commit 8772bea

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

python/templates/Interface.h.jinja2

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#include "podio/utilities/TypeHelpers.h"
1515
#include "podio/detail/OrderKey.h"
1616

17+
#include <fmt/ostream.h>
18+
1719
#include <memory>
1820
#include <ostream>
1921
#include <stdexcept>
@@ -196,4 +198,7 @@ struct std::hash<{{ class.full_type }}> {
196198
}
197199
};
198200

201+
template <>
202+
struct fmt::formatter<{{ class.full_type }}> : fmt::ostream_formatter {};
203+
199204
#endif

tests/unittests/interface_types.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,3 +195,14 @@ TEST_CASE("InterfaceType extension model", "[interface-types][extension]") {
195195
REQUIRE(wrapper.isA<iextension::AnotherHit>());
196196
REQUIRE(wrapper.as<iextension::AnotherHit>().energy() == 4.2f);
197197
}
198+
199+
TEST_CASE("InterfaceType formatting", "[interface-types][basics][formatting]") {
200+
auto iface = iextension::EnergyInterface::makeEmpty();
201+
auto formatted = fmt::format("{}", iface);
202+
REQUIRE(formatted == "[not available]");
203+
204+
iface = ExampleCluster{};
205+
formatted = fmt::format("{}", iface);
206+
REQUIRE_FALSE(formatted.empty());
207+
REQUIRE(formatted != "[not available]");
208+
}

0 commit comments

Comments
 (0)