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

Simplify API

parent 7ae8bd70
...@@ -465,7 +465,7 @@ template struct internal::BasicData<void>; ...@@ -465,7 +465,7 @@ template struct internal::BasicData<void>;
template void internal::FixedBuffer<char>::grow(std::size_t); 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); template void printf_context<char>::format(writer &writer);
...@@ -479,11 +479,11 @@ template int internal::CharTraits<char>::format_float( ...@@ -479,11 +479,11 @@ template int internal::CharTraits<char>::format_float(
// Explicit instantiations for wchar_t. // 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::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); template void printf_context<wchar_t>::format(wwriter &writer);
......
...@@ -380,10 +380,10 @@ template <typename Char> ...@@ -380,10 +380,10 @@ template <typename Char>
class PrintfArgFormatter; class PrintfArgFormatter;
template <typename Char> template <typename Char>
class basic_format_context; class basic_context;
typedef basic_format_context<char> format_context; typedef basic_context<char> context;
typedef basic_format_context<wchar_t> wformat_context; typedef basic_context<wchar_t> wcontext;
/** /**
\rst \rst
...@@ -1369,8 +1369,8 @@ class basic_arg { ...@@ -1369,8 +1369,8 @@ class basic_arg {
} }
}; };
typedef basic_arg<format_context> format_arg; typedef basic_arg<context> format_arg;
typedef basic_arg<wformat_context> wformat_arg; typedef basic_arg<wcontext> wformat_arg;
/** /**
\rst \rst
...@@ -1516,7 +1516,7 @@ inline typename std::enable_if<!IS_PACKED, basic_arg<Context>>::type ...@@ -1516,7 +1516,7 @@ inline typename std::enable_if<!IS_PACKED, basic_arg<Context>>::type
} // namespace internal } // namespace internal
template <typename Context, typename ...Args> template <typename Context, typename ...Args>
class format_arg_store { class arg_store {
private: private:
static const size_t NUM_ARGS = sizeof...(Args); static const size_t NUM_ARGS = sizeof...(Args);
...@@ -1535,22 +1535,20 @@ class format_arg_store { ...@@ -1535,22 +1535,20 @@ class format_arg_store {
public: public:
static const uint64_t TYPES = internal::make_type<Args..., void>(); static const uint64_t TYPES = internal::make_type<Args..., void>();
format_arg_store(const Args &... args) arg_store(const Args &... args)
: data_(Array{{internal::make_arg<IS_PACKED, Context>(args)...}}) {} : data_(Array{{internal::make_arg<IS_PACKED, Context>(args)...}}) {}
const value_type *data() const { return data_.data(); } const value_type *data() const { return data_.data(); }
}; };
template <typename Context, typename ...Args> template <typename Context, typename ...Args>
inline format_arg_store<Context, Args...> inline arg_store<Context, Args...> make_args(const Args & ... args) {
make_xformat_args(const Args & ... args) { return arg_store<Context, Args...>(args...);
return format_arg_store<Context, Args...>(args...);
} }
template <typename ...Args> template <typename ...Args>
inline format_arg_store<format_context, Args...> inline arg_store<context, Args...> make_args(const Args & ... args) {
make_format_args(const Args & ... args) { return arg_store<context, Args...>(args...);
return format_arg_store<format_context, Args...>(args...);
} }
/** Formatting arguments. */ /** Formatting arguments. */
...@@ -1614,7 +1612,7 @@ class basic_args { ...@@ -1614,7 +1612,7 @@ class basic_args {
basic_args() : types_(0) {} basic_args() : types_(0) {}
template <typename... Args> template <typename... Args>
basic_args(const format_arg_store<Context, Args...> &store) basic_args(const arg_store<Context, Args...> &store)
: types_(store.TYPES) { : types_(store.TYPES) {
set_data(store.data()); set_data(store.data());
} }
...@@ -1627,8 +1625,8 @@ class basic_args { ...@@ -1627,8 +1625,8 @@ class basic_args {
} }
}; };
typedef basic_args<format_context> format_args; typedef basic_args<context> format_args;
typedef basic_args<wformat_context> wformat_args; typedef basic_args<wcontext> wformat_args;
enum Alignment { enum Alignment {
ALIGN_DEFAULT, ALIGN_LEFT, ALIGN_RIGHT, ALIGN_CENTER, ALIGN_NUMERIC ALIGN_DEFAULT, ALIGN_LEFT, ALIGN_RIGHT, ALIGN_CENTER, ALIGN_NUMERIC
...@@ -1985,7 +1983,7 @@ inline void write(basic_writer<Char> &w, const Char *start, const Char *end) { ...@@ -1985,7 +1983,7 @@ inline void write(basic_writer<Char> &w, const Char *start, const Char *end) {
} }
template <typename Char, typename Context> template <typename Char, typename Context>
class format_context_base { class context_base {
private: private:
const Char *ptr_; const Char *ptr_;
basic_args<Context> args_; basic_args<Context> args_;
...@@ -1994,9 +1992,9 @@ class format_context_base { ...@@ -1994,9 +1992,9 @@ class format_context_base {
protected: protected:
typedef basic_arg<Context> format_arg; typedef basic_arg<Context> format_arg;
format_context_base(const Char *format_str, basic_args<Context> args) context_base(const Char *format_str, basic_args<Context> args)
: ptr_(format_str), args_(args), next_arg_index_(0) {} : ptr_(format_str), args_(args), next_arg_index_(0) {}
~format_context_base() {} ~context_base() {}
basic_args<Context> args() const { return args_; } basic_args<Context> args() const { return args_; }
...@@ -2042,7 +2040,7 @@ class format_context_base { ...@@ -2042,7 +2040,7 @@ class format_context_base {
template <typename Char> template <typename Char>
class ArgFormatter : public internal::ArgFormatterBase<Char> { class ArgFormatter : public internal::ArgFormatterBase<Char> {
private: private:
basic_format_context<Char> &ctx_; basic_context<Char> &ctx_;
typedef internal::ArgFormatterBase<Char> Base; typedef internal::ArgFormatterBase<Char> Base;
...@@ -2057,7 +2055,7 @@ class ArgFormatter : public internal::ArgFormatterBase<Char> { ...@@ -2057,7 +2055,7 @@ class ArgFormatter : public internal::ArgFormatterBase<Char> {
format specifier information for standard argument types. format specifier information for standard argument types.
\endrst \endrst
*/ */
ArgFormatter(basic_writer<Char> &writer, basic_format_context<Char> &ctx, ArgFormatter(basic_writer<Char> &writer, basic_context<Char> &ctx,
format_specs &spec) format_specs &spec)
: internal::ArgFormatterBase<Char>(writer, spec), ctx_(ctx) {} : internal::ArgFormatterBase<Char>(writer, spec), ctx_(ctx) {}
...@@ -2070,18 +2068,18 @@ class ArgFormatter : public internal::ArgFormatterBase<Char> { ...@@ -2070,18 +2068,18 @@ class ArgFormatter : public internal::ArgFormatterBase<Char> {
}; };
template <typename Char> template <typename Char>
class basic_format_context : class basic_context :
public internal::format_context_base<Char, basic_format_context<Char>> { public internal::context_base<Char, basic_context<Char>> {
public: public:
/** The character type for the output. */ /** The character type for the output. */
typedef Char char_type; typedef Char char_type;
private: private:
internal::ArgMap<basic_format_context<Char>> map_; internal::ArgMap<basic_context<Char>> map_;
FMT_DISALLOW_COPY_AND_ASSIGN(basic_format_context); FMT_DISALLOW_COPY_AND_ASSIGN(basic_context);
typedef internal::format_context_base<Char, basic_format_context<Char>> Base; typedef internal::context_base<Char, basic_context<Char>> Base;
typedef typename Base::format_arg format_arg; typedef typename Base::format_arg format_arg;
using Base::get_arg; using Base::get_arg;
...@@ -2093,12 +2091,12 @@ class basic_format_context : ...@@ -2093,12 +2091,12 @@ class basic_format_context :
public: public:
/** /**
\rst \rst
Constructs a ``basic_format_context`` object. References to the arguments are Constructs a ``basic_context`` object. References to the arguments are
stored in the object so make sure they have appropriate lifetimes. stored in the object so make sure they have appropriate lifetimes.
\endrst \endrst
*/ */
basic_format_context(const Char *format_str, basic_context(const Char *format_str,
basic_args<basic_format_context> args) basic_args<basic_context> args)
: Base(format_str, args) {} : Base(format_str, args) {}
// Parses argument id and returns corresponding argument. // Parses argument id and returns corresponding argument.
...@@ -2141,7 +2139,7 @@ class SystemError : public internal::RuntimeError { ...@@ -2141,7 +2139,7 @@ class SystemError : public internal::RuntimeError {
*/ */
template <typename... Args> template <typename... Args>
SystemError(int error_code, CStringRef message, const Args & ... args) { SystemError(int error_code, CStringRef message, const Args & ... args) {
init(error_code, message, make_format_args(args...)); init(error_code, message, make_args(args...));
} }
~SystemError() throw(); ~SystemError() throw();
...@@ -2349,7 +2347,7 @@ class basic_writer { ...@@ -2349,7 +2347,7 @@ class basic_writer {
} }
void vformat(BasicCStringRef<Char> format, void vformat(BasicCStringRef<Char> format,
basic_args<basic_format_context<Char>> args); basic_args<basic_context<Char>> args);
/** /**
\rst \rst
Writes formatted data. Writes formatted data.
...@@ -2377,7 +2375,7 @@ class basic_writer { ...@@ -2377,7 +2375,7 @@ class basic_writer {
*/ */
template <typename... Args> template <typename... Args>
void format(BasicCStringRef<Char> format, const Args & ... args) { void format(BasicCStringRef<Char> format, const Args & ... args) {
vformat(format, make_xformat_args<basic_format_context<Char>>(args...)); vformat(format, make_args<basic_context<Char>>(args...));
} }
void write(int value) { void write(int value) {
...@@ -2978,7 +2976,7 @@ class WindowsError : public SystemError { ...@@ -2978,7 +2976,7 @@ class WindowsError : public SystemError {
*/ */
template <typename... Args> template <typename... Args>
WindowsError(int error_code, CStringRef message, const Args & ... args) { WindowsError(int error_code, CStringRef message, const Args & ... args) {
init(error_code, message, make_format_args(args...)); init(error_code, message, make_args(args...));
} }
}; };
...@@ -3002,7 +3000,7 @@ FMT_API void vprint_colored(Color c, CStringRef format, format_args args); ...@@ -3002,7 +3000,7 @@ FMT_API void vprint_colored(Color c, CStringRef format, format_args args);
template <typename... Args> template <typename... Args>
inline void print_colored(Color c, CStringRef format_str, inline void print_colored(Color c, CStringRef format_str,
const Args & ... args) { const Args & ... args) {
vprint_colored(c, format_str, make_format_args(args...)); 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, format_args args) {
...@@ -3022,7 +3020,7 @@ inline std::string vformat(CStringRef format_str, format_args args) { ...@@ -3022,7 +3020,7 @@ inline std::string vformat(CStringRef format_str, format_args args) {
*/ */
template <typename... Args> template <typename... Args>
inline std::string format(CStringRef format_str, const Args & ... args) { inline std::string format(CStringRef format_str, const Args & ... args) {
return vformat(format_str, make_format_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, wformat_args args) {
...@@ -3033,7 +3031,7 @@ inline std::wstring vformat(WCStringRef format_str, wformat_args args) { ...@@ -3033,7 +3031,7 @@ inline std::wstring vformat(WCStringRef format_str, wformat_args args) {
template <typename... Args> template <typename... Args>
inline std::wstring format(WCStringRef format_str, const Args & ... args) { inline std::wstring format(WCStringRef format_str, const Args & ... args) {
auto vargs = make_xformat_args<wformat_context>(args...); auto vargs = make_args<wcontext>(args...);
return vformat(format_str, vargs); return vformat(format_str, vargs);
} }
...@@ -3050,7 +3048,7 @@ FMT_API void vprint(std::FILE *f, CStringRef format_str, format_args args); ...@@ -3050,7 +3048,7 @@ FMT_API void vprint(std::FILE *f, CStringRef format_str, format_args args);
*/ */
template <typename... Args> template <typename... Args>
inline void print(std::FILE *f, CStringRef format_str, const Args & ... args) { inline void print(std::FILE *f, CStringRef format_str, const Args & ... args) {
vprint(f, format_str, make_format_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, format_args args);
...@@ -3066,7 +3064,7 @@ FMT_API void vprint(CStringRef format_str, format_args args); ...@@ -3066,7 +3064,7 @@ FMT_API void vprint(CStringRef format_str, format_args args);
*/ */
template <typename... Args> template <typename... Args>
inline void print(CStringRef format_str, const Args & ... args) { inline void print(CStringRef format_str, const Args & ... args) {
vprint(format_str, make_format_args(args...)); vprint(format_str, make_args(args...));
} }
/** /**
...@@ -3185,13 +3183,13 @@ inline void format_decimal(char *&buffer, T value) { ...@@ -3185,13 +3183,13 @@ inline void format_decimal(char *&buffer, T value) {
\endrst \endrst
*/ */
template <typename T> template <typename T>
inline internal::NamedArg<format_context> arg(StringRef name, const T &arg) { inline internal::NamedArg<context> arg(StringRef name, const T &arg) {
return internal::NamedArg<format_context>(name, arg); return internal::NamedArg<context>(name, arg);
} }
template <typename T> template <typename T>
inline internal::NamedArg<wformat_context> arg(WStringRef name, const T &arg) { inline internal::NamedArg<wcontext> arg(WStringRef name, const T &arg) {
return internal::NamedArg<wformat_context>(name, arg); return internal::NamedArg<wcontext>(name, arg);
} }
// The following two functions are deleted intentionally to disable // The following two functions are deleted intentionally to disable
...@@ -3338,8 +3336,8 @@ struct PrecisionHandler { ...@@ -3338,8 +3336,8 @@ struct PrecisionHandler {
} // namespace internal } // namespace internal
template <typename Char> template <typename Char>
inline typename basic_format_context<Char>::format_arg inline typename basic_context<Char>::format_arg
basic_format_context<Char>::get_arg( basic_context<Char>::get_arg(
BasicStringRef<Char> name, const char *&error) { BasicStringRef<Char> name, const char *&error) {
if (this->check_no_auto_index(error)) { if (this->check_no_auto_index(error)) {
map_.init(this->args()); map_.init(this->args());
...@@ -3351,8 +3349,8 @@ inline typename basic_format_context<Char>::format_arg ...@@ -3351,8 +3349,8 @@ inline typename basic_format_context<Char>::format_arg
} }
template <typename Char> template <typename Char>
inline typename basic_format_context<Char>::format_arg inline typename basic_context<Char>::format_arg
basic_format_context<Char>::parse_arg_id() { basic_context<Char>::parse_arg_id() {
const Char *&s = this->ptr(); const Char *&s = this->ptr();
if (!internal::is_name_start(*s)) { if (!internal::is_name_start(*s)) {
const char *error = 0; const char *error = 0;
...@@ -3507,7 +3505,7 @@ void do_format_arg(basic_writer<Char> &writer, basic_arg<Context> arg, ...@@ -3507,7 +3505,7 @@ void do_format_arg(basic_writer<Char> &writer, basic_arg<Context> arg,
template <typename ArgFormatter, typename Char, typename Context> template <typename ArgFormatter, typename Char, typename Context>
void vwrite(basic_writer<Char> &writer, BasicCStringRef<Char> format_str, void vwrite(basic_writer<Char> &writer, BasicCStringRef<Char> format_str,
basic_args<Context> args) { basic_args<Context> args) {
basic_format_context<Char> ctx(format_str.c_str(), args); basic_context<Char> ctx(format_str.c_str(), args);
const Char *&s = ctx.ptr(); const Char *&s = ctx.ptr();
const Char *start = s; const Char *start = s;
while (*s) { while (*s) {
...@@ -3532,7 +3530,7 @@ void vwrite(basic_writer<Char> &writer, BasicCStringRef<Char> format_str, ...@@ -3532,7 +3530,7 @@ void vwrite(basic_writer<Char> &writer, BasicCStringRef<Char> format_str,
template <typename Char> template <typename Char>
inline void basic_writer<Char>::vformat( inline void basic_writer<Char>::vformat(
BasicCStringRef<Char> format, BasicCStringRef<Char> format,
basic_args<basic_format_context<Char>> args) { basic_args<basic_context<Char>> args) {
vwrite<ArgFormatter<Char>>(*this, format, args); vwrite<ArgFormatter<Char>>(*this, format, args);
} }
} // namespace fmt } // namespace fmt
...@@ -3557,7 +3555,7 @@ struct UdlArg { ...@@ -3557,7 +3555,7 @@ struct UdlArg {
const Char *str; const Char *str;
template <typename T> template <typename T>
NamedArg<basic_format_context<Char>> operator=(T &&value) const { NamedArg<basic_context<Char>> operator=(T &&value) const {
return {str, std::forward<T>(value)}; return {str, std::forward<T>(value)};
} }
}; };
......
...@@ -84,11 +84,11 @@ BasicStringRef<Char> format_value( ...@@ -84,11 +84,11 @@ BasicStringRef<Char> format_value(
// Formats a value. // Formats a value.
template <typename Char, typename T> template <typename Char, typename T>
void format_value(basic_writer<Char> &w, const T &value, 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; internal::MemoryBuffer<Char, internal::INLINE_BUFFER_SIZE> buffer;
auto str = internal::format_value(buffer, value); auto str = internal::format_value(buffer, value);
do_format_arg< ArgFormatter<Char> >( 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); 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); ...@@ -105,7 +105,7 @@ FMT_API void vprint(std::ostream &os, CStringRef format_str, format_args args);
template <typename... Args> template <typename... Args>
inline void print(std::ostream &os, CStringRef format_str, inline void print(std::ostream &os, CStringRef format_str,
const Args & ... args) { const Args & ... args) {
vprint(os, format_str, make_format_args(args...)); vprint(os, format_str, make_args(args...));
} }
} // namespace fmt } // namespace fmt
......
...@@ -172,7 +172,7 @@ public: ...@@ -172,7 +172,7 @@ public:
template <typename... Args> template <typename... Args>
inline void print(CStringRef format_str, const Args & ... 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 { ...@@ -103,7 +103,7 @@ class ArgConverter {
bool is_signed = type_ == 'd' || type_ == 'i'; bool is_signed = type_ == 'd' || type_ == 'i';
typedef typename internal::Conditional< typedef typename internal::Conditional<
is_same<T, void>::value, U, T>::type TargetType; 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)) { if (sizeof(TargetType) <= sizeof(int)) {
// Extra casts are used to silence warnings. // Extra casts are used to silence warnings.
if (is_signed) { if (is_signed) {
...@@ -287,8 +287,8 @@ class PrintfArgFormatter : public internal::ArgFormatterBase<Char> { ...@@ -287,8 +287,8 @@ class PrintfArgFormatter : public internal::ArgFormatterBase<Char> {
/** Formats an argument of a custom (user-defined) type. */ /** Formats an argument of a custom (user-defined) type. */
void operator()(internal::CustomValue<Char> c) { void operator()(internal::CustomValue<Char> c) {
const Char format_str[] = {'}', '\0'}; const Char format_str[] = {'}', '\0'};
auto args = basic_args<basic_format_context<Char>>(); auto args = basic_args<basic_context<Char>>();
basic_format_context<Char> ctx(format_str, args); basic_context<Char> ctx(format_str, args);
c.format(this->writer(), c.value, &ctx); c.format(this->writer(), c.value, &ctx);
} }
}; };
...@@ -297,14 +297,14 @@ class PrintfArgFormatter : public internal::ArgFormatterBase<Char> { ...@@ -297,14 +297,14 @@ class PrintfArgFormatter : public internal::ArgFormatterBase<Char> {
template <typename Char, template <typename Char,
typename ArgFormatter = PrintfArgFormatter<Char> > typename ArgFormatter = PrintfArgFormatter<Char> >
class printf_context : class printf_context :
private internal::format_context_base< private internal::context_base<
Char, printf_context<Char, ArgFormatter>> { Char, printf_context<Char, ArgFormatter>> {
public: public:
/** The character type for the output. */ /** The character type for the output. */
typedef Char char_type; typedef Char char_type;
private: 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 typename Base::format_arg format_arg;
typedef basic_format_specs<Char> format_specs; typedef basic_format_specs<Char> format_specs;
...@@ -539,7 +539,7 @@ inline std::string vsprintf(CStringRef format, printf_args args) { ...@@ -539,7 +539,7 @@ inline std::string vsprintf(CStringRef format, printf_args args) {
*/ */
template <typename... Args> template <typename... Args>
inline std::string sprintf(CStringRef format_str, const Args & ... 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( inline std::wstring vsprintf(
...@@ -551,7 +551,7 @@ inline std::wstring vsprintf( ...@@ -551,7 +551,7 @@ inline std::wstring vsprintf(
template <typename... Args> template <typename... Args>
inline std::wstring sprintf(WCStringRef format_str, const Args & ... 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); return vsprintf(format_str, vargs);
} }
...@@ -568,7 +568,7 @@ FMT_API int vfprintf(std::FILE *f, CStringRef format, printf_args args); ...@@ -568,7 +568,7 @@ FMT_API int vfprintf(std::FILE *f, CStringRef format, printf_args args);
*/ */
template <typename... Args> template <typename... Args>
inline int fprintf(std::FILE *f, CStringRef format_str, const Args & ... 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); return vfprintf(f, format_str, vargs);
} }
...@@ -587,7 +587,7 @@ inline int vprintf(CStringRef format, printf_args args) { ...@@ -587,7 +587,7 @@ inline int vprintf(CStringRef format, printf_args args) {
*/ */
template <typename... Args> template <typename... Args>
inline int printf(CStringRef format_str, const Args & ... 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) { 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) { ...@@ -609,7 +609,7 @@ inline int vfprintf(std::ostream &os, CStringRef format_str, printf_args args) {
template <typename... Args> template <typename... Args>
inline int fprintf(std::ostream &os, CStringRef format_str, inline int fprintf(std::ostream &os, CStringRef format_str,
const Args & ... args) { 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); return vfprintf(os, format_str, vargs);
} }
} // namespace fmt } // namespace fmt
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
namespace fmt { 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(); const char *&s = ctx.ptr();
if (*s == ':') if (*s == ':')
++s; ++s;
......
...@@ -16,7 +16,7 @@ using fmt::PrintfArgFormatter; ...@@ -16,7 +16,7 @@ using fmt::PrintfArgFormatter;
// rounded to 0. // rounded to 0.
class CustomArgFormatter : public fmt::ArgFormatter<char> { class CustomArgFormatter : public fmt::ArgFormatter<char> {
public: 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::format_specs &s)
: fmt::ArgFormatter<char>(w, ctx, s) {} : fmt::ArgFormatter<char>(w, ctx, s) {}
...@@ -54,7 +54,7 @@ std::string custom_vformat(fmt::CStringRef format_str, fmt::format_args args) { ...@@ -54,7 +54,7 @@ std::string custom_vformat(fmt::CStringRef format_str, fmt::format_args args) {
template <typename... Args> template <typename... Args>
std::string custom_format(const char *format_str, const Args & ... 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); return custom_vformat(format_str, va);
} }
...@@ -72,7 +72,7 @@ std::string custom_vsprintf( ...@@ -72,7 +72,7 @@ std::string custom_vsprintf(
template <typename... Args> template <typename... Args>
std::string custom_sprintf(const char *format_str, const Args & ... 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); return custom_vsprintf(format_str, va);
} }
......
...@@ -57,9 +57,9 @@ struct ValueExtractor { ...@@ -57,9 +57,9 @@ struct ValueExtractor {
TEST(FormatTest, ArgConverter) { TEST(FormatTest, ArgConverter) {
using fmt::format_arg; using fmt::format_arg;
fmt::LongLong value = std::numeric_limits<fmt::LongLong>::max(); 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< 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)); EXPECT_EQ(value, visit(ValueExtractor<fmt::LongLong>(), arg));
} }
......
...@@ -1366,7 +1366,7 @@ TEST(FormatterTest, FormatCStringRef) { ...@@ -1366,7 +1366,7 @@ TEST(FormatterTest, FormatCStringRef) {
EXPECT_EQ("test", format("{0}", CStringRef("test"))); 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(d.year());
w.write('-'); w.write('-');
w.write(d.month()); w.write(d.month());
...@@ -1383,7 +1383,7 @@ TEST(FormatterTest, FormatCustom) { ...@@ -1383,7 +1383,7 @@ TEST(FormatterTest, FormatCustom) {
class Answer {}; class Answer {};
template <typename Char> 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"); w.write("42");
} }
...@@ -1575,7 +1575,7 @@ std::string vformat_message(int id, const char *format, fmt::format_args args) { ...@@ -1575,7 +1575,7 @@ std::string vformat_message(int id, const char *format, fmt::format_args args) {
template <typename... Args> template <typename... Args>
std::string format_message(int id, const char *format, const Args & ... 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); return vformat_message(id, format, va);
} }
...@@ -1643,7 +1643,7 @@ class MockArgFormatter : public fmt::internal::ArgFormatterBase<char> { ...@@ -1643,7 +1643,7 @@ class MockArgFormatter : public fmt::internal::ArgFormatterBase<char> {
public: public:
typedef fmt::internal::ArgFormatterBase<char> Base; 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::format_specs &s)
: fmt::internal::ArgFormatterBase<char>(w, s) { : fmt::internal::ArgFormatterBase<char>(w, s) {
EXPECT_CALL(*this, call(42)); EXPECT_CALL(*this, call(42));
...@@ -1663,7 +1663,7 @@ void custom_vformat(fmt::CStringRef format_str, fmt::format_args args) { ...@@ -1663,7 +1663,7 @@ void custom_vformat(fmt::CStringRef format_str, fmt::format_args args) {
template <typename... Args> template <typename... Args>
void custom_format(const char *format_str, const Args & ... 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); return custom_vformat(format_str, va);
} }
......
...@@ -59,17 +59,16 @@ TEST(OStreamTest, Enum) { ...@@ -59,17 +59,16 @@ TEST(OStreamTest, Enum) {
} }
struct TestArgFormatter : fmt::ArgFormatter<char> { struct TestArgFormatter : fmt::ArgFormatter<char> {
TestArgFormatter(fmt::writer &w, fmt::format_context &ctx, TestArgFormatter(fmt::writer &w, fmt::context &ctx, fmt::format_specs &s)
fmt::format_specs &s)
: fmt::ArgFormatter<char>(w, ctx, s) {} : fmt::ArgFormatter<char>(w, ctx, s) {}
}; };
TEST(OStreamTest, CustomArg) { TEST(OStreamTest, CustomArg) {
fmt::MemoryWriter writer; fmt::MemoryWriter writer;
fmt::format_context ctx("}", fmt::format_args()); fmt::context ctx("}", fmt::format_args());
fmt::format_specs spec; fmt::format_specs spec;
TestArgFormatter af(writer, ctx, 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()); EXPECT_EQ("TestEnum", writer.str());
} }
......
...@@ -69,7 +69,7 @@ struct Test {}; ...@@ -69,7 +69,7 @@ struct Test {};
template <typename Char> template <typename Char>
void format_value(fmt::basic_writer<Char> &w, Test, void format_value(fmt::basic_writer<Char> &w, Test,
fmt::basic_format_context<Char> &) { fmt::basic_context<Char> &) {
w.write("test"); w.write("test");
} }
...@@ -487,7 +487,7 @@ VISIT_TYPE(float, double); ...@@ -487,7 +487,7 @@ VISIT_TYPE(float, double);
#define CHECK_ARG_(Char, expected, value) { \ #define CHECK_ARG_(Char, expected, value) { \
testing::StrictMock<MockVisitor<decltype(expected)>> visitor; \ testing::StrictMock<MockVisitor<decltype(expected)>> visitor; \
EXPECT_CALL(visitor, visit(expected)); \ 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) { \ #define CHECK_ARG(value) { \
...@@ -570,12 +570,12 @@ TEST(UtilTest, CustomArg) { ...@@ -570,12 +570,12 @@ TEST(UtilTest, CustomArg) {
testing::Invoke([&](fmt::internal::CustomValue<char> custom) { testing::Invoke([&](fmt::internal::CustomValue<char> custom) {
EXPECT_EQ(&test, custom.value); EXPECT_EQ(&test, custom.value);
fmt::MemoryWriter w; fmt::MemoryWriter w;
fmt::format_context ctx("}", fmt::format_args()); fmt::context ctx("}", fmt::format_args());
custom.format(w, &test, &ctx); custom.format(w, &test, &ctx);
EXPECT_EQ("test", w.str()); EXPECT_EQ("test", w.str());
return Visitor::Result(); return Visitor::Result();
})); }));
fmt::visit(visitor, make_arg<fmt::format_context>(test)); fmt::visit(visitor, make_arg<fmt::context>(test));
} }
TEST(ArgVisitorTest, VisitInvalidArg) { 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