diff --git a/include/etl/error_handler.h b/include/etl/error_handler.h index 5f59f5a6..83030acd 100644 --- a/include/etl/error_handler.h +++ b/include/etl/error_handler.h @@ -45,38 +45,6 @@ SOFTWARE. namespace etl { - namespace private_error_handler - { - // A wrapper template to allow static definition in header. - template - struct wrapper - { - typedef void(*stub_type)(void* object, const etl::exception&); - - //************************************************************************* - /// The internal invocation object. - //************************************************************************* - struct invocation_element - { - //*********************************************************************** - invocation_element() - : object(ETL_NULLPTR) - , stub(ETL_NULLPTR) - { - } - - //*********************************************************************** - void* object; - stub_type stub; - }; - - static invocation_element invocation; - }; - - template - typename wrapper::invocation_element wrapper::invocation; - } - //*************************************************************************** /// Error handler for when throwing exceptions is not required. ///\ingroup error_handler @@ -86,7 +54,7 @@ namespace etl public: //************************************************************************* - /// Callback class for free handler functions. + /// Callback class for free handler functions. Deprecated. //************************************************************************* struct free_function : public etl::function { @@ -97,7 +65,7 @@ namespace etl }; //************************************************************************* - /// Callback class for member handler functions. + /// Callback class for member handler functions. Deprecated. //************************************************************************* template struct member_function : public etl::function @@ -109,7 +77,7 @@ namespace etl }; //***************************************************************************** - /// Sets the error callback function. + /// Sets the error callback function. Deprecated. ///\param f A reference to an etl::function object that will handler errors. //***************************************************************************** static void set_callback(ifunction& f) @@ -168,9 +136,11 @@ namespace etl //***************************************************************************** static void error(const etl::exception& e) { - if (private_error_handler::wrapper::invocation.stub != ETL_NULLPTR) + invocation_element& invocation = get_invocation_element(); + + if (invocation.stub != ETL_NULLPTR) { - (*private_error_handler::wrapper::invocation.stub)(private_error_handler::wrapper::invocation.object, e); + (*invocation.stub)(invocation.object, e); } } @@ -183,24 +153,37 @@ namespace etl //************************************************************************* struct invocation_element { + //*********************************************************************** invocation_element() : object(ETL_NULLPTR) , stub(ETL_NULLPTR) { } - + //*********************************************************************** void* object; stub_type stub; }; + //************************************************************************* + /// Returns the static invocation element. + //************************************************************************* + static invocation_element& get_invocation_element() + { + static invocation_element invocation; + + return invocation; + } + //************************************************************************* /// Constructs a callback from an object and stub. //************************************************************************* static void create(void* object, stub_type stub) { - private_error_handler::wrapper::invocation.object = object; - private_error_handler::wrapper::invocation.stub = stub; + invocation_element& invocation = get_invocation_element(); + + invocation.object = object; + invocation.stub = stub; } //************************************************************************* @@ -208,8 +191,10 @@ namespace etl //************************************************************************* static void create(stub_type stub) { - private_error_handler::wrapper::invocation.object = ETL_NULLPTR; - private_error_handler::wrapper::invocation.stub = stub; + invocation_element& invocation = get_invocation_element(); + + invocation.object = ETL_NULLPTR; + invocation.stub = stub; } //*************************************************************************