Support unordered_(map|set) by stl_logging
author <shinichiro.hamaji@gmail.com> <>
Mon, 18 Feb 2013 10:45:46 +0000 (10:45 +0000)
committer <shinichiro.hamaji@gmail.com> <>
Mon, 18 Feb 2013 10:45:46 +0000 (10:45 +0000)
git-svn-id: https://google-glog.googlecode.com/svn/trunk@134 eb4d4688-79bd-11dd-afb4-1d65580434c0

src/glog/stl_logging.h.in
src/stl_logging_unittest.cc
src/windows/glog/stl_logging.h

index 30836de..600945d 100644 (file)
 // LOG(INFO) << "data: " << x;
 // vector<int> 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     - <unordered_map> and <unordered_set>
+// - GLOG_STL_LOGGING_FOR_TR1_UNORDERED - <tr1/unordered_(map|set)>
+// - GLOG_STL_LOGGING_FOR_EXT_HASH      - <ext/hash_(map|set)>
+// - GLOG_STL_LOGGING_FOR_EXT_SLIST     - <ext/slist>
+//
 
 #ifndef UTIL_GTL_STL_LOGGING_INL_H_
 #define UTIL_GTL_STL_LOGGING_INL_H_
 #include <utility>
 #include <vector>
 
-#ifdef __GNUC__
+#ifdef GLOG_STL_LOGGING_FOR_UNORDERED
+# include <unordered_map>
+# include <unordered_set>
+#endif
+
+#ifdef GLOG_STL_LOGGING_FOR_TR1_UNORDERED
+# include <tr1/unordered_map>
+# include <tr1/unordered_set>
+#endif
+
+#ifdef GLOG_STL_LOGGING_FOR_EXT_HASH
 # include <ext/hash_set>
 # include <ext/hash_map>
+#endif
+#ifdef GLOG_STL_LOGGING_FOR_EXT_SLIST
 # include <ext/slist>
 #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
index 5dcbc44..fcae9ad 100644 (file)
 
 #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 <iostream>
 #include <string>
 #include <vector>
 
-#ifdef __GNUC__
-# include <ext/hash_map>
-# include <ext/hash_set>
-#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<int> 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<int, string> 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.
index d2e7495..a97a908 100755 (executable)
 // LOG(INFO) << "data: " << x;
 // vector<int> 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     - <unordered_map> and <unordered_set>
+// - GLOG_STL_LOGGING_FOR_TR1_UNORDERED - <tr1/unordered_(map|set)>
+// - GLOG_STL_LOGGING_FOR_EXT_HASH      - <ext/hash_(map|set)>
+// - GLOG_STL_LOGGING_FOR_EXT_SLIST     - <ext/slist>
+//
 
 #ifndef UTIL_GTL_STL_LOGGING_INL_H_
 #define UTIL_GTL_STL_LOGGING_INL_H_
 #include <utility>
 #include <vector>
 
-#ifdef __GNUC__
+#ifdef GLOG_STL_LOGGING_FOR_UNORDERED
+# include <unordered_map>
+# include <unordered_set>
+#endif
+
+#ifdef GLOG_STL_LOGGING_FOR_TR1_UNORDERED
+# include <tr1/unordered_map>
+# include <tr1/unordered_set>
+#endif
+
+#ifdef GLOG_STL_LOGGING_FOR_EXT_HASH
 # include <ext/hash_set>
 # include <ext/hash_map>
+#endif
+#ifdef GLOG_STL_LOGGING_FOR_EXT_SLIST
 # include <ext/slist>
 #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