Commit 64c7e966 authored by Davis King's avatar Davis King

Added a function to check if the matlab user hit ctrl+c.

parent c35041e3
...@@ -8,6 +8,14 @@ ...@@ -8,6 +8,14 @@
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
void check_for_ctrl_c();
/*!
ensures
- If the user of MATLAB has pressed ctrl+c then this function will throw an
exception.
!*/
// ----------------------------------------------------------------------------------------
class matlab_struct class matlab_struct
{ {
......
...@@ -253,6 +253,8 @@ namespace mex_binding ...@@ -253,6 +253,8 @@ namespace mex_binding
// ------------------------------------------------------- // -------------------------------------------------------
struct user_hit_ctrl_c {};
struct invalid_args_exception struct invalid_args_exception
{ {
invalid_args_exception(const std::string& msg_): msg(msg_) {} invalid_args_exception(const std::string& msg_): msg(msg_) {}
...@@ -1573,6 +1575,10 @@ namespace mex_binding ...@@ -1573,6 +1575,10 @@ namespace mex_binding
mexErrMsgIdAndTxt("mex_function:validate_and_populate_arg", mexErrMsgIdAndTxt("mex_function:validate_and_populate_arg",
("Input" + e.msg).c_str()); ("Input" + e.msg).c_str());
} }
catch (user_hit_ctrl_c& )
{
// do nothing, just return to matlab
}
catch (dlib::error& e) catch (dlib::error& e)
{ {
mexErrMsgIdAndTxt("mex_function:error", mexErrMsgIdAndTxt("mex_function:error",
...@@ -2371,6 +2377,14 @@ void call_matlab ( ...@@ -2371,6 +2377,14 @@ void call_matlab (
call_matlab("feval", funct); call_matlab("feval", funct);
} }
extern "C" bool utIsInterruptPending();
void check_for_ctrl_c(
)
{
if (utIsInterruptPending())
throw mex_binding::user_hit_ctrl_c();
}
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment