Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dlib
Commits
7e8109b7
Commit
7e8109b7
authored
Mar 11, 2016
by
Davis King
Browse files
Made cerr print in matlab as a red warning message.
parent
82a4f00a
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
1 deletion
+53
-1
dlib/matlab/mex_wrapper.cpp
dlib/matlab/mex_wrapper.cpp
+53
-1
No files found.
dlib/matlab/mex_wrapper.cpp
View file @
7e8109b7
...
@@ -2935,6 +2935,56 @@ namespace mex_binding
...
@@ -2935,6 +2935,56 @@ namespace mex_binding
};
};
class
mex_warn_streambuf
:
public
std
::
streambuf
{
public:
mex_warn_streambuf
(
)
{
buf
.
resize
(
1000
);
setp
(
&
buf
[
0
],
&
buf
[
0
]
+
buf
.
size
()
-
2
);
// make cout send data to mex_warn_streambuf
std
::
cout
.
rdbuf
(
this
);
}
protected:
int
sync
(
)
{
int
num
=
static_cast
<
int
>
(
pptr
()
-
pbase
());
if
(
num
!=
0
)
{
buf
[
num
]
=
0
;
// null terminate the string
mexWarnMsgTxt
(
&
buf
[
0
]);
mexEvalString
(
"drawnow"
);
// flush print to screen
pbump
(
-
num
);
}
return
0
;
}
int_type
overflow
(
int_type
c
)
{
if
(
c
!=
EOF
)
{
*
pptr
()
=
c
;
pbump
(
1
);
}
sync
();
return
c
;
}
private:
std
::
vector
<
char
>
buf
;
};
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
...
@@ -4438,10 +4488,12 @@ namespace dlib
...
@@ -4438,10 +4488,12 @@ namespace dlib
void
mexFunction
(
int
nlhs
,
mxArray
*
plhs
[],
void
mexFunction
(
int
nlhs
,
mxArray
*
plhs
[],
int
nrhs
,
const
mxArray
*
prhs
[])
int
nrhs
,
const
mxArray
*
prhs
[])
{
{
// Only remap cout if we aren't using octave since octave already does this.
// Only remap cout
and cerr
if we aren't using octave since octave already does this.
#if !defined(OCTAVE_IMPORT) && !defined(OCTAVE_API)
#if !defined(OCTAVE_IMPORT) && !defined(OCTAVE_API)
// make it so cout prints to mexPrintf()
// make it so cout prints to mexPrintf()
static
mex_binding
::
mex_streambuf
sb
;
static
mex_binding
::
mex_streambuf
sb
;
// make it so cerr prints to mexWarnMsgTxt()
static
mex_binding
::
mex_warn_streambuf
wsb
;
#endif
#endif
mex_binding
::
call_mex_function
(
mex_function
,
nlhs
,
plhs
,
nrhs
,
prhs
);
mex_binding
::
call_mex_function
(
mex_function
,
nlhs
,
plhs
,
nrhs
,
prhs
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment