15 #ifndef INCG_IRIS_IUTEST_PRINTERS_HPP_A6A321C9_9279_4336_8167_058C59EC0FD0_ 
   16 #define INCG_IRIS_IUTEST_PRINTERS_HPP_A6A321C9_9279_4336_8167_058C59EC0FD0_ 
   35 inline void PrintBytesInObjectTo(
const unsigned char* buf, 
size_t size, iu_ostream* os)
 
   37 IUTEST_PRAGMA_CONSTEXPR_CALLED_AT_RUNTIME_WARN_DISABLE_BEGIN()
 
   38     const 
size_t kMaxCount = detail::kValues::MaxPrintContainerCount;
 
   39     *os << size << "-Byte 
object < ";
 
   40     if( buf != IUTEST_NULLPTR && size > 0 )
 
   42         for( 
size_t i=0; i < size; ++i )
 
   49 #ifdef __clang_analyzer__ 
   50             const unsigned char n = 0;  
 
   52             const unsigned char n = buf[i];
 
   54             *os << ToHex((n>>4)&0xF) << ToHex(n&0xF) << 
" ";
 
   58 IUTEST_PRAGMA_CONSTEXPR_CALLED_AT_RUNTIME_WARN_DISABLE_END()
 
   61 namespace printer_internal
 
   68 template<
bool convertible>
 
   72     static void Print(
const T& value, iu_ostream* os)
 
   74         const unsigned char* ptr = 
const_cast<const unsigned char*
>(
 
   75             reinterpret_cast<const volatile unsigned char*
>(&value));
 
   76         const size_t size = 
sizeof(T);
 
   77         PrintBytesInObjectTo(ptr, size, os);
 
   85     static void Print(
const T& value, iu_ostream* os)
 
   87 #if IUTEST_HAS_BIGGESTINT_OSTREAM 
   90         const Int32 v = value;
 
   99 class TypeWithoutFormatter
 
  103     static void PrintValue(
const T& value, iu_ostream* os)
 
  106             iutest_type_traits::is_convertible<const T&, BiggestInt>::value>::Print(value, os);
 
  110 #if !defined(IUTEST_NO_ARGUMENT_DEPENDENT_LOOKUP) 
  112 #if IUTEST_HAS_STRINGSTREAM || IUTEST_HAS_STRSTREAM 
  113 template<
typename Elem, 
typename Traits, 
typename T>
 
  114 ::std::basic_ostream<Elem, Traits>& operator << (::std::basic_ostream<Elem, Traits>& os, 
const T& value)
 
  116     TypeWithoutFormatter::PrintValue(value, &os);
 
  120 template<
