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&>
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>);
140 invocation_element& invocation = get_invocation_element();
142 if (invocation.stub != ETL_NULLPTR)
144 (*invocation.stub)(invocation.object, e);
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&)>
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&)>
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&)>
270 #if defined(ETL_NO_CHECKS)
271 #define ETL_ASSERT(b, e)
272 #define ETL_ALWAYS_ASSERT(e)
273 #elif defined(ETL_THROW_EXCEPTIONS)
274 #if defined(ETL_LOG_ERRORS)
275 #define ETL_ASSERT(b, e) {if (!(b)) {etl::error_handler::error((e)); throw((e));}}
276 #define ETL_ALWAYS_ASSERT(e) {etl::error_handler::error((e)); throw((e));}
278 #define ETL_ASSERT(b, e) {if (!(b)) {throw((e));}}
279 #define ETL_ALWAYS_ASSERT(e) {throw((e));}
282 #if defined(ETL_LOG_ERRORS)
283 #define ETL_ASSERT(b, e) {if(!(b)) {etl::error_handler::error((e));}}
284 #define ETL_ALWAYS_ASSERT(e) {etl::error_handler::error((e));}
287 #define ETL_ASSERT(b, e)
288 #define ETL_ALWAYS_ASSERT(e)
290 #define ETL_ASSERT(b, e) assert((b))
291 #define ETL_ALWAYS_ASSERT(e) assert(false)
296 #if defined(ETL_VERBOSE_ERRORS)
297 #define ETL_ERROR(e) (e(__FILE__, __LINE__))
299 #define ETL_ERROR(e) (e("", __LINE__))
302 #if defined(ETL_VERBOSE_ERRORS)
303 #define ETL_ERROR_TEXT(verbose_text, terse_text) (verbose_text)
305 #define ETL_ERROR_TEXT(verbose_text, terse_text) (terse_text)
Definition: exception.h:47
Definition: function.h:94
Definition: function.h:54
Definition: absolute.h:37