verbose.h 764 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #ifndef IGL_VERBOSE_H
  2. #define IGL_VERBOSE_H
  3. // This function is only useful as a header-only inlined function
  4. namespace igl
  5. {
  6. // Provide a wrapper for printf, called verbose that functions exactly like
  7. // printf if VERBOSE is defined and does exactly nothing if VERBOSE is
  8. // undefined
  9. inline int verbose(const char * msg,...);
  10. }
  11. #include <cstdio>
  12. #ifdef VERBOSE
  13. # include <cstdarg>
  14. #endif
  15. #include <string>
  16. // http://channel9.msdn.com/forums/techoff/254707-wrapping-printf-in-c/
  17. #ifdef VERBOSE
  18. inline int igl::verbose(const char * msg,...)
  19. {
  20. va_list argList;
  21. va_start(argList, msg);
  22. int count = vprintf(msg, argList);
  23. va_end(argList);
  24. return count;
  25. }
  26. #else
  27. inline int igl::verbose(const char * /*msg*/,...)
  28. {
  29. return 0;
  30. }
  31. #endif
  32. #endif