[2] | 1 | #ifndef DEBUG_H |
---|
| 2 | #define DEBUG_H |
---|
| 3 | |
---|
| 4 | #include "Behavioural/include/Debug_component.h" |
---|
| 5 | #include <stdio.h> |
---|
| 6 | #include <string.h> |
---|
| 7 | #include <iostream> |
---|
| 8 | #include <sstream> |
---|
| 9 | #include <string> |
---|
| 10 | using namespace std; |
---|
| 11 | |
---|
[15] | 12 | // Debug's Level : |
---|
| 13 | // * None : print elementary information |
---|
| 14 | // * Info : print basic information |
---|
| 15 | // * Trace : trace internal variable |
---|
| 16 | // * Func : trace call and return function |
---|
| 17 | // * All : print all information |
---|
| 18 | |
---|
[2] | 19 | enum _debug_verbosity |
---|
| 20 | { |
---|
| 21 | DEBUG_NONE , |
---|
| 22 | DEBUG_INFO , |
---|
| 23 | DEBUG_TRACE, |
---|
| 24 | DEBUG_FUNC , |
---|
| 25 | DEBUG_ALL |
---|
| 26 | }; |
---|
| 27 | |
---|
| 28 | #ifdef DEBUG |
---|
| 29 | //Debug |
---|
[15] | 30 | |
---|
| 31 | # define log_printf(level, component, func, str... ) \ |
---|
| 32 | do \ |
---|
| 33 | { \ |
---|
| 34 | if ( (DEBUG == DEBUG_ALL) or \ |
---|
| 35 | (( DEBUG_ ## level <= DEBUG) and \ |
---|
| 36 | ( DEBUG_ ## component == true )) ) \ |
---|
| 37 | { \ |
---|
| 38 | if (DEBUG >= DEBUG_ALL ) \ |
---|
| 39 | { \ |
---|
| 40 | switch (DEBUG_ ## level) \ |
---|
| 41 | { \ |
---|
| 42 | case DEBUG_NONE : fprintf(stdout,"(none ) "); break; \ |
---|
| 43 | case DEBUG_INFO : fprintf(stdout,"(information) "); break; \ |
---|
| 44 | case DEBUG_TRACE : fprintf(stdout,"(trace ) "); break; \ |
---|
| 45 | case DEBUG_FUNC : fprintf(stdout,"(function ) "); break; \ |
---|
| 46 | case DEBUG_ALL : fprintf(stdout,"(all ) "); break; \ |
---|
| 47 | default : fprintf(stdout,"(undefine ) "); break; \ |
---|
| 48 | } \ |
---|
| 49 | } \ |
---|
| 50 | fprintf(stdout,"In file %s, ",__FILE__); \ |
---|
| 51 | fprintf(stdout,"at line %d, ",__LINE__); \ |
---|
| 52 | if (DEBUG >= DEBUG_FUNC) \ |
---|
| 53 | { \ |
---|
| 54 | fprintf(stdout,"in function \"%s\" ",func); \ |
---|
| 55 | } \ |
---|
| 56 | fprintf(stdout,": "); \ |
---|
| 57 | fprintf(stdout,str); \ |
---|
| 58 | fprintf(stdout,"\n"); \ |
---|
| 59 | fflush (stdout); \ |
---|
| 60 | } \ |
---|
[2] | 61 | } while(0) |
---|
| 62 | |
---|
| 63 | #else |
---|
| 64 | // No debug |
---|
[15] | 65 | |
---|
[2] | 66 | # define log_printf(level, component, func, str... ) \ |
---|
| 67 | do \ |
---|
| 68 | { \ |
---|
| 69 | } while(0) |
---|
| 70 | |
---|
| 71 | #endif // DEBUG |
---|
| 72 | |
---|
| 73 | #endif // !DEBUG_H |
---|