Skip to content

Commit 4ca810b

Browse files
committed
DPL: use formatter for enum Lifetime
1 parent 171cdbd commit 4ca810b

2 files changed

Lines changed: 62 additions & 16 deletions

File tree

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2+
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3+
// All rights not expressly granted are reserved.
4+
//
5+
// This software is distributed under the terms of the GNU General Public
6+
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7+
//
8+
// In applying this license CERN does not waive the privileges and immunities
9+
// granted to it by virtue of its status as an Intergovernmental Organization
10+
// or submit itself to any jurisdiction.
11+
12+
#ifndef O2_FRAMEWORK_DPLFORMATTERS_H_
13+
#define O2_FRAMEWORK_DPLFORMATTERS_H_
14+
15+
#include <fmt/format.h>
16+
#include "Framework/Lifetime.h"
17+
18+
template <>
19+
struct fmt::formatter<o2::framework::Lifetime> : fmt::formatter<std::string_view> {
20+
char presentation = 's';
21+
22+
template <typename FormatContext>
23+
auto format(o2::framework::Lifetime const& h, FormatContext& ctx)
24+
{
25+
std::string_view s = "unknown";
26+
switch (h) {
27+
case o2::framework::Lifetime::Timeframe:
28+
s = "timeframe";
29+
break;
30+
case o2::framework::Lifetime::Condition:
31+
s = "condition";
32+
break;
33+
case o2::framework::Lifetime::QA:
34+
s = "qos";
35+
break;
36+
case o2::framework::Lifetime::Transient:
37+
s = "transient";
38+
break;
39+
// Complete the rest of the enum
40+
case o2::framework::Lifetime::Timer:
41+
s = "timer";
42+
break;
43+
case o2::framework::Lifetime::Enumeration:
44+
s = "enumeration";
45+
break;
46+
case o2::framework::Lifetime::Signal:
47+
s = "signal";
48+
break;
49+
case o2::framework::Lifetime::Optional:
50+
s = "optional";
51+
break;
52+
case o2::framework::Lifetime::OutOfBand:
53+
s = "out-of-band";
54+
break;
55+
};
56+
return formatter<string_view>::format(s, ctx);
57+
}
58+
};
59+
60+
#endif // O2_FRAMEWORK_DPLFORMATTERS_H_

Framework/Core/src/LifetimeHelpers.cxx

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "Framework/DataTakingContext.h"
2323
#include "Framework/InputRecord.h"
2424
#include "Framework/FairMQDeviceProxy.h"
25+
#include "Framework/Formatters.h"
2526

2627
#include "Headers/DataHeader.h"
2728
#include "Headers/DataHeaderHelpers.h"
@@ -460,24 +461,9 @@ ExpirationHandler::Handler LifetimeHelpers::dummy(ConcreteDataMatcher const& mat
460461
return f;
461462
}
462463

463-
// Life is too short. LISP rules.
464-
#define STREAM_ENUM(x) \
465-
case Lifetime::x: \
466-
oss << #x; \
467-
break;
468464
std::ostream& operator<<(std::ostream& oss, Lifetime const& val)
469465
{
470-
switch (val) {
471-
STREAM_ENUM(Timeframe)
472-
STREAM_ENUM(Condition)
473-
STREAM_ENUM(QA)
474-
STREAM_ENUM(Transient)
475-
STREAM_ENUM(Timer)
476-
STREAM_ENUM(Enumeration)
477-
STREAM_ENUM(Signal)
478-
STREAM_ENUM(Optional)
479-
STREAM_ENUM(OutOfBand)
480-
};
466+
oss << fmt::format("{}", val);
481467
return oss;
482468
}
483469

0 commit comments

Comments
 (0)