95 #ifndef GTEST_INCLUDE_GTEST_GTEST_PRINTERS_H_ 96 #define GTEST_INCLUDE_GTEST_GTEST_PRINTERS_H_ 103 #include "gtest/internal/gtest-port.h" 104 #include "gtest/internal/gtest-internal.h" 118 ::std::ostream * os);
134 template <
typename T, TypeKind kTypeKind>
151 template <
typename T>
159 short_str.length() <= kProtobufOneLinerMaxLength ?
160 short_str : (
"\n" + value.DebugString());
161 *os << (
"<" + pretty_str +
">");
165 template <
typename T>
207 template <
typename Char,
typename CharTraits,
typename T>
208 ::std::basic_ostream<Char, CharTraits> &
operator<<(
209 ::std::basic_ostream<Char, CharTraits> & os,
const T & x)
228 template <
typename T>
274 template <
typename T>
275 class UniversalPrinter;
277 template <
typename T>
282 template <
typename C>
285 const C & container, ::std::ostream * os)
287 const size_t kMaxCount = 32;
291 for (
typename C::const_iterator it = container.begin();
292 it != container.end(); ++it, ++
count)
298 if (count == kMaxCount)
325 template <
typename T>
328 T * p, ::std::ostream * os)
342 if (
IsTrue(ImplicitlyConvertible<T *, const void *>::value))
358 *os << reinterpret_cast<const void *>(
366 template <
typename T>
369 const T & value, ::std::ostream * os)
385 template <
typename T>
386 void PrintTo(
const T & value, ::std::ostream * os)
410 DefaultPrintTo(IsContainerTest<T>(0), is_pointer<T>(), value, os);
420 inline void PrintTo(
char c, ::std::ostream * os)
425 PrintTo(static_cast<unsigned char>(c), os);
429 inline void PrintTo(
bool x, ::std::ostream * os)
431 *os << (x ?
"true" :
"false");
445 inline void PrintTo(
char * s, ::std::ostream * os)
447 PrintTo(ImplicitCast_<const char *>(s), os);
452 inline void PrintTo(
const signed char * s, ::std::ostream * os)
454 PrintTo(ImplicitCast_<const void *>(s), os);
456 inline void PrintTo(
signed char * s, ::std::ostream * os)
458 PrintTo(ImplicitCast_<const void *>(s), os);
460 inline void PrintTo(
const unsigned char * s, ::std::ostream * os)
462 PrintTo(ImplicitCast_<const void *>(s), os);
464 inline void PrintTo(
unsigned char * s, ::std::ostream * os)
466 PrintTo(ImplicitCast_<const void *>(s), os);
474 #if !defined(_MSC_VER) || defined(_NATIVE_WCHAR_T_DEFINED) 477 inline void PrintTo(
wchar_t * s, ::std::ostream * os)
479 PrintTo(ImplicitCast_<const wchar_t *>(s), os);
488 template <
typename T>
493 for (
size_t i = 1; i !=
count; i++)
501 #if GTEST_HAS_GLOBAL_STRING 507 #endif // GTEST_HAS_GLOBAL_STRING 516 #if GTEST_HAS_GLOBAL_WSTRING 522 #endif // GTEST_HAS_GLOBAL_WSTRING 524 #if GTEST_HAS_STD_WSTRING 530 #endif // GTEST_HAS_STD_WSTRING 532 #if GTEST_HAS_TR1_TUPLE 538 template <
typename T>
546 inline void PrintTo(const ::std::tr1::tuple<> & t, ::std::ostream * os)
551 template <
typename T1>
552 void PrintTo(const ::std::tr1::tuple<T1> & t, ::std::ostream * os)
557 template <
typename T1,
typename T2>
558 void PrintTo(const ::std::tr1::tuple<T1, T2> & t, ::std::ostream * os)
563 template <
typename T1,
typename T2,
typename T3>
564 void PrintTo(const ::std::tr1::tuple<T1, T2, T3> & t, ::std::ostream * os)
569 template <
typename T1,
typename T2,
typename T3,
typename T4>
570 void PrintTo(const ::std::tr1::tuple<T1, T2, T3, T4> & t, ::std::ostream * os)
575 template <
typename T1,
typename T2,
typename T3,
typename T4,
typename T5>
576 void PrintTo(const ::std::tr1::tuple<T1, T2, T3, T4, T5> & t,
582 template <
typename T1,
typename T2,
typename T3,
typename T4,
typename T5,
584 void PrintTo(const ::std::tr1::tuple<T1, T2, T3, T4, T5, T6> & t,
590 template <
typename T1,
typename T2,
typename T3,
typename T4,
typename T5,
591 typename T6,
typename T7>
592 void PrintTo(const ::std::tr1::tuple<T1, T2, T3, T4, T5, T6, T7> & t,
598 template <
typename T1,
typename T2,
typename T3,
typename T4,
typename T5,
599 typename T6,
typename T7,
typename T8>
600 void PrintTo(const ::std::tr1::tuple<T1, T2, T3, T4, T5, T6, T7, T8> & t,
606 template <
typename T1,
typename T2,
typename T3,
typename T4,
typename T5,
607 typename T6,
typename T7,
typename T8,
typename T9>
608 void PrintTo(const ::std::tr1::tuple<T1, T2, T3, T4, T5, T6, T7, T8, T9> & t,
614 template <
typename T1,
typename T2,
typename T3,
typename T4,
typename T5,
615 typename T6,
typename T7,
typename T8,
typename T9,
typename T10>
617 const ::std::tr1::tuple<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> & t,
622 #endif // GTEST_HAS_TR1_TUPLE 625 template <
typename T1,
typename T2>
626 void PrintTo(const ::std::pair<T1, T2> & value, ::std::ostream * os)
639 template <
typename T>
640 class UniversalPrinter
646 # pragma warning(push) // Saves the current warning state. 647 # pragma warning(disable:4180) // Temporarily disables warning 4180. 653 static void Print(
const T & value, ::std::ostream * os)
667 # pragma warning(pop) // Restores the warning state. 673 template <
typename T>
684 const size_t kThreshold = 18;
685 const size_t kChunkSize = 8;
691 if (len <= kThreshold)
708 const char * begin,
size_t len, ::std::ostream * os);
712 const wchar_t * begin,
size_t len, ::std::ostream * os);
715 template <
typename T,
size_t N>
721 static void Print(
const T(&a)[N], ::std::ostream * os)
728 template <
typename T>
735 # pragma warning(push) // Saves the current warning state. 736 # pragma warning(disable:4180) // Temporarily disables warning 4180. 739 static void Print(
const T & value, ::std::ostream * os)
743 *os <<
"@" <<
reinterpret_cast<const void *
>(&value) <<
" ";
750 # pragma warning(pop) // Restores the warning state. 758 template <
typename T>
762 static void Print(
const T & value, ::std::ostream * os)
767 template <
typename T>
771 static void Print(
const T & value, ::std::ostream * os)
776 template <
typename T,
size_t N>
780 static void Print(
const T(&value)[N], ::std::ostream * os)
789 static void Print(
const char * str, ::std::ostream * os)
806 static void Print(
char * str, ::std::ostream * os)
812 #if GTEST_HAS_STD_WSTRING 817 static void Print(
const wchar_t * str, ::std::ostream * os)
836 static void Print(
wchar_t * str, ::std::ostream * os)
842 template <
typename T>
852 template <
typename T>
861 #if GTEST_HAS_TR1_TUPLE 862 typedef ::std::vector<string>
Strings;
876 template <
typename Tuple>
877 static void PrintPrefixTo(
const Tuple & t, ::std::ostream * os)
881 UniversalPrinter < typename ::std::tr1::tuple_element < N - 1, Tuple >::type >
882 ::Print(::std::tr1::get < N - 1 > (t), os);
887 template <
typename Tuple>
888 static void TersePrintPrefixToStrings(
const Tuple & t, Strings * strings)
891 ::std::stringstream ss;
893 strings->push_back(ss.str());
901 template <
typename Tuple>
902 static void PrintPrefixTo(
const Tuple &, ::std::ostream *) {}
904 template <
typename Tuple>
905 static void TersePrintPrefixToStrings(
const Tuple &, Strings *) {}
915 template <
typename Tuple>
916 static void PrintPrefixTo(
const Tuple & t, ::std::ostream * os)
919 Print(::std::tr1::get<0>(t), os);
922 template <
typename Tuple>
923 static void TersePrintPrefixToStrings(
const Tuple & t, Strings * strings)
925 ::std::stringstream ss;
927 strings->push_back(ss.str());
933 template <
typename T>
938 PrintPrefixTo(t, os);
945 template <
typename Tuple>
950 TersePrintPrefixToStrings(value, &result);
953 #endif // GTEST_HAS_TR1_TUPLE 957 template <
typename T>
960 ::std::stringstream ss;
967 #endif // GTEST_INCLUDE_GTEST_GTEST_PRINTERS_H_
static void Print(const T &value,::std::ostream *os)
bool IsTrue(bool condition)
void PrintRawArrayTo(const T a[], size_t count,::std::ostream *os)
static void Print(wchar_t *str,::std::ostream *os)
static void Print(const T &value,::std::ostream *os)
::std::string PrintToString(const T &value)
static void Print(const T(&value)[N],::std::ostream *os)
void UniversalTersePrint(const T &value,::std::ostream *os)
void DefaultPrintNonContainerTo(const T &value,::std::ostream *os)
static void Print(const T(&a)[N],::std::ostream *os)
TypeWithSize< 8 >::UInt UInt64
::std::basic_ostream< Char, CharTraits > & operator<<(::std::basic_ostream< Char, CharTraits > &os, const T &x)
static void Print(const T &value,::std::ostream *os)
void PrintStringTo(const ::std::string &s, ostream *os)
static void Print(const char *str,::std::ostream *os)
bool_constant< true > true_type
const size_t kProtobufOneLinerMaxLength
void PrintBytesInObjectTo(const unsigned char *obj_bytes, size_t count, ostream *os)
string Print(const T &value)
void UniversalPrint(const T &value,::std::ostream *os)
Strings UniversalTersePrintTupleFieldsToStrings(const Tuple &value)
void UniversalPrintArray(const char *begin, size_t len, ostream *os)
static void Print(char *str,::std::ostream *os)
::std::vector< string > Strings
bool_constant< false > false_type
void PrintTupleTo(const T &t,::std::ostream *os)
void PrintWideStringTo(const ::std::wstring &s, ostream *os)
static void Print(const T &value,::std::ostream *os)
void PrintTo(const ReferenceWrapper< T > &ref,::std::ostream *os)
void DefaultPrintTo(IsContainer, false_type, const C &container,::std::ostream *os)