8 #ifndef A_UTILS_ERRORS_H
9 #define A_UTILS_ERRORS_H
12 #define IS_OK(s) ( ( s ).IsOk() )
15 #define IS_FAILED(s) ( ( s ).IsFailed() )
18 #define DETAILED_RESULT(_errcode, ...) \
20 A_UTILS_NS::cString::Format(__VA_ARGS__).GetPtr(), \
22 A_UTILS_NS::cFilename(__FILE__).GetName().GetPtr(), \
27 #define RETURN_NOERROR return ERR_NOERROR
29 #if (__UCOM_ASSERT_WHEN_LOGGING_ERRORS == 1)
31 #define RETURN_ERROR(_code) assert(IS_OK(_code)); return (_code)
33 #define RETURN_ERROR_DESC(_code, ...) assert(IS_OK(_code)); return DETAILED_RESULT(_code, \
37 #define RETURN_ERROR(code) return (code)
39 #define RETURN_ERROR_DESC(_code, ...) return DETAILED_RESULT(_code, __VA_ARGS__)
44 #define RETURN_IF_FAILED(s) { tResult _errcode(s); if ( _errcode.IsFailed() ) { return (_errcode); } }
46 #define RETURN_IF_FAILED_DESC(s, ...) { tResult _errcode(s); if ( _errcode.IsFailed() ) { return DETAILED_RESULT(_errcode.GetErrorCode().value, __VA_ARGS__); } }
49 #define RETURN_IF_POINTER_NULL(_ptr) if ( nullptr == _ptr ) { RETURN_ERROR(ERR_POINTER); }
52 #define RETURN_IF_POINTER_NULL_DESC(_ptr, ...) if ( nullptr == _ptr ) { return DETAILED_RESULT(ERR_POINTER, __VA_ARGS__); }
55 #define LOG_RESULT(code) \
58 tResult _result = code; \
61 LOG_INFO(A_UTILS_NS::to_string(_result));\
65 LOG_ERROR(A_UTILS_NS::to_string(_result));\
72 #define RETURN_AND_LOG_ERROR(code) \
75 tResult _result = code; \
76 LOG_RESULT(_result); \
83 #define RETURN_AND_LOG_ERROR_STR(code, ...) \
86 LOG_ERROR(__VA_ARGS__); \
93 #define RETURN_IF_FAILED_AND_LOG_ERROR_STR(code, ...) \
96 tResult _outer_result = code; \
97 if (IS_FAILED(_outer_result)) \
99 LOG_ERROR(__VA_ARGS__); \
100 LOG_RESULT(_outer_result);\
101 return _outer_result;\
108 #define ASSERT_IF_POINTER_NULL(_ptr) A_UTILS_ASSERT( nullptr != _ptr );
110 #define ASSERT_IF_POINTER_NULL(_ptr)
115 #define __FUNC__ __FUNCTION__
117 #define __FUNC__ __func__
156 template<tErrorCode::error_code_type ReturnValue>
169 #define _MAKE_ERROR(_no, _strcode) \
171 struct tError< -_no > \
173 explicit operator tErrorCode() const \
175 return tErrorCode { -_no }; \
177 explicit operator tErrorString() const \
179 return tErrorString { tError<-_no>::error_code, tError<-_no>::str_error_code }; \
181 static constexpr const tChar* const str_error_code = #_strcode; \
182 static constexpr const tErrorCode::error_code_type error_code = -_no; \
184 static const tError<-_no> _strcode = tError<-_no>()
367 template<tErrorCode::error_code_type ErrorCodeLHS, tErrorCode::error_code_type ErrorCodeRHS>
381 template<tErrorCode::error_code_type ErrorCodeLHS, tErrorCode::error_code_type ErrorCodeRHS>
395 template<tErrorCode::error_code_type ErrorCodeLHS, tErrorCode::error_code_type ErrorCodeRHS>
409 template<tErrorCode::error_code_type ErrorCodeLHS, tErrorCode::error_code_type ErrorCodeRHS>
423 template<tErrorCode::error_code_type ErrorCodeLHS, tErrorCode::error_code_type ErrorCodeRHS>
437 template<tErrorCode::error_code_type ErrorCodeLHS, tErrorCode::error_code_type ErrorCodeRHS>
tBool operator<(const tErrorCode &lhs, const tErrorCode &rhs)
Less-than operator for POD error type.
#define _MAKE_ERROR(_no, _strcode)
Create an error type with its name and numeric representation.
tBool operator<=(const tErrorCode &lhs, const tErrorCode &rhs)
Less-than-or-equal operator for POD error type.
tBool operator>(const tErrorCode &lhs, const tErrorCode &rhs)
Greater-than operator for POD error type.
tBool operator!=(const tErrorCode &lhs, const tErrorCode &rhs)
Compare two POD error code types for inequality.
tBool operator==(const tErrorCode &lhs, const tErrorCode &rhs)
Compare two POD error code types for equality.
tBool operator>=(const tErrorCode &lhs, const tErrorCode &rhs)
Greater-than-or-equal operator for POD error type.
char tChar
The tChar defines the type for platform character set (platform and compiler dependent type).
int32_t tInt32
type definition for signed integer values (32bit) (platform and compiler independent type).
bool tBool
The tBool defines the type for the Values tTrue and tFalse (platform and compiler dependent).
C++11 POD type to distribute error codes between binary boundaries.
error_code_type value
Value of this error code.
tInt32 error_code_type
Type of the error code.
Basic error type template, specialized by _MAKE_ERROR() to create concrete error types.
Wrapper for stringification of error codes - for usage by struct tError.
const tChar * strErrorCode() const
Get the error code as string representation.
const tChar *const strValue
Pointer to existing error code string.
tErrorString()=default
Default constructor.
tErrorString(const tErrorCode::error_code_type i_nErrorCode, const tChar *i_strErrorCode)
Construct with error code and error string.