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