2007-03-08 04:03:40 +08:00
|
|
|
/**********************************************************************
|
|
|
|
* File: hashfn.h (Formerly hash.h)
|
2014-01-10 01:22:11 +08:00
|
|
|
* Description: Portability hacks for hash_map, hash_set and unique_ptr.
|
|
|
|
* Author: Ray Smith
|
|
|
|
* Created: Wed Jan 08 14:08:25 PST 2014
|
2007-03-08 04:03:40 +08:00
|
|
|
*
|
2014-01-10 01:22:11 +08:00
|
|
|
* (C) Copyright 2014, Google Inc.
|
2007-03-08 04:03:40 +08:00
|
|
|
** Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
** you may not use this file except in compliance with the License.
|
|
|
|
** You may obtain a copy of the License at
|
|
|
|
** http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
** Unless required by applicable law or agreed to in writing, software
|
|
|
|
** distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
** See the License for the specific language governing permissions and
|
|
|
|
** limitations under the License.
|
|
|
|
*
|
|
|
|
**********************************************************************/
|
|
|
|
|
|
|
|
#ifndef HASHFN_H
|
|
|
|
#define HASHFN_H
|
|
|
|
|
2014-01-10 01:22:11 +08:00
|
|
|
#if (__cplusplus >= 201103L) || defined(_MSC_VER) // Visual Studio
|
|
|
|
#include <unordered_map>
|
|
|
|
#include <unordered_set>
|
2016-11-08 03:35:45 +08:00
|
|
|
#if defined(_MSC_VER) && (_MSC_VER >= 1500 && _MSC_VER < 1600) // VS 2008
|
|
|
|
#define TessHashMap std::tr1::unordered_map
|
|
|
|
#define TessHashSet std::tr1::unordered_set
|
2014-01-11 07:52:04 +08:00
|
|
|
#else // _MSC_VER
|
2016-11-08 03:35:45 +08:00
|
|
|
#define TessHashMap std::unordered_map
|
|
|
|
#define TessHashSet std::unordered_set
|
2014-01-10 01:22:11 +08:00
|
|
|
#include <memory>
|
2014-01-10 09:38:00 +08:00
|
|
|
#define SmartPtr std::unique_ptr
|
2014-01-10 01:22:11 +08:00
|
|
|
#define HAVE_UNIQUE_PTR
|
|
|
|
#endif // _MSC_VER
|
2014-01-10 09:38:00 +08:00
|
|
|
#elif (defined(__GNUC__) && (((__GNUC__ == 3) && (__GNUC_MINOR__ > 0)) || \
|
2014-01-10 01:22:11 +08:00
|
|
|
__GNUC__ >= 4)) // gcc
|
|
|
|
// hash_set is deprecated in gcc
|
|
|
|
#include <ext/hash_map>
|
|
|
|
#include <ext/hash_set>
|
|
|
|
using __gnu_cxx::hash_map;
|
|
|
|
using __gnu_cxx::hash_set;
|
2016-11-08 03:35:45 +08:00
|
|
|
#define TessHashMap __gnu_cxx::hash_map
|
|
|
|
#define TessHashSet __gnu_cxx::hash_set
|
2014-01-10 01:22:11 +08:00
|
|
|
#else
|
|
|
|
#include <hash_map>
|
|
|
|
#include <hash_set>
|
2016-11-08 03:35:45 +08:00
|
|
|
#define TessHashMap hash_map
|
|
|
|
#define TessHashSet :hash_set
|
2014-01-10 01:22:11 +08:00
|
|
|
#endif // gcc
|
|
|
|
|
|
|
|
#ifndef HAVE_UNIQUE_PTR
|
|
|
|
// Trivial smart ptr. Expand to add features of std::unique_ptr as required.
|
|
|
|
template<class T> class SmartPtr {
|
|
|
|
public:
|
|
|
|
SmartPtr() : ptr_(NULL) {}
|
2014-01-10 09:38:00 +08:00
|
|
|
explicit SmartPtr(T* ptr) : ptr_(ptr) {}
|
2014-01-10 01:22:11 +08:00
|
|
|
~SmartPtr() {
|
|
|
|
delete ptr_;
|
|
|
|
}
|
|
|
|
|
|
|
|
T* get() const {
|
|
|
|
return ptr_;
|
|
|
|
}
|
|
|
|
void reset(T* ptr) {
|
|
|
|
if (ptr_ != NULL) delete ptr_;
|
|
|
|
ptr_ = ptr;
|
|
|
|
}
|
|
|
|
bool operator==(const T* ptr) const {
|
|
|
|
return ptr_ == ptr;
|
|
|
|
}
|
|
|
|
T* operator->() const {
|
|
|
|
return ptr_;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
T* ptr_;
|
|
|
|
};
|
|
|
|
#endif // HAVE_UNIQUE_PTR
|
|
|
|
|
|
|
|
#endif // HASHFN_H
|