Macros to simplify code.
More...
Go to the source code of this file.
|
#define | CHECK(CONDITION, MESSAGE, ...) |
| Check condition and perform goto terminate if non-successful. More...
|
|
#define | CHECK_RET(CONDITION, RETCODE, MESSAGE, ...) |
| Check condition and return RETCODE if non-successful. More...
|
|
#define | BOOL_CHECK(CONDITION, MESSAGE, ...) CHECK((CONDITION), (MESSAGE), ##__VA_ARGS__) |
| Check condition and perform goto terminate if non-successful. More...
|
|
#define | BOOL_CHECK_RET(CONDITION, MESSAGE, ...) CHECK_RET((CONDITION), false, (MESSAGE), ##__VA_ARGS__) |
| Check condition and return false if non-successful. More...
|
|
#define | MEMCMP_CHECK(BUF1, BUF2, SIZE) |
| Compares two buffer and perform goto terminate if non-successful. More...
|
|
#define | MEMCMP_CHECK_RET(BUF1, BUF2, SIZE, RETCODE) |
| Compares two buffers and return RETCODE if non-successful. More...
|
|
#define | CHECK_NOT_ZERO(ARG) CHECK((ARG), "Argument " #ARG " must not be zero") |
| Checks that ARG is non-zero and perform goto terminate in case of zero one. More...
|
|
#define | CHECK_NOT_ZERO_RET(ARG, RETCODE) CHECK_RET((ARG), (RETCODE), "Argument " #ARG " must not be zero") \ |
| Checks that ARG is non-zero and return RETCODE in case of zero one. More...
|
|
Macros to simplify code.
Here you can find different macros to simplify code usage.
Each macros does specified operation and checks its result. If it is successful, there is no other action. In another case it outputs messages and terminates its execution. There are two ways to terminate normal flow :
Message uses Logger module for output. You can use printf-like syntax with variables.
Here you can see some examples :
int a;
const char *buf1;
const char *buf2;
size_t buf_size;
CHECK(a == 3,
"a = %d while it must be equal to 3", a);
terminate:
◆ BOOL_CHECK
#define BOOL_CHECK |
( |
|
CONDITION, |
|
|
|
MESSAGE, |
|
|
|
... |
|
) |
| CHECK((CONDITION), (MESSAGE), ##__VA_ARGS__) |
Check condition and perform goto terminate if non-successful.
- CONDITION is compared with boolean false.
- If they are equal, MESSAGES is logged and function jumps to terminate label.
- Warning
- terminate label must be present in current function.
- Parameters
-
[in] | CONDITION | Operation to be checked. |
[in] | MESSAGE | String with printf-like parameter to be logged in case of non-successful operation. |
◆ BOOL_CHECK_RET
#define BOOL_CHECK_RET |
( |
|
CONDITION, |
|
|
|
MESSAGE, |
|
|
|
... |
|
) |
| CHECK_RET((CONDITION), false, (MESSAGE), ##__VA_ARGS__) |
Check condition and return false if non-successful.
- CONDITION is compared with boolean false.
- If they are equal, MESSAGES is logged and function returns false.
- Parameters
-
[in] | CONDITION | Operation to be checked. |
[in] | MESSAGE | String with printf-like parameter to be logged in case of non-successful operation. |
- Returns
- false in case of error
◆ CHECK
#define CHECK |
( |
|
CONDITION, |
|
|
|
MESSAGE, |
|
|
|
... |
|
) |
| |
Value: do { \
if (!(CONDITION)) { \
VS_LOG_ERROR((MESSAGE), ##__VA_ARGS__); \
goto terminate; \
} \
} while(0)
Check condition and perform goto terminate if non-successful.
- CONDITION is compared with zero code.
- If they are equal, MESSAGES is logged and function jumps to terminate label.
- Warning
- terminate label must be present in current function.
- Parameters
-
[in] | CONDITION | Operation to be checked. |
[in] | MESSAGE | String with printf-like parameter to be logged in case of non-successful operation. |
◆ CHECK_NOT_ZERO
#define CHECK_NOT_ZERO |
( |
|
ARG | ) |
CHECK((ARG), "Argument " #ARG " must not be zero") |
Checks that ARG is non-zero and perform goto terminate in case of zero one.
- ARG is compared with zero.
- If ARG is zero, result message is logged and function jumps to terminate label.
- Warning
- terminate label must be present in current function.
- Parameters
-
[in] | ARG | Argument to be checked. |
◆ CHECK_NOT_ZERO_RET
#define CHECK_NOT_ZERO_RET |
( |
|
ARG, |
|
|
|
RETCODE |
|
) |
| CHECK_RET((ARG), (RETCODE), "Argument " #ARG " must not be zero") \ |
Checks that ARG is non-zero and return RETCODE in case of zero one.
- ARG is compared with zero.
- If ARG is zero, result message is logged and returns RETCODE.
- Warning
- terminate label must be present in current function.
- Parameters
-
[in] | ARG | Argument to be checked. |
[in] | RETCODE | Return code in case of unsuccessful result. |
- Returns
- RETCODE in case of error
◆ CHECK_RET
#define CHECK_RET |
( |
|
CONDITION, |
|
|
|
RETCODE, |
|
|
|
MESSAGE, |
|
|
|
... |
|
) |
| |
Value: do { \
if (!(CONDITION)) { \
VS_LOG_ERROR((MESSAGE), ##__VA_ARGS__); \
return (RETCODE); \
} \
} while(0)
Check condition and return RETCODE if non-successful.
- CONDITION is compared with zero code.
- If they are equal, MESSAGES is logged and function returns RETCODE.
- Parameters
-
[in] | CONDITION | Operation to be checked. |
[in] | RETCODE | Return code in case of error. |
[in] | MESSAGE | String with printf-like parameter to be logged in case of non-successful operation. |
- Returns
- RETCODE in case of error
◆ MEMCMP_CHECK
#define MEMCMP_CHECK |
( |
|
BUF1, |
|
|
|
BUF2, |
|
|
|
SIZE |
|
) |
| |
Value:
#BUF1 " is not equal to " #BUF2 " while comparing %d bytes", \
(int)(SIZE))
Compares two buffer and perform goto terminate if non-successful.
- BUF1 is compared with BUF2. SIZE bytes are compared.
- If they are not equal, result message is logged and function jumps to terminate label.
- Warning
- terminate label must be present in current function.
-
BUF1 and BUF2 sizes must be the same or bigger than SIZE.
- Parameters
-
[in] | BUF1 | First data buffer to be checked. |
[in] | BUF2 | Second data buffer to be checked. |
[in] | SIZE | Data size. |
◆ MEMCMP_CHECK_RET
#define MEMCMP_CHECK_RET |
( |
|
BUF1, |
|
|
|
BUF2, |
|
|
|
SIZE, |
|
|
|
RETCODE |
|
) |
| |
Value:
#BUF1 " is not equal to " #BUF2 " while comparing %d bytes", \
(int)(SIZE))
Compares two buffers and return RETCODE if non-successful.
- BUF1 is compared with BUF2. SIZE bytes are compared.
- If they are not equal, result mesage is logged and function returns RET.
- Warning
- terminate label must be present in current function.
-
BUF1 and BUF2 sizes must be the same or bigger than SIZE.
- Parameters
-
[in] | BUF1 | First data buffer to be checked. |
[in] | BUF2 | Second data buffer to be checked. |
[in] | SIZE | Data size. |
[in] | RET | Return code in case of unsuccessful result. |
- Returns
- RET in case of error
#define CHECK_RET(CONDITION, RETCODE, MESSAGE,...)
Check condition and return RETCODE if non-successful.
Definition: macros.h:108
#define MEMCMP_CHECK_RET(BUF1, BUF2, SIZE, RETCODE)
Compares two buffers and return RETCODE if non-successful.
Definition: macros.h:171
#define CHECK(CONDITION, MESSAGE,...)
Check condition and perform goto terminate if non-successful.
Definition: macros.h:90