4#ifndef GREM_CORE_DEBUG_FORMATTING_HPP
5#define GREM_CORE_DEBUG_FORMATTING_HPP
49 constexpr CStringView HEXADECIMAL_DIGITS =
"0123456789ABCDEF";
53 output.
append(
StringView{&HEXADECIMAL_DIGITS[(bit_cast<uint8_t>(b) >> 4) & 0x0F], 1});
54 output.
append(
StringView{&HEXADECIMAL_DIGITS[(bit_cast<uint8_t>(b) & 0x0F)], 1});
78 constexpr CStringView HEXADECIMAL_DIGITS =
"0123456789ABCDEF";
80 output.
append(
StringView{&HEXADECIMAL_DIGITS[(bit_cast<uint8_t>(value) >> 4) & 0x0F], 1});
81 output.
append(
StringView{&HEXADECIMAL_DIGITS[(bit_cast<uint8_t>(value) & 0x0F)], 1});
106 constexpr CStringView HEXADECIMAL_DIGITS =
"0123456789ABCDEF";
109 for (
size_t i = 0; i < value.size(); ++i) {
110 const char ch = value[i];
111 if (ch <
' ' || ch >
'~' || ch ==
quote || ch ==
'\\') {
112 output.
append(value.substr(begin, i - begin));
114 case '\"': output.
append(
"\\\"'");
break;
115 case '\'': output.
append(
"\\\''");
break;
116 case '\\': output.
append(
"\\\\'");
break;
117 case '\b': output.
append(
"\\b'");
break;
118 case '\f': output.
append(
"\\f'");
break;
119 case '\n': output.
append(
"\\n'");
break;
120 case '\r': output.
append(
"\\r'");
break;
121 case '\t': output.
append(
"\\t'");
break;
122 case '\v': output.
append(
"\\v'");
break;
123 case '\0': output.
append(
"\\0'");
break;
126 output.
append(
StringView{&HEXADECIMAL_DIGITS[(bit_cast<uint8_t>(ch) >> 4) & 0x0F], 1});
127 output.
append(
StringView{&HEXADECIMAL_DIGITS[(bit_cast<uint8_t>(ch) & 0x0F)], 1});
133 if (begin < value.size()) {
134 output.
append(value.substr(begin));
158template <grem::
size_t Length>
196template <grem::
size_t N>
205template <formattable T>
234 if constexpr (
convertible_to<
typename std::iterator_traits<
decltype(std::begin(value))>::iterator_category, std::forward_iterator_tag>) {
236 for (
const auto& element : value) {
237 result +=
underlying.getRecursiveSize(element);
261 auto it = std::begin(value);
262 auto end = std::end(value);
273 auto it = std::begin(value);
274 auto end = std::end(value);
297template <input_range Range>
298requires(!formattable<Range> ||
requires {
typename Formatter<Range>::GREM_private_DefaultRangeFormatterTag; })
303template <
typename... Ts>
330 if constexpr (
sizeof...(Ts) > 0) {
334 if constexpr (index != 0) {
339 underlying.setCompact(
compact);
340 underlying.formatTo(output, field);
346 if constexpr (index != 0) {
354 underlying.setCompact(
compact);
355 underlying.formatTo(output, field);
369template <
typename T1,
typename T2>
382 return (value) ?
underlying.getRecursiveSize(*value) : 1;
390 return underlying.parseFormatSpecification(p);
410 return (value) ?
underlying.getRecursiveSize(*value) : 1;
418 return underlying.parseFormatSpecification(p);
438 return (value) ?
underlying.getRecursiveSize(*value) : 1;
446 return underlying.parseFormatSpecification(p);
466 return (value) ?
underlying.getRecursiveSize(*value) : 1;
474 return underlying.parseFormatSpecification(p);
481 output.
append(
", ... (unknown size)]");
496 return (value) ?
underlying.getRecursiveSize(*value) : 1;
504 return underlying.parseFormatSpecification(p);
525 return underlying.getRecursiveSize(
Span{value.get(), value.size()});
535 return underlying.parseFormatSpecification(p);
568 return underlying.parseFormatSpecification(p);
576 output.
append(
"<expired>");
605 return underlying.parseFormatSpecification(p);
613 output.
append(
"<expired>");
621template <
typename... Ts>
630 if (value.valueless_by_exception()) {
650 output.
append(
"<valueless by exception>");
652 match(value)([&]<
typename T>(
const T& v) ->
void {
664template <enumeration Enum>
681 if (!found && value == type) {
693template <
typename... Ts>
694consteval Variant<Ts...> getVariant(
const Variant<Ts...>&);
698template <aggregate Aggregate>
709 [&]<
typename T>(
const T& field) ->
void { result +=
DebugFormatter<std::remove_cvref_t<
decltype(field)>>{
indentation + 1}.getRecursiveSize(field); });
730 if constexpr (index != 0) {
736 underlying.setCompact(
compact);
737 underlying.formatTo(output, field);
743 if constexpr (index != 0) {
752 underlying.setCompact(
compact);
753 underlying.formatTo(output, field);
767template <
typename VariantDerived>
768requires(!formattable<VariantDerived> && !aggregate<VariantDerived> &&
requires(
const VariantDerived t) { detail::getVariant(t); })
773template <aggregate VariantDerivedAggregate>
783 [[nodiscard]]
constexpr size_t getRecursiveSize(
const VariantDerivedAggregate& value)
const noexcept {
786 [&]<
typename T>(
const T& field) ->
void { result +=
DebugFormatter<std::remove_cvref_t<
decltype(field)>>{
indentation + 1}.getRecursiveSize(field); });
813 underlying.setCompact(
compact);
814 underlying.formatTo(output, field);
828 underlying.setCompact(
compact);
829 underlying.formatTo(output, field);
843template <
typename... Args>
846 template <
typename T>
849 detail::FormatSizeCounter sizeCounter{};
864template <
typename... Args>
867template <
typename... Args>
869 detail::FormatSizeCounter sizeCounter{};
870 formatToV(sizeCounter, format.
get(), {FormatArgument::create<Args, DebugFormatter<Args>>(args)...});
871 return sizeCounter.output;
874template <
typename Output,
typename... Args>
876 if constexpr (
requires(Output out,
const size_t n) {
881 detail::FormatSizeCounter sizeCounter{};
882 formatToV(sizeCounter, format.
get(), {FormatArgument::create<Args, DebugFormatter<Args>>(args)...});
883 const size_t formattedSize = sizeCounter.output;
884 const size_t offset = output.size();
885 output.resize(offset + formattedSize);
887 char* p = output.data() + offset;
890 output.resize(offset);
893 }
else if constexpr (
requires(Output out,
const size_t n) {
897 detail::FormatSizeCounter sizeCounter{};
898 formatToV(sizeCounter, format.
get(), {FormatArgument::create<Args, DebugFormatter<Args>>(args)...});
899 const size_t formattedSize = sizeCounter.output;
900 output.reserve(output.size() + formattedSize);
901 detail::AppendingFormatWriter writer{output};
902 formatToV(writer, format.
get(), {FormatArgument::create<Args, DebugFormatter<Args>>(args)...});
903 }
else if constexpr (
requires { *output++ =
'\0'; }) {
904 detail::IteratorFormatWriter writer{output};
905 formatToV(writer, format.
get(), {FormatArgument::create<Args, DebugFormatter<Args>>(args)...});
906 output = writer.output;
908 detail::AppendingFormatWriter writer{output};
909 formatToV(writer, format.
get(), {FormatArgument::create<Args, DebugFormatter<Args>>(args)...});
913template <
typename... Args>
915 detail::CFileFormatWriter writer{output};
923template <
typename... Args>
929template <
typename... Args>
938template <
typename... Args>
943template <
typename... Args>
952template <
typename... Args>
957template <
typename... Args>
964template <
size_t N,
typename... Args>
966 detail::SmallFormattedString<N> result{};
#define GREM_ALWAYS_INLINE
Definition attributes.hpp:10
Definition ConstantString.hpp:40
Optional value type that holds either a value or no value.
Definition Optional.hpp:58
Definition SharedPointer.hpp:65
Nullable RAII data pointer with exclusive ownership of an object that is automatically destroyed on p...
Definition UniquePointer.hpp:77
Tagged union value type that holds a value of one of the given types.
Definition Variant.hpp:293
constexpr bool valueless_by_exception() const noexcept
Check if the variant is in the valueless by exception state.
Definition Variant.hpp:726
Definition SharedPointer.hpp:588
SharedPointer< T > lock() const noexcept
Definition SharedPointer.hpp:715
Definition concepts.hpp:47
constexpr tuple_element_t< Index, Pair< T1, T2 > > & get(Pair< T1, T2 > &t) noexcept
Definition Pair.hpp:202
constexpr size_t getFormattedSizeDebug(DebugFormatString< Args... > format, const Args &... args)
Definition debug_formatting.hpp:868
constexpr void formatToDebug(Output &output, DebugFormatString< Args... > format, const Args &... args)
Definition debug_formatting.hpp:875
detail::SmallFormattedString< N > formatSmallStringDebug(DebugFormatString< Args... > format, const Args &... args)
Definition debug_formatting.hpp:965
iter_value_t< iterator_t< T > > range_value_t
Definition concepts.hpp:222
constexpr void formatToV(FormatOutput &output, CStringView format, FormatArguments arguments)
Definition formatting.hpp:200
GREM_ALWAYS_INLINE void println()
Definition formatting.hpp:380
GREM_ALWAYS_INLINE void eprintlnDebug()
Definition debug_formatting.hpp:948
GREM_ALWAYS_INLINE void printDebug(std::FILE *output, DebugFormatString< Args... > format, const Args &... args)
Definition debug_formatting.hpp:914
GREM_ALWAYS_INLINE void printlnDebug()
Definition debug_formatting.hpp:934
GREM_ALWAYS_INLINE void eprintDebug(DebugFormatString< Args... > format, const Args &... args)
Definition debug_formatting.hpp:944
DebugFormatStringBase< std::type_identity_t< Args >... > DebugFormatString
Definition debug_formatting.hpp:865
StringBase< char, std::char_traits< char >, std::allocator< char > > String
Definition String.hpp:17
constexpr detail::Matcher< V > match(V &&variant)
Choose a function overload to execute based on the active alternative of a variant.
Definition Variant.hpp:1922
StringViewBase< char, std::char_traits< char > > StringView
Definition StringView.hpp:16
String formatStringDebug(DebugFormatString< Args... > format, const Args &... args)
Definition debug_formatting.hpp:958
auto asBytes(Span< T, N > s) noexcept
Definition Span.hpp:359
CStringViewBase< char, std::char_traits< char > > CStringView
Definition CStringView.hpp:635