32#ifndef ETL_ERROR_HANDLER_INCLUDED
33#define ETL_ERROR_HANDLER_INCLUDED
46#if defined(ETL_LOG_ERRORS) || defined(ETL_IN_UNIT_TEST)
60 struct free_function :
public etl::function<void, const etl::exception&>
62 explicit free_function(
void (*p_function_)(
const etl::exception&))
63 : etl::function<void, const etl::exception&>(p_function_)
71 template <
typename TObject>
72 struct member_function :
public etl::function<TObject, const etl::exception&>
74 member_function(TObject& object_,
void (TObject::*p_function_)(
const etl::exception&))
75 : etl::function<TObject, const etl::exception&>(object_, p_function_)
84 static void set_callback(ifunction<const etl::exception&>& f)
86 create((
void*)(&f), ifunction_stub);
92 template <
void (*Method)(const etl::exception&)>
93 static void set_callback()
95 create(ETL_NULLPTR, function_stub<Method>);
101 template <
typename T,
void (T::*Method)(const etl::exception&)>
102 static void set_callback(T& instance)
104 create((
void*)(&instance), method_stub<T, Method>);
110 template <
typename T,
void (T::*Method)(const etl::exception&) const>
111 static void set_callback(
const T& instance)
113 create((
void*)(&instance), const_method_stub<T, Method>);
119 template <
typename T, T& Instance,
void (T::*Method)(const etl::exception&)>
120 static void set_callback()
122 create(method_instance_stub<T, Instance, Method>);
128 template <
typename T, T const& Instance,
void (T::*Method)(const etl::exception&) const>
129 static void set_callback()
131 create(const_method_instance_stub<T, Instance, Method>);
138 static void error(
const etl::exception& e)
140 invocation_element& invocation = get_invocation_element();
142 if (invocation.stub != ETL_NULLPTR)
144 (*invocation.stub)(invocation.object, e);
150 typedef void (*stub_type)(
void* object,
const etl::exception&);
155 struct invocation_element
159 : object(ETL_NULLPTR)
172 static invocation_element& get_invocation_element()
174 static invocation_element invocation;
182 static void create(
void*
object, stub_type stub)
184 invocation_element& invocation = get_invocation_element();
186 invocation.object = object;
187 invocation.stub = stub;
193 static void create(stub_type stub)
195 invocation_element& invocation = get_invocation_element();
197 invocation.object = ETL_NULLPTR;
198 invocation.stub = stub;
204 template <
typename T,
void (T::*Method)(const etl::exception&)>
205 static void method_stub(
void*
object,
const etl::exception& e)
207 T* p =
static_cast<T*
>(object);
208 return (p->*Method)(e);
214 template <
typename T,
void (T::*Method)(const etl::exception&) const>
215 static void const_method_stub(
void*
object,
const etl::exception& e)
217 T*
const p =
static_cast<T*
>(object);
218 return (p->*Method)(e);
224 template <
typename T, T& Instance,
void (T::*Method)(const etl::exception&)>
225 static void method_instance_stub(
void*,
const etl::exception& e)
227 return (Instance.*Method)(e);
233 template <
typename T, const T& Instance,
void (T::*Method)(const etl::exception&) const>
234 static void const_method_instance_stub(
void*,
const etl::exception& e)
236 (Instance.*Method)(e);
242 template <
void (*Method)(const etl::exception&)>
243 static void function_stub(
void*,
const etl::exception& e)
251 static void ifunction_stub(
void*
object,
const etl::exception& e)
253 etl::ifunction<const etl::exception&>* p =
static_cast<etl::ifunction<const etl::exception&>*
>(object);
258#elif defined(ETL_USE_ASSERT_FUNCTION)
261 namespace private_error_handler
263 typedef void (*assert_function_ptr_t)(
const etl::exception&);
266 template <
size_t Index>
267 struct assert_handler
269 static assert_function_ptr_t assert_function_ptr;
271 static void default_assert(
const etl::exception&)
277 template <
size_t Index>
278 assert_function_ptr_t assert_handler<Index>::assert_function_ptr = assert_handler<Index>::default_assert;
285 inline void set_assert_function(etl::private_error_handler::assert_function_ptr_t afptr)
287 etl::private_error_handler::assert_handler<0>::assert_function_ptr = afptr;
305#if defined(ETL_NO_CHECKS)
306 #define ETL_ASSERT(b, e) static_cast<void>(sizeof(b))
307 #define ETL_ASSERT_OR_RETURN(b, e) static_cast<void>(sizeof(b))
308 #define ETL_ASSERT_OR_RETURN_VALUE(b, e, v) static_cast<void>(sizeof(b))
310 #define ETL_ASSERT_FAIL(e) ETL_DO_NOTHING
311 #define ETL_ASSERT_FAIL_AND_RETURN(e) ETL_DO_NOTHING
312 #define ETL_ASSERT_FAIL_AND_RETURN_VALUE(e, v) ETL_DO_NOTHING
313#elif defined(ETL_USE_ASSERT_FUNCTION)
314 #define ETL_ASSERT(b, e) \
316 if (!(b)) ETL_UNLIKELY \
318 etl::private_error_handler::assert_handler<0>::assert_function_ptr((e)); \
321 #define ETL_ASSERT_OR_RETURN(b, e) \
323 if (!(b)) ETL_UNLIKELY \
325 etl::private_error_handler::assert_handler<0>::assert_function_ptr((e)); \
329 #define ETL_ASSERT_OR_RETURN_VALUE(b, e, v) \
331 if (!(b)) ETL_UNLIKELY \
333 etl::private_error_handler::assert_handler<0>::assert_function_ptr((e)); \
339 #define ETL_ASSERT_FAIL(e) \
341 etl::private_error_handler::assert_handler<0>::assert_function_ptr((e)); \
343 #define ETL_ASSERT_FAIL_AND_RETURN(e) \
345 etl::private_error_handler::assert_handler<0>::assert_function_ptr((e)); \
348 #define ETL_ASSERT_FAIL_AND_RETURN_VALUE(e, v) \
350 etl::private_error_handler::assert_handler<0>::assert_function_ptr((e)); \
353#elif ETL_USING_EXCEPTIONS
354 #if defined(ETL_LOG_ERRORS)
355 #define ETL_ASSERT(b, e) \
357 if (!(b)) ETL_UNLIKELY \
359 etl::error_handler::error((e)); \
364 #define ETL_ASSERT_OR_RETURN(b, e) \
366 if (!(b)) ETL_UNLIKELY \
368 etl::error_handler::error((e)); \
374 #define ETL_ASSERT_OR_RETURN_VALUE(b, e, v) \
376 if (!(b)) ETL_UNLIKELY \
378 etl::error_handler::error((e)); \
385 #define ETL_ASSERT_FAIL(e) \
387 etl::error_handler::error((e)); \
390 #define ETL_ASSERT_FAIL_AND_RETURN(e) \
392 etl::error_handler::error((e)); \
396 #define ETL_ASSERT_FAIL_AND_RETURN_VALUE(e, v) \
398 etl::error_handler::error((e)); \
403 #define ETL_ASSERT(b, e) \
405 if (!(b)) ETL_UNLIKELY \
410 #define ETL_ASSERT_OR_RETURN(b, e) \
412 if (!(b)) ETL_UNLIKELY \
417 #define ETL_ASSERT_OR_RETURN_VALUE(b, e, v) \
419 if (!(b)) ETL_UNLIKELY \
425 #define ETL_ASSERT_FAIL(e) \
429 #define ETL_ASSERT_FAIL_AND_RETURN(e) \
433 #define ETL_ASSERT_FAIL_AND_RETURN_VALUE(e, v) \
439 #if defined(ETL_LOG_ERRORS)
440 #define ETL_ASSERT(b, e) \
442 if (!(b)) ETL_UNLIKELY \
444 etl::error_handler::error((e)); \
447 #define ETL_ASSERT_OR_RETURN(b, e) \
449 if (!(b)) ETL_UNLIKELY \
451 etl::error_handler::error((e)); \
455 #define ETL_ASSERT_OR_RETURN_VALUE(b, e, v) \
457 if (!(b)) ETL_UNLIKELY \
459 etl::error_handler::error((e)); \
465 #define ETL_ASSERT_FAIL(e) \
467 etl::error_handler::error((e)); \
469 #define ETL_ASSERT_FAIL_AND_RETURN(e) \
471 etl::error_handler::error((e)); \
474 #define ETL_ASSERT_FAIL_AND_RETURN_VALUE(e, v) \
476 etl::error_handler::error((e)); \
480 #if ETL_IS_DEBUG_BUILD
481 #define ETL_ASSERT(b, e) assert((b))
482 #define ETL_ASSERT_OR_RETURN(b, e) \
484 if (!(b)) ETL_UNLIKELY \
490 #define ETL_ASSERT_OR_RETURN_VALUE(b, e, v) \
492 if (!(b)) ETL_UNLIKELY \
499 #define ETL_ASSERT_FAIL(e) assert(false)
500 #define ETL_ASSERT_FAIL_AND_RETURN(e) \
505 #define ETL_ASSERT_FAIL_AND_RETURN_VALUE(e, v) \
511 #define ETL_ASSERT(b, e) static_cast<void>(sizeof(b))
512 #define ETL_ASSERT_OR_RETURN(b, e) \
514 if (!(b)) ETL_UNLIKELY \
517 #define ETL_ASSERT_OR_RETURN_VALUE(b, e, v) \
519 if (!(b)) ETL_UNLIKELY \
523 #define ETL_ASSERT_FAIL(e) ETL_DO_NOTHING
524 #define ETL_ASSERT_FAIL_AND_RETURN(e) \
528 #define ETL_ASSERT_FAIL_AND_RETURN_VALUE(e, v) \
537#if defined(ETL_CHECK_PUSH_POP)
538 #define ETL_ASSERT_CHECK_PUSH_POP(b, e) ETL_ASSERT(b, e)
539 #define ETL_ASSERT_CHECK_PUSH_POP_OR_RETURN(b, e) ETL_ASSERT_OR_RETURN(b, e)
541 #define ETL_ASSERT_CHECK_PUSH_POP(b, e)
542 #define ETL_ASSERT_CHECK_PUSH_POP_OR_RETURN(b, e)
546#ifdef ETL_CHECK_INDEX_OPERATOR
547 #define ETL_CHECKING_INDEX_OPERATOR 1
548 #define ETL_NOT_CHECKING_INDEX_OPERATOR 0
549 #define ETL_ASSERT_CHECK_INDEX_OPERATOR(b, e) ETL_ASSERT(b, e)
551 #define ETL_CHECKING_INDEX_OPERATOR 0
552 #define ETL_NOT_CHECKING_INDEX_OPERATOR 1
553 #define ETL_ASSERT_CHECK_INDEX_OPERATOR(b, e)
557#ifdef ETL_CHECK_EXTRA
558 #define ETL_CHECKING_EXTRA 1
559 #define ETL_NOT_CHECKING_EXTRA 0
560 #define ETL_ASSERT_CHECK_EXTRA(b, e) ETL_ASSERT(b, e)
562 #define ETL_CHECKING_EXTRA 0
563 #define ETL_NOT_CHECKING_EXTRA 1
564 #define ETL_ASSERT_CHECK_EXTRA(b, e)
568#if defined(ETL_VERBOSE_ERRORS)
570 #define ETL_ERROR(e) (e(__FILE__, __LINE__))
571 #define ETL_ERROR_WITH_VALUE(e, v) (e(__FILE__, __LINE__, (v)))
572 #define ETL_ERROR_TEXT(verbose_text, terse_text) (verbose_text)
573 #define ETL_ERROR_GENERIC(text) (etl::exception((text), __FILE__, __LINE__))
574#elif defined(ETL_MINIMAL_ERRORS)
576 #define ETL_ERROR(e) (e("", -1))
577 #define ETL_ERROR_WITH_VALUE(e, v) (e("", -1, (v)))
578 #define ETL_ERROR_TEXT(verbose_text, terse_text) ("")
579 #define ETL_ERROR_GENERIC(text) (etl::exception("", "", -1))
582 #define ETL_ERROR(e) (e("", -1))
583 #define ETL_ERROR_WITH_VALUE(e, v) (e("", -1, (v)))
584 #define ETL_ERROR_TEXT(verbose_text, terse_text) (terse_text)
585 #define ETL_ERROR_GENERIC(text) (etl::exception((text), "", -1))
bitset_ext
Definition absolute.h:40