ADTF
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 #ifdef _DEBUG
13 #define ASSERT_IF_POINTER_NULL(_ptr) A_UTILS_ASSERT( nullptr != _ptr );
14 #else
15 #define ASSERT_IF_POINTER_NULL(_ptr)
16 #endif
17 
18 #define __FUNC__ __func__
19 
21 struct tErrorCode
22 {
25 };//struct tErrorCode
26 
28 struct tErrorString : public tErrorCode
29 {
31  tErrorString() = default;
32 
38  tErrorString(const tErrorCode::error_code_type i_nErrorCode, const tChar* i_strErrorCode) :
39  tErrorCode{ i_nErrorCode }, strValue(i_strErrorCode) {}
40 
45  const tChar* strErrorCode() const { return strValue; }
46 
47 private:
48  const tChar* const strValue;
49 };//struct tErrorString
50 
56 template<tErrorCode::error_code_type ReturnValue>
57 struct tError;
58 
69 #define _MAKE_ERROR(_no, _strcode) /* (e.g. 2, ERR_UNKNOWN --> ERR_UNKNOWN = -2) */ \
70  template< > \
71  struct tError< -_no > \
72  { \
73  explicit operator tErrorCode() const \
74  { \
75  return tErrorCode { -_no }; \
76  } \
77  explicit operator tErrorString() const \
78  { \
79  return tErrorString { tError<-_no>::error_code, tError<-_no>::str_error_code }; \
80  } \
81  static constexpr const tChar* const str_error_code = #_strcode; \
82  static constexpr const tErrorCode::error_code_type error_code = -_no; \
83  }; \
84  static const tError<-_no> _strcode = tError<-_no>()
85 
87 _MAKE_ERROR( 0, ERR_NOERROR );
89 _MAKE_ERROR( 2, ERR_UNKNOWN );
91 _MAKE_ERROR( 3, ERR_UNEXPECTED );
93 _MAKE_ERROR( 4, ERR_POINTER );
95 _MAKE_ERROR( 5, ERR_INVALID_ARG );
97 _MAKE_ERROR( 6, ERR_INVALID_FUNCTION );
99 _MAKE_ERROR( 7, ERR_INVALID_ADDRESS );
101 _MAKE_ERROR( 8, ERR_INVALID_HANDLE );
103 _MAKE_ERROR( 9, ERR_INVALID_FLAGS );
105 _MAKE_ERROR(10, ERR_INVALID_INDEX );
107 _MAKE_ERROR(11, ERR_INVALID_FILE );
109 _MAKE_ERROR(12, ERR_MEMORY );
111 _MAKE_ERROR(13, ERR_TIMEOUT );
113 _MAKE_ERROR(14, ERR_OUT_OF_SYNC );
115 _MAKE_ERROR(15, ERR_RESOURCE_IN_USE );
117 _MAKE_ERROR(16, ERR_NOT_IMPL );
119 _MAKE_ERROR(17, ERR_NO_INTERFACE );
121 _MAKE_ERROR(18, ERR_NO_CLASS );
123 _MAKE_ERROR(19, ERR_NOT_SUPPORTED );
125 _MAKE_ERROR(20, ERR_NOT_FOUND );
127 _MAKE_ERROR(21, ERR_CANCELED );
129 _MAKE_ERROR(22, ERR_RETRY );
131 _MAKE_ERROR(23, ERR_FILE_NOT_FOUND );
133 _MAKE_ERROR(24, ERR_PATH_NOT_FOUND );
135 _MAKE_ERROR(25, ERR_ACCESS_DENIED );
137 _MAKE_ERROR(26, ERR_NOT_READY );
139 _MAKE_ERROR(27, ERR_OPEN_FAILED );
141 _MAKE_ERROR(28, ERR_IO_INCOMPLETE );
143 _MAKE_ERROR(29, ERR_IO_PENDING );
145 _MAKE_ERROR(30, ERR_NOACCESS );
147 _MAKE_ERROR(31, ERR_BAD_DEVICE );
149 _MAKE_ERROR(32, ERR_DEVICE_IO );
151 _MAKE_ERROR(33, ERR_DEVICE_NOT_READY );
153 _MAKE_ERROR(34, ERR_DEVICE_IN_USE );
155 _MAKE_ERROR(35, ERR_NOT_CONNECTED );
157 _MAKE_ERROR(36, ERR_UNKNOWN_FORMAT );
159 _MAKE_ERROR(37, ERR_NOT_INITIALIZED );
161 _MAKE_ERROR(38, ERR_FAILED );
163 _MAKE_ERROR(39, ERR_END_OF_FILE );
165 _MAKE_ERROR(40, ERR_INVALID_STATE );
167 _MAKE_ERROR(41, ERR_EXCEPTION_RAISED );
169 _MAKE_ERROR(42, ERR_INVALID_TYPE );
171 _MAKE_ERROR(43, ERR_EMPTY );
173 _MAKE_ERROR(44, ERR_INVALID_VERSION );
175 _MAKE_ERROR(45, ERR_INVALID_LICENSE );
177 _MAKE_ERROR(46, ERR_SERVICE_NOT_FOUND);
179 _MAKE_ERROR(47, ERR_DAU );
181 _MAKE_ERROR(48, ERR_IDLE_NOWAIT );
183 _MAKE_ERROR(49, ERR_OUT_OF_RANGE );
185 _MAKE_ERROR(50, ERR_KNOWN_PROBLEM );
187 _MAKE_ERROR(51, ERR_INVALID_INTERFACE);
188 
191 _MAKE_ERROR(52, ERR_INTERNAL );
192 
199 inline tBool operator== (const tErrorCode& lhs, const tErrorCode& rhs)
200 {
201  return lhs.value == rhs.value;
202 }
203 
210 inline tBool operator!= (const tErrorCode& lhs, const tErrorCode& rhs)
211 {
212  return !operator==(lhs, rhs);
213 }
214 
221 inline tBool operator< (const tErrorCode& lhs, const tErrorCode& rhs)
222 {
223  return lhs.value < rhs.value;
224 }
225 
232 inline tBool operator> (const tErrorCode& lhs, const tErrorCode& rhs)
233 {
234  return operator<(rhs, lhs);
235 }
236 
243 inline tBool operator<= (const tErrorCode& lhs, const tErrorCode& rhs)
244 {
245  return !operator>(lhs, rhs);
246 }
247 
254 inline tBool operator>= (const tErrorCode& lhs, const tErrorCode& rhs)
255 {
256  return !operator<(lhs, rhs);
257 }
258 
267 template<tErrorCode::error_code_type ErrorCodeLHS, tErrorCode::error_code_type ErrorCodeRHS>
269 {
270  return static_cast<tErrorCode>(lhs) == static_cast<tErrorCode>(rhs);
271 }
272 
281 template<tErrorCode::error_code_type ErrorCodeLHS, tErrorCode::error_code_type ErrorCodeRHS>
283 {
284  return !operator==(lhs, rhs);
285 }
286 
295 template<tErrorCode::error_code_type ErrorCodeLHS, tErrorCode::error_code_type ErrorCodeRHS>
297 {
298  return static_cast<tErrorCode>(lhs) < static_cast<tErrorCode>(rhs);
299 }
300 
309 template<tErrorCode::error_code_type ErrorCodeLHS, tErrorCode::error_code_type ErrorCodeRHS>
311 {
312  return operator<(rhs, lhs);
313 }
314 
323 template<tErrorCode::error_code_type ErrorCodeLHS, tErrorCode::error_code_type ErrorCodeRHS>
325 {
326  return !operator>(lhs, rhs);
327 }
328 
337 template<tErrorCode::error_code_type ErrorCodeLHS, tErrorCode::error_code_type ErrorCodeRHS>
339 {
340  return !operator<(lhs, rhs);
341 }
342 
343 #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.