Merge BasicArgFormatter and ArgFormatter

This commit is contained in:
Victor Zverovich
2016-11-20 09:36:27 -08:00
parent d4084ac5b1
commit 284297019f
5 changed files with 29 additions and 42 deletions
+4 -5
View File
@@ -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<CustomArgFormatter, char> {
class CustomArgFormatter : public fmt::ArgFormatter<char> {
public:
CustomArgFormatter(fmt::Writer &w, fmt::basic_format_context<char> &ctx,
fmt::FormatSpec &s)
: fmt::BasicArgFormatter<CustomArgFormatter, char>(w, ctx, s) {}
: fmt::ArgFormatter<char>(w, ctx, s) {}
using fmt::BasicArgFormatter<CustomArgFormatter, char>::operator();
using fmt::ArgFormatter<char>::operator();
void operator()(double value) {
if (round(value * pow(10, spec().precision())) == 0)
value = 0;
fmt::BasicArgFormatter<CustomArgFormatter, char>::operator()(value);
fmt::ArgFormatter<char>::operator()(value);
}
};
+4 -5
View File
@@ -1619,17 +1619,16 @@ TEST(FormatTest, Enum) {
EXPECT_EQ("0", fmt::format("{}", A));
}
class MockArgFormatter :
public fmt::internal::ArgFormatterBase<MockArgFormatter, char> {
class MockArgFormatter : public fmt::internal::ArgFormatterBase<char> {
private:
MOCK_METHOD1(call, void (int value));
public:
typedef fmt::internal::ArgFormatterBase<MockArgFormatter, char> Base;
typedef fmt::internal::ArgFormatterBase<char> Base;
MockArgFormatter(fmt::Writer &w, fmt::format_context &ctx,
fmt::FormatSpec &s)
: fmt::internal::ArgFormatterBase<MockArgFormatter, char>(w, s) {
: fmt::internal::ArgFormatterBase<char>(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) {
+2 -2
View File
@@ -58,10 +58,10 @@ TEST(OStreamTest, Enum) {
EXPECT_EQ("0", fmt::format("{}", A));
}
struct TestArgFormatter : fmt::BasicArgFormatter<TestArgFormatter, char> {
struct TestArgFormatter : fmt::ArgFormatter<char> {
TestArgFormatter(fmt::Writer &w, fmt::format_context &ctx,
fmt::FormatSpec &s)
: fmt::BasicArgFormatter<TestArgFormatter, char>(w, ctx, s) {}
: fmt::ArgFormatter<char>(w, ctx, s) {}
};
TEST(OStreamTest, CustomArg) {