tesseract
3.03
|
00001 /********************************************************************** 00002 * File: util.h 00003 * Description: Misc STL string utility functions. 00004 * Author: Samuel Charron 00005 * Created: Mon Nov 18 2013 00006 * 00007 * (C) Copyright 2013, 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 TESSERACT_TRAINING_UTIL_H_ 00021 #define TESSERACT_TRAINING_UTIL_H_ 00022 00023 #include <stddef.h> 00024 #include <stdlib.h> 00025 #include <string> 00026 #include <vector> 00027 00028 #ifdef USE_STD_NAMESPACE 00029 using std::string; 00030 using std::vector; 00031 #endif 00032 00033 // StringHash is the hashing functor needed by the stl hash map. 00034 #ifndef COMPILER_MSVC 00035 struct StringHash { 00036 size_t operator()(const string& s) const { 00037 size_t hash_code = 0; 00038 const char* str = s.c_str(); 00039 for (int ch = 0; str[ch] != 0; ++ch) { 00040 hash_code += str[ch] << (ch % 24); 00041 } 00042 return hash_code; 00043 } 00044 }; 00045 #else // COMPILER_MSVC 00046 struct StringHash : public stdext::hash_compare <string> { 00047 size_t operator()(const string& s) const { 00048 size_t hash_code = 0; 00049 const char* str = s.c_str(); 00050 for (int ch = 0; str[ch] != 0; ++ch) { 00051 hash_code += str[ch] << (ch % 24); 00052 } 00053 return hash_code; 00054 } 00055 bool operator()(const string& s1, const string& s2) const { 00056 return s1 == s2; 00057 } 00058 }; 00059 #endif // !COMPILER_MSVC 00060 00061 #ifndef USE_STD_NAMESPACE 00062 #include "base/heap-checker.h" 00063 #define DISABLE_HEAP_LEAK_CHECK HeapLeakChecker::Disabler disabler 00064 #else 00065 #define DISABLE_HEAP_LEAK_CHECK {} 00066 #endif 00067 00068 #endif // TESSERACT_TRAINING_UTIL_H_