47 lines
1.6 KiB
C++
47 lines
1.6 KiB
C++
#pragma once
|
|
#include <array>
|
|
#include <string>
|
|
#include <stdint.h>
|
|
|
|
template<size_t N>
|
|
constexpr void formatted_row(const std::array<int32_t, N>& gaps, const std::array<const char* const, N>& titles,
|
|
const char* const separator = "│") noexcept {
|
|
for(size_t i = 0; i < N; ++i)
|
|
printf("%s %*s ", separator, -gaps[i], titles[i]);
|
|
printf("%s\n", separator);
|
|
}
|
|
|
|
template<size_t N>
|
|
constexpr void formatted_line(const std::array<int32_t, N>& gaps, const char* const right, const char* const middle,
|
|
const char* const separator, const char* const left) noexcept {
|
|
printf("%s", right);
|
|
for(size_t i = 0; i < N; ++i){
|
|
for(int32_t j = std::abs(gaps[i]) + 2; j > 0; --j)
|
|
printf("%s", separator);
|
|
if(i != N - 1)
|
|
printf("%s", middle);
|
|
}
|
|
|
|
printf("%s\n", left);
|
|
}
|
|
|
|
template<size_t N>
|
|
constexpr void header(const std::array<const char* const, N>& titles, const std::array<int32_t, N>& gaps) noexcept {
|
|
formatted_line(gaps, "┌", "┬", "─", "┐");
|
|
formatted_row(gaps, titles);
|
|
formatted_line(gaps, "├", "┼", "─", "┤");
|
|
}
|
|
|
|
template<size_t N>
|
|
constexpr inline void footer(const std::array<int32_t, N>& gaps) noexcept {
|
|
formatted_line(gaps, "└", "┴", "─", "┘");
|
|
}
|
|
|
|
#define duration_ns(a) std::chrono::duration_cast<std::chrono::nanoseconds>(a).count()
|
|
#define perf_counter_ns() std::chrono::high_resolution_clock::now()
|
|
|
|
std::string format_time(uint64_t) noexcept;
|
|
std::string format_time_ns(uint64_t) noexcept;
|
|
std::string format_byte_size(uint64_t) noexcept;
|
|
std::string thousand_sep(uint64_t, const char& = ',') noexcept;
|