Better warning/error macros

pull/150/head
Fabio Alessandrelli 2018-07-05 16:23:50 +02:00
parent ec2a9345bd
commit e37b186b57
2 changed files with 34 additions and 21 deletions

View File

@ -107,32 +107,45 @@ typedef float real_t;
#define _PLANE_EQ_DOT_EPSILON 0.999 #define _PLANE_EQ_DOT_EPSILON 0.999
#define _PLANE_EQ_D_EPSILON 0.0001 #define _PLANE_EQ_D_EPSILON 0.0001
// ERR/WARN macros
#ifndef ERR_FAIL_COND_V #ifndef WARN_PRINT
#define ERR_FAIL_COND_V(cond, ret) do { if (cond) { return ret; } } while(0) #define WARN_PRINT(msg) fprintf(stdout, "ERROR: %s\n", msg); fflush(stdout)
#endif #endif
#ifndef WARN_PRINTS
#define WARN_PRINTS(msg) WARN_PRINT(msg.utf8().get_data())
#endif
#ifndef ERR_PRINT
#define ERR_PRINT(x) fprintf(stderr, "ERROR: %s\n", x)
#endif
#ifndef ERR_PRINTS
#define ERR_PRINTS(msg) ERR_PRINT(msg.utf8().get_data())
#endif
#ifndef ERR_FAIL
#define ERR_FAIL() ERR_PRINT("Failed")
#endif
#ifndef ERR_FAIL_V #ifndef ERR_FAIL_V
#define ERR_FAIL_V(a) return a #define ERR_FAIL_V(a) { ERR_FAIL(); return a; }
#endif
#ifndef ERR_FAIL_COND
#define ERR_FAIL_COND(a) do { if (a) { ERR_PRINT(#a); return; } } while(0)
#endif
#ifndef ERR_FAIL_COND_V
#define ERR_FAIL_COND_V(cond, ret) do { if (cond) { ERR_PRINT(#cond); return ret; } } while(0)
#endif #endif
#ifndef ERR_FAIL_INDEX #ifndef ERR_FAIL_INDEX
#define ERR_FAIL_INDEX(a, b) #define ERR_FAIL_INDEX(a, b) do { if (a < 0 || a >= b) { ERR_FAIL(); return; } } while(0)
#endif
#ifndef ERR_PRINT
#define ERR_PRINT(msg) fprintf(stderr, "ERROR: %S\n", (msg).unicode_str())
#endif #endif
#ifndef ERR_FAIL_INDEX_V #ifndef ERR_FAIL_INDEX_V
#define ERR_FAIL_INDEX_V(a, b, c) #define ERR_FAIL_INDEX_V(a, b, c) do { if (a < 0 || a >= b) { ERR_FAIL(); return c; } } while(0)
#endif
#ifndef ERR_FAIL_COND
#define ERR_FAIL_COND(a) do { if (a) { fprintf(stderr, #a); return; } } while(0)
#endif #endif

View File

@ -269,7 +269,7 @@ Color Color::html(const String& p_color)
} else if (color.length()==6) { } else if (color.length()==6) {
alpha=false; alpha=false;
} else { } else {
ERR_PRINT(String("Invalid Color Code: ") + p_color); ERR_PRINTS(String("Invalid Color Code: ") + p_color);
ERR_FAIL_V(Color()); ERR_FAIL_V(Color());
} }
@ -277,7 +277,7 @@ Color Color::html(const String& p_color)
if (alpha) { if (alpha) {
a=_parse_col(color,0); a=_parse_col(color,0);
if (a<0) { if (a<0) {
ERR_PRINT("Invalid Color Code: "+p_color); ERR_PRINTS(String("Invalid Color Code: ") + p_color);
ERR_FAIL_V(Color()); ERR_FAIL_V(Color());
} }
} }
@ -286,17 +286,17 @@ Color Color::html(const String& p_color)
int r=_parse_col(color,from+0); int r=_parse_col(color,from+0);
if (r<0) { if (r<0) {
ERR_PRINT("Invalid Color Code: "+p_color); ERR_PRINTS(String("Invalid Color Code: ") + p_color);
ERR_FAIL_V(Color()); ERR_FAIL_V(Color());
} }
int g=_parse_col(color,from+2); int g=_parse_col(color,from+2);
if (g<0) { if (g<0) {
ERR_PRINT("Invalid Color Code: "+p_color); ERR_PRINTS(String("Invalid Color Code: ") + p_color);
ERR_FAIL_V(Color()); ERR_FAIL_V(Color());
} }
int b=_parse_col(color,from+4); int b=_parse_col(color,from+4);
if (b<0) { if (b<0) {
ERR_PRINT("Invalid Color Code: "+p_color); ERR_PRINTS(String("Invalid Color Code: ") + p_color);
ERR_FAIL_V(Color()); ERR_FAIL_V(Color());
} }