Factor POD part of Arg into ArgInfo to be able to store it in Array.
This commit is contained in:
parent
028fb01f42
commit
5b8126f84d
123
format.h
123
format.h
@ -1001,19 +1001,6 @@ class BasicFormatter {
|
|||||||
typedef void (*FormatFunc)(
|
typedef void (*FormatFunc)(
|
||||||
BasicWriter<Char> &w, const void *arg, const FormatSpec &spec);
|
BasicWriter<Char> &w, const void *arg, const FormatSpec &spec);
|
||||||
|
|
||||||
// A format argument.
|
|
||||||
class Arg {
|
|
||||||
private:
|
|
||||||
// This method is private to disallow formatting of arbitrary pointers.
|
|
||||||
// If you want to output a pointer cast it to const void*. Do not implement!
|
|
||||||
template <typename T>
|
|
||||||
Arg(const T *value);
|
|
||||||
|
|
||||||
// This method is private to disallow formatting of arbitrary pointers.
|
|
||||||
// If you want to output a pointer cast it to void*. Do not implement!
|
|
||||||
template <typename T>
|
|
||||||
Arg(T *value);
|
|
||||||
|
|
||||||
struct StringValue {
|
struct StringValue {
|
||||||
const Char *value;
|
const Char *value;
|
||||||
std::size_t size;
|
std::size_t size;
|
||||||
@ -1024,7 +1011,9 @@ class BasicFormatter {
|
|||||||
FormatFunc format;
|
FormatFunc format;
|
||||||
};
|
};
|
||||||
|
|
||||||
public:
|
// Information about a format argument. It is a POD type to allow
|
||||||
|
// storage in internal::Array.
|
||||||
|
struct ArgInfo {
|
||||||
Type type;
|
Type type;
|
||||||
union {
|
union {
|
||||||
int int_value;
|
int int_value;
|
||||||
@ -1039,56 +1028,90 @@ class BasicFormatter {
|
|||||||
StringValue string;
|
StringValue string;
|
||||||
CustomValue custom;
|
CustomValue custom;
|
||||||
};
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
// A wrapper around a format argument used to ensure that the formatting
|
||||||
|
// is performed before the argument is destroyed.
|
||||||
|
class Arg : public ArgInfo {
|
||||||
|
private:
|
||||||
|
// This method is private to disallow formatting of arbitrary pointers.
|
||||||
|
// If you want to output a pointer cast it to const void*. Do not implement!
|
||||||
|
template <typename T>
|
||||||
|
Arg(const T *value);
|
||||||
|
|
||||||
|
// This method is private to disallow formatting of arbitrary pointers.
|
||||||
|
// If you want to output a pointer cast it to void*. Do not implement!
|
||||||
|
template <typename T>
|
||||||
|
Arg(T *value);
|
||||||
|
|
||||||
|
public:
|
||||||
mutable BasicFormatter *formatter;
|
mutable BasicFormatter *formatter;
|
||||||
|
using ArgInfo::type;
|
||||||
|
|
||||||
Arg(short value) : type(INT), int_value(value), formatter(0) {}
|
Arg(short value) : formatter(0) { type = INT; this->int_value = value; }
|
||||||
Arg(unsigned short value) : type(UINT), int_value(value), formatter(0) {}
|
Arg(unsigned short value)
|
||||||
Arg(int value) : type(INT), int_value(value), formatter(0) {}
|
: formatter(0) { type = UINT; this->int_value = value; }
|
||||||
Arg(unsigned value) : type(UINT), uint_value(value), formatter(0) {}
|
Arg(int value) : formatter(0) { type = INT; this->int_value = value; }
|
||||||
Arg(long value) : type(LONG), long_value(value), formatter(0) {}
|
Arg(unsigned value)
|
||||||
Arg(unsigned long value) : type(ULONG), ulong_value(value), formatter(0) {}
|
: formatter(0) { type = UINT; this->uint_value = value; }
|
||||||
|
Arg(long value) : formatter(0) { type = LONG; this->long_value = value; }
|
||||||
|
Arg(unsigned long value)
|
||||||
|
: formatter(0) { type = ULONG; this->ulong_value = value; }
|
||||||
Arg(LongLong value)
|
Arg(LongLong value)
|
||||||
: type(LONG_LONG), long_long_value(value), formatter(0) {}
|
: formatter(0) { type = LONG_LONG; this->long_long_value = value; }
|
||||||
Arg(ULongLong value)
|
Arg(ULongLong value)
|
||||||
: type(ULONG_LONG), ulong_long_value(value), formatter(0) {}
|
: formatter(0) { type = ULONG_LONG; this->ulong_long_value = value; }
|
||||||
Arg(float value) : type(DOUBLE), double_value(value), formatter(0) {}
|
Arg(float value)
|
||||||
Arg(double value) : type(DOUBLE), double_value(value), formatter(0) {}
|
: formatter(0) { type = DOUBLE; this->double_value = value; }
|
||||||
|
Arg(double value)
|
||||||
|
: formatter(0) { type = DOUBLE; this->double_value = value; }
|
||||||
Arg(long double value)
|
Arg(long double value)
|
||||||
: type(LONG_DOUBLE), long_double_value(value), formatter(0) {}
|
: formatter(0) { type = LONG_DOUBLE; this->long_double_value = value; }
|
||||||
Arg(char value) : type(CHAR), int_value(value), formatter(0) {}
|
Arg(char value) : formatter(0) { type = CHAR; this->int_value = value; }
|
||||||
Arg(wchar_t value)
|
Arg(wchar_t value) : formatter(0) {
|
||||||
: type(CHAR), int_value(internal::CharTraits<Char>::ConvertChar(value)),
|
type = CHAR;
|
||||||
formatter(0) {}
|
this->int_value = internal::CharTraits<Char>::ConvertChar(value);
|
||||||
|
|
||||||
Arg(const Char *value) : type(STRING), formatter(0) {
|
|
||||||
string.value = value;
|
|
||||||
string.size = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Arg(Char *value) : type(STRING), formatter(0) {
|
Arg(const Char *value) : formatter(0) {
|
||||||
string.value = value;
|
type = STRING;
|
||||||
string.size = 0;
|
this->string.value = value;
|
||||||
|
this->string.size = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Arg(const void *value)
|
Arg(Char *value) : formatter(0) {
|
||||||
: type(POINTER), pointer_value(value), formatter(0) {}
|
type = STRING;
|
||||||
|
this->string.value = value;
|
||||||
Arg(void *value) : type(POINTER), pointer_value(value), formatter(0) {}
|
this->string.size = 0;
|
||||||
|
|
||||||
Arg(const std::basic_string<Char> &value) : type(STRING), formatter(0) {
|
|
||||||
string.value = value.c_str();
|
|
||||||
string.size = value.size();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Arg(BasicStringRef<Char> value) : type(STRING), formatter(0) {
|
Arg(const void *value) : formatter(0) {
|
||||||
string.value = value.c_str();
|
type = POINTER;
|
||||||
string.size = value.size();
|
this->pointer_value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
Arg(void *value) : formatter(0) {
|
||||||
|
type = POINTER;
|
||||||
|
this->pointer_value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
Arg(const std::basic_string<Char> &value) : formatter(0) {
|
||||||
|
type = STRING;
|
||||||
|
this->string.value = value.c_str();
|
||||||
|
this->string.size = value.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
Arg(BasicStringRef<Char> value) : formatter(0) {
|
||||||
|
type = STRING;
|
||||||
|
this->string.value = value.c_str();
|
||||||
|
this->string.size = value.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
Arg(const T &value) : type(CUSTOM), formatter(0) {
|
Arg(const T &value) : formatter(0) {
|
||||||
custom.value = &value;
|
type = CUSTOM;
|
||||||
custom.format = &internal::FormatCustomArg<Char, T>;
|
this->custom.value = &value;
|
||||||
|
this->custom.format = &internal::FormatCustomArg<Char, T>;
|
||||||
}
|
}
|
||||||
|
|
||||||
~Arg() FMT_NOEXCEPT(false) {
|
~Arg() FMT_NOEXCEPT(false) {
|
||||||
|
Loading…
Reference in New Issue
Block a user