~ubuntu-branches/ubuntu/vivid/tesseract/vivid

« back to all changes in this revision

Viewing changes to training/util.h

  • Committer: Package Import Robot
  • Author(s): Jeff Breidenbach
  • Date: 2014-02-03 11:10:20 UTC
  • mfrom: (1.3.1) (19.1.1 experimental)
  • Revision ID: package-import@ubuntu.com-20140203111020-igquodd7pjlp3uri
Tags: 3.03.01-1
* New upstream release, includes critical fix to PDF rendering
* Complete leptonlib transition (see bug #735509)
* Promote from experimental to unstable

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 <stddef.h>
 
24
#include <stdlib.h>
 
25
#include <string>
 
26
#include <vector>
 
27
 
 
28
#ifdef USE_STD_NAMESPACE
 
29
using std::string;
 
30
using std::vector;
 
31
#endif
 
32
 
 
33
// StringHash is the hashing functor needed by the stl hash map.
 
34
#ifndef COMPILER_MSVC
 
35
struct StringHash {
 
36
  size_t operator()(const string& s) const {
 
37
    size_t hash_code = 0;
 
38
    const char* str = s.c_str();
 
39
    for (int ch = 0; str[ch] != 0; ++ch) {
 
40
      hash_code += str[ch] << (ch % 24);
 
41
    }
 
42
    return hash_code;
 
43
  }
 
44
};
 
45
#else  // COMPILER_MSVC
 
46
struct StringHash : public stdext::hash_compare <string> {
 
47
  size_t operator()(const string& s) const {
 
48
    size_t hash_code = 0;
 
49
    const char* str = s.c_str();
 
50
    for (int ch = 0; str[ch] != 0; ++ch) {
 
51
      hash_code += str[ch] << (ch % 24);
 
52
    }
 
53
    return hash_code;
 
54
  }
 
55
  bool operator()(const string& s1, const string& s2) const {
 
56
    return s1 == s2;
 
57
  }
 
58
};
 
59
#endif  // !COMPILER_MSVC
 
60
 
 
61
#ifndef USE_STD_NAMESPACE
 
62
#include "base/heap-checker.h"
 
63
#define DISABLE_HEAP_LEAK_CHECK HeapLeakChecker::Disabler disabler
 
64
#else
 
65
#define DISABLE_HEAP_LEAK_CHECK {}
 
66
#endif
 
67
 
 
68
#endif  // TESSERACT_TRAINING_UTIL_H_