ADTF  3.15.2
repo/src/libraries/a_utils/include/a_utils/base/error.h File Reference

Copyright © Audi Electronics Venture GmbH. More...

Go to the source code of this file.

Classes

struct  tErrorCode
 C++11 POD type to distribute error codes between binary boundaries. More...
 
struct  tErrorString
 Wrapper for stringification of error codes - for usage by struct tError. More...
 

Macros

#define IS_OK(s)   ( ( s ).IsOk() )
 Check if result is OK.
 
#define IS_FAILED(s)   ( ( s ).IsFailed() )
 Check if result is failed.
 
#define RETURN_NOERROR   return ERR_NOERROR
 Return status ERR_NOERROR, which requires the calling function's return type to be tResult.
 
#define RETURN_ERROR(code)   return (code)
 Return specific error code, which requires the calling function's return type to be tResult.
 
#define RETURN_ERROR_DESC(_code, ...)   return DETAILED_RESULT(_code, __VA_ARGS__)
 Same as RETURN_ERROR(_error) using a printf like parameter list for detailed error description.
 
#define RETURN_IF_FAILED(s)   { tResult _errcode(s); if ( _errcode.IsFailed() ) { return (_errcode); } }
 Return if expression is failed, which requires the calling function's return type to be tResult.
 
#define RETURN_IF_FAILED_DESC(s, ...)   { tResult _errcode(s); if ( _errcode.IsFailed() ) { return DETAILED_RESULT(_errcode.GetErrorCode().value, __VA_ARGS__); } }
 
#define RETURN_IF_POINTER_NULL(_ptr)   if ( nullptr == _ptr ) { RETURN_ERROR(ERR_POINTER); }
 Return ERR_POINTER if _ptr is nullptr, which requires the calling function's return type to be tResult.
 
#define RETURN_IF_POINTER_NULL_DESC(_ptr, ...)   if ( nullptr == _ptr ) { return DETAILED_RESULT(ERR_POINTER, __VA_ARGS__); }
 Return ERR_POINTER with description if _ptr is nullptr, which requires the calling function's return type to be tResult.
 
#define LOG_RESULT(code)
 Log result to console. More...
 
#define RETURN_AND_LOG_ERROR(code)
 Log error code to console and return from the current function. More...
 
#define RETURN_AND_LOG_ERROR_STR(code, ...)
 Log custom error description to console and return from the current function. More...
 
#define RETURN_IF_FAILED_AND_LOG_ERROR_STR(code, ...)
 Log custom error description to console and return from the current function. More...
 
#define ASSERT_IF_POINTER_NULL(_ptr)
 In debug mode this macro asserts if a pointer is NULL, in release mode does nothing.
 
#define __FUNC__   __func__
 MSVC 2013 doesn't know about func, so this macro enables this feature.
 
#define _MAKE_ERROR(_no, _strcode)
 Create an error type with its name and numeric representation. More...
 

