Loading...
Searching...
No Matches
Go to the documentation of this file.
5#ifndef MLAB_RESULT_MACRO_HPP
6#define MLAB_RESULT_MACRO_HPP
10#ifndef MLAB_NO_RESULT_MACROS
12#ifndef MLAB_RESULT_LOG_PREFIX
13#define MLAB_RESULT_LOG_PREFIX "MLAB"
16#define MLAB_FAIL_MSG(CMD_STR, RESULT) \
17 LOGW(MLAB_RESULT_LOG_PREFIX, "%s:%d failed %s with %s", \
18 __FILE__, __LINE__, CMD_STR, to_string((RESULT).error()));
20#define MLAB_FAIL_CMD(CMD_STR, RESULT) \
21 MLAB_FAIL_MSG(CMD_STR, RESULT) \
22 return (RESULT).error();
24#define MLAB_FAIL_CAST_CMD(CMD_STR, RESULT) \
25 MLAB_FAIL_MSG(CMD_STR, RESULT) \
26 return cast_error((RESULT).error());
28#define MLAB_CMD_WITH_NAMED_RESULT(CMD, RESULT_NAME) \
29 if (auto RESULT_NAME = (CMD); not RESULT_NAME) { \
30 MLAB_FAIL_CMD(#CMD, RESULT_NAME) \
33#define MLAB_CAST_CMD_WITH_NAMED_RESULT(CMD, RESULT_NAME) \
34 if (auto RESULT_NAME = (CMD); not RESULT_NAME) { \
35 MLAB_FAIL_CAST_CMD(#CMD, RESULT_NAME) \
38#define MLAB_CMD_WITH_NAMED_RESULT_SILENT(CMD, RESULT_NAME) \
39 if (auto RESULT_NAME = (CMD); not RESULT_NAME) { \
40 return RESULT_NAME.error(); \
43#define TRY(CMD) MLAB_CMD_WITH_NAMED_RESULT(CMD, _r)
45#define TRY_SILENT(CMD) MLAB_CMD_WITH_NAMED_RESULT_SILENT(CMD, _r)
47#define TRY_RESULT(CMD) \
48 MLAB_CMD_WITH_NAMED_RESULT(CMD, r) \
51#define TRY_RESULT_SILENT(CMD) \
52 MLAB_CMD_WITH_NAMED_RESULT_SILENT(CMD, r) \
55#define TRY_RESULT_AS(CMD, RES_VAR) \
56 MLAB_CMD_WITH_NAMED_RESULT(CMD, RES_VAR) \
59#define TRY_RESULT_AS_SILENT(CMD, RES_VAR) \
60 MLAB_CMD_WITH_NAMED_RESULT_SILENT(CMD, RES_VAR) \
63#define TRY_CAST(CMD) MLAB_CAST_CMD_WITH_NAMED_RESULT(CMD, _r)
65#define TRY_CAST_SILENT(CMD) MLAB_CAST_CMD_WITH_NAMED_RESULT_SILENT(CMD, _r)
67#define TRY_CAST_RESULT(CMD) \
68 MLAB_CAST_CMD_WITH_NAMED_RESULT(CMD, r) \
71#define TRY_CAST_RESULT_SILENT(CMD) \
72 MLAB_CAST_CMD_WITH_NAMED_RESULT_SILENT(CMD, r) \
75#define TRY_CAST_RESULT_AS(CMD, RES_VAR) \
76 MLAB_CAST_CMD_WITH_NAMED_RESULT(CMD, RES_VAR) \
79#define TRY_CAST_RESULT_AS_SILENT(CMD, RES_VAR) \
80 MLAB_CAST_CMD_WITH_NAMED_RESULT_SILENT(CMD, RES_VAR) \