/** This file is a part of rexy's general purpose library Copyright (C) 2022 rexy712 This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef REXY_DETAIL_FORMAT_FORMATTER_HPP #define REXY_DETAIL_FORMAT_FORMATTER_HPP #include //size_t, nullptr_t #include //monostate #include //locale #include //remove_cvref #include //forward #include "basic_types.hpp" //format_specs #include "internal_types.hpp" #include "standard_types.hpp" //basic_parse_context #include "specs_handler.hpp" //format_specs_checker #include "traits.hpp" #include "../../string.hpp" #include "../../string_view.hpp" #include "../../allocator.hpp" namespace rexy::fmt{ namespace detail{ namespace format{ template constexpr OutIt perform_standard_format(const void* t, OutIt out, const format_specs& specs, const std::locale& loc); template constexpr OutIt perform_standard_format(const void* t, OutIt out); template requires(!UTF8_String) constexpr OutIt perform_standard_format(const Char* c, OutIt out, const format_specs& specs, const std::locale& loc); template constexpr OutIt perform_standard_format(const Char* c, OutIt out, const format_specs& specs, const std::locale& loc); template constexpr OutIt perform_standard_format(const Char* c, OutIt out); template constexpr OutIt perform_standard_format(Char b, OutIt out, const format_specs& specs, const std::locale& loc); template constexpr OutIt perform_standard_format(Char b, OutIt out); template constexpr OutIt perform_standard_format(bool b, OutIt out, const format_specs& specs, const std::locale& loc); template constexpr OutIt perform_standard_format(bool b, OutIt out); template constexpr OutIt perform_standard_format(T b, OutIt out, const format_specs& specs, const std::locale& loc); template constexpr OutIt perform_standard_format(T b, OutIt out); template constexpr OutIt perform_standard_format(T f, OutIt out, const format_specs& specs, const std::locale& loc); template constexpr OutIt perform_standard_format(std::monostate, OutIt out, const format_specs&, const std::locale&); template constexpr OutIt perform_standard_format(std::monostate, OutIt out); template struct arg_formatter{ FmtCtx& fmt_ctx; ParseCtx& parse_ctx; const Specs& specs; template T> constexpr void operator()(T&& t); template constexpr void operator()(T&& t); }; template struct empty_formatter{ FmtCtx& fmt_ctx; ParseCtx& parse_ctx; template T> constexpr void operator()(T&& t); template constexpr void operator()(T&& t); }; } template class formatter_base { public: using char_type = Char; using parse_ctx_t = basic_format_parse_context; using fmt_ctx_t = detail::fmt_context_t; using format_spec_t = detail::dynamic_format_specs; using format_spec_handler_t = detail::format_specs_checker>; protected: format_spec_t specs; public: constexpr auto parse(basic_format_parse_context& ctx) -> decltype(ctx.begin()); template auto format(U&& t, FormatContext& ctx) -> decltype(ctx.out()); }; } } namespace rexy{ template class formatter; #define IMPLEMENT_STANDARD_FORMATTER(type) \ template \ class formatter : public fmt::detail::formatter_base>, C>{} IMPLEMENT_STANDARD_FORMATTER(int); IMPLEMENT_STANDARD_FORMATTER(unsigned int); IMPLEMENT_STANDARD_FORMATTER(long long); IMPLEMENT_STANDARD_FORMATTER(unsigned long long); IMPLEMENT_STANDARD_FORMATTER(bool); IMPLEMENT_STANDARD_FORMATTER(float); IMPLEMENT_STANDARD_FORMATTER(double); IMPLEMENT_STANDARD_FORMATTER(long double); IMPLEMENT_STANDARD_FORMATTER(std::nullptr_t); IMPLEMENT_STANDARD_FORMATTER(short); IMPLEMENT_STANDARD_FORMATTER(unsigned short); IMPLEMENT_STANDARD_FORMATTER(long); IMPLEMENT_STANDARD_FORMATTER(unsigned long); IMPLEMENT_STANDARD_FORMATTER(char); IMPLEMENT_STANDARD_FORMATTER(unsigned char); IMPLEMENT_STANDARD_FORMATTER(signed char); template class formatter : public fmt::detail::formatter_base{}; template class formatter : public fmt::detail::formatter_base{}; template class formatter : public fmt::detail::formatter_base{}; template class formatter,C> : public fmt::detail::formatter_base,C>{}; template class formatter,C> : public fmt::detail::formatter_base,C>{}; template class formatter : public fmt::detail::formatter_base{}; template class formatter : public fmt::detail::formatter_base{}; #undef IMPLEMENT_STANDARD_FORMATTER } #endif