Functions

 _MAKE_ERROR (0, ERR_NOERROR)
 Create error type ERR_NOERROR with numeric representation 0.
 
 _MAKE_ERROR (2, ERR_UNKNOWN)
 Create error type ERR_UNKNOWN with numeric representation -2.
 
 _MAKE_ERROR (3, ERR_UNEXPECTED)
 Create error type ERR_UNEXPECTED with numeric representation -3.
 
 _MAKE_ERROR (4, ERR_POINTER)
 Create error type ERR_POINTER with numeric representation -4.
 
 _MAKE_ERROR (5, ERR_INVALID_ARG)
 Create error type ERR_INVALID_ARG with numeric representation -5.
 
 _MAKE_ERROR (6, ERR_INVALID_FUNCTION)
 Create error type ERR_INVALID_FUNCTION with numeric representation -6.
 
 _MAKE_ERROR (7, ERR_INVALID_ADDRESS)
 Create error type ERR_INVALID_ADDRESS with numeric representation -7.
 
 _MAKE_ERROR (8, ERR_INVALID_HANDLE)
 Create error type ERR_INVALID_HANDLE with numeric representation -8.
 
 _MAKE_ERROR (9, ERR_INVALID_FLAGS)
 Create error type ERR_INVALID_FLAGS with numeric representation -9.
 
 _MAKE_ERROR (10, ERR_INVALID_INDEX)
 Create error type ERR_INVALID_INDEX with numeric representation -10.
 
 _MAKE_ERROR (11, ERR_INVALID_FILE)
 Create error type ERR_INVALID_FILE with numeric representation -11.
 
 _MAKE_ERROR (12, ERR_MEMORY)
 Create error type ERR_MEMORY with numeric representation -12.
 
 _MAKE_ERROR (13, ERR_TIMEOUT)
 Create error type ERR_TIMEOUT with numeric representation -13.
 
 _MAKE_ERROR (14, ERR_OUT_OF_SYNC)
 Create error type ERR_OUT_OF_SYNC with numeric representation -14.
 
 _MAKE_ERROR (15, ERR_RESOURCE_IN_USE)
 Create error type ERR_RESOURCE_IN_USE with numeric representation -15.
 
 _MAKE_ERROR (16, ERR_NOT_IMPL)
 Create error type ERR_NOT_IMPL with numeric representation -16.
 
 _MAKE_ERROR (17, ERR_NO_INTERFACE)
 Create error type ERR_NO_INTERFACE with numeric representation -17.
 
 _MAKE_ERROR (18, ERR_NO_CLASS)
 Create error type ERR_NO_CLASS with numeric representation -18.
 
 _MAKE_ERROR (19, ERR_NOT_SUPPORTED)
 Create error type ERR_NOT_SUPPORTED with numeric representation -19.
 
 _MAKE_ERROR (20, ERR_NOT_FOUND)
 Create error type ERR_NOT_FOUND with numeric representation -20.
 
 _MAKE_ERROR (21, ERR_CANCELED)
 Create error type ERR_CANCELED with numeric representation -21.
 
 _MAKE_ERROR (22, ERR_RETRY)
 Create error type ERR_RETRY with numeric representation -22.
 
 _MAKE_ERROR (23, ERR_FILE_NOT_FOUND)
 Create error type ERR_FILE_NOT_FOUND with numeric representation -23.
 
 _MAKE_ERROR (24, ERR_PATH_NOT_FOUND)
 Create error type ERR_PATH_NOT_FOUND with numeric representation -24.
 
 _MAKE_ERROR (25, ERR_ACCESS_DENIED)
 Create error type ERR_ACCESS_DENIED with numeric representation -25.
 
 _MAKE_ERROR (26, ERR_NOT_READY)
 Create error type ERR_NOT_READY with numeric representation -26.
 
 _MAKE_ERROR (27, ERR_OPEN_FAILED)
 Create error type ERR_OPEN_FAILED with numeric representation -27.
 
 _MAKE_ERROR (28, ERR_IO_INCOMPLETE)
 Create error type ERR_IO_INCOMPLETE with numeric representation -28.
 
 _MAKE_ERROR (29, ERR_IO_PENDING)
 Create error type ERR_IO_PENDING with numeric representation -29.
 
 _MAKE_ERROR (30, ERR_NOACCESS)
 Create error type ERR_NOACCESS with numeric representation -30.
 
 _MAKE_ERROR (31, ERR_BAD_DEVICE)
 Create error type ERR_BAD_DEVICE with numeric representation -31.
 
 _MAKE_ERROR (32, ERR_DEVICE_IO)
 Create error type ERR_DEVICE_IO with numeric representation -32.
 
 _MAKE_ERROR (33, ERR_DEVICE_NOT_READY)
 Create error type ERR_DEVICE_NOT_READY with numeric representation -33.
 
 _MAKE_ERROR (34, ERR_DEVICE_IN_USE)
 Create error type ERR_DEVICE_IN_USE with numeric representation -34.
 
 _MAKE_ERROR (35, ERR_NOT_CONNECTED)
 Create error type ERR_NOT_CONNECTED with numeric representation -35.
 
 _MAKE_ERROR (36, ERR_UNKNOWN_FORMAT)
 Create error type ERR_UNKNOWN_FORMAT with numeric representation -36.
 
 _MAKE_ERROR (37, ERR_NOT_INITIALIZED)
 Create error type ERR_NOT_INITIALIZED with numeric representation -37.
 
 _MAKE_ERROR (38, ERR_FAILED)
 Create error type ERR_FAILED with numeric representation -38.
 
 _MAKE_ERROR (39, ERR_END_OF_FILE)
 Create error type ERR_END_OF_FILE with numeric representation -39.
 
 _MAKE_ERROR (40, ERR_INVALID_STATE)
 Create error type ERR_INVALID_STATE with numeric representation -40.
 
 _MAKE_ERROR (41, ERR_EXCEPTION_RAISED)
 Create error type ERR_EXCEPTION_RAISED with numeric representation -41.
 
 _MAKE_ERROR (42, ERR_INVALID_TYPE)
 Create error type ERR_INVALID_TYPE with numeric representation -42.
 
 _MAKE_ERROR (43, ERR_EMPTY)
 Create error type ERR_EMPTY with numeric representation -43.
 
 _MAKE_ERROR (44, ERR_INVALID_VERSION)
 Create error type ERR_INVALID_VERSION with numeric representation -44.
 
 _MAKE_ERROR (45, ERR_INVALID_LICENSE)
 Create error type ERR_INVALID_LICENSE with numeric representation -45.
 
 _MAKE_ERROR (46, ERR_SERVICE_NOT_FOUND)
 Create error type ERR_SERVICE_NOT_FOUND with numeric representation -46.
 
 _MAKE_ERROR (47, ERR_DAU)
 Create error type ERR_DAU with numeric representation -47.
 
 _MAKE_ERROR (48, ERR_IDLE_NOWAIT)
 Create error type ERR_IDLE_NOWAIT with numeric representation -48.
 
 _MAKE_ERROR (49, ERR_OUT_OF_RANGE)
 Create error type ERR_OUT_OF_RANGE with numeric representation -49.
 
 _MAKE_ERROR (50, ERR_KNOWN_PROBLEM)
 Create error type ERR_KNOWN_PROBLEM with numeric representation -50.
 
 _MAKE_ERROR (51, ERR_INVALID_INTERFACE)
 Create error type ERR_INVALID_INTERFACE with numeric representation -51.
 
 _MAKE_ERROR (52, ERR_INTERNAL)
 This one is only for internal use and must not be obtained by any customer!!! Also note: The error code must be increased if a new error object is added.
 
