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
80 using Widths = std::span<const size_t>;
81
82private:
83 struct Row final {
84 void add_column(string_view text) { columns.emplace_back(text); }
85
86 [[nodiscard]] auto get_columns() const noexcept -> std::span<const string>
87 {
88 return columns;
89 }
90
91 [[nodiscard]] auto to_string(Widths widths) const -> string;
92
93 void print(
94 const PrintFunc& printCell,
95 const PrintFunc& printOutline,
96 std::span<const size_t> widths) const;
97
98 private:
99 std::vector<string> columns;
100 };
101
102 [[nodiscard]] auto num_columns() const -> size_t;
103
104 [[nodiscard]] auto get_column_widths() const -> std::vector<size_t>;
105
106 std::vector<Row> rows;
107
108 bool startNewRow { true };
109};
110
111} // namespace util::strings
auto append_column(string_view text) -> TextTable &
std::span< const size_t > Widths
Definition TextTable.hpp:80
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