typename Elem, 
typename Traits, 
typename T>
 
  121 detail::iu_basic_ostream<Elem, Traits>& operator << (detail::iu_basic_ostream<Elem, Traits>& os, 
const T& value)
 
  123     TypeWithoutFormatter::PrintValue(value, &os);
 
  132 namespace printer_internal2
 
  140 void DefaultPrintNonContainerTo(
const T& value, iu_ostream* os)
 
  142     using namespace ::iutest::detail::printer_internal; 
 
  151 void UniversalPrint(
const T& value, iu_ostream* os);
 
  159 inline void DefaultPrintTo(IsContainerHelper::yes_t
 
  160                         , iutest_type_traits::false_type
 
  161                         , 
const T& container, iu_ostream* os)
 
  163     const size_t kMaxCount = kValues::MaxPrintContainerCount;
 
  166     for( 
typename T::const_iterator it=container.begin(), end=container.end(); it != end; ++it, ++count)
 
  171             if( count == kMaxCount )
 
  178         UniversalPrint(*it, os);
 
  188 inline void DefaultPrintNonContainerTo(
const T& value, iu_ostream* os)
 
  190 #if !defined(IUTEST_NO_ARGUMENT_DEPENDENT_LOOKUP) 
  191     printer_internal2::DefaultPrintNonContainerTo(value, os);
 
  193     printer_internal::formatter::Printer<false>::Print(value, os);
 
  198 inline void DefaultPrintTo(IsContainerHelper::no_t
 
  199                         , iutest_type_traits::false_type
 
  200                         , 
const T& value, iu_ostream* os)
 
  202     DefaultPrintNonContainerTo(value, os);
 
  205 #if !defined(IUTEST_NO_SFINAE) && !defined(IUTEST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) 
  208 inline void DefaultPtrPrintTo(T* ptr, iu_ostream* os
 
  209     , 
typename iutest_type_traits::enable_if_t< iutest_type_traits::is_convertible<T*, const void*> >::type*& = iutest_type_traits::enabler::value)
 
  211     *os << reinterpret_cast<iu_uintptr_t>(ptr);
 
  214 inline void DefaultPtrPrintTo(T* ptr, iu_ostream* os
 
  215     , 
typename iutest_type_traits::disable_if_t< iutest_type_traits::is_convertible<T*, const void*> >::type*& = iutest_type_traits::enabler::value)
 
  217     *os << reinterpret_cast<const void*>(
reinterpret_cast<type_least_t<8>::UInt
>(ptr));
 
  223 inline void DefaultPtrPrintTo(T* ptr, iu_ostream* os)
 
  225     *os << reinterpret_cast<const void*>(
reinterpret_cast<type_least_t<8>::UInt
>(ptr));
 
  231 inline void DefaultPrintTo(IsContainerHelper::no_t
 
  232                         , iutest_type_traits::true_type
 
  233                         , T* ptr, iu_ostream* os)
 
  235     if( ptr == IUTEST_NULLPTR )
 
  237         *os << kStrings::Null;
 
  241         DefaultPtrPrintTo<T>(ptr, os);
 
  248 inline void IUTEST_ATTRIBUTE_UNUSED_ UniversalTersePrint(
const T& value, iu_ostream* os)
 
  250     UniversalPrint(value, os);
 
  253 inline void IUTEST_ATTRIBUTE_UNUSED_ UniversalTersePrint(
const char* str, iu_ostream* os)
 
  255     if( str == IUTEST_NULLPTR )
 
  257         *os << kStrings::Null;
 
  261         UniversalPrint(::std::string(str), os);
 
  265 void IUTEST_ATTRIBUTE_UNUSED_ UniversalTersePrint(
const char(&str)[N], iu_ostream* os)
 
  267     return UniversalTersePrint(
static_cast<const char*
>(str), os);
 
  269 inline void IUTEST_ATTRIBUTE_UNUSED_ UniversalTersePrint(
const wchar_t* str, iu_ostream* os)
 
  271     UniversalPrint(detail::ShowAnyCString(str), os);
 
  274 void IUTEST_ATTRIBUTE_UNUSED_ UniversalTersePrint(
const wchar_t(&str)[N], iu_ostream* os)
 
  276     UniversalPrint(detail::ShowAnyCString(str), os);
 
  278 #if IUTEST_HAS_CHAR16_T 
  279 inline void IUTEST_ATTRIBUTE_UNUSED_ UniversalTersePrint(
const char16_t* str, iu_ostream* os)
 
  281     UniversalPrint(detail::ShowAnyCString(str), os);
 
  284 void IUTEST_ATTRIBUTE_UNUSED_ UniversalTersePrint(
const char16_t(&str)[N], iu_ostream* os)
 
  286     UniversalPrint(detail::ShowAnyCString(str), os);
 
  289 #if IUTEST_HAS_CHAR32_T && (IUTEST_HAS_CXX_HDR_CUCHAR || IUTEST_HAS_CXX_HDR_CODECVT) 
  290 inline void IUTEST_ATTRIBUTE_UNUSED_ UniversalTersePrint(
const char32_t* str, iu_ostream* os)
 
  292     UniversalPrint(detail::ShowAnyCString(str), os);
 
  295 void IUTEST_ATTRIBUTE_UNUSED_ UniversalTersePrint(
const char32_t(&str)[N], iu_ostream* os)
 
  297     UniversalPrint(detail::ShowAnyCString(str), os);
 
  305 inline void PrintTo(
const T& value, iu_ostream* os) {
 
  307 #
if !defined(IUTEST_NO_EXPLICIT_FUNCTION_TEMPLATE_ARGUMENTS)
 
  308         IsContainerHelper::IsContainer<T>(0)
 
  310         IsContainerHelper::IsContainer(0, detail::explicit_type<T>())
 
  312         , iutest_type_traits::is_pointer<T>(), value, os);
 
  314 inline void PrintTo(
bool b, iu_ostream* os)         { *os << (b ? 
"true" : 
"false"); }
 
  315 inline void PrintTo(
const char* c, iu_ostream* os)  { *os << c; }
 
  316 #if defined(IUTEST_NO_ARGUMENT_DEPENDENT_LOOKUP) 
  317 inline void PrintTo(
int v, iu_ostream* os)  { *os << v; }
 
  319 inline void PrintTo(const ::std::string& str, iu_ostream* os)   { *os << str.c_str(); }
 
  320 template<