tBool operator== (const tErrorCode &lhs, const tErrorCode &rhs)
 Compare two POD error code types for equality. More...
 
tBool operator!= (const tErrorCode &lhs, const tErrorCode &rhs)
 Compare two POD error code types for inequality. More...
 
tBool operator< (const tErrorCode &lhs, const tErrorCode &rhs)
 Less-than operator for POD error type. More...
 
tBool operator> (const tErrorCode &lhs, const tErrorCode &rhs)
 Greater-than operator for POD error type. More...
 
tBool operator<= (const tErrorCode &lhs, const tErrorCode &rhs)
 Less-than-or-equal operator for POD error type. More...
 
tBool operator>= (const tErrorCode &lhs, const tErrorCode &rhs)
 Greater-than-or-equal operator for POD error type. More...
 
template<tErrorCode::error_code_type ErrorCodeLHS, tErrorCode::error_code_type ErrorCodeRHS>
tBool operator== (const tError< ErrorCodeLHS > &lhs, const tError< ErrorCodeRHS > &rhs)
 Compare two specialized error code types for equality. More...
 
template<tErrorCode::error_code_type ErrorCodeLHS, tErrorCode::error_code_type ErrorCodeRHS>
tBool operator!= (const tError< ErrorCodeLHS > &lhs, const tError< ErrorCodeRHS > &rhs)
 Compare two specialized error code types for inequality. More...
 
