tesseract v5.3.3.20231005
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 <tesseract/export.h> // for TESS_API
23
24namespace tesseract {
25
26/*Control parameters for error()*/
28 DBG = -1, /*log without alert */
29 TESSLOG = 0, /*alert user */
30 TESSEXIT = 1, /*exit after error */
31 ABORT = 2 /*abort after error */
32};
33
34#if !defined(__GNUC__) && !defined(__attribute__)
35# define __attribute__(attr) // compiler without support for __attribute__
36#endif
37
38class TESS_API ERRCODE { // error handler class
39 const char *message; // error message
40public:
41 void error( // error print function
42 const char *caller, // function location
43 TessErrorLogCode action, // action to take
44 const char *format, ... // fprintf format
45 ) const __attribute__((format(gnu_printf, 4, 5)));
46 void error(const char *caller, TessErrorLogCode action) const;
47 constexpr ERRCODE(const char *string) : message(string) {} // initialize with string
48};
49
50constexpr ERRCODE ASSERT_FAILED("Assert failed");
51
52#define DO_NOTHING static_cast<void>(0)
53
54#define ASSERT_HOST(x) \
55 (x) ? DO_NOTHING : ASSERT_FAILED.error(#x, ABORT, "in file %s, line %d", __FILE__, __LINE__)
56
57#define ASSERT_HOST_MSG(x, ...) \
58 if (!(x)) { \
59 tprintf(__VA_ARGS__); \
60 ASSERT_FAILED.error(#x, ABORT, "in file %s, line %d", __FILE__, __LINE__); \
61 }
62
63} // namespace tesseract
64
65#endif
#define __attribute__(attr)
Definition: errcode.h:35
constexpr ERRCODE ASSERT_FAILED("Assert failed")
TessErrorLogCode
Definition: errcode.h:27
@ ABORT
Definition: errcode.h:31
@ TESSLOG
Definition: errcode.h:29
@ TESSEXIT
Definition: errcode.h:30
action
Definition: upload.py:408
constexpr ERRCODE(const char *string)
Definition: errcode.h:47
#define TESS_API
Definition: export.h:32