verbose.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 Alec Jacobson <[email protected]>
  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. ///
  17. /// @param[in] msg printf style format string
  18. /// @param[in] ... printf style arguments
  19. /// @return number of characters printed
  20. inline int verbose(const char * msg,...);
  21. }
  22. #include <cstdio>
  23. #ifdef VERBOSE
  24. # include <cstdarg>
  25. #endif
  26. #include <string>
  27. // http://channel9.msdn.com/forums/techoff/254707-wrapping-printf-in-c/
  28. #ifdef VERBOSE
  29. inline int igl::verbose(const char * msg,...)
  30. {
  31. va_list argList;
  32. va_start(argList, msg);
  33. int count = vprintf(msg, argList);
  34. va_end(argList);
  35. return count;
  36. }
  37. #else
  38. inline int igl::verbose(const char * /*msg*/,...)
  39. {
  40. return 0;
  41. }
  42. #endif
  43. #endif