15 #ifndef INCG_IRIS_IUTEST_PRINTERS_HPP_A6A321C9_9279_4336_8167_058C59EC0FD0_
16 #define INCG_IRIS_IUTEST_PRINTERS_HPP_A6A321C9_9279_4336_8167_058C59EC0FD0_
26 #if IUTEST_USE_QUADMATH
27 # include <quadmath.h>
52 void UniversalPrint(
const T& value, iu_ostream* os);
54 inline void PrintBytesInObjectTo(
const unsigned char* buf,
size_t size, iu_ostream* os)
56 IUTEST_PRAGMA_CONSTEXPR_CALLED_AT_RUNTIME_WARN_DISABLE_BEGIN()
57 const
size_t kMaxCount = detail::kValues::MaxPrintContainerCount;
58 *os << size << "-Byte
object < ";
59 if( buf != IUTEST_NULLPTR && size > 0 )
61 for(
size_t i=0; i < size; ++i )
68 #ifdef __clang_analyzer__
69 const unsigned char n = 0;
71 const unsigned char n = buf[i];
73 *os << ToHex((n>>4)&0xF) << ToHex(n&0xF) <<
" ";
77 IUTEST_PRAGMA_CONSTEXPR_CALLED_AT_RUNTIME_WARN_DISABLE_END()
80 namespace printer_internal
86 struct RawBytesPrinter
89 static void Print(
const T& value, iu_ostream* os)
91 const unsigned char* ptr =
const_cast<const unsigned char*
>(
92 reinterpret_cast<const volatile unsigned char*
>(&value));
93 const size_t size =
sizeof(T);
94 PrintBytesInObjectTo(ptr, size, os);
98 struct StringViewPrinter
100 static void Print(iu_string_view value, iu_ostream* os)
102 UniversalPrint(value, os);
106 struct BiggestIntPrinter
108 static void Print(
BiggestInt value, iu_ostream* os)
110 #if IUTEST_HAS_BIGGESTINT_OSTREAM
113 const Int32 v = value;
121 struct PrinterTypeSelecter
123 typedef typename iutest_type_traits::conditional<iutest_type_traits::is_convertible<T, BiggestInt>::value
125 ,
typename iutest_type_traits::conditional<iutest_type_traits::is_convertible<T, iu_string_view>::value
135 class TypeWithoutFormatter
139 static void PrintValue(
const T& value, iu_ostream* os)
141 typedef typename formatter::PrinterTypeSelecter<const T&>::type Printer;
142 Printer::Print(value, os);
146 #if !defined(IUTEST_NO_ARGUMENT_DEPENDENT_LOOKUP)
148 #if IUTEST_HAS_STRINGSTREAM || IUTEST_HAS_STRSTREAM
149 template<
typename Elem,
typename Traits,
typename T>
150 ::std::basic_ostream<Elem, Traits>& operator << (::std::basic_ostream<Elem, Traits>& os,
const T& value)
152 TypeWithoutFormatter::PrintValue(value, &os);
156 template<
typename Elem,
typename Traits,
typename T>
157 detail::iu_basic_ostream<Elem, Traits>& operator << (detail::iu_basic_ostream<Elem, Traits>& os,
const T& value)
159 TypeWithoutFormatter::PrintValue(value, &os);
168 namespace printer_internal2
176 void DefaultPrintNonContainerTo(
const T& value, iu_ostream* os)
178 using namespace ::iutest::detail::printer_internal;
193 inline void DefaultPrintTo(IsContainerHelper::yes_t
194 , iutest_type_traits::false_type
195 ,
const T& container, iu_ostream* os)
197 const size_t kMaxCount = kValues::MaxPrintContainerCount;
200 for(
typename T::const_iterator it=container.begin(), end=container.end(); it != end; ++it, ++count)
205 if( count == kMaxCount )
212 UniversalPrint(*it, os);
222 inline void DefaultPrintNonContainerTo(
const T& value, iu_ostream* os)
224 #if !defined(IUTEST_NO_ARGUMENT_DEPENDENT_LOOKUP)
225 printer_internal2::DefaultPrintNonContainerTo(value, os);
227 printer_internal::formatter::RawBytesPrinter::Print(value, os);
232 inline void DefaultPrintTo(IsContainerHelper::no_t
233 , iutest_type_traits::false_type
234 ,
const T& value, iu_ostream* os)
236 DefaultPrintNonContainerTo(value, os);
239 #if !defined(IUTEST_NO_SFINAE) && !defined(IUTEST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
242 inline void DefaultPtrPrintTo(T* ptr, iu_ostream* os
243 ,
typename iutest_type_traits::enable_if_t< iutest_type_traits::is_convertible<T*, const void*> >::type*& = iutest_type_traits::enabler::value)
245 *os << reinterpret_cast<iu_uintptr_t>(ptr);
248 inline void DefaultPtrPrintTo(T* ptr, iu_ostream* os
249 ,
typename iutest_type_traits::disable_if_t< iutest_type_traits::is_convertible<T*, const void*> >::type*& = iutest_type_traits::enabler::value)
251 *os << reinterpret_cast<const void*>(
reinterpret_cast<type_least_t<8>::UInt
>(ptr));
257 inline void DefaultPtrPrintTo(T* ptr, iu_ostream* os)
259 *os << reinterpret_cast<const void*>(
reinterpret_cast<type_least_t<8>::UInt
>(ptr));
265 inline void DefaultPrintTo(IsContainerHelper::no_t
266 , iutest_type_traits::true_type
267 , T* ptr, iu_ostream* os)
269 if( ptr == IUTEST_NULLPTR )
271 *os << kStrings::Null;
275 DefaultPtrPrintTo<T>(ptr, os);
282 inline void IUTEST_ATTRIBUTE_UNUSED_ UniversalTersePrint(
const T& value, iu_ostream* os)
284 UniversalPrint(value, os);
287 inline void IUTEST_ATTRIBUTE_UNUSED_ UniversalTersePrint(
const char* str, iu_ostream* os)
289 if( str == IUTEST_NULLPTR )
291 *os << kStrings::Null;
295 UniversalPrint(::std::string(str), os);
299 void IUTEST_ATTRIBUTE_UNUSED_ UniversalTersePrint(
const char(&str)[N], iu_ostream* os)
301 return UniversalTersePrint(
static_cast<const char*
>(str), os);
303 inline void IUTEST_ATTRIBUTE_UNUSED_ UniversalTersePrint(
const wchar_t* str, iu_ostream* os)
305 UniversalPrint(detail::ShowAnyCString(str), os);
308 void IUTEST_ATTRIBUTE_UNUSED_ UniversalTersePrint(
const wchar_t(&str)[N], iu_ostream* os)
310 UniversalPrint(detail::ShowAnyCString(str), os);
312 #if IUTEST_HAS_CHAR16_T
313 inline void IUTEST_ATTRIBUTE_UNUSED_ UniversalTersePrint(
const char16_t* str, iu_ostream* os)
315 UniversalPrint(detail::ShowAnyCString(str), os);
318 void IUTEST_ATTRIBUTE_UNUSED_ UniversalTersePrint(
const char16_t(&str)[N], iu_ostream* os)
320 UniversalPrint(detail::ShowAnyCString(str), os);
323 #if IUTEST_HAS_CHAR32_T && (IUTEST_HAS_CXX_HDR_CUCHAR || IUTEST_HAS_CXX_HDR_CODECVT)
324 inline void IUTEST_ATTRIBUTE_UNUSED_ UniversalTersePrint(
const char32_t* str, iu_ostream* os)
326 UniversalPrint(detail::ShowAnyCString(str), os);
329 void IUTEST_ATTRIBUTE_UNUSED_ UniversalTersePrint(
const char32_t(&str)[N], iu_ostream* os)
331 UniversalPrint(detail::ShowAnyCString(str), os);
339 inline void PrintTo(
const T& value, iu_ostream* os) {
341 #
if !defined(IUTEST_NO_EXPLICIT_FUNCTION_TEMPLATE_ARGUMENTS)
342 IsContainerHelper::IsContainer<T>(0)
344 IsContainerHelper::IsContainer(0, detail::explicit_type<T>())
346 , iutest_type_traits::is_pointer<T>(), value, os);
348 inline void PrintTo(
bool b, iu_ostream* os) { *os << (b ?
"true" :
"false"); }
349 inline void PrintTo(
const char* c, iu_ostream* os) { *os << c; }
350 #if defined(IUTEST_NO_ARGUMENT_DEPENDENT_LOOKUP)
351 inline void PrintTo(
int v, iu_ostream* os) { *os << v; }
353 inline void PrintTo(const ::std::string& str, iu_ostream* os) { *os << str.c_str(); }
354 template<
typename CharT,
typename Traits,
typename Alloc>
355 inline void PrintTo(const ::std::basic_string<CharT, Traits, Alloc>& str, iu_ostream* os) { UniversalTersePrint(str.c_str(), os); }
356 #if !defined(IUTEST_NO_FUNCTION_TEMPLATE_ORDERING)
358 inline void PrintToFloatingPoint(
const floating_point<T>& f, iu_ostream* os)
361 #if IUTEST_HAS_IOMANIP
362 ss << ::std::setprecision(::std::numeric_limits<T>::digits10 + 2);
364 UniversalPrint(f.raw(), &ss);
365 *os << ss.str() <<
"(0x" << ToHexString(f.bits()) <<
")";
368 inline void PrintTo(
const floating_point<T>& f, iu_ostream* os)
370 PrintToFloatingPoint(f, os);
373 inline void PrintTo(
const internal::FloatingPoint<T>& f, iu_ostream* os)
375 PrintToFloatingPoint(f, os);
377 template<
typename T1,
typename T2>
378 inline void PrintTo(const ::std::pair<T1, T2>& value, iu_ostream* os)
381 UniversalPrint(value.first, os);
383 UniversalPrint(value.second, os);
388 #if IUTEST_HAS_INT128
389 inline void PrintTo(detail::type_fit_t<16>::Int v, iu_ostream* os)
391 *os <<
"0x" << ToHexString(v);
393 inline void PrintTo(detail::type_fit_t<16>::UInt v, iu_ostream* os)
395 *os <<
"0x" << ToHexString(v);
399 #if IUTEST_HAS_FLOAT128
401 inline void PrintToFloat128(
const T v, iu_ostream* os)
403 #if IUTEST_USE_QUADMATH
405 quadmath_snprintf(buf,
sizeof(buf),
"%Qf", v);
407 #elif IUTEST_HAS_LONG_DOUBLE && IUTEST_LONG_DOUBLE_AS_IS_DOUBLE
408 *os << static_cast<long double>(v);
410 *os << static_cast<double>(v);
415 inline void PrintTo(
const internal::Float128::Float v, iu_ostream* os)
417 PrintToFloat128(v, os);
420 #if IUTEST_HAS_LONG_DOUBLE && !IUTEST_LONG_DOUBLE_AS_IS_DOUBLE
421 inline void PrintTo(
const long double v, iu_ostream* os)
423 PrintToFloat128(v, os);
430 void PrintToChar(
const T value, iu_ostream* os)
437 else if(
static_cast<int>(value) < 0x20 )
439 *os <<
"0x" << ToHexString(value);
443 const T str[2] = { value, 0 };
444 *os <<
"\'" << detail::ShowAnyCString(str) <<
"\'";
447 inline void PrintTo(
const char value, iu_ostream* os)
449 PrintToChar(
static_cast<signed char>(value), os);
451 inline void PrintTo(
const wchar_t value, iu_ostream* os)
453 PrintToChar(value, os);
455 #if IUTEST_HAS_CHAR16_T
456 inline void PrintTo(
const char16_t value, iu_ostream* os)
458 PrintToChar(value, os);
461 #if IUTEST_HAS_CHAR32_T
462 inline void PrintTo(
const char32_t value, iu_ostream* os)
464 PrintToChar(value, os);
467 inline void PrintTo(
const unsigned char value, iu_ostream* os)
469 *os << static_cast<unsigned int>(value);
471 #if IUTEST_USE_OWN_STRING_VIEW
472 template<
typename CharT,
typename Traits>
473 inline void PrintTo(
const iu_basic_string_view<CharT, Traits>& value, iu_ostream* os)
475 const ::std::basic_string<CharT, Traits> str = value.data();
476 UniversalTersePrint(str.c_str(), os);
479 template<
typename CharT,
typename Traits>
480 inline void PrintTo(const ::std::basic_string_view<CharT, Traits>& value, iu_ostream* os)
482 const ::std::basic_string<CharT, Traits> str{ value };
483 UniversalTersePrint(str.c_str(), os);
487 #if IUTEST_HAS_CXX_HDR_OPTIONAL
489 inline void PrintTo(const ::std::optional<T>& value, iu_ostream* os)
493 UniversalPrint(value.value(), os);
502 #if IUTEST_HAS_VARIADIC_TEMPLATES && IUTEST_HAS_CXX_HDR_VARIANT
503 template<
typename... Types>
504 inline void PrintTo(const ::std::variant<Types...>& value, iu_ostream* os)
506 if (value.valueless_by_exception())
508 *os <<
"valueless_by_exception";
512 ::std::visit([&os](
const auto& v) { UniversalPrint(v, os); }, value);
515 inline void PrintTo(const ::std::monostate&, iu_ostream* os)
521 #if IUTEST_HAS_CXX_HDR_ANY
522 inline void PrintTo(const ::std::any& value, iu_ostream* os)
524 *os <<
"-Any type-name: " << value.type().name();
525 DefaultPrintNonContainerTo(value, os);
529 #if IUTEST_HAS_STD_FILESYSTEM
530 inline ::std::string FileSystemFileTypeToString(const ::std::filesystem::file_type& value)
534 IUTEST_PP_NAMESPACE_ENUM_CASE_RETURN_STRING(::std::filesystem::file_type, none);
535 IUTEST_PP_NAMESPACE_ENUM_CASE_RETURN_STRING(::std::filesystem::file_type, not_found);
536 IUTEST_PP_NAMESPACE_ENUM_CASE_RETURN_STRING(::std::filesystem::file_type, regular);
537 IUTEST_PP_NAMESPACE_ENUM_CASE_RETURN_STRING(::std::filesystem::file_type, directory);
538 IUTEST_PP_NAMESPACE_ENUM_CASE_RETURN_STRING(::std::filesystem::file_type, symlink);
539 IUTEST_PP_NAMESPACE_ENUM_CASE_RETURN_STRING(::std::filesystem::file_type, block);
540 IUTEST_PP_NAMESPACE_ENUM_CASE_RETURN_STRING(::std::filesystem::file_type, character);
541 IUTEST_PP_NAMESPACE_ENUM_CASE_RETURN_STRING(::std::filesystem::file_type, fifo);
542 IUTEST_PP_NAMESPACE_ENUM_CASE_RETURN_STRING(::std::filesystem::file_type, socket);
543 IUTEST_PP_NAMESPACE_ENUM_CASE_RETURN_STRING(::std::filesystem::file_type, unknown);
544 #if defined(IUTEST_OS_WINDOWS) && !defined(IUTEST_OS_WINDOWS_MINGW)
545 IUTEST_PP_NAMESPACE_ENUM_CASE_RETURN_STRING(::std::filesystem::file_type, junction);
551 inline void PrintTo< ::std::filesystem::path >(const ::std::filesystem::path& value, iu_ostream* os)
553 *os << value.generic_string();
555 inline void PrintTo(const ::std::filesystem::file_type& value, iu_ostream* os)
557 *os << FileSystemFileTypeToString(value);
559 inline void PrintTo(const ::std::filesystem::perms& value, iu_ostream* os)
561 *os << ToOctString(static_cast<UInt16>(value));
563 inline void PrintTo(const ::std::filesystem::file_status& value, iu_ostream* os)
565 *os << FileSystemFileTypeToString(value.type()) <<
": ";
566 PrintTo(value.permissions(), os);
568 inline void PrintTo(const ::std::filesystem::space_info& value, iu_ostream* os)
570 *os <<
"cpacity: " << detail::FormatSizeByte(value.capacity)
571 <<
", free: " << detail::FormatSizeByte(value.free)
572 <<
", available: " << detail::FormatSizeByte(value.available);
574 inline void PrintTo(const ::std::filesystem::directory_entry& value, iu_ostream* os)
576 PrintTo(value.path(), os);
578 inline void PrintTo(const ::std::filesystem::directory_iterator& value, iu_ostream* os)
584 #if IUTEST_HAS_NULLPTR
585 inline void PrintTo(const ::std::nullptr_t&, iu_ostream* os) { *os <<
"nullptr"; }
590 template<
typename T,
int I,
int SIZE>
591 inline void PrintTupleElemTo(
const T& t, iu_ostream* os
594 IUTEST_UNUSED_VAR(t);
595 IUTEST_UNUSED_VAR(os);
597 template<
typename T,
int I,
int SIZE>
598 inline void PrintTupleElemTo(
const T& t, iu_ostream* os
601 PrintTo(tuples::get<SIZE-I>(t), os);
603 template<
typename T,
int I,
int SIZE>
604 inline void PrintTupleElemTo(
const T& t, iu_ostream* os
605 ,
typename iutest_type_traits::enable_if<(I&(~1)) != 0,
void>::type*& = iutest_type_traits::enabler::value)
607 PrintTo(tuples::get<SIZE-I>(t), os);
609 PrintTupleElemTo<T, I-1, SIZE>(t, os);
613 inline void PrintTupleTo(
const T& t, iu_ostream* os)
616 PrintTupleElemTo<T, tuples::tuple_size<T>::value, tuples::tuple_size<T>::value>(t, os);
620 #if IUTEST_HAS_VARIADIC_TEMPLATES && IUTEST_HAS_TUPLE
622 template<
typename ...Args>
623 inline void PrintTo(
const tuples::tuple<Args...>& t, iu_ostream* os)
630 #define IIUT_DECL_TUPLE_PRINTTO(n) \
631 template<IUTEST_PP_ENUM_PARAMS(n, typename A)>inline void PrintTo( \
632 const tuples::tuple<IUTEST_PP_ENUM_PARAMS(n, A)>& t, iu_ostream* os) { \
633 PrintTupleTo(t, os); }
635 inline void PrintTo(
const tuples::tuple<>& t, iu_ostream* os) { PrintTupleTo(t, os); }
637 IIUT_DECL_TUPLE_PRINTTO(1)
638 IIUT_DECL_TUPLE_PRINTTO(2)
639 IIUT_DECL_TUPLE_PRINTTO(3)
640 IIUT_DECL_TUPLE_PRINTTO(4)
641 IIUT_DECL_TUPLE_PRINTTO(5)
642 IIUT_DECL_TUPLE_PRINTTO(6)
643 IIUT_DECL_TUPLE_PRINTTO(7)
644 IIUT_DECL_TUPLE_PRINTTO(8)
645 IIUT_DECL_TUPLE_PRINTTO(9)
647 #undef IIUT_DECL_TUPLE_PRINTTO
657 inline void PrintRawArrayTo(
const T* a,
size_t cnt, iu_ostream* os)
659 UniversalPrint<T>(a[0], os);
660 for(
size_t i=1; i < cnt; ++i )
663 UniversalPrint<T>(a[i], os);
671 inline void IUTEST_ATTRIBUTE_UNUSED_ UniversalPrintArray(
const T* begin,
size_t N, iu_ostream* os)
680 const size_t kThreshold = kValues::PrintArrayThreshold;
681 const size_t kChunksize = kValues::PrintArrayChunksize;
682 if( N <= kThreshold )
684 PrintRawArrayTo(begin, N, os);
688 PrintRawArrayTo(begin, kChunksize, os);
690 PrintRawArrayTo(begin + N - kChunksize, kChunksize, os);
698 inline void IUTEST_ATTRIBUTE_UNUSED_ UniversalPrintArray(
const char* begin,
size_t N, iu_ostream* os)
700 IUTEST_UNUSED_VAR(N);
701 UniversalTersePrint(begin, os);
703 inline void IUTEST_ATTRIBUTE_UNUSED_ UniversalPrintArray(
const wchar_t* begin,
size_t N, iu_ostream* os)
705 IUTEST_UNUSED_VAR(N);
706 UniversalTersePrint(begin, os);
711 inline void IUTEST_ATTRIBUTE_UNUSED_ UniversalPrintTo(
const T& value, iu_ostream* os)
720 class iuUniversalPrinter
723 static void Print(
const T& value, iu_ostream* os)
725 UniversalPrintTo(value, os);
729 #if !defined(IUTEST_NO_FUNCTION_TEMPLATE_ORDERING)
732 template<
typename T,
size_t SIZE>
733 class iuUniversalPrinter<T[SIZE]>
736 static void Print(
const T(&a)[SIZE], iu_ostream* os)
738 UniversalPrintArray(a, SIZE, os);
748 inline void UniversalPrint(
const T& value, iu_ostream* os)
750 #if !defined(IUTEST_NO_FUNCTION_TEMPLATE_ORDERING)
751 iuUniversalPrinter<T>::Print(value, os);
753 UniversalPrintTo(value, os);
769 detail::UniversalTersePrint(v, &strm);
773 #if IUTEST_HAS_VARIADIC_TEMPLATES
778 inline ::std::string
PrintToStrings(
const char* separate,
const T& v)
780 IUTEST_UNUSED_VAR(separate);
786 template<
typename T,
typename ...Args>
787 inline ::std::string
PrintToStrings(
const char* separate,
const T& v, Args... args)
テストベース
Definition: iutest_body.hpp:44
iris unit test definition
iris unit test iu_basic_ostream implimentaion
iutest root namespace
Definition: iutest_charcode.hpp:33
std::string PrintToString(const T &v)
文字列化
Definition: iutest_printers.hpp:767
detail::type_fit_t< 4 >::Int Int32
32 bit 符号付き整数型
Definition: iutest_defs.hpp:502
inline ::std::string PrintToStrings(const char *separate, const T &v)
文字列化
Definition: iutest_printers.hpp:779
detail::type_least_t< 8 >::Int BiggestInt
Biggest Int
Definition: iutest_defs.hpp:527