template<tErrorCode::error_code_type ErrorCodeLHS, tErrorCode::error_code_type ErrorCodeRHS>
tBool operator< (const tError< ErrorCodeLHS > &lhs, const tError< ErrorCodeRHS > &rhs)
 Less-than operator for two specialized error code types. More...
 
template<tErrorCode::error_code_type ErrorCodeLHS, tErrorCode::error_code_type ErrorCodeRHS>
tBool operator> (const tError< ErrorCodeLHS > &lhs, const tError< ErrorCodeRHS > &rhs)
 Greater-than operator for two specialized error code types. More...
 
template<tErrorCode::error_code_type ErrorCodeLHS, tErrorCode::error_code_type ErrorCodeRHS>
tBool operator<= (const tError< ErrorCodeLHS > &lhs, const tError< ErrorCodeRHS > &rhs)
 Less-than-or-equal operator for two specialized error code types. More...
 
template<tErrorCode::error_code_type ErrorCodeLHS, tErrorCode::error_code_type ErrorCodeRHS>
tBool operator>= (const tError< ErrorCodeLHS > &lhs, const tError< ErrorCodeRHS > &rhs)
 Greater-than-or-equal operator for two specialized error code types. More...
 

Detailed Description

Copyright © Audi Electronics Venture GmbH.

All rights reserved

Definition in file repo/src/libraries/a_utils/include/a_utils/base/error.h.

Macro Definition Documentation

◆ _MAKE_ERROR

#define _MAKE_ERROR (   _no,
  _strcode 
)
Value:
/* (e.g. 2, ERR_UNKNOWN --> ERR_UNKNOWN = -2) */ \
template< > \
struct tError< -_no > \
{ \
explicit operator tErrorCode() const \
{ \
return tErrorCode { -_no }; \
} \
explicit operator tErrorString() const \
{ \
return tErrorString { tError<-_no>::error_code, tError<-_no>::str_error_code }; \
} \
static constexpr const tChar* const str_error_code = #_strcode; \
static constexpr const tErrorCode::error_code_type error_code = -_no; \
}; \
static const tError<-_no> _strcode = tError<-_no>()
char tChar
The tChar defines the type for platform character set (platform and compiler dependent type).
C++11 POD type to distribute error codes between binary boundaries.
Basic error type template, specialized by _MAKE_ERROR() to create concrete error types.
Wrapper for stringification of error codes - for usage by struct tError.

Create an error type with its name and numeric representation.

The created error type is a specialization of tError with the numeric representation _no being negated and used as non type template parameter. The created error type may be used to construct tResult with appropriate error information. To get the POD version of the created error type, a static_cast<tErrorCode> might be used.

Parameters
[in]_noNumeric representation of the error type (gets negated!)
[in]_strcodeName as string for the error type

Definition at line 169 of file repo/src/libraries/a_utils/include/a_utils/base/error.h.

◆ LOG_RESULT

#define LOG_RESULT (   code)
Value:
do\
{ \
tResult _result = code; \
if (IS_OK(_result))\
{\
LOG_INFO(A_UTILS_NS::to_string(_result));\
} \
else \
{\
LOG_ERROR(A_UTILS_NS::to_string(_result));\
} \
} \
while(tFalse)
#define tFalse
Value for tBool.
Definition: constants.h:60
cString to_string(const tResult &i_oResult, eResultFormatFlags i_eFormatFlags=eResultFormatFlags::RFF_DisableNone, const tChar *i_strFormat=nullptr)
Copy all information of an assigned result object to a (formatted) string.
#define IS_OK(s)
Check if result is OK.

Log result to console.

Definition at line 55 of file repo/src/libraries/a_utils/include/a_utils/base/error.h.

◆ RETURN_AND_LOG_ERROR

#define RETURN_AND_LOG_ERROR (   code)
Value:
do\
{ \
tResult _result = code; \
LOG_RESULT(_result); \
return (_result); \
}\
while(tFalse)

