From a106e61178d55c4d3b296c332d3f8c1eb43bcc1e Mon Sep 17 00:00:00 2001 From: Date: Mon, 18 Feb 2013 10:45:46 +0000 Subject: [PATCH] Support unordered_(map|set) by stl_logging git-svn-id: https://google-glog.googlecode.com/svn/trunk@134 eb4d4688-79bd-11dd-afb4-1d65580434c0 --- src/glog/stl_logging.h.in | 45 +++++++++++++++++++++++++++++++--- src/stl_logging_unittest.cc | 21 +++++++++------- src/windows/glog/stl_logging.h | 45 +++++++++++++++++++++++++++++++--- 3 files changed, 94 insertions(+), 17 deletions(-) diff --git a/src/glog/stl_logging.h.in b/src/glog/stl_logging.h.in index 30836de..600945d 100644 --- a/src/glog/stl_logging.h.in +++ b/src/glog/stl_logging.h.in @@ -34,6 +34,15 @@ // LOG(INFO) << "data: " << x; // vector v1, v2; // CHECK_EQ(v1, v2); +// +// If you want to use this header file with hash maps or slist, you +// need to define macros before including this file: +// +// - GLOG_STL_LOGGING_FOR_UNORDERED - and +// - GLOG_STL_LOGGING_FOR_TR1_UNORDERED - +// - GLOG_STL_LOGGING_FOR_EXT_HASH - +// - GLOG_STL_LOGGING_FOR_EXT_SLIST - +// #ifndef UTIL_GTL_STL_LOGGING_INL_H_ #define UTIL_GTL_STL_LOGGING_INL_H_ @@ -50,9 +59,21 @@ #include #include -#ifdef __GNUC__ +#ifdef GLOG_STL_LOGGING_FOR_UNORDERED +# include +# include +#endif + +#ifdef GLOG_STL_LOGGING_FOR_TR1_UNORDERED +# include +# include +#endif + +#ifdef GLOG_STL_LOGGING_FOR_EXT_HASH # include # include +#endif +#ifdef GLOG_STL_LOGGING_FOR_EXT_SLIST # include #endif @@ -80,7 +101,7 @@ inline std::ostream& operator<<(std::ostream& out, \ OUTPUT_TWO_ARG_CONTAINER(std::vector) OUTPUT_TWO_ARG_CONTAINER(std::deque) OUTPUT_TWO_ARG_CONTAINER(std::list) -#ifdef __GNUC__ +#ifdef GLOG_STL_LOGGING_FOR_EXT_SLIST OUTPUT_TWO_ARG_CONTAINER(__gnu_cxx::slist) #endif @@ -109,7 +130,15 @@ inline std::ostream& operator<<(std::ostream& out, \ OUTPUT_FOUR_ARG_CONTAINER(std::map) OUTPUT_FOUR_ARG_CONTAINER(std::multimap) -#ifdef __GNUC__ +#ifdef GLOG_STL_LOGGING_FOR_UNORDERED +OUTPUT_FOUR_ARG_CONTAINER(std::unordered_set) +OUTPUT_FOUR_ARG_CONTAINER(std::unordered_multiset) +#endif +#ifdef GLOG_STL_LOGGING_FOR_TR1_UNORDERED +OUTPUT_FOUR_ARG_CONTAINER(std::tr1::unordered_set) +OUTPUT_FOUR_ARG_CONTAINER(std::tr1::unordered_multiset) +#endif +#ifdef GLOG_STL_LOGGING_FOR_EXT_HASH OUTPUT_FOUR_ARG_CONTAINER(__gnu_cxx::hash_set) OUTPUT_FOUR_ARG_CONTAINER(__gnu_cxx::hash_multiset) #endif @@ -124,7 +153,15 @@ inline std::ostream& operator<<(std::ostream& out, \ return out; \ } -#ifdef __GNUC__ +#ifdef GLOG_STL_LOGGING_FOR_UNORDERED +OUTPUT_FIVE_ARG_CONTAINER(std::unordered_map) +OUTPUT_FIVE_ARG_CONTAINER(std::unordered_multimap) +#endif +#ifdef GLOG_STL_LOGGING_FOR_TR1_UNORDERED +OUTPUT_FIVE_ARG_CONTAINER(std::tr1::unordered_map) +OUTPUT_FIVE_ARG_CONTAINER(std::tr1::unordered_multimap) +#endif +#ifdef GLOG_STL_LOGGING_FOR_EXT_HASH OUTPUT_FIVE_ARG_CONTAINER(__gnu_cxx::hash_map) OUTPUT_FIVE_ARG_CONTAINER(__gnu_cxx::hash_multimap) #endif diff --git a/src/stl_logging_unittest.cc b/src/stl_logging_unittest.cc index 5dcbc44..fcae9ad 100644 --- a/src/stl_logging_unittest.cc +++ b/src/stl_logging_unittest.cc @@ -31,6 +31,14 @@ #ifdef HAVE_USING_OPERATOR +#ifdef __GNUC__ +// C++0x isn't enabled by default. +// # define GLOG_STL_LOGGING_FOR_UNORDERED +# define GLOG_STL_LOGGING_FOR_TR1_UNORDERED +# define GLOG_STL_LOGGING_FOR_EXT_HASH +# define GLOG_STL_LOGGING_FOR_EXT_SLIST +#endif + #include "glog/stl_logging.h" #include @@ -39,16 +47,11 @@ #include #include -#ifdef __GNUC__ -# include -# include -#endif - #include "glog/logging.h" #include "googletest.h" using namespace std; -#ifdef __GNUC__ +#ifdef GLOG_STL_LOGGING_FOR_EXT_HASH using namespace __gnu_cxx; #endif @@ -83,7 +86,7 @@ void TestSTLLogging() { CHECK_EQ(m, copied_m); // This must compile. } -#ifdef __GNUC__ +#ifdef GLOG_STL_LOGGING_FOR_EXT_HASH { // Test a hashed simple associative container. hash_set hs; @@ -98,7 +101,7 @@ void TestSTLLogging() { } #endif -#ifdef __GNUC__ +#ifdef GLOG_STL_LOGGING_FOR_EXT_HASH { // Test a hashed pair associative container. hash_map hm; @@ -145,7 +148,7 @@ void TestSTLLogging() { CHECK_EQ(m, copied_m); // This must compile. } -#ifdef __GNUC__ +#ifdef GLOG_STL_LOGGING_FOR_EXT_HASH { // Test a hashed simple associative container. // Use a user defined hash function. diff --git a/src/windows/glog/stl_logging.h b/src/windows/glog/stl_logging.h index d2e7495..a97a908 100755 --- a/src/windows/glog/stl_logging.h +++ b/src/windows/glog/stl_logging.h @@ -38,6 +38,15 @@ // LOG(INFO) << "data: " << x; // vector v1, v2; // CHECK_EQ(v1, v2); +// +// If you want to use this header file with hash_compare maps or slist, you +// need to define macros before including this file: +// +// - GLOG_STL_LOGGING_FOR_UNORDERED - and +// - GLOG_STL_LOGGING_FOR_TR1_UNORDERED - +// - GLOG_STL_LOGGING_FOR_EXT_HASH - +// - GLOG_STL_LOGGING_FOR_EXT_SLIST - +// #ifndef UTIL_GTL_STL_LOGGING_INL_H_ #define UTIL_GTL_STL_LOGGING_INL_H_ @@ -54,9 +63,21 @@ #include #include -#ifdef __GNUC__ +#ifdef GLOG_STL_LOGGING_FOR_UNORDERED +# include +# include +#endif + +#ifdef GLOG_STL_LOGGING_FOR_TR1_UNORDERED +# include +# include +#endif + +#ifdef GLOG_STL_LOGGING_FOR_EXT_HASH # include # include +#endif +#ifdef GLOG_STL_LOGGING_FOR_EXT_SLIST # include #endif @@ -84,7 +105,7 @@ inline std::ostream& operator<<(std::ostream& out, \ OUTPUT_TWO_ARG_CONTAINER(std::vector) OUTPUT_TWO_ARG_CONTAINER(std::deque) OUTPUT_TWO_ARG_CONTAINER(std::list) -#ifdef __GNUC__ +#ifdef GLOG_STL_LOGGING_FOR_EXT_SLIST OUTPUT_TWO_ARG_CONTAINER(__gnu_cxx::slist) #endif @@ -113,7 +134,15 @@ inline std::ostream& operator<<(std::ostream& out, \ OUTPUT_FOUR_ARG_CONTAINER(std::map) OUTPUT_FOUR_ARG_CONTAINER(std::multimap) -#ifdef __GNUC__ +#ifdef GLOG_STL_LOGGING_FOR_UNORDERED +OUTPUT_FOUR_ARG_CONTAINER(std::unordered_set) +OUTPUT_FOUR_ARG_CONTAINER(std::unordered_multiset) +#endif +#ifdef GLOG_STL_LOGGING_FOR_TR1_UNORDERED +OUTPUT_FOUR_ARG_CONTAINER(std::tr1::unordered_set) +OUTPUT_FOUR_ARG_CONTAINER(std::tr1::unordered_multiset) +#endif +#ifdef GLOG_STL_LOGGING_FOR_EXT_HASH OUTPUT_FOUR_ARG_CONTAINER(__gnu_cxx::hash_set) OUTPUT_FOUR_ARG_CONTAINER(__gnu_cxx::hash_multiset) #endif @@ -128,7 +157,15 @@ inline std::ostream& operator<<(std::ostream& out, \ return out; \ } -#ifdef __GNUC__ +#ifdef GLOG_STL_LOGGING_FOR_UNORDERED +OUTPUT_FIVE_ARG_CONTAINER(std::unordered_map) +OUTPUT_FIVE_ARG_CONTAINER(std::unordered_multimap) +#endif +#ifdef GLOG_STL_LOGGING_FOR_TR1_UNORDERED +OUTPUT_FIVE_ARG_CONTAINER(std::tr1::unordered_map) +OUTPUT_FIVE_ARG_CONTAINER(std::tr1::unordered_multimap) +#endif +#ifdef GLOG_STL_LOGGING_FOR_EXT_HASH OUTPUT_FIVE_ARG_CONTAINER(__gnu_cxx::hash_map) OUTPUT_FIVE_ARG_CONTAINER(__gnu_cxx::hash_multimap) #endif -- 2.34.1