Commit 624c5868 authored by Victor Zverovich's avatar Victor Zverovich

Simplify API

parent 7ae8bd70
......@@ -465,7 +465,7 @@ template struct internal::BasicData<void>;
template void internal::FixedBuffer<char>::grow(std::size_t);
template void internal::ArgMap<format_context>::init(const format_args &args);
template void internal::ArgMap<context>::init(const format_args &args);
template void printf_context<char>::format(writer &writer);
......@@ -479,11 +479,11 @@ template int internal::CharTraits<char>::format_float(
// Explicit instantiations for wchar_t.
template class basic_format_context<wchar_t>;
template class basic_context<wchar_t>;
template void internal::FixedBuffer<wchar_t>::grow(std::size_t);
template void internal::ArgMap<wformat_context>::init(const wformat_args &args);
template void internal::ArgMap<wcontext>::init(const wformat_args &args);
template void printf_context<wchar_t>::format(wwriter &writer);
......
This diff is collapsed.
......@@ -84,11 +84,11 @@ BasicStringRef<Char> format_value(
// Formats a value.
template <typename Char, typename T>
void format_value(basic_writer<Char> &w, const T &value,
basic_format_context<Char> &ctx) {
basic_context<Char> &ctx) {
internal::MemoryBuffer<Char, internal::INLINE_BUFFER_SIZE> buffer;
auto str = internal::format_value(buffer, value);
do_format_arg< ArgFormatter<Char> >(
w, internal::make_arg< basic_format_context<Char> >(str), ctx);
w, internal::make_arg< basic_context<Char> >(str), ctx);
}
FMT_API void vprint(std::ostream &os, CStringRef format_str, format_args args);
......@@ -105,7 +105,7 @@ FMT_API void vprint(std::ostream &os, CStringRef format_str, format_args args);
template <typename... Args>
inline void print(std::ostream &os, CStringRef format_str,
const Args & ... args) {
vprint(os, format_str, make_format_args(args...));
vprint(os, format_str, make_args(args...));
}
} // namespace fmt
......
......@@ -172,7 +172,7 @@ public:
template <typename... Args>
inline void print(CStringRef format_str, const Args & ... args) {
vprint(format_str, make_format_args(args...));
vprint(format_str, make_args(args...));
}
};
......
......@@ -103,7 +103,7 @@ class ArgConverter {
bool is_signed = type_ == 'd' || type_ == 'i';
typedef typename internal::Conditional<
is_same<T, void>::value, U, T>::type TargetType;
typedef basic_format_context<Char> format_context;
typedef basic_context<Char> context;
if (sizeof(TargetType) <= sizeof(int)) {
// Extra casts are used to silence warnings.
if (is_signed) {
......@@ -287,8 +287,8 @@ class PrintfArgFormatter : public internal::ArgFormatterBase<Char> {
/** Formats an argument of a custom (user-defined) type. */
void operator()(internal::CustomValue<Char> c) {
const Char format_str[] = {'}', '\0'};
auto args = basic_args<basic_format_context<Char>>();
basic_format_context<Char> ctx(format_str, args);
auto args = basic_args<basic_context<Char>>();
basic_context<Char> ctx(format_str, args);
c.format(this->writer(), c.value, &ctx);
}
};
......@@ -297,14 +297,14 @@ class PrintfArgFormatter : public internal::ArgFormatterBase<Char> {
template <typename Char,
typename ArgFormatter = PrintfArgFormatter<Char> >
class printf_context :
private internal::format_context_base<
private internal::context_base<
Char, printf_context<Char, ArgFormatter>> {
public:
/** The character type for the output. */
typedef Char char_type;
private:
typedef internal::format_context_base<Char, printf_context> Base;
typedef internal::context_base<Char, printf_context> Base;
typedef typename Base::format_arg format_arg;
typedef basic_format_specs<Char> format_specs;
......@@ -539,7 +539,7 @@ inline std::string vsprintf(CStringRef format, printf_args args) {
*/
template <typename... Args>
inline std::string sprintf(CStringRef format_str, const Args & ... args) {
return vsprintf(format_str, make_xformat_args<printf_context<char>>(args...));
return vsprintf(format_str, make_args<printf_context<char>>(args...));
}
inline std::wstring vsprintf(
......@@ -551,7 +551,7 @@ inline std::wstring vsprintf(
template <typename... Args>
inline std::wstring sprintf(WCStringRef format_str, const Args & ... args) {
auto vargs = make_xformat_args<printf_context<wchar_t>>(args...);
auto vargs = make_args<printf_context<wchar_t>>(args...);
return vsprintf(format_str, vargs);
}
......@@ -568,7 +568,7 @@ FMT_API int vfprintf(std::FILE *f, CStringRef format, printf_args args);
*/
template <typename... Args>
inline int fprintf(std::FILE *f, CStringRef format_str, const Args & ... args) {
auto vargs = make_xformat_args<printf_context<char>>(args...);
auto vargs = make_args<printf_context<char>>(args...);
return vfprintf(f, format_str, vargs);
}
......@@ -587,7 +587,7 @@ inline int vprintf(CStringRef format, printf_args args) {
*/
template <typename... Args>
inline int printf(CStringRef format_str, const Args & ... args) {
return vprintf(format_str, make_xformat_args<printf_context<char>>(args...));
return vprintf(format_str, make_args<printf_context<char>>(args...));
}
inline int vfprintf(std::ostream &os, CStringRef format_str, printf_args args) {
......@@ -609,7 +609,7 @@ inline int vfprintf(std::ostream &os, CStringRef format_str, printf_args args) {
template <typename... Args>
inline int fprintf(std::ostream &os, CStringRef format_str,
const Args & ... args) {
auto vargs = make_xformat_args<printf_context<char>>(args...);
auto vargs = make_args<printf_context<char>>(args...);
return vfprintf(os, format_str, vargs);
}
} // namespace fmt
......
......@@ -15,7 +15,7 @@
namespace fmt {
void format_value(writer &w, const std::tm &tm, format_context &ctx) {
void format_value(writer &w, const std::tm &tm, context &ctx) {
const char *&s = ctx.ptr();
if (*s == ':')
++s;
......
......@@ -16,7 +16,7 @@ using fmt::PrintfArgFormatter;
// rounded to 0.
class CustomArgFormatter : public fmt::ArgFormatter<char> {
public:
CustomArgFormatter(fmt::writer &w, fmt::basic_format_context<char> &ctx,
CustomArgFormatter(fmt::writer &w, fmt::basic_context<char> &ctx,
fmt::format_specs &s)
: fmt::ArgFormatter<char>(w, ctx, s) {}
......@@ -54,7 +54,7 @@ std::string custom_vformat(fmt::CStringRef format_str, fmt::format_args args) {
template <typename... Args>
std::string custom_format(const char *format_str, const Args & ... args) {
auto va = fmt::make_format_args(args...);
auto va = fmt::make_args(args...);
return custom_vformat(format_str, va);
}
......@@ -72,7 +72,7 @@ std::string custom_vsprintf(
template <typename... Args>
std::string custom_sprintf(const char *format_str, const Args & ... args) {
auto va = fmt::make_xformat_args<CustomPrintfFormatter>(args...);
auto va = fmt::make_args<CustomPrintfFormatter>(args...);
return custom_vsprintf(format_str, va);
}
......
......@@ -57,9 +57,9 @@ 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::format_context>(value);
format_arg arg = fmt::internal::make_arg<fmt::context>(value);
visit(fmt::internal::ArgConverter<
fmt::LongLong, fmt::format_context>(arg, 'd'), arg);
fmt::LongLong, fmt::context>(arg, 'd'), arg);
EXPECT_EQ(value, visit(ValueExtractor<fmt::LongLong>(), arg));
}
......
......@@ -1366,7 +1366,7 @@ TEST(FormatterTest, FormatCStringRef) {
EXPECT_EQ("test", format("{0}", CStringRef("test")));
}
void format_value(fmt::writer &w, const Date &d, fmt::format_context &) {
void format_value(fmt::writer &w, const Date &d, fmt::context &) {
w.write(d.year());
w.write('-');
w.write(d.month());
......@@ -1383,7 +1383,7 @@ TEST(FormatterTest, FormatCustom) {
class Answer {};
template <typename Char>
void format_value(basic_writer<Char> &w, Answer, fmt::format_context &) {
void format_value(basic_writer<Char> &w, Answer, fmt::context &) {
w.write("42");
}
......@@ -1575,7 +1575,7 @@ std::string vformat_message(int id, const char *format, fmt::format_args args) {
template <typename... Args>
std::string format_message(int id, const char *format, const Args & ... args) {
auto va = fmt::make_format_args(args...);
auto va = fmt::make_args(args...);
return vformat_message(id, format, va);
}
......@@ -1643,7 +1643,7 @@ class MockArgFormatter : public fmt::internal::ArgFormatterBase<char> {
public:
typedef fmt::internal::ArgFormatterBase<char> Base;
MockArgFormatter(fmt::writer &w, fmt::format_context &ctx,
MockArgFormatter(fmt::writer &w, fmt::context &ctx,
fmt::format_specs &s)
: fmt::internal::ArgFormatterBase<char>(w, s) {
EXPECT_CALL(*this, call(42));
......@@ -1663,7 +1663,7 @@ void custom_vformat(fmt::CStringRef format_str, fmt::format_args args) {
template <typename... Args>
void custom_format(const char *format_str, const Args & ... args) {
auto va = fmt::make_format_args(args...);
auto va = fmt::make_args(args...);
return custom_vformat(format_str, va);
}
......
......@@ -59,17 +59,16 @@ TEST(OStreamTest, Enum) {
}
struct TestArgFormatter : fmt::ArgFormatter<char> {
TestArgFormatter(fmt::writer &w, fmt::format_context &ctx,
fmt::format_specs &s)
TestArgFormatter(fmt::writer &w, fmt::context &ctx, fmt::format_specs &s)
: fmt::ArgFormatter<char>(w, ctx, s) {}
};
TEST(OStreamTest, CustomArg) {
fmt::MemoryWriter writer;
fmt::format_context ctx("}", fmt::format_args());
fmt::context ctx("}", fmt::format_args());
fmt::format_specs spec;
TestArgFormatter af(writer, ctx, spec);
visit(af, fmt::internal::make_arg<fmt::format_context>(TestEnum()));
visit(af, fmt::internal::make_arg<fmt::context>(TestEnum()));
EXPECT_EQ("TestEnum", writer.str());
}
......
......@@ -69,7 +69,7 @@ struct Test {};
template <typename Char>
void format_value(fmt::basic_writer<Char> &w, Test,
fmt::basic_format_context<Char> &) {
fmt::basic_context<Char> &) {
w.write("test");
}
......@@ -487,7 +487,7 @@ VISIT_TYPE(float, double);
#define CHECK_ARG_(Char, expected, value) { \
testing::StrictMock<MockVisitor<decltype(expected)>> visitor; \
EXPECT_CALL(visitor, visit(expected)); \
fmt::visit(visitor, make_arg<fmt::basic_format_context<Char>>(value)); \
fmt::visit(visitor, make_arg<fmt::basic_context<Char>>(value)); \
}
#define CHECK_ARG(value) { \
......@@ -570,12 +570,12 @@ TEST(UtilTest, CustomArg) {
testing::Invoke([&](fmt::internal::CustomValue<char> custom) {
EXPECT_EQ(&test, custom.value);
fmt::MemoryWriter w;
fmt::format_context ctx("}", fmt::format_args());
fmt::context ctx("}", fmt::format_args());
custom.format(w, &test, &ctx);
EXPECT_EQ("test", w.str());
return Visitor::Result();
}));
fmt::visit(visitor, make_arg<fmt::format_context>(test));
fmt::visit(visitor, make_arg<fmt::context>(test));
}
TEST(ArgVisitorTest, VisitInvalidArg) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment