diff --git a/fmt/format.h b/fmt/format.h index dd3ac296..26ed0bbf 100644 --- a/fmt/format.h +++ b/fmt/format.h @@ -1873,7 +1873,7 @@ void ArgMap::init(const basic_format_args &args) { } } -template +template class ArgFormatterBase { private: BasicWriter &writer_; @@ -2055,9 +2055,9 @@ class format_context_base { }; } // namespace internal -/** An argument formatter. */ -template -class BasicArgFormatter : public internal::ArgFormatterBase { +/** The default argument formatter. */ +template +class ArgFormatter : public internal::ArgFormatterBase { private: basic_format_context &ctx_; @@ -2065,31 +2065,21 @@ class BasicArgFormatter : public internal::ArgFormatterBase { /** \rst Constructs an argument formatter object. - *formatter* is a reference to the main formatter object, *spec* contains - format specifier information for standard argument types, and *fmt* points - to the part of the format string being parsed for custom argument types. + *writer* is a reference to the writer to be used for output, + *ctx* is a reference to the formatting context, *spec* contains + format specifier information for standard argument types. \endrst */ - BasicArgFormatter(BasicWriter &writer, basic_format_context &ctx, - FormatSpec &spec) - : internal::ArgFormatterBase(writer, spec), ctx_(ctx) {} - - using internal::ArgFormatterBase::operator(); - - /** Formats an argument of a custom (user-defined) type. */ - void operator()(internal::Arg::CustomValue c) { - c.format(&this->writer(), c.value, &ctx_); - } -}; - -/** The default argument formatter. */ -template -class ArgFormatter : public BasicArgFormatter, Char> { - public: - /** Constructs an argument formatter object. */ ArgFormatter(BasicWriter &writer, basic_format_context &ctx, FormatSpec &spec) - : BasicArgFormatter, Char>(writer, ctx, spec) {} + : internal::ArgFormatterBase(writer, spec), ctx_(ctx) {} + + using internal::ArgFormatterBase::operator(); + + /** Formats an argument of a custom (user-defined) type. */ + void operator()(format_arg::CustomValue c) { + c.format(&this->writer(), c.value, &ctx_); + } }; template @@ -2305,7 +2295,7 @@ class BasicWriter { template void append_float_length(Char *&, T) {} - template + template friend class internal::ArgFormatterBase; template diff --git a/fmt/printf.h b/fmt/printf.h index f0adf71c..30b80953 100644 --- a/fmt/printf.h +++ b/fmt/printf.h @@ -208,15 +208,14 @@ class WidthHandler { \endrst */ template -class PrintfArgFormatter : - public internal::ArgFormatterBase, Char> { +class PrintfArgFormatter : public internal::ArgFormatterBase { private: void write_null_pointer() { this->spec().type_ = 0; this->write("(nil)"); } - typedef internal::ArgFormatterBase, Char> Base; + typedef internal::ArgFormatterBase Base; public: /** @@ -227,7 +226,7 @@ class PrintfArgFormatter : \endrst */ PrintfArgFormatter(BasicWriter &writer, FormatSpec &spec) - : internal::ArgFormatterBase, Char>(writer, spec) {} + : internal::ArgFormatterBase(writer, spec) {} using Base::operator(); diff --git a/test/custom-formatter-test.cc b/test/custom-formatter-test.cc index 9c568523..7601aeb5 100644 --- a/test/custom-formatter-test.cc +++ b/test/custom-formatter-test.cc @@ -14,19 +14,18 @@ using fmt::PrintfArgFormatter; // A custom argument formatter that doesn't print `-` for floating-point values // rounded to 0. -class CustomArgFormatter - : public fmt::BasicArgFormatter { +class CustomArgFormatter : public fmt::ArgFormatter { public: CustomArgFormatter(fmt::Writer &w, fmt::basic_format_context &ctx, fmt::FormatSpec &s) - : fmt::BasicArgFormatter(w, ctx, s) {} + : fmt::ArgFormatter(w, ctx, s) {} - using fmt::BasicArgFormatter::operator(); + using fmt::ArgFormatter::operator(); void operator()(double value) { if (round(value * pow(10, spec().precision())) == 0) value = 0; - fmt::BasicArgFormatter::operator()(value); + fmt::ArgFormatter::operator()(value); } }; diff --git a/test/format-test.cc b/test/format-test.cc index 2ce9d7f3..b8e991b0 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -1619,17 +1619,16 @@ TEST(FormatTest, Enum) { EXPECT_EQ("0", fmt::format("{}", A)); } -class MockArgFormatter : - public fmt::internal::ArgFormatterBase { +class MockArgFormatter : public fmt::internal::ArgFormatterBase { private: MOCK_METHOD1(call, void (int value)); public: - typedef fmt::internal::ArgFormatterBase Base; + typedef fmt::internal::ArgFormatterBase Base; MockArgFormatter(fmt::Writer &w, fmt::format_context &ctx, fmt::FormatSpec &s) - : fmt::internal::ArgFormatterBase(w, s) { + : fmt::internal::ArgFormatterBase(w, s) { EXPECT_CALL(*this, call(42)); } @@ -1637,7 +1636,7 @@ class MockArgFormatter : void operator()(int value) { call(value); } - void operator()(fmt::internal::Arg::CustomValue) {} + void operator()(fmt::format_arg::CustomValue) {} }; void custom_vformat(fmt::CStringRef format_str, fmt::format_args args) { diff --git a/test/ostream-test.cc b/test/ostream-test.cc index d600714c..b46418b4 100644 --- a/test/ostream-test.cc +++ b/test/ostream-test.cc @@ -58,10 +58,10 @@ TEST(OStreamTest, Enum) { EXPECT_EQ("0", fmt::format("{}", A)); } -struct TestArgFormatter : fmt::BasicArgFormatter { +struct TestArgFormatter : fmt::ArgFormatter { TestArgFormatter(fmt::Writer &w, fmt::format_context &ctx, fmt::FormatSpec &s) - : fmt::BasicArgFormatter(w, ctx, s) {} + : fmt::ArgFormatter(w, ctx, s) {} }; TEST(OStreamTest, CustomArg) {