typename CharT, 
typename Traits, 
typename Alloc>
 
  321 inline void PrintTo(const ::std::basic_string<CharT, Traits, Alloc>& str, iu_ostream* os)   { UniversalTersePrint(str.c_str(), os); }
 
  322 #if !defined(IUTEST_NO_FUNCTION_TEMPLATE_ORDERING) 
  324 inline void PrintTo(
const floating_point<T>& f, iu_ostream* os)
 
  326 #if IUTEST_HAS_IOMANIP 
  328     ss << ::std::setprecision(::std::numeric_limits<T>::digits10 + 2) << f.raw();
 
  329     *os << ss.str() << 
"(0x" << ToHexString(f.bits()) << 
")";
 
  331     *os << f.raw()  << 
"(0x" << ToHexString(f.bits()) << 
")";
 
  334 template<
typename T1, 
typename T2>
 
  335 inline void PrintTo(const ::std::pair<T1, T2>& value, iu_ostream* os)
 
  338     UniversalPrint(value.first, os);
 
  340     UniversalPrint(value.second, os);
 
  346 void PrintToChar(
const T value, iu_ostream* os)
 
  353     else if( value < 0x20 )
 
  355         *os << static_cast<int>(value);
 
  359         const T str[2] = { value, 0 };
 
  360         *os << 
"\'" << detail::ShowAnyCString(str) << 
"\'";
 
  363 inline void PrintTo(
const char value, iu_ostream* os)
 
  365     PrintToChar(value, os);
 
  367 inline void PrintTo(
const wchar_t value, iu_ostream* os)
 
  369     PrintToChar(value, os);
 
  371 #if IUTEST_HAS_CHAR16_T 
  372 inline void PrintTo(
const char16_t value, iu_ostream* os)
 
  374     PrintToChar(value, os);
 
  377 #if IUTEST_HAS_CHAR32_T 
  378 inline void PrintTo(
const char32_t value, iu_ostream* os)
 
  380     PrintToChar(value, os);
 
  383 inline void PrintTo(
const unsigned char value, iu_ostream* os)
 
  385     *os << static_cast<unsigned int>(value);
 
  387 #if IUTEST_HAS_CXX_HDR_STRING_VIEW 
  388 template<
typename CharT, 
typename Traits>
 
  389 inline void PrintTo(const ::std::basic_string_view<CharT, Traits>& value, iu_ostream* os)
 
  391     const ::std::basic_string<CharT, Traits> str{ value };
 
  392     UniversalTersePrint(str.c_str(), os);
 
  396 #if IUTEST_HAS_CXX_HDR_OPTIONAL 
  398 inline void PrintTo(const ::std::optional<T>& value, iu_ostream* os)
 
  402         UniversalPrint(value.value(), os);
 
  411 #if IUTEST_HAS_CXX_HDR_VARIANT 
  412 template<
typename... Types>
 
  413 inline void PrintTo(const ::std::variant<Types...>& value, iu_ostream* os)
 
  415     if (value.valueless_by_exception())
 
  417         *os << 
"valueless_by_exception";
 
  421         std::visit([&os](
const auto& v) { UniversalPrint(v, os); }, value);
 
  424 inline void PrintTo(const ::std::monostate&, iu_ostream* os)
 
  430 #if IUTEST_HAS_CXX_HDR_ANY 
  431 inline void PrintTo(const ::std::any& value, iu_ostream* os)
 
  433     *os << 