Log error code to console and return from the current function.

This requires the calling function's return type to be tResult.

Definition at line 72 of file repo/src/libraries/a_utils/include/a_utils/base/error.h.

◆ RETURN_AND_LOG_ERROR_STR

#define RETURN_AND_LOG_ERROR_STR (   code,
  ... 
)
Value:
do\
{ \
LOG_ERROR(__VA_ARGS__); \
return (code); \
}\
while(tFalse)

Log custom error description to console and return from the current function.

This requires the calling function's return type to be tResult.

Definition at line 83 of file repo/src/libraries/a_utils/include/a_utils/base/error.h.

◆ RETURN_IF_FAILED_AND_LOG_ERROR_STR

#define RETURN_IF_FAILED_AND_LOG_ERROR_STR (   code,
  ... 
)
Value:
do\
{ \
tResult _outer_result = code; \
if (IS_FAILED(_outer_result)) \
{\
LOG_ERROR(__VA_ARGS__); \
LOG_RESULT(_outer_result);\
return _outer_result;\
} \
}\
while(tFalse)
#define IS_FAILED(s)
Check if result is failed.

Log custom error description to console and return from the current function.

This requires the calling function's return type to be tResult.

Definition at line 93 of file repo/src/libraries/a_utils/include/a_utils/base/error.h.

Function Documentation

◆ operator!=() [1/2]

tBool operator!= ( const tError< ErrorCodeLHS > &  lhs,
const tError< ErrorCodeRHS > &  rhs 
)
inline

Compare two specialized error code types for inequality.

Template Parameters
ErrorCodeLHSLeft hand side numeric error code representation type
ErrorCodeRHSRight hand side numeric error code representation type
Parameters
[in]lhsLeft hand side error code
[in]rhsRight hand side error code
Returns
tFalse if rhs and lhs are equal, tTrue otherwise.

Definition at line 382 of file repo/src/libraries/a_utils/include/a_utils/base/error.h.

References operator==().

◆ operator!=() [2/2]

tBool operator!= ( const tErrorCode lhs,
const tErrorCode rhs 
)
inline

Compare two POD error code types for inequality.

Parameters
[in]lhsLeft hand side error code
[in]rhsRight hand side error code
Returns
tFalse if rhs and lhs are equal, tTrue otherwise.

Definition at line 310 of file repo/src/libraries/a_utils/include/a_utils/base/error.h.

References operator==().

Referenced by Value::operator<().

◆ operator<() [1/2]

tBool operator< ( const tError< ErrorCodeLHS > &  lhs,
const tError< ErrorCodeRHS > &  rhs 
)
inline

Less-than operator for two specialized error code types.

Template Parameters
ErrorCodeLHSLeft hand side numeric error code representation type
ErrorCodeRHSRight hand side numeric error code representation type
Parameters
[in]lhsLeft hand side error code
[in]rhsRight hand side error code
Returns
tTrue if lhs is less than rhs, tFalse otherwise.

Definition at line 396 of file repo/src/libraries/a_utils/include/a_utils/base/error.h.

◆ operator<() [2/2]

tBool operator< ( const tErrorCode lhs,
const tErrorCode rhs 
)
inline

Less-than operator for POD error type.

Parameters
[in]lhsLeft hand side error code
[in]rhsRight hand side error code
Returns
tTrue if lhs is less than rhs, tFalse otherwise.

Definition at line 321 of file repo/src/libraries/a_utils/include/a_utils/base/error.h.

References tErrorCode::value.

Referenced by operator>(), and operator>=().

◆ operator<=() [1/2]

tBool operator<= ( const tError< ErrorCodeLHS > &  lhs,
const tError< ErrorCodeRHS > &  rhs 
)
inline

Less-than-or-equal operator for two specialized error code types.

Template Parameters
ErrorCodeLHSLeft hand side numeric error code representation type
ErrorCodeRHSRight hand side numeric error code representation type
Parameters
[in]lhsLeft hand side error code
[in]rhsRight hand side error code
Returns
tTrue if lhs is less than or equal rhs, tFalse otherwise.

