19 #include <initializer_list>
23 #include <type_traits>
25 template <
typename T>
class UT_Array;
193 myBufferSize(buffer ? buffer_size : 0) { }
198 myBufferSize = buffer_size;
201 size_t operator()(
const char *
begin,
const char *
end)
override;
217 template<
typename>
struct TrueType : std::true_type {};
224 static auto TestHasFormat(
int) ->
226 size_t(), std::declval<T>()))>;
228 static auto TestHasFormat(
long) -> std::false_type;
234 static constexpr
bool value = decltype(Impl::TestHasFormat<T>(0))::
value;
246 Int8, UInt8, Int16, UInt16, Int32, UInt32,
Int64, UInt64,
247 Float16, Float32, Float64,
265 #if (defined(LINUX) && defined(AMD64)) || (defined(LINUX) && defined(ARM64))
269 static_assert(
sizeof(
long long) == 8,
"long long should be 8 bytes.");
271 ArgValue(
unsigned long long v) : myType(
Type::UInt64), myU64(
uint64(v)) {}
273 #if defined(MBSD) && defined(__clang__)
275 ArgValue(
size_t myValuePtr) : myType(
Type::UInt64), myU64(
uint64(myValuePtr)) {}
281 #elif defined(_WIN32)
290 mySizedStr.myStr =
"true";
291 mySizedStr.mySize = 4;
295 mySizedStr.myStr =
"false";
296 mySizedStr.mySize = 5;
312 myType(
Type::Pointer), myPtr(v)
316 myType(
Type::Pointer), myPtr(v)
320 #define UT_ENABLE_IF(T) typename std::enable_if<T>::type * = nullptr
321 #define UT_HAS_FMT(T) HasFormat<T>::value
322 #define UT_REMOVE_PTR(T) typename std::remove_pointer<T>::type
323 #define UT_IS_PTR(T) std::is_pointer<T>::value
324 #define UT_IS_ENUM(T) std::is_enum<T>::value
333 myType(
Type::Pointer), myPtr(v)
345 myCustom.myFormatFunc = customPtrWrapper<UT_REMOVE_PTR(T)>;
346 myCustom.myValuePtr =
static_cast<const void *
>(
v);
350 template<
typename T,
unsigned N>
354 myCustom.myFormatFunc = customArrayWrapper<UT_REMOVE_PTR(T),N>;
355 myCustom.myValuePtr =
static_cast<const void *
>(&v[0]);
358 template <
typename T>
365 template <
typename T>
370 myCustom.myFormatFunc = customRefWrapper<T>;
371 myCustom.myValuePtr = &
v;
379 static_assert(
UT_HAS_FMT(
T),
"No formatting function for custom type.");
380 myCustom.myFormatFunc = customRefWrapper<T>;
381 myCustom.myValuePtr = &
t;
390 return myCustom.myFormatFunc(buffer, buffer_size, myCustom.myValuePtr);
406 bool isEmpty()
const {
return myType == Type::None; }
410 return myType == Type::Int8 || myType == Type::UInt8 ||
411 myType == Type::Int16 || myType == Type::UInt16 ||
412 myType == Type::Int32 || myType == Type::UInt32 ||
413 myType == Type::Int64 || myType == Type::UInt64;
418 return myType == Type::Float16 ||
419 myType == Type::Float32 ||
420 myType == Type::Float64;
425 return myType == Type::Int8 ||
426 myType == Type::Int16 ||
427 myType == Type::Int32 ||
428 myType == Type::Int64 ||
439 return myType == Type::CharString ||
440 myType == Type::ZeroString ||
441 myType == Type::SizedString;
446 return myType == Type::Pointer;
451 return myType == Type::Custom;
499 template <
typename T>
501 customRefWrapper(
char *
buffer,
size_t buffer_size,
const void *
value)
503 return format(buffer, buffer_size, *static_cast<const T*>(value));
506 template <
typename T>
508 customPtrWrapper(
char *
buffer,
size_t buffer_size,
const void *
value);
510 template <
typename T,
unsigned N>
512 customArrayWrapper(
char *
buffer,
size_t buffer_size,
const void *
value);
529 void setReportErrors(
bool flag) { myReportErrors = flag; }
546 std::initializer_list<ArgValue>
args);
563 std::initializer_list<ArgValue>
args);
569 size_t field_width = 0;
572 enum { Left, Center, Right,
Number } align = Left;
573 enum { Minus, Plus, Space }
sign = Minus;
574 bool alt_form =
false;
575 bool digit_grouping =
false;
580 bool parseFormatSpec(
const char *&
ptr,
const ArgValue &
arg,
581 const ArgValue
args[],
size_t nb_args,
583 bool parsePrintfSpec(
const char *&
ptr,
const ArgValue &
arg,
584 const ArgValue
args[],
size_t nb_args,
587 template <
typename ListT>
588 size_t formatImpl(
W &writer,
const char *
format, ListT
args);
590 size_t formatArg(
W &writer,
const FormatSpec &spec,
const ArgValue &
arg);
591 size_t formatInteger(
W &writer,
const FormatSpec &spec,
const ArgValue &
arg);
592 size_t formatFloat(
W &writer,
const FormatSpec &spec,
const ArgValue &
arg);
593 size_t formatString(
W &writer,
const FormatSpec &spec,
const ArgValue &
arg);
594 size_t formatPointer(
W &writer,
const FormatSpec &spec,
const ArgValue &
arg);
595 size_t formatCustom(
W &writer,
const FormatSpec &spec,
const ArgValue &
arg);
596 size_t formatCodePoint(
W &writer,
const FormatSpec &spec,
const ArgValue &
arg);
597 size_t formatPercentage(
W &writer,
const FormatSpec &spec,
const ArgValue &
arg);
599 size_t formatAdjustAndFill(
W &writer,
const char *str,
size_t str_size,
600 const FormatSpec &spec);
605 const ArgValue &getFormatArg(
const char *&
ptr,
const ArgValue
args[],
607 const ArgValue &getPrintfArg(
const char *&
ptr,
const ArgValue
args[],
609 static int64 getIntValueFromArg(
const ArgValue &
arg);
610 static fpreal64 getFloatValueFromArg(
const ArgValue &
arg);
612 int64 myNextArgIndex = 0;
613 bool myReportErrors =
true;
614 bool myDigitGroupings =
false;
618 template <
typename T,
unsigned N>
620 ArgValue::customArrayWrapper(
621 char *
buffer,
size_t buffer_size,
const void *
value)
623 Writer writer(buffer, buffer_size);
626 size_t nb_needed = writer(
"[", 1);
627 for (
unsigned i = 0; i <
N; ++i)
628 nb_needed += f.format(writer, i ?
", {}" :
"{}", {ptr[i]});
629 nb_needed += writer(
"]", 1);
640 template <
typename T>
642 ArgValue::customPtrWrapper(
char *
buffer,
size_t buffer_size,
const void *
value)
645 return format(buffer, buffer_size,
"<{} {}>",
648 return format(buffer, buffer_size,
"<{}>", {value});
664 template<
typename... Args>
675 template<
typename... Args>
678 return UTformat(stdout, format, args...);
687 template<
typename... Args>
704 template<
typename... Args>
723 template<
typename... Args>
734 template<
typename... Args>
737 return UTprintf(stdout, format, args...);
746 template<
typename... Args>
763 template<
typename... Args>
772 #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
__hostdev__ bool isInteger(GridType gridType)
Return true if the GridType maps to a POD integer type.
LeafData & operator=(const LeafData &)=delete
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.