"-Any type-name: " << value.type().name();
 
  434     DefaultPrintNonContainerTo(value, os);
 
  438 #if IUTEST_HAS_STD_FILESYSTEM 
  439 inline ::std::string FileSystemFileTypeToString(const ::std::filesystem::file_type& value)
 
  443     IUTEST_PP_NAMESPACE_ENUM_CASE_RETURN_STRING(::std::filesystem::file_type, none);
 
  444     IUTEST_PP_NAMESPACE_ENUM_CASE_RETURN_STRING(::std::filesystem::file_type, not_found);
 
  445     IUTEST_PP_NAMESPACE_ENUM_CASE_RETURN_STRING(::std::filesystem::file_type, regular);
 
  446     IUTEST_PP_NAMESPACE_ENUM_CASE_RETURN_STRING(::std::filesystem::file_type, directory);
 
  447     IUTEST_PP_NAMESPACE_ENUM_CASE_RETURN_STRING(::std::filesystem::file_type, symlink);
 
  448     IUTEST_PP_NAMESPACE_ENUM_CASE_RETURN_STRING(::std::filesystem::file_type, block);
 
  449     IUTEST_PP_NAMESPACE_ENUM_CASE_RETURN_STRING(::std::filesystem::file_type, character);
 
  450     IUTEST_PP_NAMESPACE_ENUM_CASE_RETURN_STRING(::std::filesystem::file_type, fifo);
 
  451     IUTEST_PP_NAMESPACE_ENUM_CASE_RETURN_STRING(::std::filesystem::file_type, socket);
 
  452     IUTEST_PP_NAMESPACE_ENUM_CASE_RETURN_STRING(::std::filesystem::file_type, unknown);
 
  453 #if defined(IUTEST_OS_WINDOWS) && !defined(IUTEST_OS_WINDOWS_MINGW) 
  454     IUTEST_PP_NAMESPACE_ENUM_CASE_RETURN_STRING(::std::filesystem::file_type, junction);
 
  462 inline void PrintTo<::std::filesystem::path>(const ::std::filesystem::path& value, iu_ostream* os)
 
  464     *os << value.generic_string();
 
  466 inline void PrintTo(const ::std::filesystem::file_type& value, iu_ostream* os)
 
  468     *os << FileSystemFileTypeToString(value);
 
  470 inline void PrintTo(const ::std::filesystem::perms& value, iu_ostream* os)
 
  472     *os << ToOctString(static_cast<UInt16>(value));
 
  474 inline void PrintTo(const ::std::filesystem::file_status& value, iu_ostream* os)
 
  476     *os << FileSystemFileTypeToString(value.type()) << 
": ";
 
  477     PrintTo(value.permissions(), os);
 
  479 inline void PrintTo(const ::std::filesystem::space_info& value, iu_ostream* os)
 
  481     *os << 
"cpacity: " << detail::FormatSizeByte(value.capacity)
 
  482         << 
", free: " << detail::FormatSizeByte(value.free)
 
  483         << 
", available: " << detail::FormatSizeByte(value.available);
 
  485 inline void PrintTo(const ::std::filesystem::directory_entry& value, iu_ostream* os)
 
  487     PrintTo(value.path(), os);
 
  489 inline void PrintTo(const ::std::filesystem::directory_iterator& value, iu_ostream* os)
 
  495 #if IUTEST_HAS_NULLPTR 
  496 inline void PrintTo(const ::std::nullptr_t&, iu_ostream* os) { *os << 
"nullptr"; }
 
  501 template<
typename T, 
int I, 
int SIZE>
 
  502 inline void PrintTupleElemTo(
const T& t, iu_ostream* os
 
  503     , 
typename iutest_type_traits::enable_if<I == 0, void>::type*& = iutest_type_traits::enabler::value)
 
  505     IUTEST_UNUSED_VAR(t);
 
  506     IUTEST_UNUSED_VAR(os);
 
  508 template<
typename T, 
int I, 
int SIZE>
 
  509 inline void PrintTupleElemTo(
const T& t, iu_ostream* os
 
  510     , 
typename iutest_type_traits::enable_if<I == 1, void>::type*& = iutest_type_traits::enabler::value)
 
  512     PrintTo(tuples::get<SIZE-I>(t), os);
 
  514 template<
typename T, 
int I, 
int SIZE>
 
  515 inline void PrintTupleElemTo(
const T& t, iu_ostream* os
 
  516     , 
typename iutest_type_traits::enable_if<(I&(~1)) != 0, 
void>::type*& = iutest_type_traits::enabler::value)
 
  518     PrintTo(tuples::get<SIZE-I>(t), os);
 
  520     PrintTupleElemTo<T, I-1, SIZE>(t, os);
 
  524 inline void PrintTupleTo(
const T& t, iu_ostream* os)
 
  527     PrintTupleElemTo<T, tuples::tuple_size<T>::value, tuples::tuple_size<T>::value>(t, os);
 
  531 #if IUTEST_HAS_VARIADIC_TEMPLATES && IUTEST_HAS_TUPLE 
  533 template<
