From 4065a31644cf44fd84cc30491a61c4e59d0f2e2a Mon Sep 17 00:00:00 2001 From: Jisi Liu Date: Sun, 1 Mar 2015 21:02:22 -0800 Subject: Fix hash.h for MSVC and platforms without hash map/set support. Change-Id: Ic0fdb52c17b9495c73b8ce15879531383a148585 --- src/google/protobuf/stubs/hash.h | 32 ++++++++++++++++------------- vsprojects/config.h | 29 +++++++++----------------- vsprojects/google/protobuf/stubs/pbconfig.h | 30 ++++++++++++++++++--------- 3 files changed, 48 insertions(+), 43 deletions(-) mode change 100644 => 100755 src/google/protobuf/stubs/hash.h mode change 100644 => 100755 vsprojects/config.h mode change 100644 => 100755 vsprojects/google/protobuf/stubs/pbconfig.h diff --git a/src/google/protobuf/stubs/hash.h b/src/google/protobuf/stubs/hash.h old mode 100644 new mode 100755 index 96f74a67..82d5052e --- a/src/google/protobuf/stubs/hash.h +++ b/src/google/protobuf/stubs/hash.h @@ -89,16 +89,17 @@ struct hash { template , - typename EqualKey = int, + typename EqualKey = std::equal_to, typename Alloc = std::allocator< std::pair > > -class hash_map : public std::map { +class hash_map : public std::map { public: - hash_map(int = 0) {} + hash_map(int = 0, const HashFcn& = HashFcn(), const EqualKey& = EqualKey(), + const Alloc& = Alloc()) {} }; template , - typename EqualKey = int > + typename EqualKey = std::equal_to > class hash_set : public std::set { public: hash_set(int = 0) {} @@ -126,19 +127,21 @@ struct hash template , - typename EqualKey = int, + typename EqualKey = std::equal_to, typename Alloc = std::allocator< std::pair > > -class hash_map : public GOOGLE_PROTOBUF_HASH_NAMESPACE::hash_map< - Key, Data, HashFcn, Alloc> { +class hash_map + : public GOOGLE_PROTOBUF_HASH_NAMESPACE::GOOGLE_PROTOBUF_HASH_MAP_CLASS< + Key, Data, HashFcn, EqualKey, Alloc> { public: - hash_map(int = 0) {} + hash_map(int = 0, const HashFcn& = HashFcn(), const EqualKey& = EqualKey(), + const Alloc& = Alloc()) {} }; -template , - typename EqualKey = int > -class hash_set : public GOOGLE_PROTOBUF_HASH_NAMESPACE::hash_set< - Key, HashFcn> { +template , + typename EqualKey = std::equal_to > +class hash_set + : public GOOGLE_PROTOBUF_HASH_NAMESPACE::GOOGLE_PROTOBUF_HASH_SET_CLASS< + Key, HashFcn, EqualKey> { public: hash_set(int = 0) {} }; @@ -169,7 +172,8 @@ struct hash { } }; -template , +template , typename EqualKey = std::equal_to, typename Alloc = std::allocator< std::pair > > class hash_map diff --git a/vsprojects/config.h b/vsprojects/config.h old mode 100644 new mode 100755 index 2c64450a..a93bb033 --- a/vsprojects/config.h +++ b/vsprojects/config.h @@ -1,28 +1,19 @@ /* protobuf config.h for MSVC. On other platforms, this is generated * automatically by autoheader / autoconf / configure. */ -/* the location of */ -#define HASH_MAP_H +#include -/* the namespace of hash_map/hash_set */ -// Apparently Microsoft decided to move hash_map *back* to the std namespace -// in MSVC 2010: -// http://blogs.msdn.com/vcblog/archive/2009/05/25/stl-breaking-changes-in-visual-studio-2010-beta-1.aspx -// TODO(kenton): Use unordered_map instead, which is available in MSVC 2010. -#if _MSC_VER < 1310 || _MSC_VER >= 1600 -#define HASH_NAMESPACE std -#else -#define HASH_NAMESPACE stdext -#endif - -/* the location of */ -#define HASH_SET_H +#define HASH_MAP_H GOOGLE_PROTOBUF_HASH_MAP_H +#define HASH_NAMESPACE GOOGLE_PROTOBUF_HASH_NAMESPACE +#define HASH_SET_H GOOGLE_PROTOBUF_HASH_SET_H -/* define if the compiler has hash_map */ -#define HAVE_HASH_MAP 1 +#ifdef GOOGLE_PROTOBUF_HAVE_HASH_MAP +#define HAVE_HASH_MAP GOOGLE_PROTOBUF_HAVE_HASH_MAP +#endif -/* define if the compiler has hash_set */ -#define HAVE_HASH_SET 1 +#ifdef GOOGLE_PROTOBUF_HAVE_HASH_SET +#define HAVE_HASH_SET GOOGLE_PROTOBUF_HAVE_HASH_SET +#endif /* define if you want to use zlib. See readme.txt for additional * requirements. */ diff --git a/vsprojects/google/protobuf/stubs/pbconfig.h b/vsprojects/google/protobuf/stubs/pbconfig.h old mode 100644 new mode 100755 index c49d26b0..18250a22 --- a/vsprojects/google/protobuf/stubs/pbconfig.h +++ b/vsprojects/google/protobuf/stubs/pbconfig.h @@ -1,29 +1,39 @@ /* protobuf config.h for MSVC. On other platforms, this is generated * automatically by autoheader / autoconf / configure. */ -/* the location of */ -#define GOOGLE_PROTOBUF_HASH_MAP_H +// NOTE: if you add new macros in this file manually, please propagate the macro +// to vsprojects/config.h. /* the namespace of hash_map/hash_set */ // Apparently Microsoft decided to move hash_map *back* to the std namespace // in MSVC 2010: // http://blogs.msdn.com/vcblog/archive/2009/05/25/stl-breaking-changes-in-visual-studio-2010-beta-1.aspx -// TODO(kenton): Use unordered_map instead, which is available in MSVC 2010. -#if _MSC_VER < 1310 || _MSC_VER >= 1600 +// And.. they are moved back to stdext in MSVC 2013 (haven't checked 2012). That +// said, use unordered_map for MSVC 2010 and beyond is our safest bet. +#if _MSC_VER >= 1600 #define GOOGLE_PROTOBUF_HASH_NAMESPACE std -#else +#define GOOGLE_PROTOBUF_HASH_MAP_H +#define GOOGLE_PROTOBUF_HASH_MAP_CLASS unordered_map +#define GOOGLE_PROTOBUF_HASH_SET_H +#define GOOGLE_PROTOBUF_HASH_SET_CLASS unordered_set +#elif _MSC_VER >= 1310 #define GOOGLE_PROTOBUF_HASH_NAMESPACE stdext +#define GOOGLE_PROTOBUF_HASH_MAP_H +#define GOOGLE_PROTOBUF_HASH_MAP_CLASS hash_map +#define GOOGLE_PROTOBUF_HASH_SET_H +#define GOOGLE_PROTOBUF_HASH_SET_CLASS hash_set +#else +#define GOOGLE_PROTOBUF_HASH_NAMESPACE std +#define GOOGLE_PROTOBUF_HASH_MAP_H +#define GOOGLE_PROTOBUF_HASH_MAP_CLASS hash_map +#define GOOGLE_PROTOBUF_HASH_SET_H +#define GOOGLE_PROTOBUF_HASH_SET_CLASS hash_set #endif /* the location of */ -#define GOOGLE_PROTOBUF_HASH_SET_H /* define if the compiler has hash_map */ #define GOOGLE_PROTOBUF_HAVE_HASH_MAP 1 /* define if the compiler has hash_set */ #define GOOGLE_PROTOBUF_HAVE_HASH_SET 1 - -/* define if you want to use zlib. See readme.txt for additional - * requirements. */ -// #define HAVE_ZLIB 1 -- cgit v1.2.3