mirror of
https://github.com/fmtlib/fmt.git
synced 2024-12-25 15:21:54 +00:00
MakeValue -> MakeArg
This commit is contained in:
parent
00df5c91f3
commit
3c3ae4e319
64
format.h
64
format.h
@ -759,7 +759,7 @@ template <typename T = void>
|
||||
struct None {};
|
||||
|
||||
// A helper class template to enable or disable overloads taking wide
|
||||
// characters and strings in MakeValue.
|
||||
// characters and strings in MakeArg.
|
||||
template <typename T, typename Char>
|
||||
struct WCharHelper {
|
||||
typedef None<T> Supported;
|
||||
@ -807,7 +807,7 @@ struct EnableIf<true, T> { typedef T type; };
|
||||
|
||||
// Makes an Arg object from any type.
|
||||
template <typename Char>
|
||||
class MakeValue : public Arg { // TODO: rename to MakeArg
|
||||
class MakeArg : public Arg {
|
||||
private:
|
||||
// The following two methods are private to disallow formatting of
|
||||
// arbitrary pointers. If you want to output a pointer cast it to
|
||||
@ -815,19 +815,19 @@ class MakeValue : public Arg { // TODO: rename to MakeArg
|
||||
// of "[const] volatile char *" which is printed as bool by iostreams.
|
||||
// Do not implement!
|
||||
template <typename T>
|
||||
MakeValue(const T *value);
|
||||
MakeArg(const T *value);
|
||||
template <typename T>
|
||||
MakeValue(T *value);
|
||||
MakeArg(T *value);
|
||||
|
||||
// The following methods are private to disallow formatting of wide
|
||||
// characters and strings into narrow strings as in
|
||||
// fmt::format("{}", L"test");
|
||||
// To fix this, use a wide format string: fmt::format(L"{}", L"test").
|
||||
MakeValue(typename WCharHelper<wchar_t, Char>::Unsupported);
|
||||
MakeValue(typename WCharHelper<wchar_t *, Char>::Unsupported);
|
||||
MakeValue(typename WCharHelper<const wchar_t *, Char>::Unsupported);
|
||||
MakeValue(typename WCharHelper<const std::wstring &, Char>::Unsupported);
|
||||
MakeValue(typename WCharHelper<WStringRef, Char>::Unsupported);
|
||||
MakeArg(typename WCharHelper<wchar_t, Char>::Unsupported);
|
||||
MakeArg(typename WCharHelper<wchar_t *, Char>::Unsupported);
|
||||
MakeArg(typename WCharHelper<const wchar_t *, Char>::Unsupported);
|
||||
MakeArg(typename WCharHelper<const std::wstring &, Char>::Unsupported);
|
||||
MakeArg(typename WCharHelper<WStringRef, Char>::Unsupported);
|
||||
|
||||
void set_string(StringRef str) {
|
||||
string.value = str.c_str();
|
||||
@ -849,10 +849,10 @@ class MakeValue : public Arg { // TODO: rename to MakeArg
|
||||
}
|
||||
|
||||
public:
|
||||
MakeValue() {}
|
||||
MakeArg() {}
|
||||
|
||||
#define FMT_MAKE_VALUE(Type, field, TYPE) \
|
||||
MakeValue(Type value) { field = value; } \
|
||||
MakeArg(Type value) { field = value; } \
|
||||
static uint64_t type(Type) { return Arg::TYPE; }
|
||||
|
||||
FMT_MAKE_VALUE(bool, int_value, INT)
|
||||
@ -861,7 +861,7 @@ class MakeValue : public Arg { // TODO: rename to MakeArg
|
||||
FMT_MAKE_VALUE(int, int_value, INT)
|
||||
FMT_MAKE_VALUE(unsigned, uint_value, UINT)
|
||||
|
||||
MakeValue(long value) {
|
||||
MakeArg(long value) {
|
||||
// To minimize the number of types we need to deal with, long is
|
||||
// translated either to int or to long long depending on its size.
|
||||
if (sizeof(long) == sizeof(int))
|
||||
@ -873,7 +873,7 @@ class MakeValue : public Arg { // TODO: rename to MakeArg
|
||||
return sizeof(long) == sizeof(int) ? Arg::INT : Arg::LONG_LONG;
|
||||
}
|
||||
|
||||
MakeValue(unsigned long value) {
|
||||
MakeArg(unsigned long value) {
|
||||
if (sizeof(unsigned long) == sizeof(unsigned))
|
||||
uint_value = static_cast<unsigned>(value);
|
||||
else
|
||||
@ -893,13 +893,13 @@ class MakeValue : public Arg { // TODO: rename to MakeArg
|
||||
FMT_MAKE_VALUE(unsigned char, int_value, CHAR)
|
||||
FMT_MAKE_VALUE(char, int_value, CHAR)
|
||||
|
||||
MakeValue(typename WCharHelper<wchar_t, Char>::Supported value) {
|
||||
MakeArg(typename WCharHelper<wchar_t, Char>::Supported value) {
|
||||
int_value = value;
|
||||
}
|
||||
static uint64_t type(wchar_t) { return Arg::CHAR; }
|
||||
|
||||
#define FMT_MAKE_STR_VALUE(Type, TYPE) \
|
||||
MakeValue(Type value) { set_string(value); } \
|
||||
MakeArg(Type value) { set_string(value); } \
|
||||
static uint64_t type(Type) { return Arg::TYPE; }
|
||||
|
||||
FMT_MAKE_VALUE(char *, string.value, CSTRING)
|
||||
@ -910,7 +910,7 @@ class MakeValue : public Arg { // TODO: rename to MakeArg
|
||||
FMT_MAKE_STR_VALUE(StringRef, STRING)
|
||||
|
||||
#define FMT_MAKE_WSTR_VALUE(Type, TYPE) \
|
||||
MakeValue(typename WCharHelper<Type, Char>::Supported value) { \
|
||||
MakeArg(typename WCharHelper<Type, Char>::Supported value) { \
|
||||
set_string(value); \
|
||||
} \
|
||||
static uint64_t type(Type) { return Arg::TYPE; }
|
||||
@ -924,15 +924,15 @@ class MakeValue : public Arg { // TODO: rename to MakeArg
|
||||
FMT_MAKE_VALUE(const void *, pointer, POINTER)
|
||||
|
||||
template <typename T>
|
||||
MakeValue(const T &value,
|
||||
typename EnableIf<!IsConvertibleToInt<T>::value, int>::type = 0) {
|
||||
MakeArg(const T &value,
|
||||
typename EnableIf<!IsConvertibleToInt<T>::value, int>::type = 0) {
|
||||
custom.value = &value;
|
||||
custom.format = &format_custom_arg<T>;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
MakeValue(const T &value,
|
||||
typename EnableIf<IsConvertibleToInt<T>::value, int>::type = 0) {
|
||||
MakeArg(const T &value,
|
||||
typename EnableIf<IsConvertibleToInt<T>::value, int>::type = 0) {
|
||||
int_value = value;
|
||||
}
|
||||
|
||||
@ -1419,7 +1419,7 @@ namespace internal {
|
||||
inline uint64_t make_type() { return 0; }
|
||||
|
||||
template <typename T>
|
||||
inline uint64_t make_type(const T &arg) { return MakeValue<char>::type(arg); }
|
||||
inline uint64_t make_type(const T &arg) { return MakeArg<char>::type(arg); }
|
||||
|
||||
#if FMT_USE_VARIADIC_TEMPLATES
|
||||
template <typename Arg, typename... Args>
|
||||
@ -1451,8 +1451,8 @@ inline uint64_t make_type(FMT_GEN15(FMT_ARG_TYPE_DEFAULT)) {
|
||||
# define FMT_MAKE_TEMPLATE_ARG(n) typename T##n
|
||||
# define FMT_MAKE_ARG_TYPE(n) T##n
|
||||
# define FMT_MAKE_ARG(n) const T##n &v##n
|
||||
# define FMT_MAKE_REF_char(n) fmt::internal::MakeValue<char>(v##n)
|
||||
# define FMT_MAKE_REF_wchar_t(n) fmt::internal::MakeValue<wchar_t>(v##n)
|
||||
# define FMT_MAKE_REF_char(n) fmt::internal::MakeArg<char>(v##n)
|
||||
# define FMT_MAKE_REF_wchar_t(n) fmt::internal::MakeArg<wchar_t>(v##n)
|
||||
|
||||
#if FMT_USE_VARIADIC_TEMPLATES
|
||||
// Defines a variadic function returning void.
|
||||
@ -1461,7 +1461,7 @@ inline uint64_t make_type(FMT_GEN15(FMT_ARG_TYPE_DEFAULT)) {
|
||||
void func(arg_type arg1, const Args & ... args) { \
|
||||
const fmt::internal::Arg array[ \
|
||||
fmt::internal::NonZero<sizeof...(Args)>::VALUE] = { \
|
||||
fmt::internal::MakeValue<Char>(args)... \
|
||||
fmt::internal::MakeArg<Char>(args)... \
|
||||
}; \
|
||||
func(arg1, ArgList(fmt::internal::make_type(args...), array)); \
|
||||
}
|
||||
@ -1470,17 +1470,17 @@ inline uint64_t make_type(FMT_GEN15(FMT_ARG_TYPE_DEFAULT)) {
|
||||
# define FMT_VARIADIC_CTOR(ctor, func, arg0_type, arg1_type) \
|
||||
template <typename... Args> \
|
||||
ctor(arg0_type arg0, arg1_type arg1, const Args & ... args) { \
|
||||
using fmt::internal::MakeValue; \
|
||||
using fmt::internal::MakeArg; \
|
||||
const fmt::internal::Arg array[ \
|
||||
fmt::internal::NonZero<sizeof...(Args)>::VALUE] = { \
|
||||
MakeValue<Char>(args)... \
|
||||
MakeArg<Char>(args)... \
|
||||
}; \
|
||||
func(arg0, arg1, ArgList(fmt::internal::make_type(args...), array)); \
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
# define FMT_MAKE_REF(n) fmt::internal::MakeValue<Char>(v##n)
|
||||
# define FMT_MAKE_REF(n) fmt::internal::MakeArg<Char>(v##n)
|
||||
# define FMT_MAKE_REF2(n) v##n
|
||||
|
||||
// Defines a wrapper for a function taking one argument of type arg_type
|
||||
@ -2301,9 +2301,9 @@ void format(BasicFormatter<Char> &f, const Char *&format_str, const T &value) {
|
||||
std::basic_ostringstream<Char> os;
|
||||
os << value;
|
||||
std::basic_string<Char> str = os.str();
|
||||
internal::Arg arg = internal::MakeValue<Char>(str);
|
||||
internal::Arg arg = internal::MakeArg<Char>(str);
|
||||
arg.type = static_cast<internal::Arg::Type>(
|
||||
internal::MakeValue<Char>::type(str));
|
||||
internal::MakeArg<Char>::type(str));
|
||||
format_str = f.format(format_str, arg);
|
||||
}
|
||||
|
||||
@ -2605,7 +2605,7 @@ inline void set_types(Arg *) {}
|
||||
|
||||
template <typename T, typename... Args>
|
||||
inline void set_types(Arg *args, const T &arg, const Args & ... tail) {
|
||||
args->type = static_cast<Arg::Type>(MakeValue<T>::type(arg));
|
||||
args->type = static_cast<Arg::Type>(MakeArg<T>::type(arg));
|
||||
set_types(args + 1, tail...);
|
||||
}
|
||||
}
|
||||
@ -2616,9 +2616,7 @@ inline void set_types(Arg *args, const T &arg, const Args & ... tail) {
|
||||
ReturnType func(FMT_FOR_EACH(FMT_ADD_ARG_NAME, __VA_ARGS__), \
|
||||
const Args & ... args) { \
|
||||
using fmt::internal::Arg; \
|
||||
Arg array[sizeof...(Args) + 1] = { \
|
||||
fmt::internal::MakeValue<Char>(args)... \
|
||||
}; \
|
||||
Arg array[sizeof...(Args) + 1] = {fmt::internal::MakeArg<Char>(args)...}; \
|
||||
if (sizeof...(Args) > fmt::ArgList::MAX_PACKED_ARGS) { \
|
||||
set_types(array, args...); \
|
||||
array[sizeof...(Args)].type = Arg::NONE; \
|
||||
|
@ -66,9 +66,8 @@ std::basic_ostream<Char> &operator<<(std::basic_ostream<Char> &os, Test) {
|
||||
|
||||
template <typename Char, typename T>
|
||||
Arg make_arg(const T &value) {
|
||||
Arg arg = fmt::internal::MakeValue<Char>(value);
|
||||
arg.type = static_cast<Arg::Type>(
|
||||
fmt::internal::MakeValue<Char>::type(value));
|
||||
Arg arg = fmt::internal::MakeArg<Char>(value);
|
||||
arg.type = static_cast<Arg::Type>(fmt::internal::MakeArg<Char>::type(value));
|
||||
return arg;
|
||||
}
|
||||
} // namespace
|
||||
|
Loading…
Reference in New Issue
Block a user