verbose.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
  4. //
  5. // This Source Code Form is subject to the terms of the Mozilla Public License
  6. // v. 2.0. If a copy of the MPL was not distributed with this file, You can
  7. // obtain one at http://mozilla.org/MPL/2.0/.
  8. #ifndef IGL_VERBOSE_H
  9. #define IGL_VERBOSE_H
  10. // This function is only useful as a header-only inlined function
  11. namespace igl
  12. {
  13. // Provide a wrapper for printf, called verbose that functions exactly like
  14. // printf if VERBOSE is defined and does exactly nothing if VERBOSE is
  15. // undefined
  16. inline int verbose(const char * msg,...);
  17. }
  18. #include <cstdio>
  19. #ifdef VERBOSE
  20. # include <cstdarg>
  21. #endif
  22. #include <string>
  23. // http://channel9.msdn.com/forums/techoff/254707-wrapping-printf-in-c/
  24. #ifdef VERBOSE
  25. inline int igl::verbose(const char * msg,...)
  26. {
  27. va_list argList;
  28. va_start(argList, msg);
  29. int count = vprintf(msg, argList);
  30. va_end(argList);
  31. return count;
  32. }
  33. #else
  34. inline int igl::verbose(const char * /*msg*/,...)
  35. {
  36. return 0;
  37. }
  38. #endif
  39. #endif