Files
scylladb/streaming/stream_reason.hh
Kefu Chai 9215adee46 streaming: specialize fmt::formatter<stream_reason>
this is a part of a series to migrating from `operator<<(ostream&, ..)`
based formatting to fmtlib based formatting. the goal here is to enable
fmtlib to print `stream_reason` without the help of `operator<<`.

please note, because we still cannot use the generic formatter for
std::unordered_map provided by fmtlib, so in order to drop `operator<<`
for `stream_reason`, and to print `unordered_map<stream_reason>`,
`fmt::join()` is used as a temporary solution. we will audit all
`fmt::join()` calls, after removing the homebrew formatter of
`std::unordered_map`.

the corresponding `operator<<()` are dropped dropped in this change,
as all its callers are now using fmtlib for formatting now.

Refs #13245

Signed-off-by: Kefu Chai <kefu.chai@scylladb.com>

Closes #13609
2023-04-21 09:44:23 +03:00

53 lines
1.3 KiB
C++

/*
* Copyright (C) 2018-present ScyllaDB
*/
/*
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
#pragma once
#include <cstdint>
#include <string_view>
#include <fmt/format.h>
namespace streaming {
enum class stream_reason : uint8_t {
unspecified,
bootstrap,
decommission,
removenode,
rebuild,
repair,
replace,
};
}
template <>
struct fmt::formatter<streaming::stream_reason> : fmt::formatter<std::string_view> {
template <typename FormatContext>
auto format(const streaming::stream_reason& r, FormatContext& ctx) const {
using enum streaming::stream_reason;
switch (r) {
case unspecified:
return formatter<std::string_view>::format("unspecified", ctx);
case bootstrap:
return formatter<std::string_view>::format("bootstrap", ctx);
case decommission:
return formatter<std::string_view>::format("decommission", ctx);
case removenode:
return formatter<std::string_view>::format("removenode", ctx);
case rebuild:
return formatter<std::string_view>::format("rebuild", ctx);
case repair:
return formatter<std::string_view>::format("repair", ctx);
case replace:
return formatter<std::string_view>::format("replace", ctx);
}
std::abort();
}
};