22 #include <initializer_list>
26 #include <type_traits>
175 template<
typename... Args>
183 template<
typename... Args>
192 template<
typename... Args>
206 template<
typename... Args>
208 const Args& ...
args);
222 template<
typename... Args>
230 template<
typename... Args>
239 template<
typename... Args>
253 template<
typename... Args>
255 const Args& ...
args);
273 myBufferSize(std::numeric_limits<size_t>::
max()) { }
277 myBufferSize(buffer_size) { }
282 myBufferSize = buffer_size;
291 size_t size = size_t(end - begin);
292 size =
std::min(size, myBufferSize);
295 std::copy(begin, begin + size, myBuffer);
298 myBufferSize -=
size;
313 size_t operator()(
const char *
begin,
const char *
end);
324 size_t operator()(
const char *
begin,
const char *
end);
347 template<
typename>
struct TrueType : std::true_type {};
354 static auto TestHasFormat(
int) ->
356 size_t(), std::declval<T>()))>;
358 static auto TestHasFormat(
long) -> std::false_type;
364 static constexpr
bool value = decltype(Impl::TestHasFormat<T>(0))::
value;
377 Float16, Float32, Float64,
395 #if defined(LINUX) && defined(AMD64)
399 static_assert(
sizeof(
long long) == 8,
"long long should be 8 bytes.");
401 ArgValue(
unsigned long long v) : myType(
Type::UInt64), myU64(
uint64(v)) {}
403 #if defined(MBSD) && defined(__clang__)
405 ArgValue(
size_t myValuePtr) : myType(
Type::UInt64), myU64(
uint64(myValuePtr)) {}
411 #elif defined(_WIN32)
414 ArgValue(
unsigned long v) : myType(
Type::UInt32), myU32(
uint32(v)) {}
420 mySizedStr.myStr =
"true";
421 mySizedStr.mySize = 4;
425 mySizedStr.myStr =
"false";
426 mySizedStr.mySize = 5;
441 myType(
Type::Pointer), myPtr(v)
445 myType(
Type::Pointer), myPtr(v)
449 #define UT_ENABLE_IF(T) typename std::enable_if<T>::type * = nullptr
450 #define UT_HAS_FMT(T) HasFormat<T>::value
451 #define UT_REMOVE_PTR(T) typename std::remove_pointer<T>::type
452 #define UT_IS_PTR(T) std::is_pointer<T>::value
453 #define UT_IS_ENUM(T) std::is_enum<T>::value
462 myType(
Type::Pointer), myPtr(v)
474 myCustom.myFormatFunc = customPtrWrapper<UT_REMOVE_PTR(T)>;
475 myCustom.myValuePtr =
static_cast<const void *
>(
v);
479 template<
typename T,
unsigned N>
483 myCustom.myFormatFunc = customArrayWrapper<UT_REMOVE_PTR(T),N>;
484 myCustom.myValuePtr =
static_cast<const void *
>(&v[0]);
487 template <
typename T>
494 template <
typename T>
499 myCustom.myFormatFunc = customRefWrapper<T>;
500 myCustom.myValuePtr = &
v;
508 static_assert(
UT_HAS_FMT(
T),
"No formatting function for custom type.");
509 myCustom.myFormatFunc = customRefWrapper<T>;
510 myCustom.myValuePtr = &
t;
519 return myCustom.myFormatFunc(buffer, buffer_size, myCustom.myValuePtr);
533 bool isEmpty()
const {
return myType == Type::None; }
537 return myType == Type::Int8 || myType == Type::UInt8 ||
545 return myType == Type::Float16 ||
546 myType == Type::Float32 ||
547 myType == Type::Float64;
552 return myType == Type::Int8 ||
561 return isInteger() || isFloat();
566 return myType == Type::CharString ||
567 myType == Type::ZeroString ||
568 myType == Type::SizedString;
573 return myType == Type::Pointer;
578 return myType == Type::Custom;
626 template <
typename T>
628 customRefWrapper(
char *
buffer,
size_t buffer_size,
const void *
value)
630 return format(buffer, buffer_size, *static_cast<const T*>(value));
633 template <
typename T>
635 customPtrWrapper(
char *
buffer,
size_t buffer_size,
const void *
value)
638 return UTformat(buffer, buffer_size,
"<{} {}>",
639 value, *static_cast<const T*>(value));
641 return UTformat(buffer, buffer_size,
"<{}>", value);
644 template <
typename T,
unsigned N>
646 customArrayWrapper(
char *buffer,
size_t buffer_size,
const void *value);
651 template<
typename W = Writer>
657 WriteTracker(
W &
writer) : myWriter(writer), myBytesWritten(0) {}
661 size_t bytes_to_write = size_t(end - begin);
662 size_t n_written = myWriter(begin, end);
663 myBytesWritten += n_written;
664 return n_written == bytes_to_write;
666 size_t written()
const {
return myBytesWritten; }
668 void increment(
size_t n_bytes) { myBytesWritten += n_bytes; }
672 size_t myBytesWritten;
680 myReportErrors(true),
681 myDigitGroupings(false) {}
700 std::initializer_list<ArgValue>
args);
724 std::initializer_list<ArgValue>
args);
744 str_width(std::numeric_limits<size_t>::
max()),
749 digit_grouping(false),
758 enum { Left, Center, Right, Number } align;
759 enum { Minus, Plus, Space }
sign;
766 bool parseFormatSpec(
const char *&
ptr,
const ArgValue &
arg,
767 const ArgValue
args[],
size_t nb_args,
769 bool parsePrintfSpec(
const char *&
ptr,
const ArgValue &
arg,
770 const ArgValue
args[],
size_t nb_args,
773 size_t formatArg(
W &
writer,
const FormatSpec &spec,
const ArgValue &
arg);
774 size_t formatInteger(
W &
writer,
const FormatSpec &spec,
const ArgValue &
arg);
775 size_t formatFloat(
W &
writer,
const FormatSpec &spec,
const ArgValue &
arg);
776 size_t formatString(
W &
writer,
const FormatSpec &spec,
const ArgValue &
arg);
777 size_t formatPointer(
W &
writer,
const FormatSpec &spec,
const ArgValue &
arg);
778 size_t formatCustom(
W &
writer,
const FormatSpec &spec,
const ArgValue &
arg);
779 size_t formatCodePoint(
W &
writer,
const FormatSpec &spec,
const ArgValue &
arg);
780 size_t formatPercentage(
W &
writer,
const FormatSpec &spec,
const ArgValue &
arg);
782 size_t formatAdjustAndFill(
W &
writer,
const char *str,
size_t str_size,
783 const FormatSpec &spec);
788 const ArgValue &getFormatArg(
const char *&
ptr,
const ArgValue
args[],
790 const ArgValue &getPrintfArg(
const char *&
ptr,
const ArgValue
args[],
792 static int64 getIntValueFromArg(
const ArgValue &
arg);
793 static fpreal64 getFloatValueFromArg(
const ArgValue &
arg);
795 int64 myNextArgIndex;
796 bool myReportErrors:1,
806 #endif // __UT_Format__
vint4 max(const vint4 &a, const vint4 &b)
FMT_CONSTEXPR auto begin(const C &c) -> decltype(c.begin())
ImageBuf OIIO_API fill(cspan< float > values, ROI roi, int nthreads=0)
internal::named_arg< T, char > arg(string_view name, const T &arg)
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
unsigned long long uint64
A utility class to do read-only operations on a subset of an existing string.
IMATH_INTERNAL_NAMESPACE_HEADER_ENTER typedef long long unsigned int Int64
GLuint GLsizei GLsizei * length
GLuint GLuint GLsizei GLenum type
GLsizei const GLchar *const * string
OIIO_API bool copy(string_view from, string_view to, std::string &err)
GA_API const UT_StringHolder N
vint4 min(const vint4 &a, const vint4 &b)
void write(T &out, bool v)
GLenum GLint GLint * precision
GLsizei const GLfloat * value