tesseract
3.03
|
00001 /********************************************************************** 00002 * File: hashfn.h (Formerly hash.h) 00003 * Description: Portability hacks for hash_map, hash_set and unique_ptr. 00004 * Author: Ray Smith 00005 * Created: Wed Jan 08 14:08:25 PST 2014 00006 * 00007 * (C) Copyright 2014, Google Inc. 00008 ** Licensed under the Apache License, Version 2.0 (the "License"); 00009 ** you may not use this file except in compliance with the License. 00010 ** You may obtain a copy of the License at 00011 ** http://www.apache.org/licenses/LICENSE-2.0 00012 ** Unless required by applicable law or agreed to in writing, software 00013 ** distributed under the License is distributed on an "AS IS" BASIS, 00014 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00015 ** See the License for the specific language governing permissions and 00016 ** limitations under the License. 00017 * 00018 **********************************************************************/ 00019 00020 #ifndef HASHFN_H 00021 #define HASHFN_H 00022 00023 #ifdef USE_STD_NAMESPACE 00024 #if (__cplusplus >= 201103L) || defined(_MSC_VER) // Visual Studio 00025 #include <unordered_map> 00026 #include <unordered_set> 00027 #define hash_map std::unordered_map 00028 #if (_MSC_VER >= 1500 && _MSC_VER < 1600) // Visual Studio 2008 00029 using namespace std::tr1; 00030 #else // _MSC_VER 00031 using std::unordered_map; 00032 using std::unordered_set; 00033 #include <memory> 00034 #define SmartPtr std::unique_ptr 00035 #define HAVE_UNIQUE_PTR 00036 #endif // _MSC_VER 00037 #elif (defined(__GNUC__) && (((__GNUC__ == 3) && (__GNUC_MINOR__ > 0)) || \ 00038 __GNUC__ >= 4)) // gcc 00039 // hash_set is deprecated in gcc 00040 #include <ext/hash_map> 00041 #include <ext/hash_set> 00042 using __gnu_cxx::hash_map; 00043 using __gnu_cxx::hash_set; 00044 #define unordered_map hash_map 00045 #define unordered_set hash_set 00046 #else 00047 #include <hash_map> 00048 #include <hash_set> 00049 #endif // gcc 00050 #else // USE_STD_NAMESPACE 00051 #include <hash_map> 00052 #include <hash_set> 00053 #define unordered_map hash_map 00054 #define unordered_set hash_set 00055 #endif // USE_STD_NAMESPACE 00056 00057 #ifndef HAVE_UNIQUE_PTR 00058 // Trivial smart ptr. Expand to add features of std::unique_ptr as required. 00059 template<class T> class SmartPtr { 00060 public: 00061 SmartPtr() : ptr_(NULL) {} 00062 explicit SmartPtr(T* ptr) : ptr_(ptr) {} 00063 ~SmartPtr() { 00064 delete ptr_; 00065 } 00066 00067 T* get() const { 00068 return ptr_; 00069 } 00070 void reset(T* ptr) { 00071 if (ptr_ != NULL) delete ptr_; 00072 ptr_ = ptr; 00073 } 00074 bool operator==(const T* ptr) const { 00075 return ptr_ == ptr; 00076 } 00077 T* operator->() const { 00078 return ptr_; 00079 } 00080 private: 00081 T* ptr_; 00082 }; 00083 #endif // HAVE_UNIQUE_PTR 00084 00085 #endif // HASHFN_H