21#ifndef LIBSEMIGROUPS_DETAIL_REPORT_HPP_
22#define LIBSEMIGROUPS_DETAIL_REPORT_HPP_
32#include "libsemigroups/exception.hpp"
35#include "formatters.hpp"
43 t_id this_threads_id();
44 t_id thread_id(std::thread::id);
45 void reset_thread_ids();
47 bool is_report_suppressed_for(std::string_view);
59 TickerImpl* _ticker_impl;
64 template <
typename Func,
typename Time = std::chrono::seconds>
65 explicit Ticker(Func&& func, Time time = std::chrono::seconds(1));
67 template <
typename Func,
typename Time = std::chrono::seconds>
68 void operator()(Func&& func, Time time = std::chrono::seconds(1));
70 Ticker() : _ticker_impl(nullptr) {}
71 Ticker(Ticker
const&) =
delete;
72 Ticker(Ticker&&) =
delete;
73 Ticker& operator=(Ticker
const&) =
delete;
74 Ticker& operator=(Ticker&&) =
delete;
79 enum class Align : uint8_t { left, right };
91 using Row = std::array<std::string, C + 1>;
92 std::array<Align, C + 1> _align;
93 std::array<size_t, C + 1> _col_widths;
94 std::vector<Row> _rows;
97 ReportCell() : _align(), _col_widths(), _rows() {
98 _align.fill(Align::right);
102 ReportCell(ReportCell
const&) =
default;
103 ReportCell(ReportCell&&) =
default;
104 ReportCell& operator=(ReportCell
const&) =
default;
105 ReportCell& operator=(ReportCell&&) =
default;
112 ReportCell& min_width(
size_t val) {
113 _col_widths.fill(val);
118 ReportCell& min_width(
size_t col,
size_t val) {
119 LIBSEMIGROUPS_ASSERT(col < C);
120 _col_widths[col + 1] = val;
124 ReportCell& align(
size_t col, Align val)
noexcept {
125 LIBSEMIGROUPS_ASSERT(col < C);
126 _align[col + 1] = val;
130 ReportCell& align(Align val)
noexcept {
135 Align align(
size_t col)
const noexcept {
136 LIBSEMIGROUPS_ASSERT(col < C);
137 return _align[col + 1];
141 template <
typename... Args>
142 void operator()(std::string_view fmt_str, Args&&... args);
146 template <
typename Func,
typename... Args>
147 void operator()(Func&& f,
char const* fmt_str, Args&&... args) {
148 operator()(fmt_str, f(args)...);
161 template <typename... Args>
163 std::string prefix = fmt::format(
"#{}: ", detail::this_threads_id());
173 template <
typename... Args>
176 fmt::print(
"{}", line);
180 template <
typename... Args>
189 template <
typename... Args>
192 std::string_view prefix(sv);
193 auto pos = prefix.find(
":");
194 if (pos != std::string::npos) {
195 prefix.remove_suffix(prefix.size() - prefix.find(
":"));
196 if (detail::is_report_suppressed_for((prefix))) {
223 class SuppressReportFor {
224 std::string_view _prefix;
227 explicit SuppressReportFor(std::string_view);
228 ~SuppressReportFor();
Namespace for everything in the libsemigroups library.
Definition action.hpp:44
bool reporting_enabled() noexcept
No doc.
void report_default(std::string_view sv, Args &&... args)
No doc.
Definition report.hpp:190
std::string fmt_default(std::string_view sv, Args &&... args)
No doc.
Definition report.hpp:162
void report_no_lock_no_prefix(std::string_view sv, Args &&... args)
No doc.
Definition report.hpp:174
void report_no_prefix(std::string_view sv, Args &&... args)
No doc.
Definition report.hpp:181
std::mutex & report_mutex()
No doc.
ReportGuard(bool val=true)
Constructs a ReportGuard with reporting enabled by default.