tesseract  3.05.02
hashfn.h
Go to the documentation of this file.
1 /**********************************************************************
2  * File: hashfn.h (Formerly hash.h)
3  * Description: Portability hacks for hash_map, hash_set and unique_ptr.
4  * Author: Ray Smith
5  * Created: Wed Jan 08 14:08:25 PST 2014
6  *
7  * (C) Copyright 2014, Google Inc.
8  ** Licensed under the Apache License, Version 2.0 (the "License");
9  ** you may not use this file except in compliance with the License.
10  ** You may obtain a copy of the License at
11  ** http://www.apache.org/licenses/LICENSE-2.0
12  ** Unless required by applicable law or agreed to in writing, software
13  ** distributed under the License is distributed on an "AS IS" BASIS,
14  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  ** See the License for the specific language governing permissions and
16  ** limitations under the License.
17  *
18  **********************************************************************/
19 
20 #ifndef HASHFN_H
21 #define HASHFN_H
22 
23 #if (__cplusplus >= 201103L) || defined(_MSC_VER) // Visual Studio
24 #include <unordered_map>
25 #include <unordered_set>
26 #if defined(_MSC_VER) && (_MSC_VER >= 1500 && _MSC_VER < 1600) // VS 2008
27 #define TessHashMap std::tr1::unordered_map
28 #define TessHashSet std::tr1::unordered_set
29 #else // _MSC_VER
30 #define TessHashMap std::unordered_map
31 #define TessHashSet std::unordered_set
32 #include <memory>
33 #define SmartPtr std::unique_ptr
34 #define HAVE_UNIQUE_PTR
35 #endif // _MSC_VER
36 #elif (defined(__GNUC__) && (((__GNUC__ == 3) && (__GNUC_MINOR__ > 0)) || \
37  __GNUC__ >= 4)) // gcc
38 // hash_set is deprecated in gcc
39 #include <ext/hash_map>
40 #include <ext/hash_set>
41 using __gnu_cxx::hash_map;
42 using __gnu_cxx::hash_set;
43 #define TessHashMap __gnu_cxx::hash_map
44 #define TessHashSet __gnu_cxx::hash_set
45 #else
46 #include <hash_map>
47 #include <hash_set>
48 #define TessHashMap hash_map
49 #define TessHashSet :hash_set
50 #endif // gcc
51 
52 #ifndef HAVE_UNIQUE_PTR
53 // Trivial smart ptr. Expand to add features of std::unique_ptr as required.
54 template<class T> class SmartPtr {
55  public:
56  SmartPtr() : ptr_(NULL) {}
57  explicit SmartPtr(T* ptr) : ptr_(ptr) {}
59  delete ptr_;
60  }
61 
62  T* get() const {
63  return ptr_;
64  }
65  void reset(T* ptr) {
66  delete ptr_;
67  ptr_ = ptr;
68  }
69  bool operator==(const T* ptr) const {
70  return ptr_ == ptr;
71  }
72  T* operator->() const {
73  return ptr_;
74  }
75  private:
76  T* ptr_;
77 };
78 #endif // HAVE_UNIQUE_PTR
79 
80 #endif // HASHFN_H
SmartPtr()
Definition: hashfn.h:56
void reset(T *ptr)
Definition: hashfn.h:65
SmartPtr(T *ptr)
Definition: hashfn.h:57
bool operator==(const T *ptr) const
Definition: hashfn.h:69
~SmartPtr()
Definition: hashfn.h:58
T * operator->() const
Definition: hashfn.h:72