tesseract  v4.0.0-17-g361f3264
Open Source OCR Engine
util.h
1 /**********************************************************************
2  * File: util.h
3  * Description: Misc STL string utility functions.
4  * Author: Samuel Charron
5  * Created: Mon Nov 18 2013
6  *
7  * (C) Copyright 2013, 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 TESSERACT_TRAINING_UTIL_H_
21 #define TESSERACT_TRAINING_UTIL_H_
22 
23 #include <cstddef>
24 #include <cstdlib>
25 #include <string>
26 #include <vector>
27 
28 #include "platform.h"
29 
30 // StringHash is the hashing functor needed by the stl hash map.
31 #ifndef COMPILER_MSVC
32 struct StringHash {
33  size_t operator()(const std::string& s) const {
34  size_t hash_code = 0;
35  const char* str = s.c_str();
36  for (int ch = 0; str[ch] != 0; ++ch) {
37  hash_code += str[ch] << (ch % 24);
38  }
39  return hash_code;
40  }
41 };
42 #else // COMPILER_MSVC
43 struct StringHash : public stdext::hash_compare <std::string> {
44  size_t operator()(const std::string& s) const {
45  size_t hash_code = 0;
46  const char* str = s.c_str();
47  for (int ch = 0; str[ch] != 0; ++ch) {
48  hash_code += str[ch] << (ch % 24);
49  }
50  return hash_code;
51  }
52  bool operator()(const std::string& s1, const std::string& s2) const {
53  return s1 == s2;
54  }
55 };
56 #endif // !COMPILER_MSVC
57 
58 #ifdef GOOGLE_TESSERACT
59 #include "base/heap-checker.h"
60 #define DISABLE_HEAP_LEAK_CHECK HeapLeakChecker::Disabler disabler
61 #else
62 #define DISABLE_HEAP_LEAK_CHECK {}
63 #endif
64 
65 #endif // TESSERACT_TRAINING_UTIL_H_
Definition: util.h:32
size_t operator()(const std::string &s) const
Definition: util.h:33