Advertisement
Tainel

src/base/features/debug.hpp

May 21st, 2023 (edited)
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.54 KB | Source Code | 0 0
  1. #pragma once
  2.  
  3. #include"base/dependencies/index.hpp"
  4.  
  5. #include"attributes.hpp"
  6. #include"characters.hpp"
  7. #include"output.hpp"
  8.  
  9. // Control sequence introducer for the terminal.
  10. #define CSI "\033["
  11.  
  12. // RGB foreground color prefix sequence.
  13. #define RGB CSI"38;2;"
  14.  
  15. // Color sequences.
  16. #define BLUE RGB"30;144;255m"
  17. #define CYAN RGB"0;206;209m"
  18. #define GRAY RGB"119;136;153m"
  19. #define GREEN RGB"50;205;50m"
  20. #define RED RGB"255;0;0m"
  21. #define VIOLET RGB"148;0;211m"
  22. #define YELLOW RGB"255;215;0m"
  23.  
  24. // Font style sequences.
  25. #define BOLD CSI"1m"
  26. #define ITALIC CSI"3m"
  27. #define NOBOLD CSI"22m"
  28. #define NOITALIC CSI"23m"
  29. #define NOUNDERLINE CSI"24m"
  30. #define UNDERLINE CSI"4m"
  31.  
  32. // Reset sequence.
  33. #define RESET CSI"m"
  34.  
  35. // Constant expression that evaluates to nothing.
  36. #define NOOP ((void)0)
  37.  
  38. // Assert that an expression is true locally.
  39. #ifdef LOCAL
  40. #define ASSERT(x)({if(!(x))UNLIKELY{write(cerr,RED,BOLD,"Error",NOBOLD,": fail\
  41. ed assertion in line ",UNDERLINE,__FILE__,':',__LINE__,NOUNDERLINE,": ",ITALIC\
  42. ,#x,RESET,lf);abort();}})
  43. #else
  44. #define ASSERT(x)NOOP
  45. #endif
  46.  
  47. // Print an expression and its value to standard error locally.
  48. #ifdef LOCAL
  49. #define DEBUG(x)(write(cerr,BLUE,ITALIC,#x,NOITALIC," = ",(x),RESET,lf))
  50. #else
  51. #define DEBUG(x)NOOP
  52. #endif
  53.  
  54. // Print multiple values to standard error locally.
  55. #ifdef LOCAL
  56. #define LOG(...)(write(cerr,GRAY,__VA_ARGS__,RESET,lf))
  57. #else
  58. #define LOG(...)NOOP
  59. #endif
  60.  
  61. // Print a new line to standard error locally.
  62. #ifdef LOCAL
  63. #define LINE (cerr<<lf)
  64. #else
  65. #define LINE NOOP
  66. #endif
  67.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement