From 5063e218af602a7dcf5323ad07e5521c9ce99057 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Wed, 18 Jan 2023 16:48:02 -0500 Subject: [PATCH] AK: Move the AK::FixedPoint formatter to FixedPoint.h This does not need to be defined in Format.h. This causes FixedPoint.h to be included everywhere. This is particularly going to be an issue when trying to include on macOS. The macOS SDK defines its own FixedPoint structure which will conflict with ours. --- AK/FixedPoint.h | 39 +++++++++++++++++++++++++++++++++++++++ AK/Format.h | 39 --------------------------------------- 2 files changed, 39 insertions(+), 39 deletions(-) diff --git a/AK/FixedPoint.h b/AK/FixedPoint.h index ed37f9320a3..38360777759 100644 --- a/AK/FixedPoint.h +++ b/AK/FixedPoint.h @@ -7,6 +7,7 @@ #pragma once #include +#include #include #include #include @@ -388,6 +389,44 @@ private: Underlying m_value; }; +template +struct Formatter> : StandardFormatter { + Formatter() = default; + explicit Formatter(StandardFormatter formatter) + : StandardFormatter(formatter) + { + } + + ErrorOr format(FormatBuilder& builder, FixedPoint value) + { + u8 base; + bool upper_case; + FormatBuilder::RealNumberDisplayMode real_number_display_mode = FormatBuilder::RealNumberDisplayMode::General; + if (m_mode == Mode::Default || m_mode == Mode::FixedPoint) { + base = 10; + upper_case = false; + if (m_mode == Mode::FixedPoint) + real_number_display_mode = FormatBuilder::RealNumberDisplayMode::FixedPoint; + } else if (m_mode == Mode::Hexfloat) { + base = 16; + upper_case = false; + } else if (m_mode == Mode::HexfloatUppercase) { + base = 16; + upper_case = true; + } else { + VERIFY_NOT_REACHED(); + } + + m_width = m_width.value_or(0); + m_precision = m_precision.value_or(6); + + i64 integer = value.ltrunk(); + constexpr u64 one = static_cast(1) << precision; + u64 fraction_raw = value.raw() & (one - 1); + return builder.put_fixed_point(integer, fraction_raw, one, base, upper_case, m_zero_pad, m_align, m_width.value(), m_precision.value(), m_fill, m_sign_mode, real_number_display_mode); + } +}; + } #if USING_AK_GLOBALLY diff --git a/AK/Format.h b/AK/Format.h index ed31bb4f4c5..6f9ffe1d9be 100644 --- a/AK/Format.h +++ b/AK/Format.h @@ -12,7 +12,6 @@ #include #include #include -#include #include #include #include @@ -534,44 +533,6 @@ struct Formatter : StandardFormatter { }; #endif -template -struct Formatter> : StandardFormatter { - Formatter() = default; - explicit Formatter(StandardFormatter formatter) - : StandardFormatter(formatter) - { - } - - ErrorOr format(FormatBuilder& builder, FixedPoint value) - { - u8 base; - bool upper_case; - FormatBuilder::RealNumberDisplayMode real_number_display_mode = FormatBuilder::RealNumberDisplayMode::General; - if (m_mode == Mode::Default || m_mode == Mode::FixedPoint) { - base = 10; - upper_case = false; - if (m_mode == Mode::FixedPoint) - real_number_display_mode = FormatBuilder::RealNumberDisplayMode::FixedPoint; - } else if (m_mode == Mode::Hexfloat) { - base = 16; - upper_case = false; - } else if (m_mode == Mode::HexfloatUppercase) { - base = 16; - upper_case = true; - } else { - VERIFY_NOT_REACHED(); - } - - m_width = m_width.value_or(0); - m_precision = m_precision.value_or(6); - - i64 integer = value.ltrunk(); - constexpr u64 one = static_cast(1) << precision; - u64 fraction_raw = value.raw() & (one - 1); - return builder.put_fixed_point(integer, fraction_raw, one, base, upper_case, m_zero_pad, m_align, m_width.value(), m_precision.value(), m_fill, m_sign_mode, real_number_display_mode); - } -}; - template<> struct Formatter : Formatter { ErrorOr format(FormatBuilder& builder, nullptr_t)