95 #ifndef GTEST_INCLUDE_GTEST_GTEST_PRINTERS_H_
96 #define GTEST_INCLUDE_GTEST_GTEST_PRINTERS_H_
98 #pragma GCC system_header
113 namespace internal2 {
134 template <
typename T, TypeKind kTypeKind>
149 template <
typename T>
156 short_str : (
"\n" + value.DebugString());
157 *os << (
"<" + pretty_str +
">");
161 template <
typename T>
201 template <
typename Char,
typename CharTraits,
typename T>
203 ::std::basic_ostream<Char, CharTraits>& os,
const T& x) {
220 template <
typename T>
263 template <
typename T>
266 template <
typename T>
271 template <
typename C>
274 const C& container, ::std::ostream* os) {
275 const size_t kMaxCount = 32;
278 for (
typename C::const_iterator it = container.begin();
279 it != container.end(); ++it, ++count) {
282 if (count == kMaxCount) {
305 template <
typename T>
308 T* p, ::std::ostream* os) {
329 *os << reinterpret_cast<const void*>(
337 template <
typename T>
340 const T& value, ::std::ostream* os) {
355 template <
typename T>
356 void PrintTo(
const T& value, ::std::ostream* os) {
389 inline void PrintTo(
char c, ::std::ostream* os) {
393 PrintTo(
static_cast<unsigned char>(c), os);
397 inline void PrintTo(
bool x, ::std::ostream* os) {
398 *os << (x ?
"true" :
"false");
412 inline void PrintTo(
char* s, ::std::ostream* os) {
413 PrintTo(ImplicitCast_<const char*>(s), os);
418 inline void PrintTo(
const signed char* s, ::std::ostream* os) {
419 PrintTo(ImplicitCast_<const void*>(s), os);
421 inline void PrintTo(
signed char* s, ::std::ostream* os) {
422 PrintTo(ImplicitCast_<const void*>(s), os);
424 inline void PrintTo(
const unsigned char* s, ::std::ostream* os) {
425 PrintTo(ImplicitCast_<const void*>(s), os);
427 inline void PrintTo(
unsigned char* s, ::std::ostream* os) {
428 PrintTo(ImplicitCast_<const void*>(s), os);
436 #if !defined(_MSC_VER) || defined(_NATIVE_WCHAR_T_DEFINED)
439 inline void PrintTo(
wchar_t* s, ::std::ostream* os) {
440 PrintTo(ImplicitCast_<const wchar_t*>(s), os);
449 template <
typename T>
452 for (
size_t i = 1; i != count; i++) {
459 #if GTEST_HAS_GLOBAL_STRING
464 #endif // GTEST_HAS_GLOBAL_STRING
472 #if GTEST_HAS_GLOBAL_WSTRING
475 PrintWideStringTo(s, os);
477 #endif // GTEST_HAS_GLOBAL_WSTRING
479 #if GTEST_HAS_STD_WSTRING
482 PrintWideStringTo(s, os);
484 #endif // GTEST_HAS_STD_WSTRING
486 #if GTEST_HAS_TR1_TUPLE
492 template <
typename T>
493 void PrintTupleTo(
const T& t, ::std::ostream* os);
500 inline void PrintTo(const ::std::tr1::tuple<>& t, ::std::ostream* os) {
504 template <
typename T1>
505 void PrintTo(const ::std::tr1::tuple<T1>& t, ::std::ostream* os) {
509 template <
typename T1,
typename T2>
510 void PrintTo(const ::std::tr1::tuple<T1, T2>& t, ::std::ostream* os) {
514 template <
typename T1,
typename T2,
typename T3>
515 void PrintTo(const ::std::tr1::tuple<T1, T2, T3>& t, ::std::ostream* os) {
519 template <
typename T1,
typename T2,
typename T3,
typename T4>
520 void PrintTo(const ::std::tr1::tuple<T1, T2, T3, T4>& t, ::std::ostream* os) {
524 template <
typename T1,
typename T2,
typename T3,
typename T4,
typename T5>
525 void PrintTo(const ::std::tr1::tuple<T1, T2, T3, T4, T5>& t,
526 ::std::ostream* os) {
530 template <
typename T1,
typename T2,
typename T3,
typename T4,
typename T5,
532 void PrintTo(const ::std::tr1::tuple<T1, T2, T3, T4, T5, T6>& t,
533 ::std::ostream* os) {
537 template <
typename T1,
typename T2,
typename T3,
typename T4,
typename T5,
538 typename T6,
typename T7>
539 void PrintTo(const ::std::tr1::tuple<T1, T2, T3, T4, T5, T6, T7>& t,
540 ::std::ostream* os) {
544 template <
typename T1,
typename T2,
typename T3,
typename T4,
typename T5,
545 typename T6,
typename T7,
typename T8>
546 void PrintTo(const ::std::tr1::tuple<T1, T2, T3, T4, T5, T6, T7, T8>& t,
547 ::std::ostream* os) {
551 template <
typename T1,
typename T2,
typename T3,
typename T4,
typename T5,
552 typename T6,
typename T7,
typename T8,
typename T9>
553 void PrintTo(const ::std::tr1::tuple<T1, T2, T3, T4, T5, T6, T7, T8, T9>& t,
554 ::std::ostream* os) {
558 template <
typename T1,
typename T2,
typename T3,
typename T4,
typename T5,
559 typename T6,
typename T7,
typename T8,
typename T9,
typename T10>
561 const ::std::tr1::tuple<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>& t,
562 ::std::ostream* os) {
565 #endif // GTEST_HAS_TR1_TUPLE
568 template <
typename T1,
typename T2>
569 void PrintTo(const ::std::pair<T1, T2>& value, ::std::ostream* os) {
581 template <
typename T>
582 class UniversalPrinter {
587 # pragma warning(push) // Saves the current warning state.
588 # pragma warning(disable:4180) // Temporarily disables warning 4180.
594 static void Print(
const T& value, ::std::ostream* os) {
607 # pragma warning(pop) // Restores the warning state.
613 template <
typename T>
619 const size_t kThreshold = 18;
620 const size_t kChunkSize = 8;
625 if (len <= kThreshold) {
637 const char* begin,
size_t len, ::std::ostream* os);
641 const wchar_t* begin,
size_t len, ::std::ostream* os);
644 template <
typename T,
size_t N>
649 static void Print(
const T (&a)[N], ::std::ostream* os) {
655 template <
typename T>
661 # pragma warning(push) // Saves the current warning state.
662 # pragma warning(disable:4180) // Temporarily disables warning 4180.
665 static void Print(
const T& value, ::std::ostream* os) {
668 *os <<
"@" <<
reinterpret_cast<const void*
>(&value) <<
" ";
675 # pragma warning(pop) // Restores the warning state.
683 template <
typename T>
686 static void Print(
const T& value, ::std::ostream* os) {
690 template <
typename T>
693 static void Print(
const T& value, ::std::ostream* os) {
697 template <
typename T,
size_t N>
700 static void Print(
const T (&value)[N], ::std::ostream* os) {
707 static void Print(
const char* str, ::std::ostream* os) {
718 static void Print(
char* str, ::std::ostream* os) {
723 #if GTEST_HAS_STD_WSTRING
725 class UniversalTersePrinter<const wchar_t*> {
727 static void Print(
const wchar_t* str, ::std::ostream* os) {
740 static void Print(
wchar_t* str, ::std::ostream* os) {
745 template <
typename T>
754 template <
typename T>
762 #if GTEST_HAS_TR1_TUPLE
763 typedef ::std::vector<string> Strings;
774 struct TuplePrefixPrinter {
776 template <
typename Tuple>
777 static void PrintPrefixTo(
const Tuple& t, ::std::ostream* os) {
778 TuplePrefixPrinter<N - 1>::PrintPrefixTo(t, os);
780 UniversalPrinter<typename ::std::tr1::tuple_element<N - 1, Tuple>::type>
781 ::Print(::std::tr1::get<N - 1>(t), os);
786 template <
typename Tuple>
787 static void TersePrintPrefixToStrings(
const Tuple& t, Strings* strings) {
788 TuplePrefixPrinter<N - 1>::TersePrintPrefixToStrings(t, strings);
789 ::std::stringstream ss;
791 strings->push_back(ss.str());
797 struct TuplePrefixPrinter<0> {
798 template <
typename Tuple>
799 static void PrintPrefixTo(
const Tuple&, ::std::ostream*) {}
801 template <
typename Tuple>
802 static void TersePrintPrefixToStrings(
const Tuple&, Strings*) {}
810 struct TuplePrefixPrinter<1> {
811 template <
typename Tuple>
812 static void PrintPrefixTo(
const Tuple& t, ::std::ostream* os) {
813 UniversalPrinter<typename ::std::tr1::tuple_element<0, Tuple>::type>::
814 Print(::std::tr1::get<0>(t), os);
817 template <
typename Tuple>
818 static void TersePrintPrefixToStrings(
const Tuple& t, Strings* strings) {
819 ::std::stringstream ss;
821 strings->push_back(ss.str());
827 template <
typename T>
828 void PrintTupleTo(
const T& t, ::std::ostream* os) {
830 TuplePrefixPrinter< ::std::tr1::tuple_size<T>::value>::
831 PrintPrefixTo(t, os);
838 template <
typename Tuple>
839 Strings UniversalTersePrintTupleFieldsToStrings(
const Tuple& value) {
841 TuplePrefixPrinter< ::std::tr1::tuple_size<Tuple>::value>::
842 TersePrintPrefixToStrings(value, &result);
845 #endif // GTEST_HAS_TR1_TUPLE
849 template <
typename T>
851 ::std::stringstream ss;
858 #endif // GTEST_INCLUDE_GTEST_GTEST_PRINTERS_H_