tesseract  5.0.0-alpha-619-ge9db
util.h
Go to the documentation of this file.
1 /**********************************************************************
2  * File: util.h
3  * Description: Misc STL string utility functions.
4  * Author: Samuel Charron
5  *
6  * (C) Copyright 2013, Google Inc.
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * http://www.apache.org/licenses/LICENSE-2.0
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  **********************************************************************/
18 
19 #ifndef TESSERACT_TRAINING_UTIL_H_
20 #define TESSERACT_TRAINING_UTIL_H_
21 
22 #include <cstddef>
23 #include <cstdlib>
24 #include <string>
25 #include <vector>
26 
27 #include <tesseract/platform.h>
28 
29 // StringHash is the hashing functor needed by the stl hash map.
30 #ifndef COMPILER_MSVC
31 struct StringHash {
32  size_t operator()(const std::string& s) const {
33  size_t hash_code = 0;
34  const uint8_t* str = reinterpret_cast<const uint8_t*>(s.c_str());
35  for (unsigned ch = 0; str[ch] != 0; ++ch) {
36  hash_code += str[ch] << (ch % 24);
37  }
38  return hash_code;
39  }
40 };
41 #else // COMPILER_MSVC
42 struct StringHash : public stdext::hash_compare <std::string> {
43  size_t operator()(const std::string& s) const {
44  size_t hash_code = 0;
45  const uint8_t* str = reinterpret_cast<const uint8_t*>(s.c_str());
46  for (unsigned ch = 0; str[ch] != 0; ++ch) {
47  hash_code += str[ch] << (ch % 24);
48  }
49  return hash_code;
50  }
51  bool operator()(const std::string& s1, const std::string& s2) const {
52  return s1 == s2;
53  }
54 };
55 #endif // !COMPILER_MSVC
56 
57 #ifdef GOOGLE_TESSERACT
58 #include "base/heap-checker.h"
59 #define DISABLE_HEAP_LEAK_CHECK HeapLeakChecker::Disabler disabler
60 #else
61 #define DISABLE_HEAP_LEAK_CHECK {}
62 #endif
63 
64 #endif // TESSERACT_TRAINING_UTIL_H_
string
std::string string
Definition: equationdetect_test.cc:21
platform.h
StringHash::operator()
size_t operator()(const std::string &s) const
Definition: util.h:46
StringHash
Definition: util.h:30