Support unordered_(map|set) by stl_logging
git-svn-id: https://google-glog.googlecode.com/svn/trunk@134 eb4d4688-79bd-11dd-afb4-1d65580434c0
This commit is contained in:
parent
cba9095278
commit
a106e61178
@ -34,6 +34,15 @@
|
|||||||
// LOG(INFO) << "data: " << x;
|
// LOG(INFO) << "data: " << x;
|
||||||
// vector<int> v1, v2;
|
// vector<int> v1, v2;
|
||||||
// CHECK_EQ(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_
|
#ifndef UTIL_GTL_STL_LOGGING_INL_H_
|
||||||
#define UTIL_GTL_STL_LOGGING_INL_H_
|
#define UTIL_GTL_STL_LOGGING_INL_H_
|
||||||
@ -50,9 +59,21 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#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_set>
|
||||||
# include <ext/hash_map>
|
# include <ext/hash_map>
|
||||||
|
#endif
|
||||||
|
#ifdef GLOG_STL_LOGGING_FOR_EXT_SLIST
|
||||||
# include <ext/slist>
|
# include <ext/slist>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -80,7 +101,7 @@ inline std::ostream& operator<<(std::ostream& out, \
|
|||||||
OUTPUT_TWO_ARG_CONTAINER(std::vector)
|
OUTPUT_TWO_ARG_CONTAINER(std::vector)
|
||||||
OUTPUT_TWO_ARG_CONTAINER(std::deque)
|
OUTPUT_TWO_ARG_CONTAINER(std::deque)
|
||||||
OUTPUT_TWO_ARG_CONTAINER(std::list)
|
OUTPUT_TWO_ARG_CONTAINER(std::list)
|
||||||
#ifdef __GNUC__
|
#ifdef GLOG_STL_LOGGING_FOR_EXT_SLIST
|
||||||
OUTPUT_TWO_ARG_CONTAINER(__gnu_cxx::slist)
|
OUTPUT_TWO_ARG_CONTAINER(__gnu_cxx::slist)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -109,7 +130,15 @@ inline std::ostream& operator<<(std::ostream& out, \
|
|||||||
|
|
||||||
OUTPUT_FOUR_ARG_CONTAINER(std::map)
|
OUTPUT_FOUR_ARG_CONTAINER(std::map)
|
||||||
OUTPUT_FOUR_ARG_CONTAINER(std::multimap)
|
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_set)
|
||||||
OUTPUT_FOUR_ARG_CONTAINER(__gnu_cxx::hash_multiset)
|
OUTPUT_FOUR_ARG_CONTAINER(__gnu_cxx::hash_multiset)
|
||||||
#endif
|
#endif
|
||||||
@ -124,7 +153,15 @@ inline std::ostream& operator<<(std::ostream& out, \
|
|||||||
return 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_map)
|
||||||
OUTPUT_FIVE_ARG_CONTAINER(__gnu_cxx::hash_multimap)
|
OUTPUT_FIVE_ARG_CONTAINER(__gnu_cxx::hash_multimap)
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -31,6 +31,14 @@
|
|||||||
|
|
||||||
#ifdef HAVE_USING_OPERATOR
|
#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 "glog/stl_logging.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@ -39,16 +47,11 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#ifdef __GNUC__
|
|
||||||
# include <ext/hash_map>
|
|
||||||
# include <ext/hash_set>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "glog/logging.h"
|
#include "glog/logging.h"
|
||||||
#include "googletest.h"
|
#include "googletest.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
#ifdef __GNUC__
|
#ifdef GLOG_STL_LOGGING_FOR_EXT_HASH
|
||||||
using namespace __gnu_cxx;
|
using namespace __gnu_cxx;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -83,7 +86,7 @@ void TestSTLLogging() {
|
|||||||
CHECK_EQ(m, copied_m); // This must compile.
|
CHECK_EQ(m, copied_m); // This must compile.
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __GNUC__
|
#ifdef GLOG_STL_LOGGING_FOR_EXT_HASH
|
||||||
{
|
{
|
||||||
// Test a hashed simple associative container.
|
// Test a hashed simple associative container.
|
||||||
hash_set<int> hs;
|
hash_set<int> hs;
|
||||||
@ -98,7 +101,7 @@ void TestSTLLogging() {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __GNUC__
|
#ifdef GLOG_STL_LOGGING_FOR_EXT_HASH
|
||||||
{
|
{
|
||||||
// Test a hashed pair associative container.
|
// Test a hashed pair associative container.
|
||||||
hash_map<int, string> hm;
|
hash_map<int, string> hm;
|
||||||
@ -145,7 +148,7 @@ void TestSTLLogging() {
|
|||||||
CHECK_EQ(m, copied_m); // This must compile.
|
CHECK_EQ(m, copied_m); // This must compile.
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __GNUC__
|
#ifdef GLOG_STL_LOGGING_FOR_EXT_HASH
|
||||||
{
|
{
|
||||||
// Test a hashed simple associative container.
|
// Test a hashed simple associative container.
|
||||||
// Use a user defined hash function.
|
// Use a user defined hash function.
|
||||||
|
|||||||
@ -38,6 +38,15 @@
|
|||||||
// LOG(INFO) << "data: " << x;
|
// LOG(INFO) << "data: " << x;
|
||||||
// vector<int> v1, v2;
|
// vector<int> v1, v2;
|
||||||
// CHECK_EQ(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_
|
#ifndef UTIL_GTL_STL_LOGGING_INL_H_
|
||||||
#define UTIL_GTL_STL_LOGGING_INL_H_
|
#define UTIL_GTL_STL_LOGGING_INL_H_
|
||||||
@ -54,9 +63,21 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#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_set>
|
||||||
# include <ext/hash_map>
|
# include <ext/hash_map>
|
||||||
|
#endif
|
||||||
|
#ifdef GLOG_STL_LOGGING_FOR_EXT_SLIST
|
||||||
# include <ext/slist>
|
# include <ext/slist>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -84,7 +105,7 @@ inline std::ostream& operator<<(std::ostream& out, \
|
|||||||
OUTPUT_TWO_ARG_CONTAINER(std::vector)
|
OUTPUT_TWO_ARG_CONTAINER(std::vector)
|
||||||
OUTPUT_TWO_ARG_CONTAINER(std::deque)
|
OUTPUT_TWO_ARG_CONTAINER(std::deque)
|
||||||
OUTPUT_TWO_ARG_CONTAINER(std::list)
|
OUTPUT_TWO_ARG_CONTAINER(std::list)
|
||||||
#ifdef __GNUC__
|
#ifdef GLOG_STL_LOGGING_FOR_EXT_SLIST
|
||||||
OUTPUT_TWO_ARG_CONTAINER(__gnu_cxx::slist)
|
OUTPUT_TWO_ARG_CONTAINER(__gnu_cxx::slist)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -113,7 +134,15 @@ inline std::ostream& operator<<(std::ostream& out, \
|
|||||||
|
|
||||||
OUTPUT_FOUR_ARG_CONTAINER(std::map)
|
OUTPUT_FOUR_ARG_CONTAINER(std::map)
|
||||||
OUTPUT_FOUR_ARG_CONTAINER(std::multimap)
|
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_set)
|
||||||
OUTPUT_FOUR_ARG_CONTAINER(__gnu_cxx::hash_multiset)
|
OUTPUT_FOUR_ARG_CONTAINER(__gnu_cxx::hash_multiset)
|
||||||
#endif
|
#endif
|
||||||
@ -128,7 +157,15 @@ inline std::ostream& operator<<(std::ostream& out, \
|
|||||||
return 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_map)
|
||||||
OUTPUT_FIVE_ARG_CONTAINER(__gnu_cxx::hash_multimap)
|
OUTPUT_FIVE_ARG_CONTAINER(__gnu_cxx::hash_multimap)
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user