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;
303#if defined(ETL_NO_CHECKS)
304 #define ETL_ASSERT(b, e) static_cast<void>(sizeof(b))
305 #define ETL_ASSERT_OR_RETURN(b, e) static_cast<void>(sizeof(b))
306 #define ETL_ASSERT_OR_RETURN_VALUE(b, e, v) static_cast<void>(sizeof(b))
308 #define ETL_ASSERT_FAIL(e) static_cast<void>(sizeof(b))
309 #define ETL_ASSERT_FAIL_AND_RETURN(e) static_cast<void>(sizeof(b))
310 #define ETL_ASSERT_FAIL_AND_RETURN_VALUE(e, v) static_cast<void>(sizeof(b))
311#elif defined(ETL_USE_ASSERT_FUNCTION)
312 #define ETL_ASSERT(b, e) do {if (!(b)) ETL_UNLIKELY {etl::private_error_handler::assert_handler<0>::assert_function_ptr((e));}} while(false)
313 #define ETL_ASSERT_OR_RETURN(b, e) do {if (!(b)) ETL_UNLIKELY {etl::private_error_handler::assert_handler<0>::assert_function_ptr((e)); return;}} while(false)
314 #define ETL_ASSERT_OR_RETURN_VALUE(b, e, v) do {if (!(b)) ETL_UNLIKELY {etl::private_error_handler::assert_handler<0>::assert_function_ptr((e)); return (v);}} while(false)
316 #define ETL_ASSERT_FAIL(e) do {etl::private_error_handler::assert_handler<0>::assert_function_ptr((e));} while(false)
317 #define ETL_ASSERT_FAIL_AND_RETURN(e) do {etl::private_error_handler::assert_handler<0>::assert_function_ptr((e)); return;} while(false)
318 #define ETL_ASSERT_FAIL_AND_RETURN_VALUE(e, v) do {etl::private_error_handler::assert_handler<0>::assert_function_ptr((e)); return (v);} while(false)
319#elif ETL_USING_EXCEPTIONS
320 #if defined(ETL_LOG_ERRORS)
321 #define ETL_ASSERT(b, e) do {if (!(b)) ETL_UNLIKELY {etl::error_handler::error((e)); throw((e));}} while(false)
322 #define ETL_ASSERT_OR_RETURN(b, e) do {if (!(b)) ETL_UNLIKELY {etl::error_handler::error((e)); throw((e)); return;}} while(false)
323 #define ETL_ASSERT_OR_RETURN_VALUE(b, e, v) do {if (!(b)) ETL_UNLIKELY {etl::error_handler::error((e)); throw((e)); return(v);}} while(false)
325 #define ETL_ASSERT_FAIL(e) do {etl::error_handler::error((e)); throw((e));} while(false)
326 #define ETL_ASSERT_FAIL_AND_RETURN(e) do {etl::error_handler::error((e)); throw((e)); return;} while(false)
327 #define ETL_ASSERT_FAIL_AND_RETURN_VALUE(e, v) do {etl::error_handler::error((e)); throw((e)); return(v);} while(false)
329 #define ETL_ASSERT(b, e) do {if (!(b)) ETL_UNLIKELY {throw((e));}} while(false)
330 #define ETL_ASSERT_OR_RETURN(b, e) do {if (!(b)) ETL_UNLIKELY {throw((e));}} while(false)
331 #define ETL_ASSERT_OR_RETURN_VALUE(b, e, v) do {if (!(b)) ETL_UNLIKELY {throw((e));}} while(false)
333 #define ETL_ASSERT_FAIL(e) do {throw((e));} while(false)
334 #define ETL_ASSERT_FAIL_AND_RETURN(e) do {throw((e));} while(false)
335 #define ETL_ASSERT_FAIL_AND_RETURN_VALUE(e, v) do {throw((e));} while(false)
338 #if defined(ETL_LOG_ERRORS)
339 #define ETL_ASSERT(b, e) do {if (!(b)) ETL_UNLIKELY {etl::error_handler::error((e));}} while(false)
340 #define ETL_ASSERT_OR_RETURN(b, e) do {if (!(b)) ETL_UNLIKELY {etl::error_handler::error((e)); return;}} while(false)
341 #define ETL_ASSERT_OR_RETURN_VALUE(b, e, v) do {if (!(b)) ETL_UNLIKELY {etl::error_handler::error((e)); return (v);}} while(false)
343 #define ETL_ASSERT_FAIL(e) do {etl::error_handler::error((e));} while(false)
344 #define ETL_ASSERT_FAIL_AND_RETURN(e) do {etl::error_handler::error((e)); return;} while(false)
345 #define ETL_ASSERT_FAIL_AND_RETURN_VALUE(e, v) do {etl::error_handler::error((e)); return (v);} while(false)
347 #if ETL_IS_DEBUG_BUILD
348 #define ETL_ASSERT(b, e) assert((b))
349 #define ETL_ASSERT_OR_RETURN(b, e) do {if (!(b)) ETL_UNLIKELY {assert(false); return;}} while(false)
350 #define ETL_ASSERT_OR_RETURN_VALUE(b, e, v) do {if (!(b)) ETL_UNLIKELY {assert(false); return(v);}} while(false)
352 #define ETL_ASSERT_FAIL(e) assert(false)
353 #define ETL_ASSERT_FAIL_AND_RETURN(e) do {assert(false); return;} while(false)
354 #define ETL_ASSERT_FAIL_AND_RETURN_VALUE(e, v) do {assert(false); return(v);} while(false)
356 #define ETL_ASSERT(b, e) static_cast<void>(sizeof(b))
357 #define ETL_ASSERT_OR_RETURN(b, e) do {if (!(b)) ETL_UNLIKELY return;} while(false)
358 #define ETL_ASSERT_OR_RETURN_VALUE(b, e, v) do {if (!(b)) ETL_UNLIKELY return(v);} while(false)
360 #define ETL_ASSERT_FAIL(e) ETL_DO_NOTHING
361 #define ETL_ASSERT_FAIL_AND_RETURN(e) do {return;} while(false)
362 #define ETL_ASSERT_FAIL_AND_RETURN_VALUE(e, v) do {return(v);} while(false)
368#if defined(ETL_CHECK_PUSH_POP)
369 #define ETL_ASSERT_CHECK_PUSH_POP(b, e) ETL_ASSERT(b, e)
370 #define ETL_ASSERT_CHECK_PUSH_POP_OR_RETURN(b, e) ETL_ASSERT_OR_RETURN(b, e)
372 #define ETL_ASSERT_CHECK_PUSH_POP(b, e)
373 #define ETL_ASSERT_CHECK_PUSH_POP_OR_RETURN(b, e)
377#ifdef ETL_CHECK_INDEX_OPERATOR
378 #define ETL_CHECKING_INDEX_OPERATOR 1
379 #define ETL_NOT_CHECKING_INDEX_OPERATOR 0
380 #define ETL_ASSERT_CHECK_INDEX_OPERATOR(b, e) ETL_ASSERT(b,e)
382 #define ETL_CHECKING_INDEX_OPERATOR 0
383 #define ETL_NOT_CHECKING_INDEX_OPERATOR 1
384 #define ETL_ASSERT_CHECK_INDEX_OPERATOR(b, e)
388#ifdef ETL_CHECK_EXTRA
389 #define ETL_CHECKING_EXTRA 1
390 #define ETL_NOT_CHECKING_EXTRA 0
391 #define ETL_ASSERT_CHECK_EXTRA(b, e) ETL_ASSERT(b,e)
393 #define ETL_CHECKING_EXTRA 0
394 #define ETL_NOT_CHECKING_EXTRA 1
395 #define ETL_ASSERT_CHECK_EXTRA(b, e)
399#if defined(ETL_VERBOSE_ERRORS)
400 #define ETL_ERROR(e) (e(__FILE__, __LINE__))
401 #define ETL_ERROR_WITH_VALUE(e, v) (e(__FILE__, __LINE__, (v)))
402 #define ETL_ERROR_TEXT(verbose_text, terse_text) (verbose_text)
403 #define ETL_ERROR_GENERIC(text) (etl::exception((text),__FILE__, __LINE__))
405 #define ETL_ERROR(e) (e("", __LINE__))
406 #define ETL_ERROR_WITH_VALUE(e, v) (e("", __LINE__, (v)))
407 #define ETL_ERROR_TEXT(verbose_text, terse_text) (terse_text)
408 #define ETL_ERROR_GENERIC(text) (etl::exception((text),"", __LINE__))
bitset_ext
Definition absolute.h:39
T * create(Args &&... args)
Creates the object from a type. Variadic parameter constructor.
Definition variant_pool_generator.h:348