UtilsLite
Utilities for C++ programming
Loading...
Searching...
No Matches
mex_workaround.hxx
Go to the documentation of this file.
1#ifdef UTILS_OS_LINUX
2
3class mystream : public std::streambuf {
4protected:
5 virtual
6 std::streamsize
7 xsputn(const char *s, std::streamsize n) override
8 { mexPrintf("%.*s", n, s); mexEvalString("drawnow;"); return n; }
9
10 virtual
11 int
12 overflow(int c=EOF) override
13 { if (c != EOF) { mexPrintf("%.1s", &c); } return 1; }
14
15};
16
17class scoped_redirect_cout {
18public:
19 scoped_redirect_cout()
20 { old_buf = std::cout.rdbuf(); std::cout.rdbuf(&mout); }
21 ~scoped_redirect_cout()
22 { std::cout.rdbuf(old_buf); }
23private:
24 mystream mout;
25 std::streambuf *old_buf;
26};
27static scoped_redirect_cout mycout_redirect;
28
29#endif