Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef BASE_LOGGING_H_ | 5 #ifndef BASE_LOGGING_H_ |
| 6 #define BASE_LOGGING_H_ | 6 #define BASE_LOGGING_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <cassert> | 10 #include <cassert> |
| 11 #include <cstring> | 11 #include <cstring> |
| 12 #include <sstream> | 12 #include <sstream> |
| 13 #include <string> | 13 #include <string> |
| 14 #include <type_traits> | |
| 15 #include <utility> | |
| 14 | 16 |
| 15 #include "base/base_export.h" | 17 #include "base/base_export.h" |
| 16 #include "base/debug/debugger.h" | 18 #include "base/debug/debugger.h" |
| 17 #include "base/macros.h" | 19 #include "base/macros.h" |
| 20 #include "base/template_util.h" | |
| 18 #include "build/build_config.h" | 21 #include "build/build_config.h" |
| 19 | 22 |
| 20 // | 23 // |
| 21 // Optional message capabilities | 24 // Optional message capabilities |
| 22 // ----------------------------- | 25 // ----------------------------- |
| 23 // Assertion failed messages and fatal errors are displayed in a dialog box | 26 // Assertion failed messages and fatal errors are displayed in a dialog box |
| 24 // before the application exits. However, running this UI creates a message | 27 // before the application exits. However, running this UI creates a message |
| 25 // loop, which causes application messages to be processed and potentially | 28 // loop, which causes application messages to be processed and potentially |
| 26 // dispatched to existing application windows. Since the application is in a | 29 // dispatched to existing application windows. Since the application is in a |
| 27 // bad state when this assertion dialog is displayed, these messages may not | 30 // bad state when this assertion dialog is displayed, these messages may not |
| (...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 515 #val1 " " #op " " #val2)) \ | 518 #val1 " " #op " " #val2)) \ |
| 516 ; \ | 519 ; \ |
| 517 else \ | 520 else \ |
| 518 logging::LogMessage(__FILE__, __LINE__, true_if_passed.message()).stream() | 521 logging::LogMessage(__FILE__, __LINE__, true_if_passed.message()).stream() |
| 519 | 522 |
| 520 #endif // !(OFFICIAL_BUILD && NDEBUG) | 523 #endif // !(OFFICIAL_BUILD && NDEBUG) |
| 521 | 524 |
| 522 // This formats a value for a failing CHECK_XX statement. Ordinarily, | 525 // This formats a value for a failing CHECK_XX statement. Ordinarily, |
| 523 // it uses the definition for operator<<, with a few special cases below. | 526 // it uses the definition for operator<<, with a few special cases below. |
| 524 template <typename T> | 527 template <typename T> |
| 525 inline void MakeCheckOpValueString(std::ostream* os, const T& v) { | 528 inline typename std::enable_if< |
| 529 base::internal::SupportsOstreamOperator<const T&>::value, | |
| 530 void>::type | |
| 531 MakeCheckOpValueString(std::ostream* os, const T& v) { | |
| 526 (*os) << v; | 532 (*os) << v; |
| 527 } | 533 } |
| 528 | 534 |
| 529 // We need an explicit specialization for std::nullptr_t. | 535 // We need overloads for enums that don't support operator<<. |
| 530 template <> | 536 // (i.e. scoped enums where no operator<< overload was declared). |
| 531 BASE_EXPORT void MakeCheckOpValueString(std::ostream* os, | 537 template <typename T> |
| 532 const std::nullptr_t& p); | 538 inline typename std::enable_if< |
| 539 !base::internal::SupportsOstreamOperator<const T&>::value && | |
| 540 std::is_enum<T>::value, | |
| 541 void>::type | |
| 542 MakeCheckOpValueString(std::ostream* os, const T& v) { | |
| 543 (*os) << static_cast<typename base::underlying_type<T>::type>(v); | |
| 544 } | |
| 545 | |
| 546 // We need an explicit overload for std::nullptr_t. | |
| 547 BASE_EXPORT void MakeCheckOpValueString(std::ostream* os, std::nullptr_t p); | |
| 533 | 548 |
| 534 // Build the error message string. This is separate from the "Impl" | 549 // Build the error message string. This is separate from the "Impl" |
| 535 // function template because it is not performance critical and so can | 550 // function template because it is not performance critical and so can |
| 536 // be out of line, while the "Impl" code should be inline. Caller | 551 // be out of line, while the "Impl" code should be inline. Caller |
| 537 // takes ownership of the returned string. | 552 // takes ownership of the returned string. |
| 538 template<class t1, class t2> | 553 template<class t1, class t2> |
| 539 std::string* MakeCheckOpString(const t1& v1, const t2& v2, const char* names) { | 554 std::string* MakeCheckOpString(const t1& v1, const t2& v2, const char* names) { |
| 540 std::ostringstream ss; | 555 std::ostringstream ss; |
| 541 ss << names << " ("; | 556 ss << names << " ("; |
| 542 MakeCheckOpValueString(&ss, v1); | 557 MakeCheckOpValueString(&ss, v1); |
| 543 ss << " vs. "; | 558 ss << " vs. "; |
| 544 MakeCheckOpValueString(&ss, v2); | 559 MakeCheckOpValueString(&ss, v2); |
| 545 ss << ")"; | 560 ss << ")"; |
| 546 std::string* msg = new std::string(ss.str()); | 561 std::string* msg = new std::string(ss.str()); |
| 547 return msg; | 562 return msg; |
| 548 } | 563 } |
| 549 | 564 |
| 550 // Commonly used instantiations of MakeCheckOpString<>. Explicitly instantiated | 565 // Commonly used instantiations of MakeCheckOpString<>. Explicitly instantiated |
| 551 // in logging.cc. | 566 // in logging.cc. |
|
Nico
2016/05/26 00:44:55
Hm, this will never fire for enum classes since th
| |
| 552 extern template BASE_EXPORT std::string* MakeCheckOpString<int, int>( | 567 extern template BASE_EXPORT std::string* MakeCheckOpString<int, int>( |
| 553 const int&, const int&, const char* names); | 568 const int&, const int&, const char* names); |
| 554 extern template BASE_EXPORT | 569 extern template BASE_EXPORT |
| 555 std::string* MakeCheckOpString<unsigned long, unsigned long>( | 570 std::string* MakeCheckOpString<unsigned long, unsigned long>( |
| 556 const unsigned long&, const unsigned long&, const char* names); | 571 const unsigned long&, const unsigned long&, const char* names); |
| 557 extern template BASE_EXPORT | 572 extern template BASE_EXPORT |
| 558 std::string* MakeCheckOpString<unsigned long, unsigned int>( | 573 std::string* MakeCheckOpString<unsigned long, unsigned int>( |
| 559 const unsigned long&, const unsigned int&, const char* names); | 574 const unsigned long&, const unsigned int&, const char* names); |
| 560 extern template BASE_EXPORT | 575 extern template BASE_EXPORT |
| 561 std::string* MakeCheckOpString<unsigned int, unsigned long>( | 576 std::string* MakeCheckOpString<unsigned int, unsigned long>( |
| (...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 979 #elif NOTIMPLEMENTED_POLICY == 5 | 994 #elif NOTIMPLEMENTED_POLICY == 5 |
| 980 #define NOTIMPLEMENTED() do {\ | 995 #define NOTIMPLEMENTED() do {\ |
| 981 static bool logged_once = false;\ | 996 static bool logged_once = false;\ |
| 982 LOG_IF(ERROR, !logged_once) << NOTIMPLEMENTED_MSG;\ | 997 LOG_IF(ERROR, !logged_once) << NOTIMPLEMENTED_MSG;\ |
| 983 logged_once = true;\ | 998 logged_once = true;\ |
| 984 } while(0);\ | 999 } while(0);\ |
| 985 EAT_STREAM_PARAMETERS | 1000 EAT_STREAM_PARAMETERS |
| 986 #endif | 1001 #endif |
| 987 | 1002 |
| 988 #endif // BASE_LOGGING_H_ | 1003 #endif // BASE_LOGGING_H_ |
| OLD | NEW |