melder_warning.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #ifndef _melder_warning_h_
  2. #define _melder_warning_h_
  3. /* melder_warning.h
  4. *
  5. * Copyright (C) 1992-2018 Paul Boersma
  6. *
  7. * This code is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * This code is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. * See the GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this work. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. /*
  21. SYNOPSIS (2018-08-08)
  22. Melder_warning (args...);
  23. Gives a warning to stderr (batch) or to a "Warning" dialog.
  24. Use sparingly, because it interrupts the user's workflow.
  25. */
  26. namespace MelderWarning {
  27. extern int _depth;
  28. extern MelderString _buffer;
  29. using Proc = void (*) (conststring32 message);
  30. void _defaultProc (conststring32 message);
  31. extern Proc _p_currentProc;
  32. }
  33. template <typename... Args>
  34. void Melder_warning (const MelderArg& first, Args... rest);
  35. template <typename... Args>
  36. void Melder_warning (const MelderArg& first, Args... rest) {
  37. if (MelderWarning::_depth < 0)
  38. return;
  39. MelderString_copy (& MelderWarning::_buffer, first, rest...);
  40. (*MelderWarning::_p_currentProc) (MelderWarning::_buffer.string);
  41. }
  42. void Melder_warningOff ();
  43. void Melder_warningOn ();
  44. class autoMelderWarningOff {
  45. public:
  46. autoMelderWarningOff () { Melder_warningOff (); }
  47. ~autoMelderWarningOff () { Melder_warningOn (); }
  48. };
  49. void Melder_setWarningProc (MelderWarning::Proc p_proc);
  50. /* End of file melder_warning.h */
  51. #endif