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" 110 namespace internal2 {
114 GTEST_API_
void PrintBytesInObjectTo(
const unsigned char* obj_bytes,
122 kConvertibleToInteger,
131 template <
typename T, TypeKind kTypeKind>
132 class TypeWithoutFormatter {
135 static void PrintValue(
const T& value, ::std::ostream* os) {
136 PrintBytesInObjectTo(reinterpret_cast<const unsigned char*>(&value),
144 const size_t kProtobufOneLinerMaxLength = 50;
146 template <
typename T>
147 class TypeWithoutFormatter<
T, kProtobuf> {
149 static void PrintValue(
const T& value, ::std::ostream* os) {
150 const ::testing::internal::string short_str = value.ShortDebugString();
151 const ::testing::internal::string pretty_str =
152 short_str.length() <= kProtobufOneLinerMaxLength ?
153 short_str : (
"\n" + value.DebugString());
154 *os << (
"<" + pretty_str +
">");
158 template <
typename T>
159 class TypeWithoutFormatter<
T, kConvertibleToInteger> {
168 static void PrintValue(
const T& value, ::std::ostream* os) {
169 const internal::BiggestInt kBigInt = value;
198 template <
typename Char,
typename CharTraits,
typename T>
199 ::std::basic_ostream<Char, CharTraits>& operator<<(
200 ::std::basic_ostream<Char, CharTraits>& os,
const T& x) {
201 TypeWithoutFormatter<
T,
202 (internal::IsAProtocolMessage<T>::value ? kProtobuf :
203 internal::ImplicitlyConvertible<const T&, internal::BiggestInt>::value ?
204 kConvertibleToInteger : kOtherType)>::PrintValue(x, &os);
217 template <
typename T>
218 void DefaultPrintNonContainerTo(
const T& value, ::std::ostream* os) {
260 template <
typename T>
261 class UniversalPrinter;
263 template <
typename T>
264 void UniversalPrint(
const T& value, ::std::ostream* os);
268 template <
typename C>
269 void DefaultPrintTo(IsContainer ,
271 const C&
container, ::std::ostream* os) {
272 const size_t kMaxCount = 32;
275 for (
typename C::const_iterator it = container.begin();
276 it != container.end(); ++it, ++count) {
279 if (count == kMaxCount) {
287 internal::UniversalPrint(*it, os);
302 template <
typename T>
303 void DefaultPrintTo(IsNotContainer ,
305 T* p, ::std::ostream* os) {
314 if (IsTrue(ImplicitlyConvertible<T*, const void*>::value)) {
326 *os << reinterpret_cast<const void*>(
327 reinterpret_cast<internal::UInt64
>(p));
334 template <
typename T>
335 void DefaultPrintTo(IsNotContainer ,
337 const T& value, ::std::ostream* os) {
338 ::testing_internal::DefaultPrintNonContainerTo(value, os);
352 template <
typename T>
353 void PrintTo(
const T& value, ::std::ostream* os) {
376 DefaultPrintTo(IsContainerTest<T>(0), is_pointer<T>(), value, os);
384 GTEST_API_
void PrintTo(
unsigned char c, ::std::ostream* os);
385 GTEST_API_
void PrintTo(
signed char c, ::std::ostream* os);
386 inline void PrintTo(
char c, ::std::ostream* os) {
390 PrintTo(static_cast<unsigned char>(c), os);
394 inline void PrintTo(
bool x, ::std::ostream* os) {
395 *os << (x ?
"true" :
"false");
405 GTEST_API_
void PrintTo(
wchar_t wc, ::std::ostream* os);
408 GTEST_API_
void PrintTo(
const char* s, ::std::ostream* os);
409 inline void PrintTo(
char* s, ::std::ostream* os) {
410 PrintTo(ImplicitCast_<const char*>(s), os);
415 inline void PrintTo(
const signed char* s, ::std::ostream* os) {
416 PrintTo(ImplicitCast_<const void*>(s), os);
418 inline void PrintTo(
signed char* s, ::std::ostream* os) {
419 PrintTo(ImplicitCast_<const void*>(s), os);
421 inline void PrintTo(
const unsigned char* s, ::std::ostream* os) {
422 PrintTo(ImplicitCast_<const void*>(s), os);
424 inline void PrintTo(
unsigned char* s, ::std::ostream* os) {
425 PrintTo(ImplicitCast_<const void*>(s), os);
433 #if !defined(_MSC_VER) || defined(_NATIVE_WCHAR_T_DEFINED) 435 GTEST_API_
void PrintTo(
const wchar_t* s, ::std::ostream* os);
436 inline void PrintTo(
wchar_t* s, ::std::ostream* os) {
437 PrintTo(ImplicitCast_<const wchar_t*>(s), os);
446 template <
typename T>
447 void PrintRawArrayTo(
const T a[],
size_t count, ::std::ostream* os) {
448 UniversalPrint(a[0], os);
449 for (
size_t i = 1; i != count; i++) {
451 UniversalPrint(a[i], os);
456 #if GTEST_HAS_GLOBAL_STRING 457 GTEST_API_
void PrintStringTo(const ::string&s, ::std::ostream* os);
458 inline void PrintTo(const ::string& s, ::std::ostream* os) {
459 PrintStringTo(s, os);
461 #endif // GTEST_HAS_GLOBAL_STRING 463 GTEST_API_
void PrintStringTo(const ::std::string&s, ::std::ostream* os);
464 inline void PrintTo(const ::std::string& s, ::std::ostream* os) {
465 PrintStringTo(s, os);
469 #if GTEST_HAS_GLOBAL_WSTRING 470 GTEST_API_
void PrintWideStringTo(const ::wstring&s, ::std::ostream* os);
471 inline void PrintTo(const ::wstring& s, ::std::ostream* os) {
472 PrintWideStringTo(s, os);
474 #endif // GTEST_HAS_GLOBAL_WSTRING 476 #if GTEST_HAS_STD_WSTRING 477 GTEST_API_
void PrintWideStringTo(const ::std::wstring&s, ::std::ostream* os);
478 inline void PrintTo(const ::std::wstring& s, ::std::ostream* os) {
479 PrintWideStringTo(s, os);
481 #endif // GTEST_HAS_STD_WSTRING 483 #if GTEST_HAS_TR1_TUPLE 489 template <
typename T>
490 void PrintTupleTo(
const T& t, ::std::ostream* os);
497 inline void PrintTo(const ::std::tr1::tuple<>& t, ::std::ostream* os) {
501 template <
typename T1>
502 void PrintTo(const ::std::tr1::tuple<T1>& t, ::std::ostream* os) {
506 template <
typename T1,
typename T2>
507 void PrintTo(const ::std::tr1::tuple<T1, T2>& t, ::std::ostream* os) {
511 template <
typename T1,
typename T2,
typename T3>
512 void PrintTo(const ::std::tr1::tuple<T1, T2, T3>& t, ::std::ostream* os) {
516 template <
typename T1,
typename T2,
typename T3,
typename T4>
517 void PrintTo(const ::std::tr1::tuple<T1, T2, T3, T4>& t, ::std::ostream* os) {
521 template <
typename T1,
typename T2,
typename T3,
typename T4,
typename T5>
522 void PrintTo(const ::std::tr1::tuple<T1, T2, T3, T4, T5>& t,
523 ::std::ostream* os) {
527 template <
typename T1,
typename T2,
typename T3,
typename T4,
typename T5,
529 void PrintTo(const ::std::tr1::tuple<T1, T2, T3, T4, T5, T6>& t,
530 ::std::ostream* os) {
534 template <
typename T1,
typename T2,
typename T3,
typename T4,
typename T5,
535 typename T6,
typename T7>
536 void PrintTo(const ::std::tr1::tuple<T1, T2, T3, T4, T5, T6, T7>& t,
537 ::std::ostream* os) {
541 template <
typename T1,
typename T2,
typename T3,
typename T4,
typename T5,
542 typename T6,
typename T7,
typename T8>
543 void PrintTo(const ::std::tr1::tuple<T1, T2, T3, T4, T5, T6, T7, T8>& t,
544 ::std::ostream* os) {
548 template <
typename T1,
typename T2,
typename T3,
typename T4,
typename T5,
549 typename T6,
typename T7,
typename T8,
typename T9>
550 void PrintTo(const ::std::tr1::tuple<T1, T2, T3, T4, T5, T6, T7, T8, T9>& t,
551 ::std::ostream* os) {
555 template <
typename T1,
typename T2,
typename T3,
typename T4,
typename T5,
556 typename T6,
typename T7,
typename T8,
typename T9,
typename T10>
558 const ::std::tr1::tuple<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>& t,
559 ::std::ostream* os) {
562 #endif // GTEST_HAS_TR1_TUPLE 565 template <
typename T1,
typename T2>
566 void PrintTo(const ::std::pair<T1, T2>& value, ::std::ostream* os) {
570 UniversalPrinter<T1>::Print(value.first, os);
572 UniversalPrinter<T2>::Print(value.second, os);
578 template <
typename T>
579 class UniversalPrinter {
584 # pragma warning(push) // Saves the current warning state. 585 # pragma warning(disable:4180) // Temporarily disables warning 4180. 591 static void Print(
const T& value, ::std::ostream* os) {
604 # pragma warning(pop) // Restores the warning state. 610 template <
typename T>
611 void UniversalPrintArray(
const T* begin,
size_t len, ::std::ostream* os) {
616 const size_t kThreshold = 18;
617 const size_t kChunkSize = 8;
622 if (len <= kThreshold) {
623 PrintRawArrayTo(begin, len, os);
625 PrintRawArrayTo(begin, kChunkSize, os);
627 PrintRawArrayTo(begin + len - kChunkSize, kChunkSize, os);
633 GTEST_API_
void UniversalPrintArray(
634 const char* begin,
size_t len, ::std::ostream* os);
637 GTEST_API_
void UniversalPrintArray(
638 const wchar_t* begin,
size_t len, ::std::ostream* os);
641 template <
typename T,
size_t N>
642 class UniversalPrinter<
T[N]> {
646 static void Print(
const T (&a)[N], ::std::ostream* os) {
647 UniversalPrintArray(a, N, os);
652 template <
typename T>
653 class UniversalPrinter<
T&> {
658 # pragma warning(push) // Saves the current warning state. 659 # pragma warning(disable:4180) // Temporarily disables warning 4180. 662 static void Print(
const T& value, ::std::ostream* os) {
665 *os <<
"@" <<
reinterpret_cast<const void*
>(&value) <<
" ";
668 UniversalPrint(value, os);
672 # pragma warning(pop) // Restores the warning state. 680 template <
typename T>
681 class UniversalTersePrinter {
683 static void Print(
const T& value, ::std::ostream* os) {
684 UniversalPrint(value, os);
687 template <
typename T>
688 class UniversalTersePrinter<
T&> {
690 static void Print(
const T& value, ::std::ostream* os) {
691 UniversalPrint(value, os);
694 template <
typename T,
size_t N>
695 class UniversalTersePrinter<
T[N]> {
697 static void Print(
const T (&value)[N], ::std::ostream* os) {
698 UniversalPrinter<T[N]>::Print(value, os);
702 class UniversalTersePrinter<const char*> {
704 static void Print(
const char* str, ::std::ostream* os) {
708 UniversalPrint(
string(str), os);
713 class UniversalTersePrinter<char*> {
715 static void Print(
char* str, ::std::ostream* os) {
716 UniversalTersePrinter<const char*>::Print(str, os);
720 #if GTEST_HAS_STD_WSTRING 722 class UniversalTersePrinter<const wchar_t*> {
724 static void Print(
const wchar_t* str, ::std::ostream* os) {
728 UniversalPrint(::std::wstring(str), os);
735 class UniversalTersePrinter<wchar_t*> {
737 static void Print(
wchar_t* str, ::std::ostream* os) {
738 UniversalTersePrinter<const wchar_t*>::Print(str, os);
742 template <
typename T>
743 void UniversalTersePrint(
const T& value, ::std::ostream* os) {
744 UniversalTersePrinter<T>::Print(value, os);
751 template <
typename T>
752 void UniversalPrint(
const T& value, ::std::ostream* os) {
756 UniversalPrinter<T1>::Print(value, os);
759 #if GTEST_HAS_TR1_TUPLE 760 typedef ::std::vector<string> Strings;
771 struct TuplePrefixPrinter {
773 template <
typename Tuple>
774 static void PrintPrefixTo(
const Tuple& t, ::std::ostream* os) {
775 TuplePrefixPrinter<N - 1>::PrintPrefixTo(t, os);
777 UniversalPrinter<typename ::std::tr1::tuple_element<N - 1, Tuple>::type>
778 ::Print(::std::tr1::get<N - 1>(t), os);
783 template <
typename Tuple>
784 static void TersePrintPrefixToStrings(
const Tuple& t, Strings* strings) {
785 TuplePrefixPrinter<N - 1>::TersePrintPrefixToStrings(t, strings);
786 ::std::stringstream ss;
787 UniversalTersePrint(::std::tr1::get<N - 1>(t), &ss);
788 strings->push_back(ss.str());
794 struct TuplePrefixPrinter<0> {
795 template <
typename Tuple>
796 static void PrintPrefixTo(
const Tuple&, ::std::ostream*) {}
798 template <
typename Tuple>
799 static void TersePrintPrefixToStrings(
const Tuple&, Strings*) {}
807 struct TuplePrefixPrinter<1> {
808 template <
typename Tuple>
809 static void PrintPrefixTo(
const Tuple& t, ::std::ostream* os) {
810 UniversalPrinter<typename ::std::tr1::tuple_element<0, Tuple>::type>::
811 Print(::std::tr1::get<0>(t), os);
814 template <
typename Tuple>
815 static void TersePrintPrefixToStrings(
const Tuple& t, Strings* strings) {
816 ::std::stringstream ss;
817 UniversalTersePrint(::std::tr1::get<0>(t), &ss);
818 strings->push_back(ss.str());
824 template <
typename T>
825 void PrintTupleTo(
const T& t, ::std::ostream* os) {
827 TuplePrefixPrinter< ::std::tr1::tuple_size<T>::value>::
828 PrintPrefixTo(t, os);
835 template <
typename Tuple>
836 Strings UniversalTersePrintTupleFieldsToStrings(
const Tuple& value) {
838 TuplePrefixPrinter< ::std::tr1::tuple_size<Tuple>::value>::
839 TersePrintPrefixToStrings(value, &result);
842 #endif // GTEST_HAS_TR1_TUPLE 846 template <
typename T>
847 ::std::string PrintToString(
const T& value) {
848 ::std::stringstream ss;
849 internal::UniversalTersePrinter<T>::Print(value, &ss);
855 #endif // GTEST_INCLUDE_GTEST_GTEST_PRINTERS_H_ Definition: gtest-all.cc:113
A small structure to hold a non zero as a triplet (i,j,value).
Definition: SparseUtil.h:148
Definition: BandTriangularSolver.h:13
Definition: gtest-all.cc:9116
A "Unique Container" designed for composition, not inheritance.
Definition: UniqueContainer.h:327