From ae8bc36e57b6ad0227d97f8a2ea954b8b62342fc Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Wed, 24 Sep 2014 08:07:50 -0700 Subject: [PATCH] MakeArg -> MakeValue --- format.h | 105 +++++++++++++++++++++++----------------------- test/util-test.cc | 5 ++- 2 files changed, 56 insertions(+), 54 deletions(-) diff --git a/format.h b/format.h index 23eec7d7..d76ceae8 100644 --- a/format.h +++ b/format.h @@ -650,9 +650,9 @@ struct Arg : Value { Type type; }; -// Makes an Arg object from any type. +// Makes a Value object from any type. template -class MakeArg : public Value { +class MakeValue : public Value { private: // The following two methods are private to disallow formatting of // arbitrary pointers. If you want to output a pointer cast it to @@ -660,9 +660,9 @@ class MakeArg : public Value { // of "[const] volatile char *" which is printed as bool by iostreams. // Do not implement! template - MakeArg(const T *value); + MakeValue(const T *value); template - MakeArg(T *value); + MakeValue(T *value); void set_string(StringRef str) { string.value = str.c_str(); @@ -680,23 +680,24 @@ class MakeArg : public Value { static void format_custom_arg( void *formatter, const void *arg, void *format_str_ptr) { format(*static_cast*>(formatter), - *static_cast(format_str_ptr), *static_cast(arg)); + *static_cast(format_str_ptr), + *static_cast(arg)); } public: - MakeArg() {} + MakeValue() {} -#define FMT_MAKE_ARG_CTOR(Type, field, TYPE) \ - MakeArg(Type value) { field = value; } \ +#define FMT_MAKE_VALUE(Type, field, TYPE) \ + MakeValue(Type value) { field = value; } \ static fmt::ULongLong type(Type) { return Arg::TYPE; } - FMT_MAKE_ARG_CTOR(bool, int_value, INT) - FMT_MAKE_ARG_CTOR(short, int_value, INT) - FMT_MAKE_ARG_CTOR(unsigned short, uint_value, UINT) - FMT_MAKE_ARG_CTOR(int, int_value, INT) - FMT_MAKE_ARG_CTOR(unsigned, uint_value, UINT) + FMT_MAKE_VALUE(bool, int_value, INT) + FMT_MAKE_VALUE(short, int_value, INT) + FMT_MAKE_VALUE(unsigned short, uint_value, UINT) + FMT_MAKE_VALUE(int, int_value, INT) + FMT_MAKE_VALUE(unsigned, uint_value, UINT) - MakeArg(long value) { + MakeValue(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)) @@ -708,7 +709,7 @@ public: return sizeof(long) == sizeof(int) ? Arg::INT : Arg::LONG_LONG; } - MakeArg(unsigned long value) { + MakeValue(unsigned long value) { if (sizeof(unsigned long) == sizeof(unsigned)) uint_value = static_cast(value); else @@ -719,39 +720,39 @@ public: Arg::UINT : Arg::ULONG_LONG; } - FMT_MAKE_ARG_CTOR(LongLong, long_long_value, LONG_LONG) - FMT_MAKE_ARG_CTOR(ULongLong, ulong_long_value, ULONG_LONG) - FMT_MAKE_ARG_CTOR(float, double_value, DOUBLE) - FMT_MAKE_ARG_CTOR(double, double_value, DOUBLE) - FMT_MAKE_ARG_CTOR(long double, long_double_value, LONG_DOUBLE) - FMT_MAKE_ARG_CTOR(signed char, int_value, CHAR) - FMT_MAKE_ARG_CTOR(unsigned char, int_value, CHAR) - FMT_MAKE_ARG_CTOR(char, int_value, CHAR) + FMT_MAKE_VALUE(LongLong, long_long_value, LONG_LONG) + FMT_MAKE_VALUE(ULongLong, ulong_long_value, ULONG_LONG) + FMT_MAKE_VALUE(float, double_value, DOUBLE) + FMT_MAKE_VALUE(double, double_value, DOUBLE) + FMT_MAKE_VALUE(long double, long_double_value, LONG_DOUBLE) + FMT_MAKE_VALUE(signed char, int_value, CHAR) + FMT_MAKE_VALUE(unsigned char, int_value, CHAR) + FMT_MAKE_VALUE(char, int_value, CHAR) - MakeArg(wchar_t value) { + MakeValue(wchar_t value) { int_value = internal::CharTraits::convert(value); } static fmt::ULongLong type(wchar_t) { return Arg::CHAR; } -#define FMT_MAKE_ARG_CTOR_STR(Type, TYPE) \ - MakeArg(Type value) { set_string(value); } \ +#define FMT_MAKE_STR_VALUE(Type, TYPE) \ + MakeValue(Type value) { set_string(value); } \ static fmt::ULongLong type(Type) { return Arg::TYPE; } - FMT_MAKE_ARG_CTOR_STR(char *, STRING) - FMT_MAKE_ARG_CTOR_STR(const char *, STRING) - FMT_MAKE_ARG_CTOR_STR(const std::string &, STRING) - FMT_MAKE_ARG_CTOR_STR(StringRef, STRING) + FMT_MAKE_STR_VALUE(char *, STRING) + FMT_MAKE_STR_VALUE(const char *, STRING) + FMT_MAKE_STR_VALUE(const std::string &, STRING) + FMT_MAKE_STR_VALUE(StringRef, STRING) - FMT_MAKE_ARG_CTOR_STR(wchar_t *, WSTRING) - FMT_MAKE_ARG_CTOR_STR(const wchar_t *, WSTRING) - FMT_MAKE_ARG_CTOR_STR(const std::wstring &, WSTRING) - FMT_MAKE_ARG_CTOR_STR(WStringRef, WSTRING) + FMT_MAKE_STR_VALUE(wchar_t *, WSTRING) + FMT_MAKE_STR_VALUE(const wchar_t *, WSTRING) + FMT_MAKE_STR_VALUE(const std::wstring &, WSTRING) + FMT_MAKE_STR_VALUE(WStringRef, WSTRING) - FMT_MAKE_ARG_CTOR(void *, pointer, POINTER) - FMT_MAKE_ARG_CTOR(const void *, pointer, POINTER) + FMT_MAKE_VALUE(void *, pointer, POINTER) + FMT_MAKE_VALUE(const void *, pointer, POINTER) template - MakeArg(const T &value) { + MakeValue(const T &value) { custom.value = &value; custom.format = &format_custom_arg; } @@ -1226,37 +1227,37 @@ inline StrFormatSpec pad( # 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::MakeArg(v##n) -# define FMT_MAKE_REF_wchar_t(n) fmt::internal::MakeArg(v##n) +# define FMT_MAKE_REF_char(n) fmt::internal::MakeValue(v##n) +# define FMT_MAKE_REF_wchar_t(n) fmt::internal::MakeValue(v##n) #if FMT_USE_VARIADIC_TEMPLATES // Defines a variadic function returning void. # define FMT_VARIADIC_VOID(func, arg_type) \ template \ void func(arg_type arg1, const Args & ... args) { \ - using fmt::internal::MakeArg; \ + using fmt::internal::MakeValue; \ const fmt::internal::Value values[ \ fmt::internal::NonZero::VALUE] = { \ - MakeArg(args)... \ + MakeValue(args)... \ }; \ - func(arg1, ArgList(MakeArg::type(args...), values)); \ + func(arg1, ArgList(MakeValue::type(args...), values)); \ } // Defines a variadic constructor. # define FMT_VARIADIC_CTOR(ctor, func, arg0_type, arg1_type) \ template \ ctor(arg0_type arg0, arg1_type arg1, const Args & ... args) { \ - using fmt::internal::MakeArg; \ + using fmt::internal::MakeValue; \ const fmt::internal::Value values[ \ fmt::internal::NonZero::VALUE] = { \ - MakeArg(args)... \ + MakeValue(args)... \ }; \ - func(arg0, arg1, ArgList(MakeArg::type(args...), values)); \ + func(arg0, arg1, ArgList(MakeValue::type(args...), values)); \ } #else -# define FMT_MAKE_REF(n) fmt::internal::MakeArg(v##n) +# define FMT_MAKE_REF(n) fmt::internal::MakeValue(v##n) # define FMT_MAKE_REF2(n) v##n // Defines a wrapper for a function taking one argument of type arg_type @@ -1266,7 +1267,7 @@ inline StrFormatSpec pad( inline void func(arg_type arg1, FMT_GEN(n, FMT_MAKE_ARG)) { \ const fmt::internal::Value vals[] = {FMT_GEN(n, FMT_MAKE_REF)}; \ func(arg1, fmt::ArgList( \ - fmt::internal::MakeArg::type(FMT_GEN(n, FMT_MAKE_REF2)), vals)); \ + fmt::internal::MakeValue::type(FMT_GEN(n, FMT_MAKE_REF2)), vals)); \ } // Emulates a variadic function returning void on a pre-C++11 compiler. @@ -1282,7 +1283,7 @@ inline StrFormatSpec pad( ctor(arg0_type arg0, arg1_type arg1, FMT_GEN(n, FMT_MAKE_ARG)) { \ const fmt::internal::Value vals[] = {FMT_GEN(n, FMT_MAKE_REF)}; \ func(arg0, arg1, fmt::ArgList( \ - fmt::internal::MakeArg::type(FMT_GEN(n, FMT_MAKE_REF2)), vals)); \ + fmt::internal::MakeValue::type(FMT_GEN(n, FMT_MAKE_REF2)), vals)); \ } // Emulates a variadic constructor on a pre-C++11 compiler. @@ -1957,7 +1958,7 @@ void format(BasicFormatter &f, const Char *&format_str, const T &value) { os << value; internal::Arg arg; internal::Value &arg_value = arg; - arg_value = internal::MakeArg(os.str()); + arg_value = internal::MakeValue(os.str()); arg.type = internal::Arg::STRING; format_str = f.format(format_str, arg); } @@ -2244,10 +2245,10 @@ inline void format_decimal(char *&buffer, T value) { const Args & ... args) { \ using fmt::internal::Value; \ const Value values[fmt::internal::NonZero::VALUE] = { \ - fmt::internal::MakeArg(args)... \ + fmt::internal::MakeValue(args)... \ }; \ call(FMT_FOR_EACH(FMT_GET_ARG_NAME, __VA_ARGS__), fmt::ArgList( \ - fmt::internal::MakeArg::type(args...), values)); \ + fmt::internal::MakeValue::type(args...), values)); \ } #else // Defines a wrapper for a function taking __VA_ARGS__ arguments @@ -2258,7 +2259,7 @@ inline void format_decimal(char *&buffer, T value) { FMT_GEN(n, FMT_MAKE_ARG)) { \ const fmt::internal::Value vals[] = {FMT_GEN(n, FMT_MAKE_REF_##Char)}; \ call(FMT_FOR_EACH(FMT_GET_ARG_NAME, __VA_ARGS__), fmt::ArgList( \ - fmt::internal::MakeArg::type(FMT_GEN(n, FMT_MAKE_REF2)), vals)); \ + fmt::internal::MakeValue::type(FMT_GEN(n, FMT_MAKE_REF2)), vals)); \ } # define FMT_VARIADIC_(Char, ReturnType, func, call, ...) \ diff --git a/test/util-test.cc b/test/util-test.cc index 9cfa6f70..cf4adb90 100644 --- a/test/util-test.cc +++ b/test/util-test.cc @@ -57,8 +57,9 @@ template Arg make_arg(const T &value) { Arg arg = Arg(); Value &arg_value = arg; - arg_value = fmt::internal::MakeArg(value); - arg.type = static_cast(fmt::internal::MakeArg::type(value)); + arg_value = fmt::internal::MakeValue(value); + arg.type = static_cast( + fmt::internal::MakeValue::type(value)); return arg; }