-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.h
More file actions
71 lines (52 loc) · 2.38 KB
/
Copy patherrors.h
File metadata and controls
71 lines (52 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#ifndef MTX_ERRORS_H
#define MTX_ERRORS_H
#ifdef __cplusplus
extern "C" {
#endif
typedef enum error_codes {
MTX_SUCCESS = 0,
MTX_NULL_ERR,
MTX_DIMEN_ERR,
MTX_INVALID_ERR,
MTX_BOUNDS_ERR,
MTX_OVERLAP_ERR,
MTX_SYSTEM_ERR,
} mtx_error_t;
// filename, function name, line, error code and extra details.
typedef void (*mtx_error_handler_t)(const char *, const char *, int,
mtx_error_t, ...);
extern mtx_error_handler_t __mtx_cfg_error_handler;
// Seta a função que atuará como o handler de erros.
void mtx_cfg_set_error_handler(mtx_error_handler_t handler);
#define mtx_error_handler(file, fun, line, error, ...) \
__mtx_cfg_error_handler(file, fun, line, error, __VA_ARGS__)
// Handler padrão de erros.
void mtx_default_error_handler(const char *file, const char *fun, int line,
mtx_error_t error, ...);
#define MTX_ERROR(error, ...) \
mtx_error_handler(__FILE__, __func__, __LINE__, error, __VA_ARGS__)
#define MTX_NULL_ERR_TEXT "matrix %s is unitialized."
#define MTX_DIMEN_ERR_TEXT "matrix (%d, %d) %s has invalid dimensions."
#define MTX_INVALID_ERR_TEXT "matrix %s is invalid."
#define MTX_BOUNDS_ERR_TEXT "matrix (%d, %d,%d, %d) %s is out of bounds."
#define MTX_OVERLAP_ERR_TEXT_1 \
"matrix (%d, %d, %d, %d) %s has an unsafe overlap with matrix " \
"(%d, %d, %d, %d) %s."
#define MTX_OVERLAP_ERR_TEXT_2 \
"matrix (%d, %d) %s and %s are the same and it isn't allowed in " \
"this function."
#define MTX_SYSTEM_ERR_TEXT "Got a system error after a call to %s()"
#define MTX_NULL_ERR(M) MTX_ERROR(MTX_NULL_ERR, M, #M)
#define MTX_DIMEN_ERR(M) MTX_ERROR(MTX_DIMEN_ERR, M, #M)
#define MTX_INVALID_ERR(M) MTX_ERROR(MTX_INVALID_ERR, M, #M)
#define MTX_BOUNDS_ERR(M) MTX_ERROR(MTX_BOUNDS_ERR, M, #M)
#define MTX_OVERLAP_ERR(M1, M2) MTX_ERROR(MTX_OVERLAP_ERR, M1, #M1, M2, #M2)
#define MTX_SYSTEM_ERR(fun_error) MTX_ERROR(MTX_SYSTEM_ERR, fun_error)
#define MTX_ENSURE_INIT(M) \
if ((M)->data == NULL) { \
MTX_NULL_ERR(M); \
}
#ifdef __cplusplus
}
#endif
#endif