Definition at line 424 of file repo/src/libraries/a_utils/include/a_utils/base/error.h.

References operator>().

◆ operator<=() [2/2]

tBool operator<= ( const tErrorCode lhs,
const tErrorCode rhs 
)
inline

Less-than-or-equal operator for POD error type.

Parameters
[in]lhsLeft hand side error code
[in]rhsRight hand side error code
Returns
tTrue if lhs is less than or equal rhs, tFalse otherwise.

Definition at line 343 of file repo/src/libraries/a_utils/include/a_utils/base/error.h.

References operator>().

◆ operator==() [1/2]

tBool operator== ( const tError< ErrorCodeLHS > &  lhs,
const tError< ErrorCodeRHS > &  rhs 
)
inline

Compare two specialized error code types for equality.

Template Parameters
ErrorCodeLHSLeft hand side numeric error code representation type
ErrorCodeRHSRight hand side numeric error code representation type
Parameters
[in]lhsLeft hand side error code
[in]rhsRight hand side error code
Returns
tTrue if rhs and lhs are equal, tFalse otherwise.

Definition at line 368 of file repo/src/libraries/a_utils/include/a_utils/base/error.h.

◆ operator==() [2/2]

tBool operator== ( const tErrorCode lhs,
const tErrorCode rhs 
)
inline

Compare two POD error code types for equality.

Parameters
[in]lhsLeft hand side error code
[in]rhsRight hand side error code
Returns
tTrue if rhs and lhs are equal, tFalse otherwise.

Definition at line 299 of file repo/src/libraries/a_utils/include/a_utils/base/error.h.

References tErrorCode::value.

Referenced by operator!=(), and Value::operator<().

◆ operator>() [1/2]

tBool operator> ( const tError< ErrorCodeLHS > &  lhs,
const tError< ErrorCodeRHS > &  rhs 
)
inline

Greater-than operator for two specialized error code types.

Template Parameters
ErrorCodeLHSLeft hand side numeric error code representation type
ErrorCodeRHSRight hand side numeric error code representation type
Parameters
[in]lhsLeft hand side error code
[in]rhsRight hand side error code
Returns
tFalse if lhs is less than or equal rhs, tTrue otherwise.

Definition at line 410 of file repo/src/libraries/a_utils/include/a_utils/base/error.h.

References operator<().

◆ operator>() [2/2]

tBool operator> ( const tErrorCode lhs,
const tErrorCode rhs 
)
inline

Greater-than operator for POD error type.

Parameters
[in]lhsLeft hand side error code
[in]rhsRight hand side error code
Returns
tFalse if lhs is less than or equal rhs, tTrue otherwise.

Definition at line 332 of file repo/src/libraries/a_utils/include/a_utils/base/error.h.

References operator<().

Referenced by operator<=().

◆ operator>=() [1/2]

tBool operator>= ( const tError< ErrorCodeLHS > &  lhs,
const tError< ErrorCodeRHS > &  rhs 
)
inline

Greater-than-or-equal operator for two specialized error code types.

Template Parameters
ErrorCodeLHSLeft hand side numeric error code representation type
ErrorCodeRHSRight hand side numeric error code representation type
Parameters
[in]lhsLeft hand side error code
[in]rhsRight hand side error code
Returns
tFalse if lhs is less than rhs, tTrue otherwise.

Definition at line 438 of file repo/src/libraries/a_utils/include/a_utils/base/error.h.

References operator<().

◆ operator>=() [2/2]

tBool operator>= ( const tErrorCode lhs,
const tErrorCode rhs 
)
inline

Greater-than-or-equal operator for POD error type.

Parameters
[in]lhsLeft hand side error code
[in]rhsRight hand side error code
Returns
tFalse if lhs is less than rhs, tTrue otherwise.

Definition at line 354 of file repo/src/libraries/a_utils/include/a_utils/base/error.h.

References operator<().