Simplify API

This commit is contained in:
Victor Zverovich 2017-02-05 06:54:03 -08:00
parent 624c58682d
commit a13b96ed88
10 changed files with 28 additions and 33 deletions

View File

@ -224,7 +224,7 @@ FMT_FUNC void format_system_error(
} // namespace internal
FMT_FUNC void SystemError::init(
int err_code, CStringRef format_str, format_args args) {
int err_code, CStringRef format_str, args args) {
error_code_ = err_code;
MemoryWriter w;
format_system_error(w, err_code, vformat(format_str, args));
@ -348,7 +348,7 @@ FMT_FUNC int internal::UTF16ToUTF8::convert(WStringRef s) {
}
FMT_FUNC void WindowsError::init(
int err_code, CStringRef format_str, format_args args) {
int err_code, CStringRef format_str, args args) {
error_code_ = err_code;
MemoryWriter w;
internal::format_windows_error(w, err_code, vformat(format_str, args));
@ -428,17 +428,17 @@ FMT_FUNC void report_windows_error(
}
#endif
FMT_FUNC void vprint(std::FILE *f, CStringRef format_str, format_args args) {
FMT_FUNC void vprint(std::FILE *f, CStringRef format_str, args args) {
MemoryWriter w;
w.vformat(format_str, args);
std::fwrite(w.data(), 1, w.size(), f);
}
FMT_FUNC void vprint(CStringRef format_str, format_args args) {
FMT_FUNC void vprint(CStringRef format_str, args args) {
vprint(stdout, format_str, args);
}
FMT_FUNC void vprint_colored(Color c, CStringRef format, format_args args) {
FMT_FUNC void vprint_colored(Color c, CStringRef format, args args) {
char escape[] = "\x1b[30m";
escape[3] = static_cast<char>('0' + c);
std::fputs(escape, stdout);
@ -448,7 +448,7 @@ FMT_FUNC void vprint_colored(Color c, CStringRef format, format_args args) {
template <typename Char>
void printf(basic_writer<Char> &w, BasicCStringRef<Char> format,
format_args args);
args args);
FMT_FUNC int vfprintf(std::FILE *f, CStringRef format, printf_args args) {
MemoryWriter w;
@ -465,7 +465,7 @@ template struct internal::BasicData<void>;
template void internal::FixedBuffer<char>::grow(std::size_t);
template void internal::ArgMap<context>::init(const format_args &args);
template void internal::ArgMap<context>::init(const args &args);
template void printf_context<char>::format(writer &writer);
@ -483,7 +483,7 @@ template class basic_context<wchar_t>;
template void internal::FixedBuffer<wchar_t>::grow(std::size_t);
template void internal::ArgMap<wcontext>::init(const wformat_args &args);
template void internal::ArgMap<wcontext>::init(const wargs &args);
template void printf_context<wchar_t>::format(wwriter &writer);

View File

@ -1369,9 +1369,6 @@ class basic_arg {
}
};
typedef basic_arg<context> format_arg;
typedef basic_arg<wcontext> wformat_arg;
/**
\rst
Visits an argument dispatching to the appropriate visit method based on
@ -1625,8 +1622,8 @@ class basic_args {
}
};
typedef basic_args<context> format_args;
typedef basic_args<wcontext> wformat_args;
typedef basic_args<context> args;
typedef basic_args<wcontext> wargs;
enum Alignment {
ALIGN_DEFAULT, ALIGN_LEFT, ALIGN_RIGHT, ALIGN_CENTER, ALIGN_NUMERIC
@ -2111,7 +2108,7 @@ class basic_context :
*/
class SystemError : public internal::RuntimeError {
private:
void init(int err_code, CStringRef format_str, format_args args);
void init(int err_code, CStringRef format_str, args args);
protected:
int error_code_;
@ -2943,7 +2940,7 @@ FMT_API void report_system_error(int error_code,
/** A Windows error. */
class WindowsError : public SystemError {
private:
FMT_API void init(int error_code, CStringRef format_str, format_args args);
FMT_API void init(int error_code, CStringRef format_str, args args);
public:
/**
@ -2989,7 +2986,7 @@ FMT_API void report_windows_error(int error_code,
enum Color { BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE };
FMT_API void vprint_colored(Color c, CStringRef format, format_args args);
FMT_API void vprint_colored(Color c, CStringRef format, args args);
/**
Formats a string and prints it to stdout using ANSI escape sequences
@ -3003,7 +3000,7 @@ inline void print_colored(Color c, CStringRef format_str,
vprint_colored(c, format_str, make_args(args...));
}
inline std::string vformat(CStringRef format_str, format_args args) {
inline std::string vformat(CStringRef format_str, args args) {
MemoryWriter w;
w.vformat(format_str, args);
return w.str();
@ -3023,7 +3020,7 @@ inline std::string format(CStringRef format_str, const Args & ... args) {
return vformat(format_str, make_args(args...));
}
inline std::wstring vformat(WCStringRef format_str, wformat_args args) {
inline std::wstring vformat(WCStringRef format_str, wargs args) {
WMemoryWriter w;
w.vformat(format_str, args);
return w.str();
@ -3035,7 +3032,7 @@ inline std::wstring format(WCStringRef format_str, const Args & ... args) {
return vformat(format_str, vargs);
}
FMT_API void vprint(std::FILE *f, CStringRef format_str, format_args args);
FMT_API void vprint(std::FILE *f, CStringRef format_str, args args);
/**
\rst
@ -3051,7 +3048,7 @@ inline void print(std::FILE *f, CStringRef format_str, const Args & ... args) {
vprint(f, format_str, make_args(args...));
}
FMT_API void vprint(CStringRef format_str, format_args args);
FMT_API void vprint(CStringRef format_str, args args);
/**
\rst

View File

@ -28,7 +28,7 @@ FMT_FUNC void write(std::ostream &os, writer &w) {
}
FMT_FUNC void vprint(std::ostream &os, CStringRef format_str,
format_args args) {
args args) {
MemoryWriter w;
w.vformat(format_str, args);
internal::write(os, w);

View File

@ -91,7 +91,7 @@ void format_value(basic_writer<Char> &w, const T &value,
w, internal::make_arg< basic_context<Char> >(str), ctx);
}
FMT_API void vprint(std::ostream &os, CStringRef format_str, format_args args);
FMT_API void vprint(std::ostream &os, CStringRef format_str, args args);
/**
\rst

View File

@ -166,7 +166,7 @@ public:
// of MinGW that define fileno as a macro.
int (fileno)() const;
void vprint(CStringRef format_str, const format_args &args) {
void vprint(CStringRef format_str, const args &args) {
fmt::vprint(file_, format_str, args);
}

View File

@ -45,7 +45,7 @@ class CustomPrintfArgFormatter : public PrintfArgFormatter<char> {
}
};
std::string custom_vformat(fmt::CStringRef format_str, fmt::format_args args) {
std::string custom_vformat(fmt::CStringRef format_str, fmt::args args) {
fmt::MemoryWriter writer;
// Pass custom argument formatter as a template arg to vformat.
fmt::vwrite<CustomArgFormatter>(writer, format_str, args);

View File

@ -55,9 +55,8 @@ struct ValueExtractor {
};
TEST(FormatTest, ArgConverter) {
using fmt::format_arg;
fmt::LongLong value = std::numeric_limits<fmt::LongLong>::max();
format_arg arg = fmt::internal::make_arg<fmt::context>(value);
auto arg = fmt::internal::make_arg<fmt::context>(value);
visit(fmt::internal::ArgConverter<
fmt::LongLong, fmt::context>(arg, 'd'), arg);
EXPECT_EQ(value, visit(ValueExtractor<fmt::LongLong>(), arg));

View File

@ -1566,7 +1566,7 @@ TEST(StrTest, Convert) {
EXPECT_EQ("2012-12-9", s);
}
std::string vformat_message(int id, const char *format, fmt::format_args args) {
std::string vformat_message(int id, const char *format, fmt::args args) {
MemoryWriter w;
w.format("[{}] ", id);
w.vformat(format, args);
@ -1656,7 +1656,7 @@ class MockArgFormatter : public fmt::internal::ArgFormatterBase<char> {
void operator()(fmt::internal::CustomValue<char>) {}
};
void custom_vformat(fmt::CStringRef format_str, fmt::format_args args) {
void custom_vformat(fmt::CStringRef format_str, fmt::args args) {
fmt::MemoryWriter writer;
fmt::vwrite<MockArgFormatter>(writer, format_str, args);
}

View File

@ -65,7 +65,7 @@ struct TestArgFormatter : fmt::ArgFormatter<char> {
TEST(OStreamTest, CustomArg) {
fmt::MemoryWriter writer;
fmt::context ctx("}", fmt::format_args());
fmt::context ctx("}", fmt::args());
fmt::format_specs spec;
TestArgFormatter af(writer, ctx, spec);
visit(af, fmt::internal::make_arg<fmt::context>(TestEnum()));

View File

@ -53,7 +53,6 @@
#undef max
using fmt::basic_arg;
using fmt::format_arg;
using fmt::buffer;
using fmt::StringRef;
using fmt::internal::MemoryBuffer;
@ -408,7 +407,7 @@ TEST(UtilTest, Increment) {
}
TEST(UtilTest, FormatArgs) {
fmt::format_args args;
fmt::args args;
EXPECT_FALSE(args[1]);
}
@ -570,7 +569,7 @@ TEST(UtilTest, CustomArg) {
testing::Invoke([&](fmt::internal::CustomValue<char> custom) {
EXPECT_EQ(&test, custom.value);
fmt::MemoryWriter w;
fmt::context ctx("}", fmt::format_args());
fmt::context ctx("}", fmt::args());
custom.format(w, &test, &ctx);
EXPECT_EQ("test", w.str());
return Visitor::Result();
@ -582,7 +581,7 @@ TEST(ArgVisitorTest, VisitInvalidArg) {
typedef MockVisitor<fmt::monostate> Visitor;
testing::StrictMock<Visitor> visitor;
EXPECT_CALL(visitor, visit(_));
format_arg arg;
fmt::basic_arg<fmt::context> arg;
visit(visitor, arg);
}