19 #include <initializer_list>
23 #include <type_traits>
192 myBufferSize(buffer ? buffer_size : 0) { }
197 myBufferSize = buffer_size;
200 size_t operator()(
const char *
begin,
const char *
end)
override;
216 template<
typename>
struct TrueType : std::true_type {};
223 static auto TestHasFormat(
int) ->
225 size_t(), std::declval<T>()))>;
227 static auto TestHasFormat(
long) -> std::false_type;
233 static constexpr
bool value = decltype(Impl::TestHasFormat<T>(0))::
value;
246 Float16, Float32, Float64,
264 #if (defined(LINUX) && defined(AMD64)) || (defined(LINUX) && defined(ARM64))
268 static_assert(
sizeof(
long long) == 8,
"long long should be 8 bytes.");
270 ArgValue(
unsigned long long v) : myType(
Type::UInt64), myU64(
uint64(v)) {}
272 #if defined(MBSD) && defined(__clang__)
274 ArgValue(
size_t myValuePtr) : myType(
Type::UInt64), myU64(
uint64(myValuePtr)) {}
280 #elif defined(_WIN32)
283 ArgValue(
unsigned long v) : myType(
Type::UInt32), myU32(
uint32(v)) {}
289 mySizedStr.myStr =
"true";
290 mySizedStr.mySize = 4;
294 mySizedStr.myStr =
"false";
295 mySizedStr.mySize = 5;
311 myType(
Type::Pointer), myPtr(v)
315 myType(
Type::Pointer), myPtr(v)
319 #define UT_ENABLE_IF(T) typename std::enable_if<T>::type * = nullptr
320 #define UT_HAS_FMT(T) HasFormat<T>::value
321 #define UT_REMOVE_PTR(T) typename std::remove_pointer<T>::type
322 #define UT_IS_PTR(T) std::is_pointer<T>::value
323 #define UT_IS_ENUM(T) std::is_enum<T>::value
332 myType(
Type::Pointer), myPtr(v)
344 myCustom.myFormatFunc = customPtrWrapper<UT_REMOVE_PTR(T)>;
345 myCustom.myValuePtr =
static_cast<const void *
>(
v);
349 template<
typename T,
unsigned N>
353 myCustom.myFormatFunc = customArrayWrapper<UT_REMOVE_PTR(T),N>;
354 myCustom.myValuePtr =
static_cast<const void *
>(&v[0]);
357 template <
typename T>
364 template <
typename T>
369 myCustom.myFormatFunc = customRefWrapper<T>;
370 myCustom.myValuePtr = &
v;
378 static_assert(
UT_HAS_FMT(
T),
"No formatting function for custom type.");
379 myCustom.myFormatFunc = customRefWrapper<T>;
380 myCustom.myValuePtr = &
t;
389 return myCustom.myFormatFunc(buffer, buffer_size, myCustom.myValuePtr);
405 bool isEmpty()
const {
return myType == Type::None; }
409 return myType == Type::Int8 || myType == Type::UInt8 ||
417 return myType == Type::Float16 ||
418 myType == Type::Float32 ||
419 myType == Type::Float64;
424 return myType == Type::Int8 ||
433 return isInteger() || isFloat();
438 return myType == Type::CharString ||
439 myType == Type::ZeroString ||
440 myType == Type::SizedString;
445 return myType == Type::Pointer;
450 return myType == Type::Custom;
498 template <
typename T>
500 customRefWrapper(
char *
buffer,
size_t buffer_size,
const void *
value)
502 return format(buffer, buffer_size, *static_cast<const T*>(value));
505 template <
typename T>
507 customPtrWrapper(
char *
buffer,
size_t buffer_size,
const void *
value);
509 template <
typename T,
unsigned N>
511 customArrayWrapper(
char *
buffer,
size_t buffer_size,
const void *
value);
528 void setReportErrors(
bool flag) { myReportErrors = flag; }
545 std::initializer_list<ArgValue>
args);
558 std::initializer_list<ArgValue>
args);
564 size_t field_width = 0;
567 enum { Left, Center, Right,
Number } align = Left;
568 enum { Minus, Plus, Space }
sign = Minus;
569 bool alt_form =
false;
570 bool digit_grouping =
false;
575 bool parseFormatSpec(
const char *&
ptr,
const ArgValue &
arg,
576 const ArgValue
args[],
size_t nb_args,
578 bool parsePrintfSpec(
const char *&
ptr,
const ArgValue &
arg,
579 const ArgValue
args[],
size_t nb_args,
582 size_t formatArg(
W &writer,
const FormatSpec &spec,
const ArgValue &
arg);
583 size_t formatInteger(
W &writer,
const FormatSpec &spec,
const ArgValue &
arg);
584 size_t formatFloat(
W &writer,
const FormatSpec &spec,
const ArgValue &
arg);
585 size_t formatString(
W &writer,
const FormatSpec &spec,
const ArgValue &
arg);
586 size_t formatPointer(
W &writer,
const FormatSpec &spec,
const ArgValue &
arg);
587 size_t formatCustom(
W &writer,
const FormatSpec &spec,
const ArgValue &
arg);
588 size_t formatCodePoint(
W &writer,
const FormatSpec &spec,
const ArgValue &
arg);
589 size_t formatPercentage(
W &writer,
const FormatSpec &spec,
const ArgValue &
arg);
591 size_t formatAdjustAndFill(
W &writer,
const char *str,
size_t str_size,
592 const FormatSpec &spec);
597 const ArgValue &getFormatArg(
const char *&
ptr,
const ArgValue
args[],
599 const ArgValue &getPrintfArg(
const char *&
ptr,
const ArgValue
args[],
601 static int64 getIntValueFromArg(
const ArgValue &
arg);
602 static fpreal64 getFloatValueFromArg(
const ArgValue &
arg);
604 int64 myNextArgIndex = 0;
605 bool myReportErrors =
true;
606 bool myDigitGroupings =
false;
610 template <
typename T,
unsigned N>
612 ArgValue::customArrayWrapper(
613 char *
buffer,
size_t buffer_size,
const void *
value)
615 Writer writer(buffer, buffer_size);
618 size_t nb_needed = writer(
"[", 1);
619 for (
unsigned i = 0; i <
N; ++i)
620 nb_needed += f.format(writer, i ?
", {}" :
"{}", {ptr[i]});
621 nb_needed += writer(
"]", 1);
632 template <
typename T>
634 ArgValue::customPtrWrapper(
char *
buffer,
size_t buffer_size,
const void *
value)
637 return format(buffer, buffer_size,
"<{} {}>",
640 return format(buffer, buffer_size,
"<{}>", {value});
656 template<
typename... Args>
667 template<
typename... Args>
670 return UTformat(stdout, format, args...);
679 template<
typename... Args>
696 template<
typename... Args>
715 template<
typename... Args>
726 template<
typename... Args>
729 return UTprintf(stdout, format, args...);
738 template<
typename... Args>
755 template<
typename... Args>
764 #endif // __UT_Format__
auto printf(const S &fmt, const T &...args) -> int
GLsizei const GLchar *const * string
GLsizei const GLfloat * value
GLuint GLsizei GLsizei * length
unsigned long long uint64
auto arg(const Char *name, const T &arg) -> detail::named_arg< Char, T >
A utility class to do read-only operations on a subset of an existing string.
const TypeValidator< double > Number("NUMBER")
Check for a number.
IMATH_INTERNAL_NAMESPACE_HEADER_ENTER typedef long long unsigned int Int64
Int64 - unsigned 64-bit integer.
GLint GLint GLsizei GLint GLenum format
#define UT_NON_COPYABLE(CLASS)
Define deleted copy constructor and assignment operator inside a class.
IMATH_HOSTDEVICE constexpr int sign(T a) IMATH_NOEXCEPT
GLenum GLint GLint * precision
ImageBuf OIIO_API max(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
GA_API const UT_StringHolder N
**If you just want to fire and args
PcpNodeRef_ChildrenIterator begin(const PcpNodeRef::child_const_range &r)
Support for range-based for loops for PcpNodeRef children ranges.