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 <cassert> | 8 #include <cassert> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <cstring> | 10 #include <cstring> |
| 11 #include <sstream> | 11 #include <sstream> |
| 12 #include <type_traits> | |
| 12 | 13 |
| 13 #include "base/base_export.h" | 14 #include "base/base_export.h" |
| 14 #include "base/basictypes.h" | 15 #include "base/basictypes.h" |
| 15 #include "base/debug/debugger.h" | 16 #include "base/debug/debugger.h" |
| 16 #include "build/build_config.h" | 17 #include "build/build_config.h" |
| 17 | 18 |
| 18 // | 19 // |
| 19 // Optional message capabilities | 20 // Optional message capabilities |
| 20 // ----------------------------- | 21 // ----------------------------- |
| 21 // Assertion failed messages and fatal errors are displayed in a dialog box | 22 // Assertion failed messages and fatal errors are displayed in a dialog box |
| (...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 506 switch (0) case 0: default: \ | 507 switch (0) case 0: default: \ |
| 507 if (logging::CheckOpResult true_if_passed = \ | 508 if (logging::CheckOpResult true_if_passed = \ |
| 508 logging::Check##name##Impl((val1), (val2), \ | 509 logging::Check##name##Impl((val1), (val2), \ |
| 509 #val1 " " #op " " #val2)) \ | 510 #val1 " " #op " " #val2)) \ |
| 510 ; \ | 511 ; \ |
| 511 else \ | 512 else \ |
| 512 logging::LogMessage(__FILE__, __LINE__, true_if_passed.message()).stream() | 513 logging::LogMessage(__FILE__, __LINE__, true_if_passed.message()).stream() |
| 513 | 514 |
| 514 #endif | 515 #endif |
| 515 | 516 |
| 517 namespace internal { | |
| 518 // Type trait helper to detect scoped enums. | |
|
danakj
2015/11/20 21:33:58
Can you add comments here about how unscoped enums
dcheng
2015/11/23 18:42:13
Done.
| |
| 519 template <typename T> | |
| 520 using is_scoped_enum = | |
| 521 std::integral_constant<bool, | |
| 522 std::is_enum<T>::value && | |
| 523 !std::is_convertible<T, int>::value>; | |
| 524 } // namespace internal | |
| 525 | |
| 526 template <class T, | |
| 527 typename std::enable_if<internal::is_scoped_enum<T>::value && | |
| 528 std::is_signed<T>::value>::type* = nullptr> | |
| 529 std::ostream& operator<<(std::ostream& os, T v) { | |
| 530 os << static_cast<intmax_t>(v); | |
|
danakj
2015/11/20 21:33:58
can you mention underlying_type with a TODO here a
dcheng
2015/11/23 18:42:13
Done (though I just made it a top-level comment ab
| |
| 531 return os; | |
| 532 } | |
| 533 | |
| 534 template <class T, | |
| 535 typename std::enable_if<internal::is_scoped_enum<T>::value && | |
| 536 !std::is_signed<T>::value>::type* = nullptr> | |
| 537 std::ostream& operator<<(std::ostream& os, T v) { | |
| 538 os << static_cast<uintmax_t>(v); | |
| 539 return os; | |
| 540 } | |
| 541 | |
| 516 // Build the error message string. This is separate from the "Impl" | 542 // Build the error message string. This is separate from the "Impl" |
| 517 // function template because it is not performance critical and so can | 543 // function template because it is not performance critical and so can |
| 518 // be out of line, while the "Impl" code should be inline. Caller | 544 // be out of line, while the "Impl" code should be inline. Caller |
| 519 // takes ownership of the returned string. | 545 // takes ownership of the returned string. |
| 520 template<class t1, class t2> | 546 template <class T1, class T2> |
| 521 std::string* MakeCheckOpString(const t1& v1, const t2& v2, const char* names) { | 547 std::string* MakeCheckOpString(const T1& v1, const T2& v2, const char* names) { |
| 522 std::ostringstream ss; | 548 std::ostringstream ss; |
| 523 ss << names << " (" << v1 << " vs. " << v2 << ")"; | 549 ss << names << " (" << v1 << " vs. " << v2 << ")"; |
| 524 std::string* msg = new std::string(ss.str()); | 550 std::string* msg = new std::string(ss.str()); |
| 525 return msg; | 551 return msg; |
| 526 } | 552 } |
| 527 | 553 |
| 528 // Commonly used instantiations of MakeCheckOpString<>. Explicitly instantiated | 554 // Commonly used instantiations of MakeCheckOpString<>. Explicitly instantiated |
| 529 // in logging.cc. | 555 // in logging.cc. |
| 530 extern template BASE_EXPORT std::string* MakeCheckOpString<int, int>( | 556 extern template BASE_EXPORT std::string* MakeCheckOpString<int, int>( |
| 531 const int&, const int&, const char* names); | 557 const int&, const int&, const char* names); |
| (...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 962 #elif NOTIMPLEMENTED_POLICY == 5 | 988 #elif NOTIMPLEMENTED_POLICY == 5 |
| 963 #define NOTIMPLEMENTED() do {\ | 989 #define NOTIMPLEMENTED() do {\ |
| 964 static bool logged_once = false;\ | 990 static bool logged_once = false;\ |
| 965 LOG_IF(ERROR, !logged_once) << NOTIMPLEMENTED_MSG;\ | 991 LOG_IF(ERROR, !logged_once) << NOTIMPLEMENTED_MSG;\ |
| 966 logged_once = true;\ | 992 logged_once = true;\ |
| 967 } while(0);\ | 993 } while(0);\ |
| 968 EAT_STREAM_PARAMETERS | 994 EAT_STREAM_PARAMETERS |
| 969 #endif | 995 #endif |
| 970 | 996 |
| 971 #endif // BASE_LOGGING_H_ | 997 #endif // BASE_LOGGING_H_ |
| OLD | NEW |