Get rid of fmt::internal::Arg
This commit is contained in:
parent
5f022ae081
commit
9cf6c8fdc6
@ -51,8 +51,6 @@
|
|||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
using fmt::internal::Arg;
|
|
||||||
|
|
||||||
#if FMT_EXCEPTIONS
|
#if FMT_EXCEPTIONS
|
||||||
# define FMT_TRY try
|
# define FMT_TRY try
|
||||||
# define FMT_CATCH(x) catch (x)
|
# define FMT_CATCH(x) catch (x)
|
||||||
|
191
fmt/format.h
191
fmt/format.h
@ -1039,8 +1039,6 @@ struct format_arg : internal::Value {
|
|||||||
|
|
||||||
namespace internal {
|
namespace internal {
|
||||||
|
|
||||||
typedef format_arg Arg;
|
|
||||||
|
|
||||||
template <typename Char>
|
template <typename Char>
|
||||||
struct NamedArg;
|
struct NamedArg;
|
||||||
|
|
||||||
@ -1180,61 +1178,80 @@ typedef Value::Type Type;
|
|||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
constexpr Type gettype() {
|
constexpr Type gettype() {
|
||||||
|
typedef format_arg Arg;
|
||||||
return IsNamedArg<T>::value ?
|
return IsNamedArg<T>::value ?
|
||||||
Arg::NAMED_ARG : (ConvertToInt<T>::value ? Arg::INT : Arg::CUSTOM);
|
Arg::NAMED_ARG : (ConvertToInt<T>::value ? Arg::INT : Arg::CUSTOM);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <> constexpr Type gettype<bool>() { return Arg::BOOL; }
|
template <> constexpr Type gettype<bool>() { return format_arg::BOOL; }
|
||||||
template <> constexpr Type gettype<short>() { return Arg::INT; }
|
template <> constexpr Type gettype<short>() { return format_arg::INT; }
|
||||||
template <> constexpr Type gettype<unsigned short>() { return Arg::UINT; }
|
template <> constexpr Type gettype<unsigned short>() {
|
||||||
template <> constexpr Type gettype<int>() { return Arg::INT; }
|
return format_arg::UINT;
|
||||||
template <> constexpr Type gettype<unsigned>() { return Arg::UINT; }
|
}
|
||||||
|
template <> constexpr Type gettype<int>() { return format_arg::INT; }
|
||||||
|
template <> constexpr Type gettype<unsigned>() { return format_arg::UINT; }
|
||||||
template <> constexpr Type gettype<long>() {
|
template <> constexpr Type gettype<long>() {
|
||||||
return sizeof(long) == sizeof(int) ? Arg::INT : Arg::LONG_LONG;
|
return sizeof(long) == sizeof(int) ? format_arg::INT : format_arg::LONG_LONG;
|
||||||
}
|
}
|
||||||
template <> constexpr Type gettype<unsigned long>() {
|
template <> constexpr Type gettype<unsigned long>() {
|
||||||
return sizeof(unsigned long) == sizeof(unsigned) ?
|
return sizeof(unsigned long) == sizeof(unsigned) ?
|
||||||
Arg::UINT : Arg::ULONG_LONG;
|
format_arg::UINT : format_arg::ULONG_LONG;
|
||||||
}
|
}
|
||||||
template <> constexpr Type gettype<LongLong>() { return Arg::LONG_LONG; }
|
template <> constexpr Type gettype<LongLong>() { return format_arg::LONG_LONG; }
|
||||||
template <> constexpr Type gettype<ULongLong>() { return Arg::ULONG_LONG; }
|
template <> constexpr Type gettype<ULongLong>() {
|
||||||
template <> constexpr Type gettype<float>() { return Arg::DOUBLE; }
|
return format_arg::ULONG_LONG;
|
||||||
template <> constexpr Type gettype<double>() { return Arg::DOUBLE; }
|
}
|
||||||
template <> constexpr Type gettype<long double>() { return Arg::LONG_DOUBLE; }
|
template <> constexpr Type gettype<float>() { return format_arg::DOUBLE; }
|
||||||
template <> constexpr Type gettype<signed char>() { return Arg::INT; }
|
template <> constexpr Type gettype<double>() { return format_arg::DOUBLE; }
|
||||||
template <> constexpr Type gettype<unsigned char>() { return Arg::UINT; }
|
template <> constexpr Type gettype<long double>() {
|
||||||
template <> constexpr Type gettype<char>() { return Arg::CHAR; }
|
return format_arg::LONG_DOUBLE;
|
||||||
|
}
|
||||||
|
template <> constexpr Type gettype<signed char>() { return format_arg::INT; }
|
||||||
|
template <> constexpr Type gettype<unsigned char>() { return format_arg::UINT; }
|
||||||
|
template <> constexpr Type gettype<char>() { return format_arg::CHAR; }
|
||||||
|
|
||||||
#if !defined(_MSC_VER) || defined(_NATIVE_WCHAR_T_DEFINED)
|
#if !defined(_MSC_VER) || defined(_NATIVE_WCHAR_T_DEFINED)
|
||||||
template <> constexpr Type gettype<wchar_t>() { return Arg::CHAR; }
|
template <> constexpr Type gettype<wchar_t>() { return format_arg::CHAR; }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
template <> constexpr Type gettype<char *>() { return Arg::CSTRING; }
|
template <> constexpr Type gettype<char *>() { return format_arg::CSTRING; }
|
||||||
template <> constexpr Type gettype<const char *>() { return Arg::CSTRING; }
|
template <> constexpr Type gettype<const char *>() {
|
||||||
template <> constexpr Type gettype<signed char *>() { return Arg::CSTRING; }
|
return format_arg::CSTRING;
|
||||||
|
}
|
||||||
|
template <> constexpr Type gettype<signed char *>() {
|
||||||
|
return format_arg::CSTRING;
|
||||||
|
}
|
||||||
template <> constexpr Type gettype<const signed char *>() {
|
template <> constexpr Type gettype<const signed char *>() {
|
||||||
return Arg::CSTRING;
|
return format_arg::CSTRING;
|
||||||
|
}
|
||||||
|
template <> constexpr Type gettype<unsigned char *>() {
|
||||||
|
return format_arg::CSTRING;
|
||||||
}
|
}
|
||||||
template <> constexpr Type gettype<unsigned char *>() { return Arg::CSTRING; }
|
|
||||||
template <> constexpr Type gettype<const unsigned char *>() {
|
template <> constexpr Type gettype<const unsigned char *>() {
|
||||||
return Arg::CSTRING;
|
return format_arg::CSTRING;
|
||||||
|
}
|
||||||
|
template <> constexpr Type gettype<std::string>() { return format_arg::STRING; }
|
||||||
|
template <> constexpr Type gettype<StringRef>() { return format_arg::STRING; }
|
||||||
|
template <> constexpr Type gettype<CStringRef>() { return format_arg::CSTRING; }
|
||||||
|
template <> constexpr Type gettype<wchar_t *>() { return format_arg::WSTRING; }
|
||||||
|
template <> constexpr Type gettype<const wchar_t *>() {
|
||||||
|
return format_arg::WSTRING;
|
||||||
|
}
|
||||||
|
template <> constexpr Type gettype<std::wstring>() {
|
||||||
|
return format_arg::WSTRING;
|
||||||
|
}
|
||||||
|
template <> constexpr Type gettype<WStringRef>() { return format_arg::WSTRING; }
|
||||||
|
template <> constexpr Type gettype<void *>() { return format_arg::POINTER; }
|
||||||
|
template <> constexpr Type gettype<const void *>() {
|
||||||
|
return format_arg::POINTER;
|
||||||
}
|
}
|
||||||
template <> constexpr Type gettype<std::string>() { return Arg::STRING; }
|
|
||||||
template <> constexpr Type gettype<StringRef>() { return Arg::STRING; }
|
|
||||||
template <> constexpr Type gettype<CStringRef>() { return Arg::CSTRING; }
|
|
||||||
template <> constexpr Type gettype<wchar_t *>() { return Arg::WSTRING; }
|
|
||||||
template <> constexpr Type gettype<const wchar_t *>() { return Arg::WSTRING; }
|
|
||||||
template <> constexpr Type gettype<std::wstring>() { return Arg::WSTRING; }
|
|
||||||
template <> constexpr Type gettype<WStringRef>() { return Arg::WSTRING; }
|
|
||||||
template <> constexpr Type gettype<void *>() { return Arg::POINTER; }
|
|
||||||
template <> constexpr Type gettype<const void *>() { return Arg::POINTER; }
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
constexpr Type type() { return gettype<typename std::decay<T>::type>(); }
|
constexpr Type type() { return gettype<typename std::decay<T>::type>(); }
|
||||||
|
|
||||||
// Makes an Arg object from any type.
|
// Makes a format_arg object from any type.
|
||||||
template <typename Context>
|
template <typename Context>
|
||||||
class MakeValue : public Arg {
|
class MakeValue : public format_arg {
|
||||||
public:
|
public:
|
||||||
typedef typename Context::char_type Char;
|
typedef typename Context::char_type Char;
|
||||||
|
|
||||||
@ -1387,27 +1404,27 @@ class MakeValue : public Arg {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename Formatter>
|
template <typename Context>
|
||||||
class MakeArg : public Arg {
|
class MakeArg : public format_arg {
|
||||||
public:
|
public:
|
||||||
MakeArg() {
|
MakeArg() {
|
||||||
type = Arg::NONE;
|
type = format_arg::NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
MakeArg(const T &value)
|
MakeArg(const T &value)
|
||||||
: Arg(MakeValue<Formatter>(value)) {
|
: format_arg(MakeValue<Context>(value)) {
|
||||||
type = internal::type<T>();
|
type = internal::type<T>();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename Char>
|
template <typename Char>
|
||||||
struct NamedArg : Arg {
|
struct NamedArg : format_arg {
|
||||||
BasicStringRef<Char> name;
|
BasicStringRef<Char> name;
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
NamedArg(BasicStringRef<Char> argname, const T &value)
|
NamedArg(BasicStringRef<Char> argname, const T &value)
|
||||||
: Arg(MakeArg< basic_format_context<Char> >(value)), name(argname) {}
|
: format_arg(MakeArg< basic_format_context<Char> >(value)), name(argname) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
class RuntimeError : public std::runtime_error {
|
class RuntimeError : public std::runtime_error {
|
||||||
@ -1438,7 +1455,7 @@ class format_arg_store {
|
|||||||
static const bool IS_PACKED = NUM_ARGS <= internal::MAX_PACKED_ARGS;
|
static const bool IS_PACKED = NUM_ARGS <= internal::MAX_PACKED_ARGS;
|
||||||
|
|
||||||
typedef typename std::conditional<
|
typedef typename std::conditional<
|
||||||
IS_PACKED, internal::Value, internal::Arg>::type value_type;
|
IS_PACKED, internal::Value, format_arg>::type value_type;
|
||||||
|
|
||||||
// If the arguments are not packed, add one more element to mark the end.
|
// If the arguments are not packed, add one more element to mark the end.
|
||||||
std::array<value_type, NUM_ARGS + (IS_PACKED ? 0 : 1)> data_;
|
std::array<value_type, NUM_ARGS + (IS_PACKED ? 0 : 1)> data_;
|
||||||
@ -1805,7 +1822,7 @@ template <typename Char>
|
|||||||
class ArgMap {
|
class ArgMap {
|
||||||
private:
|
private:
|
||||||
typedef std::vector<
|
typedef std::vector<
|
||||||
std::pair<fmt::BasicStringRef<Char>, internal::Arg> > MapType;
|
std::pair<fmt::BasicStringRef<Char>, format_arg> > MapType;
|
||||||
typedef typename MapType::value_type Pair;
|
typedef typename MapType::value_type Pair;
|
||||||
|
|
||||||
MapType map_;
|
MapType map_;
|
||||||
@ -1814,7 +1831,7 @@ class ArgMap {
|
|||||||
template <typename Formatter>
|
template <typename Formatter>
|
||||||
void init(const basic_format_args<Formatter> &args);
|
void init(const basic_format_args<Formatter> &args);
|
||||||
|
|
||||||
const internal::Arg* find(const fmt::BasicStringRef<Char> &name) const {
|
const format_arg *find(const fmt::BasicStringRef<Char> &name) const {
|
||||||
// The list is unsorted, so just return the first matching name.
|
// The list is unsorted, so just return the first matching name.
|
||||||
for (typename MapType::const_iterator it = map_.begin(), end = map_.end();
|
for (typename MapType::const_iterator it = map_.begin(), end = map_.end();
|
||||||
it != end; ++it) {
|
it != end; ++it) {
|
||||||
@ -1833,14 +1850,14 @@ void ArgMap<Char>::init(const basic_format_args<Formatter> &args) {
|
|||||||
typedef internal::NamedArg<Char> NamedArg;
|
typedef internal::NamedArg<Char> NamedArg;
|
||||||
const NamedArg *named_arg = 0;
|
const NamedArg *named_arg = 0;
|
||||||
bool use_values =
|
bool use_values =
|
||||||
args.type(MAX_PACKED_ARGS - 1) == internal::Arg::NONE;
|
args.type(MAX_PACKED_ARGS - 1) == format_arg::NONE;
|
||||||
if (use_values) {
|
if (use_values) {
|
||||||
for (unsigned i = 0;/*nothing*/; ++i) {
|
for (unsigned i = 0;/*nothing*/; ++i) {
|
||||||
internal::Arg::Type arg_type = args.type(i);
|
format_arg::Type arg_type = args.type(i);
|
||||||
switch (arg_type) {
|
switch (arg_type) {
|
||||||
case internal::Arg::NONE:
|
case format_arg::NONE:
|
||||||
return;
|
return;
|
||||||
case internal::Arg::NAMED_ARG:
|
case format_arg::NAMED_ARG:
|
||||||
named_arg = static_cast<const NamedArg*>(args.values_[i].pointer);
|
named_arg = static_cast<const NamedArg*>(args.values_[i].pointer);
|
||||||
map_.push_back(Pair(named_arg->name, *named_arg));
|
map_.push_back(Pair(named_arg->name, *named_arg));
|
||||||
break;
|
break;
|
||||||
@ -1851,17 +1868,17 @@ void ArgMap<Char>::init(const basic_format_args<Formatter> &args) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (unsigned i = 0; i != MAX_PACKED_ARGS; ++i) {
|
for (unsigned i = 0; i != MAX_PACKED_ARGS; ++i) {
|
||||||
internal::Arg::Type arg_type = args.type(i);
|
format_arg::Type arg_type = args.type(i);
|
||||||
if (arg_type == internal::Arg::NAMED_ARG) {
|
if (arg_type == format_arg::NAMED_ARG) {
|
||||||
named_arg = static_cast<const NamedArg*>(args.args_[i].pointer);
|
named_arg = static_cast<const NamedArg*>(args.args_[i].pointer);
|
||||||
map_.push_back(Pair(named_arg->name, *named_arg));
|
map_.push_back(Pair(named_arg->name, *named_arg));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (unsigned i = MAX_PACKED_ARGS;/*nothing*/; ++i) {
|
for (unsigned i = MAX_PACKED_ARGS;/*nothing*/; ++i) {
|
||||||
switch (args.args_[i].type) {
|
switch (args.args_[i].type) {
|
||||||
case internal::Arg::NONE:
|
case format_arg::NONE:
|
||||||
return;
|
return;
|
||||||
case internal::Arg::NAMED_ARG:
|
case format_arg::NAMED_ARG:
|
||||||
named_arg = static_cast<const NamedArg*>(args.args_[i].pointer);
|
named_arg = static_cast<const NamedArg*>(args.args_[i].pointer);
|
||||||
map_.push_back(Pair(named_arg->name, *named_arg));
|
map_.push_back(Pair(named_arg->name, *named_arg));
|
||||||
break;
|
break;
|
||||||
@ -1886,18 +1903,18 @@ class ArgFormatterBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename StrChar>
|
template <typename StrChar>
|
||||||
void write_str(Arg::StringValue<StrChar> value,
|
void write_str(format_arg::StringValue<StrChar> value,
|
||||||
typename EnableIf<
|
typename EnableIf<
|
||||||
std::is_same<Char, wchar_t>::value &&
|
std::is_same<Char, wchar_t>::value &&
|
||||||
std::is_same<StrChar, wchar_t>::value, int>::type = 0) {
|
std::is_same<StrChar, wchar_t>::value, int>::type = 0) {
|
||||||
writer_.write_str(value, spec_);
|
writer_.write_str(value, spec_);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename StrChar>
|
template <typename StrChar>
|
||||||
void write_str(Arg::StringValue<StrChar> value,
|
void write_str(format_arg::StringValue<StrChar> value,
|
||||||
typename EnableIf<
|
typename EnableIf<
|
||||||
!std::is_same<Char, wchar_t>::value ||
|
!std::is_same<Char, wchar_t>::value ||
|
||||||
!std::is_same<StrChar, wchar_t>::value, int>::type = 0) {
|
!std::is_same<StrChar, wchar_t>::value, int>::type = 0) {
|
||||||
// Do nothing.
|
// Do nothing.
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1907,12 +1924,14 @@ class ArgFormatterBase {
|
|||||||
|
|
||||||
void write(bool value) {
|
void write(bool value) {
|
||||||
const char *str_value = value ? "true" : "false";
|
const char *str_value = value ? "true" : "false";
|
||||||
Arg::StringValue<char> str = { str_value, std::strlen(str_value) };
|
format_arg::StringValue<char> str = { str_value, std::strlen(str_value) };
|
||||||
writer_.write_str(str, spec_);
|
writer_.write_str(str, spec_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void write(const char *value) {
|
void write(const char *value) {
|
||||||
Arg::StringValue<char> str = {value, value != 0 ? std::strlen(value) : 0};
|
format_arg::StringValue<char> str = {
|
||||||
|
value, value != 0 ? std::strlen(value) : 0
|
||||||
|
};
|
||||||
writer_.write_str(str, spec_);
|
writer_.write_str(str, spec_);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1972,11 +1991,11 @@ class ArgFormatterBase {
|
|||||||
write(value);
|
write(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void operator()(Arg::StringValue<char> value) {
|
void operator()(format_arg::StringValue<char> value) {
|
||||||
writer_.write_str(value, spec_);
|
writer_.write_str(value, spec_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void operator()(Arg::StringValue<wchar_t> value) {
|
void operator()(format_arg::StringValue<wchar_t> value) {
|
||||||
write_str(value);
|
write_str(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2273,7 +2292,7 @@ class BasicWriter {
|
|||||||
CharPtr write_str(const StrChar *s, std::size_t size, const AlignSpec &spec);
|
CharPtr write_str(const StrChar *s, std::size_t size, const AlignSpec &spec);
|
||||||
|
|
||||||
template <typename StrChar>
|
template <typename StrChar>
|
||||||
void write_str(const internal::Arg::StringValue<StrChar> &str,
|
void write_str(const format_arg::StringValue<StrChar> &str,
|
||||||
const FormatSpec &spec);
|
const FormatSpec &spec);
|
||||||
|
|
||||||
// This following methods are private to disallow writing wide characters
|
// This following methods are private to disallow writing wide characters
|
||||||
@ -2497,7 +2516,7 @@ typename BasicWriter<Char>::CharPtr BasicWriter<Char>::write_str(
|
|||||||
template <typename Char>
|
template <typename Char>
|
||||||
template <typename StrChar>
|
template <typename StrChar>
|
||||||
void BasicWriter<Char>::write_str(
|
void BasicWriter<Char>::write_str(
|
||||||
const internal::Arg::StringValue<StrChar> &s, const FormatSpec &spec) {
|
const format_arg::StringValue<StrChar> &s, const FormatSpec &spec) {
|
||||||
// Check if StrChar is convertible to Char.
|
// Check if StrChar is convertible to Char.
|
||||||
internal::CharTraits<Char>::convert(StrChar());
|
internal::CharTraits<Char>::convert(StrChar());
|
||||||
if (spec.type_ && spec.type_ != 's')
|
if (spec.type_ && spec.type_ != 's')
|
||||||
@ -3262,8 +3281,8 @@ unsigned parse_nonnegative_int(const Char *&s) {
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void require_numeric_argument(const Arg &arg, char spec) {
|
inline void require_numeric_argument(const format_arg &arg, char spec) {
|
||||||
if (arg.type > Arg::LAST_NUMERIC_TYPE) {
|
if (arg.type > format_arg::LAST_NUMERIC_TYPE) {
|
||||||
std::string message =
|
std::string message =
|
||||||
fmt::format("format specifier '{}' requires numeric argument", spec);
|
fmt::format("format specifier '{}' requires numeric argument", spec);
|
||||||
FMT_THROW(fmt::format_error(message));
|
FMT_THROW(fmt::format_error(message));
|
||||||
@ -3271,10 +3290,10 @@ inline void require_numeric_argument(const Arg &arg, char spec) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename Char>
|
template <typename Char>
|
||||||
void check_sign(const Char *&s, const Arg &arg) {
|
void check_sign(const Char *&s, const format_arg &arg) {
|
||||||
char sign = static_cast<char>(*s);
|
char sign = static_cast<char>(*s);
|
||||||
require_numeric_argument(arg, sign);
|
require_numeric_argument(arg, sign);
|
||||||
if (arg.type == Arg::UINT || arg.type == Arg::ULONG_LONG) {
|
if (arg.type == format_arg::UINT || arg.type == format_arg::ULONG_LONG) {
|
||||||
FMT_THROW(format_error(fmt::format(
|
FMT_THROW(format_error(fmt::format(
|
||||||
"format specifier '{}' requires signed argument", sign)));
|
"format specifier '{}' requires signed argument", sign)));
|
||||||
}
|
}
|
||||||
@ -3287,7 +3306,7 @@ inline format_arg basic_format_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());
|
||||||
const internal::Arg *arg = map_.find(name);
|
const format_arg *arg = map_.find(name);
|
||||||
if (arg)
|
if (arg)
|
||||||
return *arg;
|
return *arg;
|
||||||
error = "argument not found";
|
error = "argument not found";
|
||||||
@ -3322,13 +3341,12 @@ inline format_arg basic_format_context<Char>::parse_arg_id() {
|
|||||||
|
|
||||||
// Formats a single argument.
|
// Formats a single argument.
|
||||||
template <typename ArgFormatter, typename Char, typename Context>
|
template <typename ArgFormatter, typename Char, typename Context>
|
||||||
void do_format_arg(BasicWriter<Char> &writer, const internal::Arg &arg,
|
void do_format_arg(BasicWriter<Char> &writer, const format_arg &arg,
|
||||||
Context &ctx) {
|
Context &ctx) {
|
||||||
using internal::Arg;
|
|
||||||
const Char *&s = ctx.ptr();
|
const Char *&s = ctx.ptr();
|
||||||
FormatSpec spec;
|
FormatSpec spec;
|
||||||
if (*s == ':') {
|
if (*s == ':') {
|
||||||
if (arg.type == Arg::CUSTOM) {
|
if (arg.type == format_arg::CUSTOM) {
|
||||||
arg.custom.format(&writer, arg.custom.value, &ctx);
|
arg.custom.format(&writer, arg.custom.value, &ctx);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -3402,25 +3420,25 @@ void do_format_arg(BasicWriter<Char> &writer, const internal::Arg &arg,
|
|||||||
spec.width_ = internal::parse_nonnegative_int(s);
|
spec.width_ = internal::parse_nonnegative_int(s);
|
||||||
} else if (*s == '{') {
|
} else if (*s == '{') {
|
||||||
++s;
|
++s;
|
||||||
Arg width_arg = ctx.parse_arg_id();
|
format_arg width_arg = ctx.parse_arg_id();
|
||||||
if (*s++ != '}')
|
if (*s++ != '}')
|
||||||
FMT_THROW(format_error("invalid format string"));
|
FMT_THROW(format_error("invalid format string"));
|
||||||
ULongLong value = 0;
|
ULongLong value = 0;
|
||||||
switch (width_arg.type) {
|
switch (width_arg.type) {
|
||||||
case Arg::INT:
|
case format_arg::INT:
|
||||||
if (width_arg.int_value < 0)
|
if (width_arg.int_value < 0)
|
||||||
FMT_THROW(format_error("negative width"));
|
FMT_THROW(format_error("negative width"));
|
||||||
value = width_arg.int_value;
|
value = width_arg.int_value;
|
||||||
break;
|
break;
|
||||||
case Arg::UINT:
|
case format_arg::UINT:
|
||||||
value = width_arg.uint_value;
|
value = width_arg.uint_value;
|
||||||
break;
|
break;
|
||||||
case Arg::LONG_LONG:
|
case format_arg::LONG_LONG:
|
||||||
if (width_arg.long_long_value < 0)
|
if (width_arg.long_long_value < 0)
|
||||||
FMT_THROW(format_error("negative width"));
|
FMT_THROW(format_error("negative width"));
|
||||||
value = width_arg.long_long_value;
|
value = width_arg.long_long_value;
|
||||||
break;
|
break;
|
||||||
case Arg::ULONG_LONG:
|
case format_arg::ULONG_LONG:
|
||||||
value = width_arg.ulong_long_value;
|
value = width_arg.ulong_long_value;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -3439,25 +3457,25 @@ void do_format_arg(BasicWriter<Char> &writer, const internal::Arg &arg,
|
|||||||
spec.precision_ = internal::parse_nonnegative_int(s);
|
spec.precision_ = internal::parse_nonnegative_int(s);
|
||||||
} else if (*s == '{') {
|
} else if (*s == '{') {
|
||||||
++s;
|
++s;
|
||||||
Arg precision_arg = ctx.parse_arg_id();
|
format_arg precision_arg = ctx.parse_arg_id();
|
||||||
if (*s++ != '}')
|
if (*s++ != '}')
|
||||||
FMT_THROW(format_error("invalid format string"));
|
FMT_THROW(format_error("invalid format string"));
|
||||||
ULongLong value = 0;
|
ULongLong value = 0;
|
||||||
switch (precision_arg.type) {
|
switch (precision_arg.type) {
|
||||||
case Arg::INT:
|
case format_arg::INT:
|
||||||
if (precision_arg.int_value < 0)
|
if (precision_arg.int_value < 0)
|
||||||
FMT_THROW(format_error("negative precision"));
|
FMT_THROW(format_error("negative precision"));
|
||||||
value = precision_arg.int_value;
|
value = precision_arg.int_value;
|
||||||
break;
|
break;
|
||||||
case Arg::UINT:
|
case format_arg::UINT:
|
||||||
value = precision_arg.uint_value;
|
value = precision_arg.uint_value;
|
||||||
break;
|
break;
|
||||||
case Arg::LONG_LONG:
|
case format_arg::LONG_LONG:
|
||||||
if (precision_arg.long_long_value < 0)
|
if (precision_arg.long_long_value < 0)
|
||||||
FMT_THROW(format_error("negative precision"));
|
FMT_THROW(format_error("negative precision"));
|
||||||
value = precision_arg.long_long_value;
|
value = precision_arg.long_long_value;
|
||||||
break;
|
break;
|
||||||
case Arg::ULONG_LONG:
|
case format_arg::ULONG_LONG:
|
||||||
value = precision_arg.ulong_long_value;
|
value = precision_arg.ulong_long_value;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -3469,10 +3487,11 @@ void do_format_arg(BasicWriter<Char> &writer, const internal::Arg &arg,
|
|||||||
} else {
|
} else {
|
||||||
FMT_THROW(format_error("missing precision specifier"));
|
FMT_THROW(format_error("missing precision specifier"));
|
||||||
}
|
}
|
||||||
if (arg.type <= Arg::LAST_INTEGER_TYPE || arg.type == Arg::POINTER) {
|
if (arg.type <= format_arg::LAST_INTEGER_TYPE ||
|
||||||
|
arg.type == format_arg::POINTER) {
|
||||||
FMT_THROW(format_error(
|
FMT_THROW(format_error(
|
||||||
fmt::format("precision not allowed in {} format specifier",
|
fmt::format("precision not allowed in {} format specifier",
|
||||||
arg.type == Arg::POINTER ? "pointer" : "integer")));
|
arg.type == format_arg::POINTER ? "pointer" : "integer")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
36
fmt/printf.h
36
fmt/printf.h
@ -83,11 +83,11 @@ struct is_same<T, T> {
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
class ArgConverter {
|
class ArgConverter {
|
||||||
private:
|
private:
|
||||||
internal::Arg &arg_;
|
format_arg &arg_;
|
||||||
wchar_t type_;
|
wchar_t type_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ArgConverter(internal::Arg &arg, wchar_t type)
|
ArgConverter(format_arg &arg, wchar_t type)
|
||||||
: arg_(arg), type_(type) {}
|
: arg_(arg), type_(type) {}
|
||||||
|
|
||||||
void operator()(bool value) {
|
void operator()(bool value) {
|
||||||
@ -99,28 +99,27 @@ class ArgConverter {
|
|||||||
typename std::enable_if<std::is_integral<U>::value>::type
|
typename std::enable_if<std::is_integral<U>::value>::type
|
||||||
operator()(U value) {
|
operator()(U value) {
|
||||||
bool is_signed = type_ == 'd' || type_ == 'i';
|
bool is_signed = type_ == 'd' || type_ == 'i';
|
||||||
using internal::Arg;
|
|
||||||
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;
|
||||||
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) {
|
||||||
arg_.type = Arg::INT;
|
arg_.type = format_arg::INT;
|
||||||
arg_.int_value = static_cast<int>(static_cast<TargetType>(value));
|
arg_.int_value = static_cast<int>(static_cast<TargetType>(value));
|
||||||
} else {
|
} else {
|
||||||
arg_.type = Arg::UINT;
|
arg_.type = format_arg::UINT;
|
||||||
typedef typename internal::MakeUnsigned<TargetType>::Type Unsigned;
|
typedef typename internal::MakeUnsigned<TargetType>::Type Unsigned;
|
||||||
arg_.uint_value = static_cast<unsigned>(static_cast<Unsigned>(value));
|
arg_.uint_value = static_cast<unsigned>(static_cast<Unsigned>(value));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (is_signed) {
|
if (is_signed) {
|
||||||
arg_.type = Arg::LONG_LONG;
|
arg_.type = format_arg::LONG_LONG;
|
||||||
// glibc's printf doesn't sign extend arguments of smaller types:
|
// glibc's printf doesn't sign extend arguments of smaller types:
|
||||||
// std::printf("%lld", -42); // prints "4294967254"
|
// std::printf("%lld", -42); // prints "4294967254"
|
||||||
// but we don't have to do the same because it's a UB.
|
// but we don't have to do the same because it's a UB.
|
||||||
arg_.long_long_value = static_cast<LongLong>(value);
|
arg_.long_long_value = static_cast<LongLong>(value);
|
||||||
} else {
|
} else {
|
||||||
arg_.type = Arg::ULONG_LONG;
|
arg_.type = format_arg::ULONG_LONG;
|
||||||
arg_.ulong_long_value =
|
arg_.ulong_long_value =
|
||||||
static_cast<typename internal::MakeUnsigned<U>::Type>(value);
|
static_cast<typename internal::MakeUnsigned<U>::Type>(value);
|
||||||
}
|
}
|
||||||
@ -146,17 +145,17 @@ void convert_arg(format_arg &arg, wchar_t type) {
|
|||||||
// Converts an integer argument to char for printf.
|
// Converts an integer argument to char for printf.
|
||||||
class CharConverter {
|
class CharConverter {
|
||||||
private:
|
private:
|
||||||
internal::Arg &arg_;
|
format_arg &arg_;
|
||||||
|
|
||||||
FMT_DISALLOW_COPY_AND_ASSIGN(CharConverter);
|
FMT_DISALLOW_COPY_AND_ASSIGN(CharConverter);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit CharConverter(internal::Arg &arg) : arg_(arg) {}
|
explicit CharConverter(format_arg &arg) : arg_(arg) {}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
typename std::enable_if<std::is_integral<T>::value>::type
|
typename std::enable_if<std::is_integral<T>::value>::type
|
||||||
operator()(T value) {
|
operator()(T value) {
|
||||||
arg_.type = internal::Arg::CHAR;
|
arg_.type = format_arg::CHAR;
|
||||||
arg_.int_value = static_cast<char>(value);
|
arg_.int_value = static_cast<char>(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -281,7 +280,7 @@ 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::Arg::CustomValue c) {
|
void operator()(format_arg::CustomValue c) {
|
||||||
const Char format_str[] = {'}', '\0'};
|
const Char format_str[] = {'}', '\0'};
|
||||||
auto args = basic_format_args<basic_format_context<Char>>();
|
auto args = basic_format_args<basic_format_context<Char>>();
|
||||||
basic_format_context<Char> ctx(format_str, args);
|
basic_format_context<Char> ctx(format_str, args);
|
||||||
@ -306,7 +305,7 @@ class printf_context :
|
|||||||
|
|
||||||
// Returns the argument with specified index or, if arg_index is equal
|
// Returns the argument with specified index or, if arg_index is equal
|
||||||
// to the maximum unsigned value, the next argument.
|
// to the maximum unsigned value, the next argument.
|
||||||
internal::Arg get_arg(
|
format_arg get_arg(
|
||||||
const Char *s,
|
const Char *s,
|
||||||
unsigned arg_index = (std::numeric_limits<unsigned>::max)());
|
unsigned arg_index = (std::numeric_limits<unsigned>::max)());
|
||||||
|
|
||||||
@ -356,11 +355,11 @@ void printf_context<Char, AF>::parse_flags(FormatSpec &spec, const Char *&s) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename Char, typename AF>
|
template <typename Char, typename AF>
|
||||||
internal::Arg printf_context<Char, AF>::get_arg(const Char *s,
|
format_arg printf_context<Char, AF>::get_arg(const Char *s,
|
||||||
unsigned arg_index) {
|
unsigned arg_index) {
|
||||||
(void)s;
|
(void)s;
|
||||||
const char *error = 0;
|
const char *error = 0;
|
||||||
internal::Arg arg = arg_index == std::numeric_limits<unsigned>::max() ?
|
format_arg arg = arg_index == std::numeric_limits<unsigned>::max() ?
|
||||||
this->next_arg(error) : Base::get_arg(arg_index - 1, error);
|
this->next_arg(error) : Base::get_arg(arg_index - 1, error);
|
||||||
if (error)
|
if (error)
|
||||||
FMT_THROW(format_error(!*s ? "invalid format string" : error));
|
FMT_THROW(format_error(!*s ? "invalid format string" : error));
|
||||||
@ -432,12 +431,11 @@ void printf_context<Char, AF>::format(BasicWriter<Char> &writer) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
using internal::Arg;
|
format_arg arg = get_arg(s, arg_index);
|
||||||
Arg arg = get_arg(s, arg_index);
|
|
||||||
if (spec.flag(HASH_FLAG) && visit(internal::IsZeroInt(), arg))
|
if (spec.flag(HASH_FLAG) && visit(internal::IsZeroInt(), arg))
|
||||||
spec.flags_ &= ~internal::to_unsigned<int>(HASH_FLAG);
|
spec.flags_ &= ~internal::to_unsigned<int>(HASH_FLAG);
|
||||||
if (spec.fill_ == '0') {
|
if (spec.fill_ == '0') {
|
||||||
if (arg.type <= Arg::LAST_NUMERIC_TYPE)
|
if (arg.type <= format_arg::LAST_NUMERIC_TYPE)
|
||||||
spec.align_ = ALIGN_NUMERIC;
|
spec.align_ = ALIGN_NUMERIC;
|
||||||
else
|
else
|
||||||
spec.fill_ = ' '; // Ignore '0' flag for non-numeric types.
|
spec.fill_ = ' '; // Ignore '0' flag for non-numeric types.
|
||||||
@ -480,7 +478,7 @@ void printf_context<Char, AF>::format(BasicWriter<Char> &writer) {
|
|||||||
if (!*s)
|
if (!*s)
|
||||||
FMT_THROW(format_error("invalid format string"));
|
FMT_THROW(format_error("invalid format string"));
|
||||||
spec.type_ = static_cast<char>(*s++);
|
spec.type_ = static_cast<char>(*s++);
|
||||||
if (arg.type <= Arg::LAST_INTEGER_TYPE) {
|
if (arg.type <= format_arg::LAST_INTEGER_TYPE) {
|
||||||
// Normalize type.
|
// Normalize type.
|
||||||
switch (spec.type_) {
|
switch (spec.type_) {
|
||||||
case 'i': case 'u':
|
case 'i': case 'u':
|
||||||
|
@ -42,12 +42,12 @@
|
|||||||
#undef max
|
#undef max
|
||||||
|
|
||||||
TEST(FormatTest, ArgConverter) {
|
TEST(FormatTest, ArgConverter) {
|
||||||
using fmt::internal::Arg;
|
using fmt::format_arg;
|
||||||
Arg arg = Arg();
|
format_arg arg = format_arg();
|
||||||
arg.type = Arg::LONG_LONG;
|
arg.type = format_arg::LONG_LONG;
|
||||||
arg.long_long_value = std::numeric_limits<fmt::LongLong>::max();
|
arg.long_long_value = std::numeric_limits<fmt::LongLong>::max();
|
||||||
visit(fmt::internal::ArgConverter<fmt::LongLong>(arg, 'd'), arg);
|
visit(fmt::internal::ArgConverter<fmt::LongLong>(arg, 'd'), arg);
|
||||||
EXPECT_EQ(Arg::LONG_LONG, arg.type);
|
EXPECT_EQ(format_arg::LONG_LONG, arg.type);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(FormatTest, FormatNegativeNaN) {
|
TEST(FormatTest, FormatNegativeNaN) {
|
||||||
|
@ -51,9 +51,9 @@
|
|||||||
|
|
||||||
#undef max
|
#undef max
|
||||||
|
|
||||||
using fmt::StringRef;
|
using fmt::format_arg;
|
||||||
using fmt::internal::Arg;
|
|
||||||
using fmt::Buffer;
|
using fmt::Buffer;
|
||||||
|
using fmt::StringRef;
|
||||||
using fmt::internal::MemoryBuffer;
|
using fmt::internal::MemoryBuffer;
|
||||||
|
|
||||||
using testing::Return;
|
using testing::Return;
|
||||||
@ -70,9 +70,9 @@ void format_value(fmt::BasicWriter<Char> &w, Test,
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename Char, typename T>
|
template <typename Char, typename T>
|
||||||
Arg make_arg(const T &value) {
|
format_arg make_arg(const T &value) {
|
||||||
typedef fmt::internal::MakeValue< fmt::basic_format_context<Char> > MakeValue;
|
typedef fmt::internal::MakeValue< fmt::basic_format_context<Char> > MakeValue;
|
||||||
Arg arg = MakeValue(value);
|
format_arg arg = MakeValue(value);
|
||||||
arg.type = fmt::internal::type<T>();
|
arg.type = fmt::internal::type<T>();
|
||||||
return arg;
|
return arg;
|
||||||
}
|
}
|
||||||
@ -406,13 +406,13 @@ TEST(UtilTest, Increment) {
|
|||||||
EXPECT_STREQ("200", s);
|
EXPECT_STREQ("200", s);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <Arg::Type>
|
template <format_arg::Type>
|
||||||
struct ArgInfo;
|
struct ArgInfo;
|
||||||
|
|
||||||
#define ARG_INFO(type_code, Type, field) \
|
#define ARG_INFO(type_code, Type, field) \
|
||||||
template <> \
|
template <> \
|
||||||
struct ArgInfo<Arg::type_code> { \
|
struct ArgInfo<format_arg::type_code> { \
|
||||||
static Type get(const Arg &arg) { return arg.field; } \
|
static Type get(const format_arg &arg) { return arg.field; } \
|
||||||
}
|
}
|
||||||
|
|
||||||
ARG_INFO(INT, int, int_value);
|
ARG_INFO(INT, int, int_value);
|
||||||
@ -427,12 +427,12 @@ ARG_INFO(CSTRING, const char *, string.value);
|
|||||||
ARG_INFO(STRING, const char *, string.value);
|
ARG_INFO(STRING, const char *, string.value);
|
||||||
ARG_INFO(WSTRING, const wchar_t *, wstring.value);
|
ARG_INFO(WSTRING, const wchar_t *, wstring.value);
|
||||||
ARG_INFO(POINTER, const void *, pointer);
|
ARG_INFO(POINTER, const void *, pointer);
|
||||||
ARG_INFO(CUSTOM, Arg::CustomValue, custom);
|
ARG_INFO(CUSTOM, format_arg::CustomValue, custom);
|
||||||
|
|
||||||
#define CHECK_ARG_INFO(Type, field, value) { \
|
#define CHECK_ARG_INFO(Type, field, value) { \
|
||||||
Arg arg = Arg(); \
|
format_arg arg = format_arg(); \
|
||||||
arg.field = value; \
|
arg.field = value; \
|
||||||
EXPECT_EQ(value, ArgInfo<Arg::Type>::get(arg)); \
|
EXPECT_EQ(value, ArgInfo<format_arg::Type>::get(arg)); \
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(ArgTest, ArgInfo) {
|
TEST(ArgTest, ArgInfo) {
|
||||||
@ -449,17 +449,17 @@ TEST(ArgTest, ArgInfo) {
|
|||||||
CHECK_ARG_INFO(WSTRING, wstring.value, WSTR);
|
CHECK_ARG_INFO(WSTRING, wstring.value, WSTR);
|
||||||
int p = 0;
|
int p = 0;
|
||||||
CHECK_ARG_INFO(POINTER, pointer, &p);
|
CHECK_ARG_INFO(POINTER, pointer, &p);
|
||||||
Arg arg = Arg();
|
format_arg arg = format_arg();
|
||||||
arg.custom.value = &p;
|
arg.custom.value = &p;
|
||||||
EXPECT_EQ(&p, ArgInfo<Arg::CUSTOM>::get(arg).value);
|
EXPECT_EQ(&p, ArgInfo<format_arg::CUSTOM>::get(arg).value);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define EXPECT_ARG_(Char, type_code, MakeArgType, ExpectedType, value) { \
|
#define EXPECT_ARG_(Char, type_code, MakeArgType, ExpectedType, value) { \
|
||||||
MakeArgType input = static_cast<MakeArgType>(value); \
|
MakeArgType input = static_cast<MakeArgType>(value); \
|
||||||
Arg arg = make_arg<Char>(input); \
|
format_arg arg = make_arg<Char>(input); \
|
||||||
EXPECT_EQ(Arg::type_code, arg.type); \
|
EXPECT_EQ(format_arg::type_code, arg.type); \
|
||||||
ExpectedType expected_value = static_cast<ExpectedType>(value); \
|
ExpectedType expected_value = static_cast<ExpectedType>(value); \
|
||||||
EXPECT_EQ(expected_value, ArgInfo<Arg::type_code>::get(arg)); \
|
EXPECT_EQ(expected_value, ArgInfo<format_arg::type_code>::get(arg)); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define EXPECT_ARG(type_code, Type, value) \
|
#define EXPECT_ARG(type_code, Type, value) \
|
||||||
@ -563,8 +563,8 @@ TEST(ArgTest, MakeArg) {
|
|||||||
EXPECT_ARG(POINTER, const void*, &n);
|
EXPECT_ARG(POINTER, const void*, &n);
|
||||||
|
|
||||||
::Test t;
|
::Test t;
|
||||||
Arg arg = make_arg<char>(t);
|
format_arg arg = make_arg<char>(t);
|
||||||
EXPECT_EQ(fmt::internal::Arg::CUSTOM, arg.type);
|
EXPECT_EQ(format_arg::CUSTOM, arg.type);
|
||||||
EXPECT_EQ(&t, arg.custom.value);
|
EXPECT_EQ(&t, arg.custom.value);
|
||||||
fmt::MemoryWriter w;
|
fmt::MemoryWriter w;
|
||||||
fmt::format_context ctx("}", fmt::format_args());
|
fmt::format_context ctx("}", fmt::format_args());
|
||||||
@ -574,7 +574,7 @@ TEST(ArgTest, MakeArg) {
|
|||||||
|
|
||||||
TEST(UtilTest, FormatArgs) {
|
TEST(UtilTest, FormatArgs) {
|
||||||
fmt::format_args args;
|
fmt::format_args args;
|
||||||
EXPECT_EQ(Arg::NONE, args[1].type);
|
EXPECT_EQ(format_arg::NONE, args[1].type);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct CustomFormatter {
|
struct CustomFormatter {
|
||||||
@ -588,7 +588,7 @@ void format_value(fmt::Writer &, const Test &, CustomFormatter &ctx) {
|
|||||||
|
|
||||||
TEST(UtilTest, MakeValueWithCustomFormatter) {
|
TEST(UtilTest, MakeValueWithCustomFormatter) {
|
||||||
::Test t;
|
::Test t;
|
||||||
Arg arg = fmt::internal::MakeValue<CustomFormatter>(t);
|
format_arg arg = fmt::internal::MakeValue<CustomFormatter>(t);
|
||||||
CustomFormatter ctx = {false};
|
CustomFormatter ctx = {false};
|
||||||
fmt::MemoryWriter w;
|
fmt::MemoryWriter w;
|
||||||
arg.custom.format(&w, &t, &ctx);
|
arg.custom.format(&w, &t, &ctx);
|
||||||
@ -596,7 +596,7 @@ TEST(UtilTest, MakeValueWithCustomFormatter) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct Result {
|
struct Result {
|
||||||
Arg arg;
|
format_arg arg;
|
||||||
|
|
||||||
Result() : arg(make_arg<char>(0xdeadbeef)) {}
|
Result() : arg(make_arg<char>(0xdeadbeef)) {}
|
||||||
|
|
||||||
@ -627,10 +627,10 @@ struct TestVisitor {
|
|||||||
};
|
};
|
||||||
|
|
||||||
#define EXPECT_RESULT_(Char, type_code, value) { \
|
#define EXPECT_RESULT_(Char, type_code, value) { \
|
||||||
Arg arg = make_arg<Char>(value); \
|
format_arg arg = make_arg<Char>(value); \
|
||||||
Result result = fmt::visit(TestVisitor(), arg); \
|
Result result = fmt::visit(TestVisitor(), arg); \
|
||||||
EXPECT_EQ(Arg::type_code, result.arg.type); \
|
EXPECT_EQ(format_arg::type_code, result.arg.type); \
|
||||||
EXPECT_EQ(value, ArgInfo<Arg::type_code>::get(result.arg)); \
|
EXPECT_EQ(value, ArgInfo<format_arg::type_code>::get(result.arg)); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define EXPECT_RESULT(type_code, value) \
|
#define EXPECT_RESULT(type_code, value) \
|
||||||
@ -654,13 +654,13 @@ TEST(ArgVisitorTest, VisitAll) {
|
|||||||
EXPECT_RESULT(POINTER, p);
|
EXPECT_RESULT(POINTER, p);
|
||||||
::Test t;
|
::Test t;
|
||||||
Result result = visit(TestVisitor(), make_arg<char>(t));
|
Result result = visit(TestVisitor(), make_arg<char>(t));
|
||||||
EXPECT_EQ(Arg::CUSTOM, result.arg.type);
|
EXPECT_EQ(format_arg::CUSTOM, result.arg.type);
|
||||||
EXPECT_EQ(&t, result.arg.custom.value);
|
EXPECT_EQ(&t, result.arg.custom.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(ArgVisitorTest, VisitInvalidArg) {
|
TEST(ArgVisitorTest, VisitInvalidArg) {
|
||||||
Arg arg = Arg();
|
format_arg arg = format_arg();
|
||||||
arg.type = static_cast<Arg::Type>(Arg::NONE);
|
arg.type = static_cast<format_arg::Type>(format_arg::NONE);
|
||||||
EXPECT_ASSERT(visit(TestVisitor(), arg), "invalid argument type");
|
EXPECT_ASSERT(visit(TestVisitor(), arg), "invalid argument type");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user