diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2017-03-05 16:44:50 +0100 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2017-03-05 16:44:50 +0100 |
commit | 5dbf1809c6e3e905b94b8764e99491e608122261 (patch) | |
tree | 5e5a5360db15d86d59ec8c6e4f7eb511388c5a9a /core/error_macros.h | |
parent | 45438e9918d421b244bfd7776a30e67dc7f2d3e3 (diff) |
A Whole New World (clang-format edition)
I can show you the code
Pretty, with proper whitespace
Tell me, coder, now when did
You last write readable code?
I can open your eyes
Make you see your bad indent
Force you to respect the style
The core devs agreed upon
A whole new world
A new fantastic code format
A de facto standard
With some sugar
Enforced with clang-format
A whole new world
A dazzling style we all dreamed of
And when we read it through
It's crystal clear
That now we're in a whole new world of code
Diffstat (limited to 'core/error_macros.h')
-rw-r--r-- | core/error_macros.h | 209 |
1 files changed, 121 insertions, 88 deletions
diff --git a/core/error_macros.h b/core/error_macros.h index ac86ef432b..02a15de067 100644 --- a/core/error_macros.h +++ b/core/error_macros.h @@ -29,7 +29,6 @@ #ifndef ERROR_MACROS_H #define ERROR_MACROS_H - /** * Error macros. Unlike exceptions and asserts, these macros try to mantain consistency and stability * inside the code. It is recommended to always return processable data, so in case of an error, the @@ -53,8 +52,8 @@ enum ErrorHandlerType { ERR_HANDLER_SHADER, }; -typedef void (*ErrorHandlerFunc)(void*,const char*,const char*,int p_line,const char *, const char *,ErrorHandlerType p_type); -void _err_set_last_error(const char* p_err); +typedef void (*ErrorHandlerFunc)(void *, const char *, const char *, int p_line, const char *, const char *, ErrorHandlerType p_type); +void _err_set_last_error(const char *p_err); void _err_clear_last_error(); struct ErrorHandlerList { @@ -62,22 +61,26 @@ struct ErrorHandlerList { ErrorHandlerFunc errfunc; void *userdata; - ErrorHandlerList*next; + ErrorHandlerList *next; - ErrorHandlerList() { errfunc=0; next=0; userdata=0; } + ErrorHandlerList() { + errfunc = 0; + next = 0; + userdata = 0; + } }; void add_error_handler(ErrorHandlerList *p_handler); void remove_error_handler(ErrorHandlerList *p_handler); -void _err_print_error(const char* p_function,const char* p_file,int p_line,const char *p_error,ErrorHandlerType p_type=ERR_HANDLER_ERROR); +void _err_print_error(const char *p_function, const char *p_file, int p_line, const char *p_error, ErrorHandlerType p_type = ERR_HANDLER_ERROR); #ifndef _STR #define _STR(m_x) #m_x #define _MKSTR(m_x) _STR(m_x) #endif -#define _FNL __FILE__":" +#define _FNL __FILE__ ":" /** An index has failed if m_index<0 or m_index >=m_size, the function exists */ @@ -86,13 +89,21 @@ extern bool _err_error_exists; #ifdef DEBUG_ENABLED /** Print a warning string. */ -#define ERR_EXPLAINC(m_reason) {_err_set_last_error(m_reason); _err_error_exists=true;} -#define ERR_EXPLAIN(m_string) {_err_set_last_error(String(m_string).utf8().get_data()); _err_error_exists=true;} +#define ERR_EXPLAINC(m_reason) \ + { \ + _err_set_last_error(m_reason); \ + _err_error_exists = true; \ + } +#define ERR_EXPLAIN(m_string) \ + { \ + _err_set_last_error(String(m_string).utf8().get_data()); \ + _err_error_exists = true; \ + } #else -#define ERR_EXPLAIN( m_text ) -#define ERR_EXPLAINC( m_text ) +#define ERR_EXPLAIN(m_text) +#define ERR_EXPLAINC(m_text) #endif @@ -103,49 +114,63 @@ extern bool _err_error_exists; #define FUNCTION_STR __FUNCTION__ #endif -#define ERR_FAIL_INDEX(m_index,m_size) \ - do {if ((m_index)<0 || (m_index)>=(m_size)) { \ - _err_print_error(FUNCTION_STR,__FILE__,__LINE__,"Index " _STR(m_index)" out of size (" _STR(m_size)")."); \ - return; \ - } else _err_error_exists=false; } while(0); \ +#define ERR_FAIL_INDEX(m_index, m_size) \ + do { \ + if ((m_index) < 0 || (m_index) >= (m_size)) { \ + _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Index " _STR(m_index) " out of size (" _STR(m_size) ")."); \ + return; \ + } else \ + _err_error_exists = false; \ + } while (0); /** An index has failed if m_index<0 or m_index >=m_size, the function exists. * This function returns an error value, if returning Error, please select the most * appropriate error condition from error_macros.h */ -#define ERR_FAIL_INDEX_V(m_index,m_size,m_retval) \ - do {if ((m_index)<0 || (m_index)>=(m_size)) { \ - _err_print_error(FUNCTION_STR,__FILE__,__LINE__,"Index " _STR(m_index)" out of size (" _STR(m_size)")."); \ - return m_retval; \ - } else _err_error_exists=false;} while (0); +#define ERR_FAIL_INDEX_V(m_index, m_size, m_retval) \ + do { \ + if ((m_index) < 0 || (m_index) >= (m_size)) { \ + _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Index " _STR(m_index) " out of size (" _STR(m_size) ")."); \ + return m_retval; \ + } else \ + _err_error_exists = false; \ + } while (0); - /** An error condition happened (m_cond tested true) (WARNING this is the opposite as assert(). +/** An error condition happened (m_cond tested true) (WARNING this is the opposite as assert(). * the function will exit. */ - #define ERR_FAIL_NULL(m_param) \ - { if ( !m_param ) { \ - _err_print_error(FUNCTION_STR,__FILE__,__LINE__,"Parameter ' " _STR(m_param)" ' is null."); \ - return; \ - }else _err_error_exists=false; } \ - - -#define ERR_FAIL_NULL_V(m_param,m_retval) \ - { if ( !m_param ) { \ - _err_print_error(FUNCTION_STR,__FILE__,__LINE__,"Parameter ' " _STR(m_param)" ' is null."); \ - return m_retval; \ - }else _err_error_exists=false; } \ +#define ERR_FAIL_NULL(m_param) \ + { \ + if (!m_param) { \ + _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Parameter ' " _STR(m_param) " ' is null."); \ + return; \ + } else \ + _err_error_exists = false; \ + } + +#define ERR_FAIL_NULL_V(m_param, m_retval) \ + { \ + if (!m_param) { \ + _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Parameter ' " _STR(m_param) " ' is null."); \ + return m_retval; \ + } else \ + _err_error_exists = false; \ + } /** An error condition happened (m_cond tested true) (WARNING this is the opposite as assert(). * the function will exit. */ -#define ERR_FAIL_COND(m_cond) \ - { if ( m_cond ) { \ - _err_print_error(FUNCTION_STR,__FILE__,__LINE__,"Condition ' " _STR(m_cond)" ' is true."); \ - return; \ - }else _err_error_exists=false; } \ +#define ERR_FAIL_COND(m_cond) \ + { \ + if (m_cond) { \ + _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition ' " _STR(m_cond) " ' is true."); \ + return; \ + } else \ + _err_error_exists = false; \ + } /** An error condition happened (m_cond tested true) (WARNING this is the opposite as assert(). * the function will exit. @@ -153,81 +178,89 @@ extern bool _err_error_exists; * appropriate error condition from error_macros.h */ -#define ERR_FAIL_COND_V(m_cond,m_retval) \ - { if ( m_cond ) { \ - _err_print_error(FUNCTION_STR,__FILE__,__LINE__,"Condition ' " _STR(m_cond)" ' is true. returned: " _STR(m_retval)); \ - return m_retval; \ - }else _err_error_exists=false; } \ +#define ERR_FAIL_COND_V(m_cond, m_retval) \ + { \ + if (m_cond) { \ + _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition ' " _STR(m_cond) " ' is true. returned: " _STR(m_retval)); \ + return m_retval; \ + } else \ + _err_error_exists = false; \ + } /** An error condition happened (m_cond tested true) (WARNING this is the opposite as assert(). * the loop will skip to the next iteration. */ -#define ERR_CONTINUE(m_cond) \ - { if ( m_cond ) { \ - _err_print_error(FUNCTION_STR,__FILE__,__LINE__,"Condition ' " _STR(m_cond)" ' is true. Continuing..:"); \ - continue;\ - } else _err_error_exists=false;} \ +#define ERR_CONTINUE(m_cond) \ + { \ + if (m_cond) { \ + _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition ' " _STR(m_cond) " ' is true. Continuing..:"); \ + continue; \ + } else \ + _err_error_exists = false; \ + } /** An error condition happened (m_cond tested true) (WARNING this is the opposite as assert(). * the loop will break */ -#define ERR_BREAK(m_cond) \ - { if ( m_cond ) { \ - _err_print_error(FUNCTION_STR,__FILE__,__LINE__,"Condition ' " _STR(m_cond)" ' is true. Breaking..:"); \ - break;\ - } else _err_error_exists=false;} \ +#define ERR_BREAK(m_cond) \ + { \ + if (m_cond) { \ + _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition ' " _STR(m_cond) " ' is true. Breaking..:"); \ + break; \ + } else \ + _err_error_exists = false; \ + } /** Print an error string and return */ -#define ERR_FAIL() \ -{ \ - _err_print_error(FUNCTION_STR,__FILE__,__LINE__,"Method/Function Failed."); \ - _err_error_exists=false;\ - return;\ -} \ +#define ERR_FAIL() \ + { \ + _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Method/Function Failed."); \ + _err_error_exists = false; \ + return; \ + } /** Print an error string and return with value */ -#define ERR_FAIL_V(m_value) \ -{ \ - _err_print_error(FUNCTION_STR,__FILE__,__LINE__,"Method/Function Failed, returning: " __STR(m_value)); \ - _err_error_exists=false; \ - return m_value;\ -} \ +#define ERR_FAIL_V(m_value) \ + { \ + _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Method/Function Failed, returning: " __STR(m_value)); \ + _err_error_exists = false; \ + return m_value; \ + } /** Print an error string. */ -#define ERR_PRINT(m_string) \ - { \ - _err_print_error(FUNCTION_STR,__FILE__,__LINE__,m_string); \ - _err_error_exists=false;\ - } \ +#define ERR_PRINT(m_string) \ + { \ + _err_print_error(FUNCTION_STR, __FILE__, __LINE__, m_string); \ + _err_error_exists = false; \ + } -#define ERR_PRINTS(m_string) \ - { \ - _err_print_error(FUNCTION_STR,__FILE__,__LINE__,String(m_string).utf8().get_data()); \ - _err_error_exists=false;\ - } \ +#define ERR_PRINTS(m_string) \ + { \ + _err_print_error(FUNCTION_STR, __FILE__, __LINE__, String(m_string).utf8().get_data()); \ + _err_error_exists = false; \ + } /** Print a warning string. */ -#define WARN_PRINT(m_string) \ - { \ - _err_print_error(FUNCTION_STR,__FILE__,__LINE__,m_string,ERR_HANDLER_WARNING); \ - _err_error_exists=false;\ - } \ - - -#define WARN_PRINTS(m_string) \ - { \ - _err_print_error(FUNCTION_STR,__FILE__,__LINE__,String(m_string).utf8().get_data(),ERR_HANDLER_WARNING); \ - _err_error_exists=false;\ - } \ +#define WARN_PRINT(m_string) \ + { \ + _err_print_error(FUNCTION_STR, __FILE__, __LINE__, m_string, ERR_HANDLER_WARNING); \ + _err_error_exists = false; \ + } + +#define WARN_PRINTS(m_string) \ + { \ + _err_print_error(FUNCTION_STR, __FILE__, __LINE__, String(m_string).utf8().get_data(), ERR_HANDLER_WARNING); \ + _err_error_exists = false; \ + } #endif |