typename ...Args>
 
  534 inline void PrintTo(
const tuples::tuple<Args...>& t, iu_ostream* os)
 
  541 #define IIUT_DECL_TUPLE_PRINTTO(n)                                              \ 
  542     template<IUTEST_PP_ENUM_PARAMS(n, typename A)>inline void PrintTo(          \ 
  543         const tuples::tuple<IUTEST_PP_ENUM_PARAMS(n, A)>& t, iu_ostream* os) {  \ 
  544             PrintTupleTo(t, os); } 
  546 inline void PrintTo(
const tuples::tuple<>& t, iu_ostream* os) { PrintTupleTo(t, os); }
 
  548 IIUT_DECL_TUPLE_PRINTTO(1)
 
  549 IIUT_DECL_TUPLE_PRINTTO(2)
 
  550 IIUT_DECL_TUPLE_PRINTTO(3)
 
  551 IIUT_DECL_TUPLE_PRINTTO(4)
 
  552 IIUT_DECL_TUPLE_PRINTTO(5)
 
  553 IIUT_DECL_TUPLE_PRINTTO(6)
 
  554 IIUT_DECL_TUPLE_PRINTTO(7)
 
  555 IIUT_DECL_TUPLE_PRINTTO(8)
 
  556 IIUT_DECL_TUPLE_PRINTTO(9)
 
  558 #undef IIUT_DECL_TUPLE_PRINTTO 
  568 inline void PrintRawArrayTo(
const T* a, 
size_t cnt, iu_ostream* os)
 
  570     UniversalPrint<T>(a[0], os);
 
  571     for( 
size_t i=1; i < cnt; ++i )
 
  574         UniversalPrint<T>(a[i], os);
 
  582 inline void IUTEST_ATTRIBUTE_UNUSED_ UniversalPrintArray(
const T* begin, 
size_t N, iu_ostream* os)
 
  591         const size_t kThreshold = kValues::PrintArrayThreshold;
 
  592         const size_t kChunksize = kValues::PrintArrayChunksize;
 
  593         if( N <= kThreshold )
 
  595             PrintRawArrayTo(begin, N, os);
 
  599             PrintRawArrayTo(begin, kChunksize, os);
 
  601             PrintRawArrayTo(begin + N - kChunksize, kChunksize, os);
 
  609 inline void IUTEST_ATTRIBUTE_UNUSED_ UniversalPrintArray(
const char* begin, 
size_t N, iu_ostream* os)
 
  611     IUTEST_UNUSED_VAR(N);
 
  612     UniversalTersePrint(begin, os);
 
  614 inline void IUTEST_ATTRIBUTE_UNUSED_ UniversalPrintArray(
const wchar_t* begin, 
size_t N, iu_ostream* os)
 
  616     IUTEST_UNUSED_VAR(N);
 
  617     UniversalTersePrint(begin, os);
 
  622 inline void IUTEST_ATTRIBUTE_UNUSED_ UniversalPrintTo(
const T& value, iu_ostream* os)
 
  631 class iuUniversalPrinter
 
  634     static void Print(
const T& value, iu_ostream* os)
 
  636         UniversalPrintTo(value, os);
 
  640 #if !defined(IUTEST_NO_FUNCTION_TEMPLATE_ORDERING) 
  643 template<
typename T, 
size_t SIZE>
 
  644 class iuUniversalPrinter<T[SIZE]>
 
  647     static void Print(
const T(&a)[SIZE], iu_ostream* os)
 
  649         UniversalPrintArray(a, SIZE, os);
 
  659 inline void UniversalPrint(
const T& value, iu_ostream* os)
 
  661 #if !defined(IUTEST_NO_FUNCTION_TEMPLATE_ORDERING) 
  662     iuUniversalPrinter<T>::Print(value, os);
 
  664     UniversalPrintTo(value, os);
 
  680     detail::UniversalTersePrint(v, &strm);
 
  684 #if IUTEST_HAS_VARIADIC_TEMPLATES 
  689 inline ::std::string 
PrintToStrings(
const char* separate, 
const T& v)
 
  691     IUTEST_UNUSED_VAR(separate);
 
  697 template<
typename T, 
typename ...Args>
 
  698 inline ::std::string 
PrintToStrings(
const char* separate, 
const T& v, Args... args)
 
  709 #endif // INCG_IRIS_IUTEST_PRINTERS_HPP_A6A321C9_9279_4336_8167_058C59EC0FD0_