Files
scylla/sstables/component_type.hh
Kefu Chai c5fa1ac9f7 sstable: specialize fmt::formatter<component_type>
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 `component_type` without the help of `operator<<`.

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

also, please note, to enable fmtlib to format `std::set<component_type>`
in `test/boost/sstable_3_x_test.cc` , we need to include
`<fmt/ranges.h>` in that source file.

Refs #13245

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

Closes #13598
2023-04-21 09:49:24 +03:00

71 lines
1.9 KiB
C++

/*
* Copyright (C) 2018-present ScyllaDB
*
*/
/*
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
#pragma once
#include <fmt/format.h>
namespace sstables {
enum class component_type {
Index,
CompressionInfo,
Data,
TOC,
Summary,
Digest,
CRC,
Filter,
Statistics,
TemporaryTOC,
TemporaryStatistics,
Scylla,
Unknown,
};
}
using component_type = ::sstables::component_type;
template <>
struct fmt::formatter<sstables::component_type> : fmt::formatter<std::string_view> {
template <typename FormatContext>
auto format(const sstables::component_type& comp_type, FormatContext& ctx) const {
using enum sstables::component_type;
switch (comp_type) {
case Index:
return formatter<std::string_view>::format("Index", ctx);
case CompressionInfo:
return formatter<std::string_view>::format("CompressionInfo", ctx);
case Data:
return formatter<std::string_view>::format("Data", ctx);
case TOC:
return formatter<std::string_view>::format("TOC", ctx);
case Summary:
return formatter<std::string_view>::format("Summary", ctx);
case Digest:
return formatter<std::string_view>::format("Digest", ctx);
case CRC:
return formatter<std::string_view>::format("CRC", ctx);
case Filter:
return formatter<std::string_view>::format("Filter", ctx);
case Statistics:
return formatter<std::string_view>::format("Statistics", ctx);
case TemporaryTOC:
return formatter<std::string_view>::format("TemporaryTOC", ctx);
case TemporaryStatistics:
return formatter<std::string_view>::format("TemporaryStatistics", ctx);
case Scylla:
return formatter<std::string_view>::format("Scylla", ctx);
case Unknown:
return formatter<std::string_view>::format("Unknown", ctx);
}
}
};