tesseract  4.00.00dev
errcode.h
Go to the documentation of this file.
1 /**********************************************************************
2  * File: errcode.h (Formerly error.h)
3  * Description: Header file for generic error handler class
4  * Author: Ray Smith
5  * Created: Tue May 1 16:23:36 BST 1990
6  *
7  * (C) Copyright 1990, Hewlett-Packard Ltd.
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 ERRCODE_H
21 #define ERRCODE_H
22 
23 #include "host.h"
24 
25 /*Control parameters for error()*/
27  DBG = -1, /*log without alert */
28  TESSLOG = 0, /*alert user */
29  TESSEXIT = 1, /*exit after erro */
30  ABORT = 2 /*abort after error */
31 };
32 
33 /* Explicit Error Abort codes */
34 #define NO_ABORT_CODE 0
35 #define LIST_ABORT 1
36 #define MEMORY_ABORT 2
37 #define FILE_ABORT 3
38 
39 /* Location of code at error codes Reserve 0..2 (status codes 0..23 for UNLV)*/
40 #define LOC_UNUSED0 0
41 #define LOC_UNUSED1 1
42 #define LOC_UNUSED2 2
43 #define LOC_INIT 3
44 #define LOC_EDGE_PROG 4
45 #define LOC_TEXT_ORD_ROWS 5
46 #define LOC_TEXT_ORD_WORDS 6
47 #define LOC_PASS1 7
48 #define LOC_PASS2 8
49 /* Reserve up to 8..13 for adding subloc 0/3 plus subsubloc 0/1/2 */
50 #define LOC_FUZZY_SPACE 14
51 /* Reserve up to 14..20 for adding subloc 0/3 plus subsubloc 0/1/2 */
52 #define LOC_MM_ADAPT 21
53 #define LOC_DOC_BLK_REJ 22
54 #define LOC_WRITE_RESULTS 23
55 #define LOC_ADAPTIVE 24
56 /* DON'T DEFINE ANY LOCATION > 31 !!! */
57 
58 /* Sub locatation determines whether pass2 was in normal mode or fix xht mode*/
59 #define SUBLOC_NORM 0
60 #define SUBLOC_FIX_XHT 3
61 
62 /* Sub Sub locatation determines whether match_word_pass2 was in Tess
63  matcher, NN matcher or somewhere else */
64 
65 #define SUBSUBLOC_OTHER 0
66 #define SUBSUBLOC_TESS 1
67 #define SUBSUBLOC_NN 2
68 
69 class TESS_API ERRCODE { // error handler class
70  const char *message; // error message
71  public:
72  void error( // error print function
73  const char *caller, // function location
74  TessErrorLogCode action, // action to take
75  const char *format, ... // fprintf format
76  ) const;
77  ERRCODE(const char *string) {
78  message = string;
79  } // initialize with string
80 };
81 
82 const ERRCODE ASSERT_FAILED = "Assert failed";
83 
84 #define ASSERT_HOST(x) if (!(x)) \
85  { \
86  ASSERT_FAILED.error(#x, ABORT, "in file %s, line %d", \
87  __FILE__, __LINE__); \
88  }
89 
90 #define ASSERT_HOST_MSG(x, ...) \
91  if (!(x)) { \
92  tprintf(__VA_ARGS__); \
93  ASSERT_FAILED.error(#x, ABORT, "in file %s, line %d", __FILE__, __LINE__); \
94  }
95 
96 void signal_exit(int signal_code);
97 
98 void set_global_loc_code(int loc_code);
99 
100 void set_global_subloc_code(int loc_code);
101 
102 void set_global_subsubloc_code(int loc_code);
103 #endif
void signal_exit(int signal_code)
Definition: globaloc.cpp:52
void set_global_loc_code(int loc_code)
Definition: globaloc.cpp:79
#define TESS_API
Definition: platform.h:81
TessErrorLogCode
Definition: errcode.h:26
void set_global_subsubloc_code(int loc_code)
Definition: globaloc.cpp:91
void set_global_subloc_code(int loc_code)
Definition: globaloc.cpp:85
const ERRCODE ASSERT_FAILED
Definition: errcode.h:82
ERRCODE(const char *string)
Definition: errcode.h:77
Definition: errcode.h:27
Definition: errcode.h:30