ArgList -> format_args

This commit is contained in:
Victor Zverovich 2016-08-25 08:50:07 -07:00
parent 92605eb4f7
commit fc73e10620
11 changed files with 59 additions and 59 deletions

View File

@ -223,7 +223,7 @@ FMT_FUNC void format_system_error(
} // namespace internal
FMT_FUNC void SystemError::init(
int err_code, CStringRef format_str, ArgList args) {
int err_code, CStringRef format_str, format_args args) {
error_code_ = err_code;
MemoryWriter w;
format_system_error(w, err_code, format(format_str, args));
@ -347,7 +347,7 @@ FMT_FUNC int internal::UTF16ToUTF8::convert(WStringRef s) {
}
FMT_FUNC void WindowsError::init(
int err_code, CStringRef format_str, ArgList args) {
int err_code, CStringRef format_str, format_args args) {
error_code_ = err_code;
MemoryWriter w;
internal::format_windows_error(w, err_code, format(format_str, args));
@ -404,13 +404,13 @@ FMT_FUNC void format_system_error(
}
template <typename Char>
void internal::ArgMap<Char>::init(const ArgList &args) {
void internal::ArgMap<Char>::init(const format_args &args) {
if (!map_.empty())
return;
typedef internal::NamedArg<Char> NamedArg;
const NamedArg *named_arg = 0;
bool use_values =
args.type(ArgList::MAX_PACKED_ARGS - 1) == internal::Arg::NONE;
args.type(format_args::MAX_PACKED_ARGS - 1) == internal::Arg::NONE;
if (use_values) {
for (unsigned i = 0;/*nothing*/; ++i) {
internal::Arg::Type arg_type = args.type(i);
@ -427,14 +427,14 @@ void internal::ArgMap<Char>::init(const ArgList &args) {
}
return;
}
for (unsigned i = 0; i != ArgList::MAX_PACKED_ARGS; ++i) {
for (unsigned i = 0; i != format_args::MAX_PACKED_ARGS; ++i) {
internal::Arg::Type arg_type = args.type(i);
if (arg_type == internal::Arg::NAMED_ARG) {
named_arg = static_cast<const NamedArg*>(args.args_[i].pointer);
map_.push_back(Pair(named_arg->name, *named_arg));
}
}
for (unsigned i = ArgList::MAX_PACKED_ARGS;/*nothing*/; ++i) {
for (unsigned i = format_args::MAX_PACKED_ARGS;/*nothing*/; ++i) {
switch (args.args_[i].type) {
case internal::Arg::NONE:
return;
@ -483,17 +483,17 @@ FMT_FUNC void report_windows_error(
}
#endif
FMT_FUNC void print(std::FILE *f, CStringRef format_str, ArgList args) {
FMT_FUNC void print(std::FILE *f, CStringRef format_str, format_args args) {
MemoryWriter w;
w.write(format_str, args);
std::fwrite(w.data(), 1, w.size(), f);
}
FMT_FUNC void print(CStringRef format_str, ArgList args) {
FMT_FUNC void print(CStringRef format_str, format_args args) {
print(stdout, format_str, args);
}
FMT_FUNC void print_colored(Color c, CStringRef format, ArgList args) {
FMT_FUNC void print_colored(Color c, CStringRef format, format_args args) {
char escape[] = "\x1b[30m";
escape[3] = static_cast<char>('0' + c);
std::fputs(escape, stdout);
@ -502,9 +502,9 @@ FMT_FUNC void print_colored(Color c, CStringRef format, ArgList args) {
}
template <typename Char>
void printf(BasicWriter<Char> &w, BasicCStringRef<Char> format, ArgList args);
void printf(BasicWriter<Char> &w, BasicCStringRef<Char> format, format_args args);
FMT_FUNC int fprintf(std::FILE *f, CStringRef format, ArgList args) {
FMT_FUNC int fprintf(std::FILE *f, CStringRef format, format_args args) {
MemoryWriter w;
printf(w, format, args);
std::size_t size = w.size();
@ -519,7 +519,7 @@ template struct internal::BasicData<void>;
template void internal::FixedBuffer<char>::grow(std::size_t);
template void internal::ArgMap<char>::init(const ArgList &args);
template void internal::ArgMap<char>::init(const format_args &args);
template void PrintfFormatter<char>::format(CStringRef format);
@ -535,7 +535,7 @@ template int internal::CharTraits<char>::format_float(
template void internal::FixedBuffer<wchar_t>::grow(std::size_t);
template void internal::ArgMap<wchar_t>::init(const ArgList &args);
template void internal::ArgMap<wchar_t>::init(const format_args &args);
template void PrintfFormatter<wchar_t>::format(WCStringRef format);

View File

@ -1351,8 +1351,8 @@ template <typename Char>
class ArgMap;
} // namespace internal
/** An argument list. */
class ArgList {
/** Formatting arguments. */
class format_args {
private:
// To reduce compiled code size per formatting function call, types of first
// MAX_PACKED_ARGS arguments are passed in the types_ field.
@ -1381,11 +1381,11 @@ class ArgList {
// Maximum number of arguments with packed types.
enum { MAX_PACKED_ARGS = 16 };
ArgList() : types_(0) {}
format_args() : types_(0) {}
ArgList(ULongLong types, const internal::Value *values)
format_args(ULongLong types, const internal::Value *values)
: types_(types), values_(values) {}
ArgList(ULongLong types, const internal::Arg *args)
format_args(ULongLong types, const internal::Arg *args)
: types_(types), args_(args) {}
/** Returns the argument at specified index. */
@ -1809,7 +1809,7 @@ class ArgMap {
MapType map_;
public:
FMT_API void init(const ArgList &args);
FMT_API void init(const format_args &args);
const internal::Arg* find(const fmt::BasicStringRef<Char> &name) const {
// The list is unsorted, so just return the first matching name.
@ -1922,16 +1922,16 @@ class ArgFormatterBase : public ArgVisitor<Impl, void> {
class FormatterBase {
private:
ArgList args_;
format_args args_;
int next_arg_index_;
// Returns the argument with specified index.
FMT_API Arg do_get_arg(unsigned arg_index, const char *&error);
protected:
const ArgList &args() const { return args_; }
const format_args &args() const { return args_; }
explicit FormatterBase(const ArgList &args) {
explicit FormatterBase(const format_args &args) {
args_ = args;
next_arg_index_ = 0;
}
@ -2053,7 +2053,7 @@ class BasicFormatter : private internal::FormatterBase {
appropriate lifetimes.
\endrst
*/
BasicFormatter(const ArgList &args, BasicWriter<Char> &w)
BasicFormatter(const format_args &args, BasicWriter<Char> &w)
: internal::FormatterBase(args), writer_(w) {}
/** Returns a reference to the writer associated with this formatter. */
@ -2093,7 +2093,7 @@ inline uint64_t make_type(const T &arg) {
return MakeValue< BasicFormatter<char> >::type(arg);
}
template <unsigned N, bool/*IsPacked*/= (N < ArgList::MAX_PACKED_ARGS)>
template <unsigned N, bool/*IsPacked*/= (N < format_args::MAX_PACKED_ARGS)>
struct ArgArray;
template <unsigned N>
@ -2143,7 +2143,7 @@ inline uint64_t make_type(const Arg &first, const Args & ... tail) {
typedef fmt::internal::ArgArray<sizeof...(Args)> ArgArray; \
typename ArgArray::Type array{ \
ArgArray::template make<fmt::BasicFormatter<Char> >(args)...}; \
func(arg0, fmt::ArgList(fmt::internal::make_type(args...), array)); \
func(arg0, fmt::format_args(fmt::internal::make_type(args...), array)); \
}
// Defines a variadic constructor.
@ -2153,7 +2153,7 @@ inline uint64_t make_type(const Arg &first, const Args & ... tail) {
typedef fmt::internal::ArgArray<sizeof...(Args)> ArgArray; \
typename ArgArray::Type array{ \
ArgArray::template make<fmt::BasicFormatter<Char> >(args)...}; \
func(arg0, arg1, fmt::ArgList(fmt::internal::make_type(args...), array)); \
func(arg0, arg1, fmt::format_args(fmt::internal::make_type(args...), array)); \
}
// Generates a comma-separated list with results of applying f to pairs
@ -2184,7 +2184,7 @@ inline uint64_t make_type(const Arg &first, const Args & ... tail) {
*/
class SystemError : public internal::RuntimeError {
private:
void init(int err_code, CStringRef format_str, ArgList args);
void init(int err_code, CStringRef format_str, format_args args);
protected:
int error_code_;
@ -2213,7 +2213,7 @@ class SystemError : public internal::RuntimeError {
\endrst
*/
SystemError(int error_code, CStringRef message) {
init(error_code, message, ArgList());
init(error_code, message, format_args());
}
FMT_VARIADIC_CTOR(SystemError, init, int, CStringRef)
@ -2433,7 +2433,7 @@ class BasicWriter {
See also :ref:`syntax`.
\endrst
*/
void write(BasicCStringRef<Char> format, ArgList args) {
void write(BasicCStringRef<Char> format, format_args args) {
BasicFormatter<Char>(args, *this).format(format);
}
FMT_VARIADIC_VOID(write, BasicCStringRef<Char>)
@ -3030,7 +3030,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, ArgList args);
FMT_API void init(int error_code, CStringRef format_str, format_args args);
public:
/**
@ -3062,7 +3062,7 @@ class WindowsError : public SystemError {
\endrst
*/
WindowsError(int error_code, CStringRef message) {
init(error_code, message, ArgList());
init(error_code, message, format_args());
}
FMT_VARIADIC_CTOR(WindowsError, init, int, CStringRef)
};
@ -3082,7 +3082,7 @@ enum Color { BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE };
Example:
print_colored(fmt::RED, "Elapsed time: {0:.2f} seconds", 1.23);
*/
FMT_API void print_colored(Color c, CStringRef format, ArgList args);
FMT_API void print_colored(Color c, CStringRef format, format_args args);
/**
\rst
@ -3093,13 +3093,13 @@ FMT_API void print_colored(Color c, CStringRef format, ArgList args);
std::string message = format("The answer is {}", 42);
\endrst
*/
inline std::string format(CStringRef format_str, ArgList args) {
inline std::string format(CStringRef format_str, format_args args) {
MemoryWriter w;
w.write(format_str, args);
return w.str();
}
inline std::wstring format(WCStringRef format_str, ArgList args) {
inline std::wstring format(WCStringRef format_str, format_args args) {
WMemoryWriter w;
w.write(format_str, args);
return w.str();
@ -3114,7 +3114,7 @@ inline std::wstring format(WCStringRef format_str, ArgList args) {
print(stderr, "Don't {}!", "panic");
\endrst
*/
FMT_API void print(std::FILE *f, CStringRef format_str, ArgList args);
FMT_API void print(std::FILE *f, CStringRef format_str, format_args args);
/**
\rst
@ -3125,7 +3125,7 @@ FMT_API void print(std::FILE *f, CStringRef format_str, ArgList args);
print("Elapsed time: {0:.2f} seconds", 1.23);
\endrst
*/
FMT_API void print(CStringRef format_str, ArgList args);
FMT_API void print(CStringRef format_str, format_args args);
/**
Fast integer formatter.
@ -3294,7 +3294,7 @@ void arg(WStringRef, const internal::NamedArg<Char>&) FMT_DELETED_OR_UNDEFINED;
typename ArgArray::Type array{ \
ArgArray::template make<fmt::BasicFormatter<Char> >(args)...}; \
call(FMT_FOR_EACH(FMT_GET_ARG_NAME, __VA_ARGS__), \
fmt::ArgList(fmt::internal::make_type(args...), array)); \
fmt::format_args(fmt::internal::make_type(args...), array)); \
}
/**
@ -3305,7 +3305,7 @@ void arg(WStringRef, const internal::NamedArg<Char>&) FMT_DELETED_OR_UNDEFINED;
**Example**::
void print_error(const char *file, int line, const char *format,
fmt::ArgList args) {
fmt::format_args args) {
fmt::print("{}: {}: ", file, line);
fmt::print(format, args);
}

View File

@ -27,7 +27,7 @@ FMT_FUNC void write(std::ostream &os, Writer &w) {
}
}
FMT_FUNC void print(std::ostream &os, CStringRef format_str, ArgList args) {
FMT_FUNC void print(std::ostream &os, CStringRef format_str, format_args args) {
MemoryWriter w;
w.write(format_str, args);
internal::write(os, w);

View File

@ -95,7 +95,7 @@ void format_arg(BasicFormatter<Char, ArgFormatter> &f,
print(cerr, "Don't {}!", "panic");
\endrst
*/
FMT_API void print(std::ostream &os, CStringRef format_str, ArgList args);
FMT_API void print(std::ostream &os, CStringRef format_str, format_args args);
FMT_VARIADIC(void, print, std::ostream &, CStringRef)
} // namespace fmt

View File

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

View File

@ -262,7 +262,7 @@ class BasicPrintfArgFormatter : public internal::ArgFormatterBase<Impl, Char> {
/** Formats an argument of a custom (user-defined) type. */
void visit_custom(internal::Arg::CustomValue c) {
BasicFormatter<Char> formatter(ArgList(), this->writer());
BasicFormatter<Char> formatter(format_args(), this->writer());
const Char format_str[] = {'}', 0};
const Char *format = format_str;
c.format(&formatter, c.value, &format);
@ -304,7 +304,7 @@ class PrintfFormatter : private internal::FormatterBase {
appropriate lifetimes.
\endrst
*/
explicit PrintfFormatter(const ArgList &args, BasicWriter<Char> &w)
explicit PrintfFormatter(const format_args &args, BasicWriter<Char> &w)
: FormatterBase(args), writer_(w) {}
/** Formats stored arguments and writes the output to the writer. */
@ -484,7 +484,7 @@ void PrintfFormatter<Char, AF>::format(BasicCStringRef<Char> format_str) {
}
template <typename Char>
void printf(BasicWriter<Char> &w, BasicCStringRef<Char> format, ArgList args) {
void printf(BasicWriter<Char> &w, BasicCStringRef<Char> format, format_args args) {
PrintfFormatter<Char>(args, w).format(format);
}
@ -497,14 +497,14 @@ void printf(BasicWriter<Char> &w, BasicCStringRef<Char> format, ArgList args) {
std::string message = fmt::sprintf("The answer is %d", 42);
\endrst
*/
inline std::string sprintf(CStringRef format, ArgList args) {
inline std::string sprintf(CStringRef format, format_args args) {
MemoryWriter w;
printf(w, format, args);
return w.str();
}
FMT_VARIADIC(std::string, sprintf, CStringRef)
inline std::wstring sprintf(WCStringRef format, ArgList args) {
inline std::wstring sprintf(WCStringRef format, format_args args) {
WMemoryWriter w;
printf(w, format, args);
return w.str();
@ -520,7 +520,7 @@ FMT_VARIADIC_W(std::wstring, sprintf, WCStringRef)
fmt::fprintf(stderr, "Don't %s!", "panic");
\endrst
*/
FMT_API int fprintf(std::FILE *f, CStringRef format, ArgList args);
FMT_API int fprintf(std::FILE *f, CStringRef format, format_args args);
FMT_VARIADIC(int, fprintf, std::FILE *, CStringRef)
/**
@ -532,7 +532,7 @@ FMT_VARIADIC(int, fprintf, std::FILE *, CStringRef)
fmt::printf("Elapsed time: %.2f seconds", 1.23);
\endrst
*/
inline int printf(CStringRef format, ArgList args) {
inline int printf(CStringRef format, format_args args) {
return fprintf(stdout, format, args);
}
FMT_VARIADIC(int, printf, CStringRef)
@ -546,7 +546,7 @@ FMT_VARIADIC(int, printf, CStringRef)
fprintf(cerr, "Don't %s!", "panic");
\endrst
*/
inline int fprintf(std::ostream &os, CStringRef format_str, ArgList args) {
inline int fprintf(std::ostream &os, CStringRef format_str, format_args args) {
MemoryWriter w;
printf(w, format_str, args);
internal::write(os, w);

View File

@ -45,7 +45,7 @@ class CustomPrintfArgFormatter :
}
};
std::string custom_format(const char *format_str, fmt::ArgList args) {
std::string custom_format(const char *format_str, fmt::format_args args) {
fmt::MemoryWriter writer;
// Pass custom argument formatter as a template arg to BasicFormatter.
fmt::BasicFormatter<char, CustomArgFormatter> formatter(args, writer);
@ -54,7 +54,7 @@ std::string custom_format(const char *format_str, fmt::ArgList args) {
}
FMT_VARIADIC(std::string, custom_format, const char *)
std::string custom_sprintf(const char* format_str, fmt::ArgList args){
std::string custom_sprintf(const char* format_str, fmt::format_args args){
fmt::MemoryWriter writer;
fmt::PrintfFormatter<char, CustomPrintfArgFormatter> formatter(args, writer);
formatter.format(format_str);

View File

@ -1564,7 +1564,7 @@ TEST(StrTest, Convert) {
}
std::string format_message(int id, const char *format,
const fmt::ArgList &args) {
const fmt::format_args &args) {
MemoryWriter w;
w.write("[{}] ", id);
w.write(format, args);
@ -1643,7 +1643,7 @@ class MockArgFormatter :
MOCK_METHOD1(visit_int, void (int value));
};
void custom_format(const char *format_str, fmt::ArgList args) {
void custom_format(const char *format_str, fmt::format_args args) {
fmt::MemoryWriter writer;
fmt::BasicFormatter<char, MockArgFormatter> formatter(args, writer);
formatter.format(format_str);

View File

@ -67,7 +67,7 @@ TEST(UtilTest, NArg) {
int result;
#define MAKE_TEST(func) \
void func(const char *, const fmt::ArgList &args) { \
void func(const char *, const fmt::format_args &args) { \
result = 0; \
for (unsigned i = 0; args[i].type; ++i) \
result += args[i].int_value; \
@ -91,7 +91,7 @@ struct S {};
#define GET_TYPE(n) S<n>
int test_variadic(FMT_GEN(10, GET_TYPE), const fmt::ArgList &args) { \
int test_variadic(FMT_GEN(10, GET_TYPE), const fmt::format_args &args) { \
int result = 0; \
for (unsigned i = 0; args[i].type; ++i) \
result += args[i].int_value; \

View File

@ -67,7 +67,7 @@ struct TestArgFormatter : fmt::BasicArgFormatter<TestArgFormatter, char> {
TEST(OStreamTest, CustomArg) {
fmt::MemoryWriter writer;
typedef fmt::BasicFormatter<char, TestArgFormatter> Formatter;
Formatter formatter(fmt::ArgList(), writer);
Formatter formatter(fmt::format_args(), writer);
fmt::FormatSpec spec;
TestArgFormatter af(formatter, spec, "}");
af.visit(fmt::internal::MakeArg<Formatter>(TestEnum()));

View File

@ -566,14 +566,14 @@ TEST(ArgTest, MakeArg) {
EXPECT_EQ(fmt::internal::Arg::CUSTOM, arg.type);
EXPECT_EQ(&t, arg.custom.value);
fmt::MemoryWriter w;
fmt::BasicFormatter<char> formatter(fmt::ArgList(), w);
fmt::BasicFormatter<char> formatter(fmt::format_args(), w);
const char *s = "}";
arg.custom.format(&formatter, &t, &s);
EXPECT_EQ("test", w.str());
}
TEST(UtilTest, ArgList) {
fmt::ArgList args;
TEST(UtilTest, FormatArgs) {
fmt::format_args args;
EXPECT_EQ(Arg::NONE, args[1].type);
}