ADTF  3.18.2
builds/digitalwerk/solutions/adtf_content/adtf_base/adtf_core/src/libraries/a_utils/include/a_utils/base/error.h
Go to the documentation of this file.
1 
8 #ifndef A_UTILS_ERRORS_H
9 #define A_UTILS_ERRORS_H
10 
12 #define IS_OK(s) ( ( s ).IsOk() )
13 
15 #define IS_FAILED(s) ( ( s ).IsFailed() )
16 
18 #define DETAILED_RESULT(_errcode, ...) \
19  tResult(_errcode, \
20  A_UTILS_NS::cString::Format(__VA_ARGS__).GetPtr(), \
21  __LINE__, \
22  A_UTILS_NS::cFilename(__FILE__).GetName().GetPtr(), \
23  __FUNC__)
27 #define RETURN_NOERROR return ERR_NOERROR
28 
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, \
34  __VA_ARGS__)
35 #else
37 #define RETURN_ERROR(code) return (code)
39 #define RETURN_ERROR_DESC(_code, ...) return DETAILED_RESULT(_code, __VA_ARGS__)
40 
41 #endif
42 
44 #define RETURN_IF_FAILED(s) { tResult _errcode(s); if ( _errcode.IsFailed() ) { return (_errcode); } }
45 
46 #define RETURN_IF_FAILED_DESC(s, ...) { tResult _errcode(s); if ( _errcode.IsFailed() ) { return DETAILED_RESULT(_errcode.GetErrorCode().value, __VA_ARGS__); } }
47 
49 #define RETURN_IF_POINTER_NULL(_ptr) if ( nullptr == _ptr ) { RETURN_ERROR(ERR_POINTER); }
50 
52 #define RETURN_IF_POINTER_NULL_DESC(_ptr, ...) if ( nullptr == _ptr ) { return DETAILED_RESULT(ERR_POINTER, __VA_ARGS__); }
53 
55 #define LOG_RESULT(code) \
56 do\
57 { \
58  tResult _result = code; \
59  if (IS_OK(_result))\
60  {\
61  LOG_INFO("%s", A_UTILS_NS::to_string(_result).GetPtr());\
62  } \
63  else \
64  {\
65  LOG_ERROR("%s", A_UTILS_NS::to_string(_result).GetPtr());\
66  } \
67 } \
68 while(tFalse)
69 
72 #define RETURN_AND_LOG_ERROR(code) \
73 do\
74 { \
75  tResult _result = code; \
76  LOG_RESULT(_result); \
77  return (_result); \
78 }\
79 while(tFalse)
80 
83 #define RETURN_AND_LOG_ERROR_STR(code, ...) \
84 do\
85 { \
86  LOG_ERROR(__VA_ARGS__); \
87  return (code); \
88 }\
89 while(tFalse)
90 
93 #define RETURN_IF_FAILED_AND_LOG_ERROR_STR(code, ...) \
94 do\
95 { \
96  tResult _outer_result = code; \
97  if (IS_FAILED(_outer_result)) \
98  {\
99  LOG_ERROR(__VA_ARGS__); \
100  LOG_RESULT(_outer_result);\
101  return _outer_result;\
102  } \
103 }\
104 while(tFalse)
105 
107 #ifdef _DEBUG
108 #define ASSERT_IF_POINTER_NULL(_ptr) A_UTILS_ASSERT( nullptr != _ptr );
109 #else
110 #define ASSERT_IF_POINTER_NULL(_ptr)
111 #endif
112 
113 #define __FUNC__ __func__
114 
117 {
120 };//struct tErrorCode
121 
123 struct tErrorString : public tErrorCode
124 {
126  tErrorString() = default;
127 
133  tErrorString(const tErrorCode::error_code_type i_nErrorCode, const tChar* i_strErrorCode) :
134  tErrorCode{ i_nErrorCode }, strValue(i_strErrorCode) {}
135 
140  const tChar* strErrorCode() const { return strValue; }
141 
142 private:
143  const tChar* const strValue;
144 };//struct tErrorString
145 
151 template<tErrorCode::error_code_type ReturnValue>
152 struct tError;
153 
164 #define _MAKE_ERROR(_no, _strcode) /* (e.g. 2, ERR_UNKNOWN --> ERR_UNKNOWN = -2) */ \
165  template< > \
166  struct tError< -_no > \
167  { \
168  explicit operator tErrorCode() const \
169  { \
170  return tErrorCode { -_no }; \
171  } \
172  explicit operator tErrorString() const \
173  { \
174  return tErrorString { tError<-_no>::error_code, tError<-_no>::str_error_code }; \
175  } \
176  static constexpr const tChar* const str_error_code = #_strcode; \
177  static constexpr const tErrorCode::error_code_type error_code = -_no; \
178  }; \
179  static const tError<-_no> _strcode = tError<-_no>()
180 
182 _MAKE_ERROR( 0, ERR_NOERROR );
184 _MAKE_ERROR( 2, ERR_UNKNOWN );
186 _MAKE_ERROR( 3, ERR_UNEXPECTED );
188 _MAKE_ERROR( 4, ERR_POINTER );
190 _MAKE_ERROR( 5, ERR_INVALID_ARG );
192 _MAKE_ERROR( 6, ERR_INVALID_FUNCTION );
194 _MAKE_ERROR( 7, ERR_INVALID_ADDRESS );
196 _MAKE_ERROR( 8, ERR_INVALID_HANDLE );
198 _MAKE_ERROR( 9, ERR_INVALID_FLAGS );
200 _MAKE_ERROR(10, ERR_INVALID_INDEX );
202 _MAKE_ERROR(11, ERR_INVALID_FILE );
204 _MAKE_ERROR(12, ERR_MEMORY );
206 _MAKE_ERROR(13, ERR_TIMEOUT );
208 _MAKE_ERROR(14, ERR_OUT_OF_SYNC );
210 _MAKE_ERROR(15, ERR_RESOURCE_IN_USE );
212 _MAKE_ERROR(16, ERR_NOT_IMPL );
214 _MAKE_ERROR(17, ERR_NO_INTERFACE );
216 _MAKE_ERROR(18, ERR_NO_CLASS );
218 _MAKE_ERROR(19, ERR_NOT_SUPPORTED );
220 _MAKE_ERROR(20, ERR_NOT_FOUND );
222 _MAKE_ERROR(21, ERR_CANCELED );
224 _MAKE_ERROR(22, ERR_RETRY );
226 _MAKE_ERROR(23, ERR_FILE_NOT_FOUND );
228 _MAKE_ERROR(24, ERR_PATH_NOT_FOUND );
230 _MAKE_ERROR(25, ERR_ACCESS_DENIED );
232 _MAKE_ERROR(26, ERR_NOT_READY );
234 _MAKE_ERROR(27, ERR_OPEN_FAILED );
236 _MAKE_ERROR(28, ERR_IO_INCOMPLETE );
238 _MAKE_ERROR(29, ERR_IO_PENDING );
240 _MAKE_ERROR(30, ERR_NOACCESS );
242 _MAKE_ERROR(31, ERR_BAD_DEVICE );
244 _MAKE_ERROR(32, ERR_DEVICE_IO );
246 _MAKE_ERROR(33, ERR_DEVICE_NOT_READY );
248 _MAKE_ERROR(34, ERR_DEVICE_IN_USE );
250 _MAKE_ERROR(35, ERR_NOT_CONNECTED );
252 _MAKE_ERROR(36, ERR_UNKNOWN_FORMAT );
254 _MAKE_ERROR(37, ERR_NOT_INITIALIZED );
256 _MAKE_ERROR(38, ERR_FAILED );
258 _MAKE_ERROR(39, ERR_END_OF_FILE );
260 _MAKE_ERROR(40, ERR_INVALID_STATE );
262 _MAKE_ERROR(41, ERR_EXCEPTION_RAISED );
264 _MAKE_ERROR(42, ERR_INVALID_TYPE );
266 _MAKE_ERROR(43, ERR_EMPTY );
268 _MAKE_ERROR(44, ERR_INVALID_VERSION );
270 _MAKE_ERROR(45, ERR_INVALID_LICENSE );
272 _MAKE_ERROR(46, ERR_SERVICE_NOT_FOUND);
274 _MAKE_ERROR(47, ERR_DAU );
276 _MAKE_ERROR(48, ERR_IDLE_NOWAIT );
278 _MAKE_ERROR(49, ERR_OUT_OF_RANGE );
280 _MAKE_ERROR(50, ERR_KNOWN_PROBLEM );
282 _MAKE_ERROR(51, ERR_INVALID_INTERFACE);
283 
286 _MAKE_ERROR(52, ERR_INTERNAL );
287 
294 inline tBool operator== (const tErrorCode& lhs, const tErrorCode& rhs)
295 {
296  return lhs.value == rhs.value;
297 }
298 
305 inline tBool operator!= (const tErrorCode& lhs, const tErrorCode& rhs)
306 {
307  return !operator==(lhs, rhs);
308 }
309 
316 inline tBool operator< (const tErrorCode& lhs, const tErrorCode& rhs)
317 {
318  return lhs.value < rhs.value;
319 }
320 
327 inline tBool operator> (const tErrorCode& lhs, const tErrorCode& rhs)
328 {
329  return operator<(rhs, lhs);
330 }
331 
338 inline tBool operator<= (const tErrorCode& lhs, const tErrorCode& rhs)
339 {
340  return !operator>(lhs, rhs);
341 }
342 
349 inline tBool operator>= (const tErrorCode& lhs, const tErrorCode& rhs)
350 {
351  return !operator<(lhs, rhs);
352 }
353 
362 template<tErrorCode::error_code_type ErrorCodeLHS, tErrorCode::error_code_type ErrorCodeRHS>
364 {
365  return static_cast<tErrorCode>(lhs) == static_cast<tErrorCode>(rhs);
366 }
367 
376 template<tErrorCode::error_code_type ErrorCodeLHS, tErrorCode::error_code_type ErrorCodeRHS>
378 {
379  return !operator==(lhs, rhs);
380 }
381 
390 template<tErrorCode::error_code_type ErrorCodeLHS, tErrorCode::error_code_type ErrorCodeRHS>
392 {
393  return static_cast<tErrorCode>(lhs) < static_cast<tErrorCode>(rhs);
394 }
395 
404 template<tErrorCode::error_code_type ErrorCodeLHS, tErrorCode::error_code_type ErrorCodeRHS>
406 {
407  return operator<(rhs, lhs);
408 }
409 
418 template<tErrorCode::error_code_type ErrorCodeLHS, tErrorCode::error_code_type ErrorCodeRHS>
420 {
421  return !operator>(lhs, rhs);
422 }
423 
432 template<tErrorCode::error_code_type ErrorCodeLHS, tErrorCode::error_code_type ErrorCodeRHS>
434 {
435  return !operator<(lhs, rhs);
436 }
437 
438 #endif //A_UTILS_ERRORS_H
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).
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.
Basic error type template, specialized by _MAKE_ERROR() to create concrete error types.
tErrorString()=default
Default constructor.
tErrorString(const tErrorCode::error_code_type i_nErrorCode, const tChar *i_strErrorCode)
Construct with error code and error string.