Coverage Report

Created: 2025-11-16 06:50

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/tesseract/src/ccutil/errcode.h
Line
Count
Source
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
24
namespace tesseract {
25
26
/*Control parameters for error()*/
27
enum TessErrorLogCode {
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
38
class TESS_API ERRCODE { // error handler class
39
  const char *message;   // error message
40
public:
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(printf, 4, 5)));
46
0
  void error(const char *caller, TessErrorLogCode action) const {
47
0
    error(caller, action, nullptr);
48
0
  }
49
0
  constexpr ERRCODE(const char *string) : message(string) {} // initialize with string
50
};
51
52
constexpr ERRCODE ASSERT_FAILED("Assert failed");
53
54
6.35G
#define DO_NOTHING static_cast<void>(0)
55
56
#define ASSERT_HOST(x) \
57
6.35G
  (x) ? DO_NOTHING : ASSERT_FAILED.error(#x, ABORT, "in file %s, line %d", __FILE__, __LINE__)
58
59
#define ASSERT_HOST_MSG(x, ...)                                                \
60
  if (!(x)) {                                                                  \
61
    tprintf(__VA_ARGS__);                                                      \
62
    ASSERT_FAILED.error(#x, ABORT, "in file %s, line %d", __FILE__, __LINE__); \
63
  }
64
65
} // namespace tesseract
66
67
#endif