BenBot 1.7.5
A chess engine
Loading...
Searching...
No Matches
TextTable.hpp
Go to the documentation of this file.
1/*
2 * ======================================================================================
3 *
4 * ░▒▓███████▓▒░░▒▓████████▓▒░▒▓███████▓▒░ ░▒▓███████▓▒░ ░▒▓██████▓▒░▒▓████████▓▒░
5 * ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░
6 * ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░
7 * ░▒▓███████▓▒░░▒▓██████▓▒░ ░▒▓█▓▒░░▒▓█▓▒░ ░▒▓███████▓▒░░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░
8 * ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░
9 * ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░
10 * ░▒▓███████▓▒░░▒▓████████▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓███████▓▒░ ░▒▓██████▓▒░ ░▒▓█▓▒░
11 *
12 * ======================================================================================
13 */
14
19
20#pragma once
21
22#include <cstddef> // IWYU pragma: keep - for size_t
23#include <functional>
24#include <span>
25#include <string>
26#include <string_view>
27#include <vector>
28
29namespace util::strings {
30
31using std::size_t;
32using std::string;
33using std::string_view;
34
41struct [[nodiscard]] TextTable final {
43 auto append_column(string_view text) -> TextTable&;
44
48 auto new_row() -> TextTable&;
49
51 [[nodiscard]] auto to_string() const -> string;
52
54 using PrintFunc = std::function<void(string_view)>;
55
73 void print(
74 PrintFunc&& printHeading,
75 PrintFunc&& printCell,
76 PrintFunc&& printOutline,
77 std::function<void()> printNewline) const;
78
79private:
80 struct Row final {
81 void add_column(string_view text) { columns.emplace_back(text); }
82
83 [[nodiscard]] auto get_columns() const noexcept -> std::span<const string>
84 {
85 return columns;
86 }
87
88 [[nodiscard]] auto to_string(std::span<const size_t> widths) const -> string;
89
90 void print(
91 PrintFunc printCell,
92 PrintFunc printOutline,
93 std::span<const size_t> widths) const;
94
95 private:
96 std::vector<string> columns;
97 };
98
99 [[nodiscard]] auto num_columns() const -> size_t;
100
101 [[nodiscard]] auto get_column_widths() const -> std::vector<size_t>;
102
103 std::vector<Row> rows;
104
105 bool startNewRow { true };
106};
107
108} // namespace util::strings
auto append_column(string_view text) -> TextTable &
std::function< void(string_view)> PrintFunc
Definition TextTable.hpp:54
auto to_string() const -> string
auto new_row() -> TextTable &
void print(PrintFunc &&printHeading, PrintFunc &&printCell, PrintFunc &&printOutline, std::function< void()> printNewline) const