mexStream.h 737 B

1234567891011121314151617181920212223242526272829
  1. #ifndef IGL_MEX_STREAM_H
  2. #define IGL_MEX_STREAM_H
  3. #include <iostream>
  4. namespace igl
  5. {
  6. // http://stackoverflow.com/a/249008/148668
  7. // Class to implement "cout" for mex files to print to the matlab terminal
  8. // window.
  9. //
  10. // Insert at the beginning of mexFunction():
  11. // mexStream mout;
  12. // std::streambuf *outbuf = std::cout.rdbuf(&mout);
  13. // ...
  14. // ALWAYS restore original buffer to avoid memory leak problems in matlab
  15. // std::cout.rdbuf(outbuf);
  16. //
  17. class mexStream : public std::streambuf
  18. {
  19. public:
  20. protected:
  21. virtual std::streamsize xsputn(const char *s, std::streamsize n);
  22. virtual int overflow(int c = EOF);
  23. };
  24. }
  25. #ifdef IGL_HEADER_ONLY
  26. # include "mexStream.cpp"
  27. #endif
  28. #endif