Commit 82a4f00a authored by Davis King's avatar Davis King

Renamed check_for_ctrl_c() to check_for_matlab_ctrl_c(), put everything in

call_matlab.h into dlib namespace, and also added missing overloads for
call_matlab().
parent af27ab2f
...@@ -6,9 +6,12 @@ ...@@ -6,9 +6,12 @@
#include <string> #include <string>
namespace dlib
{
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
void check_for_ctrl_c(); void check_for_matlab_ctrl_c();
/*! /*!
ensures ensures
- If the user of MATLAB has pressed ctrl+c then this function will throw an - If the user of MATLAB has pressed ctrl+c then this function will throw an
...@@ -302,55 +305,164 @@ void call_matlab ( ...@@ -302,55 +305,164 @@ void call_matlab (
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
template < template <
typename T1, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename
typename T2, T7, typename T8, typename T9
typename T3,
typename T4,
typename T5,
typename T6,
typename T7,
typename T8,
typename T9
> >
void call_matlab ( void call_matlab (
const std::string& function_name, const std::string& function_name,
const T1& A1, const T1& A1, const T2& A2, const T3& A3, const T4& A4, const T5& A5, const T6& A6,
const T2& A2, const T7& A7, const T8& A8, const T9& A9
const T3& A3,
const T4& A4,
const T5& A5,
const T6& A6,
const T7& A7,
const T8& A8,
const T9& A9
); );
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
template < template <
typename T1, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename
typename T2, T7, typename T8, typename T9, typename T10
typename T3,
typename T4,
typename T5,
typename T6,
typename T7,
typename T8,
typename T9,
typename T10
> >
void call_matlab ( void call_matlab (
const std::string& function_name, const std::string& function_name,
const T1& A1, const T1& A1, const T2& A2, const T3& A3, const T4& A4, const T5& A5, const T6& A6,
const T2& A2, const T7& A7, const T8& A8, const T9& A9, const T10& A10
const T3& A3, );
const T4& A4,
const T5& A5, // ----------------------------------------------------------------------------------------
const T6& A6,
const T7& A7, template <
const T8& A8, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename
const T9& A9, T7, typename T8, typename T9, typename T10, typename T11
const T10& A10 >
void call_matlab (
const std::string& function_name,
const T1& A1, const T2& A2, const T3& A3, const T4& A4, const T5& A5, const T6& A6,
const T7& A7, const T8& A8, const T9& A9, const T10& A10, const T11& A11
);
// ----------------------------------------------------------------------------------------
template <
typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename
T7, typename T8, typename T9, typename T10, typename T11, typename T12
>
void call_matlab (
const std::string& function_name,
const T1& A1, const T2& A2, const T3& A3, const T4& A4, const T5& A5, const T6& A6,
const T7& A7, const T8& A8, const T9& A9, const T10& A10, const T11& A11, const T12& A12
);
// ----------------------------------------------------------------------------------------
template <
typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename
T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13
>
void call_matlab (
const std::string& function_name,
const T1& A1, const T2& A2, const T3& A3, const T4& A4, const T5& A5, const T6& A6,
const T7& A7, const T8& A8, const T9& A9, const T10& A10, const T11& A11, const T12&
A12, const T13& A13
);
// ----------------------------------------------------------------------------------------
template <
typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename
T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13,
typename T14
>
void call_matlab (
const std::string& function_name,
const T1& A1, const T2& A2, const T3& A3, const T4& A4, const T5& A5, const T6& A6,
const T7& A7, const T8& A8, const T9& A9, const T10& A10, const T11& A11, const T12&
A12, const T13& A13, const T14& A14
);
// ----------------------------------------------------------------------------------------
template <
typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename
T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13,
typename T14, typename T15
>
void call_matlab (
const std::string& function_name,
const T1& A1, const T2& A2, const T3& A3, const T4& A4, const T5& A5, const T6& A6,
const T7& A7, const T8& A8, const T9& A9, const T10& A10, const T11& A11, const T12&
A12, const T13& A13, const T14& A14, const T15& A15
);
// ----------------------------------------------------------------------------------------
template <
typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename
T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13,
typename T14, typename T15, typename T16
>
void call_matlab (
const std::string& function_name,
const T1& A1, const T2& A2, const T3& A3, const T4& A4, const T5& A5, const T6& A6,
const T7& A7, const T8& A8, const T9& A9, const T10& A10, const T11& A11, const T12&
A12, const T13& A13, const T14& A14, const T15& A15, const T16& A16
);
// ----------------------------------------------------------------------------------------
template <
typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename
T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13,
typename T14, typename T15, typename T16, typename T17
>
void call_matlab (
const std::string& function_name,
const T1& A1, const T2& A2, const T3& A3, const T4& A4, const T5& A5, const T6& A6,
const T7& A7, const T8& A8, const T9& A9, const T10& A10, const T11& A11, const T12&
A12, const T13& A13, const T14& A14, const T15& A15, const T16& A16, const T17& A17
);
// ----------------------------------------------------------------------------------------
template <
typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename
T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13,
typename T14, typename T15, typename T16, typename T17, typename T18
>
void call_matlab (
const std::string& function_name,
const T1& A1, const T2& A2, const T3& A3, const T4& A4, const T5& A5, const T6& A6,
const T7& A7, const T8& A8, const T9& A9, const T10& A10, const T11& A11, const T12&
A12, const T13& A13, const T14& A14, const T15& A15, const T16& A16, const T17& A17,
const T18& A18
);
// ----------------------------------------------------------------------------------------
template <
typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename
T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13,
typename T14, typename T15, typename T16, typename T17, typename T18, typename T19
>
void call_matlab (
const std::string& function_name,
const T1& A1, const T2& A2, const T3& A3, const T4& A4, const T5& A5, const T6& A6,
const T7& A7, const T8& A8, const T9& A9, const T10& A10, const T11& A11, const T12&
A12, const T13& A13, const T14& A14, const T15& A15, const T16& A16, const T17& A17,
const T18& A18, const T19& A19
);
// ----------------------------------------------------------------------------------------
template <
typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename
T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13,
typename T14, typename T15, typename T16, typename T17, typename T18, typename T19,
typename T20
>
void call_matlab (
const std::string& function_name,
const T1& A1, const T2& A2, const T3& A3, const T4& A4, const T5& A5, const T6& A6,
const T7& A7, const T8& A8, const T9& A9, const T10& A10, const T11& A11, const T12&
A12, const T13& A13, const T14& A14, const T15& A15, const T16& A16, const T17& A17,
const T18& A18, const T19& A19, const T20& A20
); );
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
...@@ -492,40 +604,174 @@ void call_matlab ( ...@@ -492,40 +604,174 @@ void call_matlab (
} }
template < template <
typename T1, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename
typename T2, T7, typename T8, typename T9
typename T3,
typename T4,
typename T5,
typename T6,
typename T7,
typename T8,
typename T9
> >
void call_matlab ( void call_matlab (
const function_handle& funct, const function_handle& funct,
const T1& A1, const T1& A1, const T2& A2, const T3& A3, const T4& A4, const T5& A5, const T6& A6,
const T2& A2, const T7& A7, const T8& A8, const T9& A9
const T3& A3,
const T4& A4,
const T5& A5,
const T6& A6,
const T7& A7,
const T8& A8,
const T9& A9
) )
{ {
call_matlab("feval", funct, A1, A2, A3, A4, A5, A6, A7, A8, A9); call_matlab("feval", funct, A1, A2, A3, A4, A5, A6, A7, A8, A9);
} }
template <
typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename
T7, typename T8, typename T9, typename T10
>
void call_matlab (
const function_handle& funct,
const T1& A1, const T2& A2, const T3& A3, const T4& A4, const T5& A5, const T6& A6,
const T7& A7, const T8& A8, const T9& A9, const T10& A10
)
{
call_matlab("feval", funct, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10);
}
template <
typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename
T7, typename T8, typename T9, typename T10, typename T11
>
void call_matlab (
const function_handle& funct,
const T1& A1, const T2& A2, const T3& A3, const T4& A4, const T5& A5, const T6& A6,
const T7& A7, const T8& A8, const T9& A9, const T10& A10, const T11& A11
)
{
call_matlab("feval", funct, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11);
}
template <
typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename
T7, typename T8, typename T9, typename T10, typename T11, typename T12
>
void call_matlab (
const function_handle& funct,
const T1& A1, const T2& A2, const T3& A3, const T4& A4, const T5& A5, const T6& A6,
const T7& A7, const T8& A8, const T9& A9, const T10& A10, const T11& A11, const T12&
A12
)
{
call_matlab("feval", funct, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12);
}
template <
typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename
T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13
>
void call_matlab (
const function_handle& funct,
const T1& A1, const T2& A2, const T3& A3, const T4& A4, const T5& A5, const T6& A6,
const T7& A7, const T8& A8, const T9& A9, const T10& A10, const T11& A11, const T12&
A12, const T13& A13
)
{
call_matlab("feval", funct, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13);
}
template <
typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename
T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13,
typename T14
>
void call_matlab (
const function_handle& funct,
const T1& A1, const T2& A2, const T3& A3, const T4& A4, const T5& A5, const T6& A6,
const T7& A7, const T8& A8, const T9& A9, const T10& A10, const T11& A11, const T12&
A12, const T13& A13, const T14& A14
)
{
call_matlab("feval", funct, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14);
}
template <
typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename
T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13,
typename T14, typename T15
>
void call_matlab (
const function_handle& funct,
const T1& A1, const T2& A2, const T3& A3, const T4& A4, const T5& A5, const T6& A6,
const T7& A7, const T8& A8, const T9& A9, const T10& A10, const T11& A11, const T12&
A12, const T13& A13, const T14& A14, const T15& A15
)
{
call_matlab("feval", funct, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15);
}
template <
typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename
T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13,
typename T14, typename T15, typename T16
>
void call_matlab (
const function_handle& funct,
const T1& A1, const T2& A2, const T3& A3, const T4& A4, const T5& A5, const T6& A6,
const T7& A7, const T8& A8, const T9& A9, const T10& A10, const T11& A11, const T12&
A12, const T13& A13, const T14& A14, const T15& A15, const T16& A16
)
{
call_matlab("feval", funct, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16);
}
template <
typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename
T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13,
typename T14, typename T15, typename T16, typename T17
>
void call_matlab (
const function_handle& funct,
const T1& A1, const T2& A2, const T3& A3, const T4& A4, const T5& A5, const T6& A6,
const T7& A7, const T8& A8, const T9& A9, const T10& A10, const T11& A11, const T12&
A12, const T13& A13, const T14& A14, const T15& A15, const T16& A16, const T17& A17
)
{
call_matlab("feval", funct, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17);
}
template <
typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename
T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13,
typename T14, typename T15, typename T16, typename T17, typename T18
>
void call_matlab (
const function_handle& funct,
const T1& A1, const T2& A2, const T3& A3, const T4& A4, const T5& A5, const T6& A6,
const T7& A7, const T8& A8, const T9& A9, const T10& A10, const T11& A11, const T12&
A12, const T13& A13, const T14& A14, const T15& A15, const T16& A16, const T17& A17,
const T18& A18
)
{
call_matlab("feval", funct, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18);
}
template <
typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename
T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13,
typename T14, typename T15, typename T16, typename T17, typename T18, typename T19
>
void call_matlab (
const function_handle& funct,
const T1& A1, const T2& A2, const T3& A3, const T4& A4, const T5& A5, const T6& A6,
const T7& A7, const T8& A8, const T9& A9, const T10& A10, const T11& A11, const T12&
A12, const T13& A13, const T14& A14, const T15& A15, const T16& A16, const T17& A17,
const T18& A18, const T19& A19
)
{
call_matlab("feval", funct, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19);
}
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
// We define this function here so that, if you write some code that has check_for_ctrl_c() // We define this function here so that, if you write some code that has check_for_matlab_ctrl_c()
// sprinkled throughout it you can still compile that code outside the mex wrapper // sprinkled throughout it you can still compile that code outside the mex wrapper
// environment and these calls will simply be no-ops. // environment and these calls will simply be no-ops.
#ifndef MATLAB_MEX_FILE #ifndef MATLAB_MEX_FILE
inline void check_for_ctrl_c() {} inline void check_for_matlab_ctrl_c() {}
#endif #endif
}
#endif // MIT_LL_CALL_MATLAB_H__ #endif // MIT_LL_CALL_MATLAB_H__
...@@ -3021,23 +3021,25 @@ namespace mex_binding ...@@ -3021,23 +3021,25 @@ namespace mex_binding
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
void call_matlab ( namespace dlib
const std::string& function_name
)
{ {
void call_matlab (
const std::string& function_name
)
{
using namespace mex_binding; using namespace mex_binding;
call_matlab_for_real(0,NULL,0,NULL, function_name); call_matlab_for_real(0,NULL,0,NULL, function_name);
} }
template <typename T1> template <typename T1>
void free_callback_resources ( void free_callback_resources (
int nlhs, int nlhs,
mxArray* plhs[], mxArray* plhs[],
int nrhs, int nrhs,
mxArray* prhs[] mxArray* prhs[]
) )
{ {
// free resources // free resources
for (int i = 0; i < nlhs; ++i) for (int i = 0; i < nlhs; ++i)
mxDestroyArray(plhs[i]); mxDestroyArray(plhs[i]);
...@@ -3049,16 +3051,16 @@ void free_callback_resources ( ...@@ -3049,16 +3051,16 @@ void free_callback_resources (
continue; continue;
mxDestroyArray(prhs[i]); mxDestroyArray(prhs[i]);
} }
} }
template < template <
typename T1 typename T1
> >
void call_matlab ( void call_matlab (
const std::string& function_name, const std::string& function_name,
const T1& A1 const T1& A1
) )
{ {
using namespace mex_binding; using namespace mex_binding;
const int num_args = 1; const int num_args = 1;
mxArray* plhs[num_args] = {0}; mxArray* plhs[num_args] = {0};
...@@ -3074,18 +3076,18 @@ void call_matlab ( ...@@ -3074,18 +3076,18 @@ void call_matlab (
setup_output_args(function_name, plhs[i], A1, i); setup_output_args(function_name, plhs[i], A1, i);
free_callback_resources<T1>(nlhs,plhs,nrhs,prhs); free_callback_resources<T1>(nlhs,plhs,nrhs,prhs);
} }
template < template <
typename T1, typename T1,
typename T2 typename T2
> >
void call_matlab ( void call_matlab (
const std::string& function_name, const std::string& function_name,
const T1& A1, const T1& A1,
const T2& A2 const T2& A2
) )
{ {
using namespace mex_binding; using namespace mex_binding;
const int num_args = 2; const int num_args = 2;
mxArray* plhs[num_args] = {0}; mxArray* plhs[num_args] = {0};
...@@ -3103,20 +3105,20 @@ void call_matlab ( ...@@ -3103,20 +3105,20 @@ void call_matlab (
setup_output_args(function_name, plhs[i], A2, i); setup_output_args(function_name, plhs[i], A2, i);
free_callback_resources<T1>(nlhs,plhs,nrhs,prhs); free_callback_resources<T1>(nlhs,plhs,nrhs,prhs);
} }
template < template <
typename T1, typename T1,
typename T2, typename T2,
typename T3 typename T3
> >
void call_matlab ( void call_matlab (
const std::string& function_name, const std::string& function_name,
const T1& A1, const T1& A1,
const T2& A2, const T2& A2,
const T3& A3 const T3& A3
) )
{ {
using namespace mex_binding; using namespace mex_binding;
const int num_args = 3; const int num_args = 3;
mxArray* plhs[num_args] = {0}; mxArray* plhs[num_args] = {0};
...@@ -3136,23 +3138,23 @@ void call_matlab ( ...@@ -3136,23 +3138,23 @@ void call_matlab (
setup_output_args(function_name, plhs[i], A3, i); setup_output_args(function_name, plhs[i], A3, i);
free_callback_resources<T1>(nlhs,plhs,nrhs,prhs); free_callback_resources<T1>(nlhs,plhs,nrhs,prhs);
} }
template < template <
typename T1, typename T1,
typename T2, typename T2,
typename T3, typename T3,
typename T4 typename T4
> >
void call_matlab ( void call_matlab (
const std::string& function_name, const std::string& function_name,
const T1& A1, const T1& A1,
const T2& A2, const T2& A2,
const T3& A3, const T3& A3,
const T4& A4 const T4& A4
) )
{ {
using namespace mex_binding; using namespace mex_binding;
const int num_args = 4; const int num_args = 4;
mxArray* plhs[num_args] = {0}; mxArray* plhs[num_args] = {0};
...@@ -3174,25 +3176,25 @@ void call_matlab ( ...@@ -3174,25 +3176,25 @@ void call_matlab (
setup_output_args(function_name, plhs[i], A4, i); setup_output_args(function_name, plhs[i], A4, i);
free_callback_resources<T1>(nlhs,plhs,nrhs,prhs); free_callback_resources<T1>(nlhs,plhs,nrhs,prhs);
} }
template < template <
typename T1, typename T1,
typename T2, typename T2,
typename T3, typename T3,
typename T4, typename T4,
typename T5 typename T5
> >
void call_matlab ( void call_matlab (
const std::string& function_name, const std::string& function_name,
const T1& A1, const T1& A1,
const T2& A2, const T2& A2,
const T3& A3, const T3& A3,
const T4& A4, const T4& A4,
const T5& A5 const T5& A5
) )
{ {
using namespace mex_binding; using namespace mex_binding;
const int num_args = 5; const int num_args = 5;
mxArray* plhs[num_args] = {0}; mxArray* plhs[num_args] = {0};
...@@ -3216,10 +3218,10 @@ void call_matlab ( ...@@ -3216,10 +3218,10 @@ void call_matlab (
setup_output_args(function_name, plhs[i], A5, i); setup_output_args(function_name, plhs[i], A5, i);
free_callback_resources<T1>(nlhs,plhs,nrhs,prhs); free_callback_resources<T1>(nlhs,plhs,nrhs,prhs);
} }
template < template <
typename T1, typename T1,
typename T2, typename T2,
typename T3, typename T3,
...@@ -3227,7 +3229,7 @@ template < ...@@ -3227,7 +3229,7 @@ template <
typename T5, typename T5,
typename T6 typename T6
> >
void call_matlab ( void call_matlab (
const std::string& function_name, const std::string& function_name,
const T1& A1, const T1& A1,
const T2& A2, const T2& A2,
...@@ -3235,8 +3237,8 @@ void call_matlab ( ...@@ -3235,8 +3237,8 @@ void call_matlab (
const T4& A4, const T4& A4,
const T5& A5, const T5& A5,
const T6& A6 const T6& A6
) )
{ {
using namespace mex_binding; using namespace mex_binding;
const int num_args = 6; const int num_args = 6;
mxArray* plhs[num_args] = {0}; mxArray* plhs[num_args] = {0};
...@@ -3262,10 +3264,10 @@ void call_matlab ( ...@@ -3262,10 +3264,10 @@ void call_matlab (
setup_output_args(function_name, plhs[i], A6, i); setup_output_args(function_name, plhs[i], A6, i);
free_callback_resources<T1>(nlhs,plhs,nrhs,prhs); free_callback_resources<T1>(nlhs,plhs,nrhs,prhs);
} }
template < template <
typename T1, typename T1,
typename T2, typename T2,
typename T3, typename T3,
...@@ -3274,7 +3276,7 @@ template < ...@@ -3274,7 +3276,7 @@ template <
typename T6, typename T6,
typename T7 typename T7
> >
void call_matlab ( void call_matlab (
const std::string& function_name, const std::string& function_name,
const T1& A1, const T1& A1,
const T2& A2, const T2& A2,
...@@ -3283,8 +3285,8 @@ void call_matlab ( ...@@ -3283,8 +3285,8 @@ void call_matlab (
const T5& A5, const T5& A5,
const T6& A6, const T6& A6,
const T7& A7 const T7& A7
) )
{ {
using namespace mex_binding; using namespace mex_binding;
const int num_args = 7; const int num_args = 7;
mxArray* plhs[num_args] = {0}; mxArray* plhs[num_args] = {0};
...@@ -3312,10 +3314,10 @@ void call_matlab ( ...@@ -3312,10 +3314,10 @@ void call_matlab (
setup_output_args(function_name, plhs[i], A7, i); setup_output_args(function_name, plhs[i], A7, i);
free_callback_resources<T1>(nlhs,plhs,nrhs,prhs); free_callback_resources<T1>(nlhs,plhs,nrhs,prhs);
} }
template < template <
typename T1, typename T1,
typename T2, typename T2,
typename T3, typename T3,
...@@ -3325,7 +3327,7 @@ template < ...@@ -3325,7 +3327,7 @@ template <
typename T7, typename T7,
typename T8 typename T8
> >
void call_matlab ( void call_matlab (
const std::string& function_name, const std::string& function_name,
const T1& A1, const T1& A1,
const T2& A2, const T2& A2,
...@@ -3335,8 +3337,8 @@ void call_matlab ( ...@@ -3335,8 +3337,8 @@ void call_matlab (
const T6& A6, const T6& A6,
const T7& A7, const T7& A7,
const T8& A8 const T8& A8
) )
{ {
using namespace mex_binding; using namespace mex_binding;
const int num_args = 8; const int num_args = 8;
mxArray* plhs[num_args] = {0}; mxArray* plhs[num_args] = {0};
...@@ -3366,11 +3368,11 @@ void call_matlab ( ...@@ -3366,11 +3368,11 @@ void call_matlab (
setup_output_args(function_name, plhs[i], A8, i); setup_output_args(function_name, plhs[i], A8, i);
free_callback_resources<T1>(nlhs,plhs,nrhs,prhs); free_callback_resources<T1>(nlhs,plhs,nrhs,prhs);
} }
template < template <
typename T1, typename T1,
typename T2, typename T2,
typename T3, typename T3,
...@@ -3381,7 +3383,7 @@ template < ...@@ -3381,7 +3383,7 @@ template <
typename T8, typename T8,
typename T9 typename T9
> >
void call_matlab ( void call_matlab (
const std::string& function_name, const std::string& function_name,
const T1& A1, const T1& A1,
const T2& A2, const T2& A2,
...@@ -3392,8 +3394,8 @@ void call_matlab ( ...@@ -3392,8 +3394,8 @@ void call_matlab (
const T7& A7, const T7& A7,
const T8& A8, const T8& A8,
const T9& A9 const T9& A9
) )
{ {
using namespace mex_binding; using namespace mex_binding;
const int num_args = 9; const int num_args = 9;
mxArray* plhs[num_args] = {0}; mxArray* plhs[num_args] = {0};
...@@ -3425,10 +3427,10 @@ void call_matlab ( ...@@ -3425,10 +3427,10 @@ void call_matlab (
setup_output_args(function_name, plhs[i], A9, i); setup_output_args(function_name, plhs[i], A9, i);
free_callback_resources<T1>(nlhs,plhs,nrhs,prhs); free_callback_resources<T1>(nlhs,plhs,nrhs,prhs);
} }
template < template <
typename T1, typename T1,
typename T2, typename T2,
typename T3, typename T3,
...@@ -3440,7 +3442,7 @@ template < ...@@ -3440,7 +3442,7 @@ template <
typename T9, typename T9,
typename T10 typename T10
> >
void call_matlab ( void call_matlab (
const std::string& function_name, const std::string& function_name,
const T1& A1, const T1& A1,
const T2& A2, const T2& A2,
...@@ -3452,8 +3454,8 @@ void call_matlab ( ...@@ -3452,8 +3454,8 @@ void call_matlab (
const T8& A8, const T8& A8,
const T9& A9, const T9& A9,
const T10& A10 const T10& A10
) )
{ {
using namespace mex_binding; using namespace mex_binding;
const int num_args = 10; const int num_args = 10;
mxArray* plhs[num_args] = {0}; mxArray* plhs[num_args] = {0};
...@@ -3487,9 +3489,9 @@ void call_matlab ( ...@@ -3487,9 +3489,9 @@ void call_matlab (
setup_output_args(function_name, plhs[i], A10, i); setup_output_args(function_name, plhs[i], A10, i);
free_callback_resources<T1>(nlhs,plhs,nrhs,prhs); free_callback_resources<T1>(nlhs,plhs,nrhs,prhs);
} }
template < template <
typename T1, typename T1,
typename T2, typename T2,
typename T3, typename T3,
...@@ -3502,7 +3504,7 @@ template < ...@@ -3502,7 +3504,7 @@ template <
typename T10, typename T10,
typename T11 typename T11
> >
void call_matlab ( void call_matlab (
const std::string& function_name, const std::string& function_name,
const T1& A1, const T1& A1,
const T2& A2, const T2& A2,
...@@ -3515,8 +3517,8 @@ void call_matlab ( ...@@ -3515,8 +3517,8 @@ void call_matlab (
const T9& A9, const T9& A9,
const T10& A10, const T10& A10,
const T11& A11 const T11& A11
) )
{ {
using namespace mex_binding; using namespace mex_binding;
const int num_args = 11; const int num_args = 11;
mxArray* plhs[num_args] = {0}; mxArray* plhs[num_args] = {0};
...@@ -3552,9 +3554,9 @@ void call_matlab ( ...@@ -3552,9 +3554,9 @@ void call_matlab (
setup_output_args(function_name, plhs[i], A11, i); setup_output_args(function_name, plhs[i], A11, i);
free_callback_resources<T1>(nlhs,plhs,nrhs,prhs); free_callback_resources<T1>(nlhs,plhs,nrhs,prhs);
} }
template < template <
typename T1, typename T1,
typename T2, typename T2,
typename T3, typename T3,
...@@ -3568,7 +3570,7 @@ template < ...@@ -3568,7 +3570,7 @@ template <
typename T11, typename T11,
typename T12 typename T12
> >
void call_matlab ( void call_matlab (
const std::string& function_name, const std::string& function_name,
const T1& A1, const T1& A1,
const T2& A2, const T2& A2,
...@@ -3582,8 +3584,8 @@ void call_matlab ( ...@@ -3582,8 +3584,8 @@ void call_matlab (
const T10& A10, const T10& A10,
const T11& A11, const T11& A11,
const T12& A12 const T12& A12
) )
{ {
using namespace mex_binding; using namespace mex_binding;
const int num_args = 12; const int num_args = 12;
mxArray* plhs[num_args] = {0}; mxArray* plhs[num_args] = {0};
...@@ -3621,9 +3623,9 @@ void call_matlab ( ...@@ -3621,9 +3623,9 @@ void call_matlab (
setup_output_args(function_name, plhs[i], A12, i); setup_output_args(function_name, plhs[i], A12, i);
free_callback_resources<T1>(nlhs,plhs,nrhs,prhs); free_callback_resources<T1>(nlhs,plhs,nrhs,prhs);
} }
template < template <
typename T1, typename T1,
typename T2, typename T2,
typename T3, typename T3,
...@@ -3638,7 +3640,7 @@ template < ...@@ -3638,7 +3640,7 @@ template <
typename T12, typename T12,
typename T13 typename T13
> >
void call_matlab ( void call_matlab (
const std::string& function_name, const std::string& function_name,
const T1& A1, const T1& A1,
const T2& A2, const T2& A2,
...@@ -3653,8 +3655,8 @@ void call_matlab ( ...@@ -3653,8 +3655,8 @@ void call_matlab (
const T11& A11, const T11& A11,
const T12& A12, const T12& A12,
const T13& A13 const T13& A13
) )
{ {
using namespace mex_binding; using namespace mex_binding;
const int num_args = 13; const int num_args = 13;
mxArray* plhs[num_args] = {0}; mxArray* plhs[num_args] = {0};
...@@ -3694,9 +3696,9 @@ void call_matlab ( ...@@ -3694,9 +3696,9 @@ void call_matlab (
setup_output_args(function_name, plhs[i], A13, i); setup_output_args(function_name, plhs[i], A13, i);
free_callback_resources<T1>(nlhs,plhs,nrhs,prhs); free_callback_resources<T1>(nlhs,plhs,nrhs,prhs);
} }
template < template <
typename T1, typename T1,
typename T2, typename T2,
typename T3, typename T3,
...@@ -3712,7 +3714,7 @@ template < ...@@ -3712,7 +3714,7 @@ template <
typename T13, typename T13,
typename T14 typename T14
> >
void call_matlab ( void call_matlab (
const std::string& function_name, const std::string& function_name,
const T1& A1, const T1& A1,
const T2& A2, const T2& A2,
...@@ -3728,8 +3730,8 @@ void call_matlab ( ...@@ -3728,8 +3730,8 @@ void call_matlab (
const T12& A12, const T12& A12,
const T13& A13, const T13& A13,
const T14& A14 const T14& A14
) )
{ {
using namespace mex_binding; using namespace mex_binding;
const int num_args = 14; const int num_args = 14;
mxArray* plhs[num_args] = {0}; mxArray* plhs[num_args] = {0};
...@@ -3771,9 +3773,9 @@ void call_matlab ( ...@@ -3771,9 +3773,9 @@ void call_matlab (
setup_output_args(function_name, plhs[i], A14, i); setup_output_args(function_name, plhs[i], A14, i);
free_callback_resources<T1>(nlhs,plhs,nrhs,prhs); free_callback_resources<T1>(nlhs,plhs,nrhs,prhs);
} }
template < template <
typename T1, typename T1,
typename T2, typename T2,
typename T3, typename T3,
...@@ -3790,7 +3792,7 @@ template < ...@@ -3790,7 +3792,7 @@ template <
typename T14, typename T14,
typename T15 typename T15
> >
void call_matlab ( void call_matlab (
const std::string& function_name, const std::string& function_name,
const T1& A1, const T1& A1,
const T2& A2, const T2& A2,
...@@ -3807,8 +3809,8 @@ void call_matlab ( ...@@ -3807,8 +3809,8 @@ void call_matlab (
const T13& A13, const T13& A13,
const T14& A14, const T14& A14,
const T15& A15 const T15& A15
) )
{ {
using namespace mex_binding; using namespace mex_binding;
const int num_args = 15; const int num_args = 15;
mxArray* plhs[num_args] = {0}; mxArray* plhs[num_args] = {0};
...@@ -3852,9 +3854,9 @@ void call_matlab ( ...@@ -3852,9 +3854,9 @@ void call_matlab (
setup_output_args(function_name, plhs[i], A15, i); setup_output_args(function_name, plhs[i], A15, i);
free_callback_resources<T1>(nlhs,plhs,nrhs,prhs); free_callback_resources<T1>(nlhs,plhs,nrhs,prhs);
} }
template < template <
typename T1, typename T1,
typename T2, typename T2,
typename T3, typename T3,
...@@ -3872,7 +3874,7 @@ template < ...@@ -3872,7 +3874,7 @@ template <
typename T15, typename T15,
typename T16 typename T16
> >
void call_matlab ( void call_matlab (
const std::string& function_name, const std::string& function_name,
const T1& A1, const T1& A1,
const T2& A2, const T2& A2,
...@@ -3890,8 +3892,8 @@ void call_matlab ( ...@@ -3890,8 +3892,8 @@ void call_matlab (
const T14& A14, const T14& A14,
const T15& A15, const T15& A15,
const T16& A16 const T16& A16
) )
{ {
using namespace mex_binding; using namespace mex_binding;
const int num_args = 16; const int num_args = 16;
mxArray* plhs[num_args] = {0}; mxArray* plhs[num_args] = {0};
...@@ -3937,9 +3939,9 @@ void call_matlab ( ...@@ -3937,9 +3939,9 @@ void call_matlab (
setup_output_args(function_name, plhs[i], A16, i); setup_output_args(function_name, plhs[i], A16, i);
free_callback_resources<T1>(nlhs,plhs,nrhs,prhs); free_callback_resources<T1>(nlhs,plhs,nrhs,prhs);
} }
template < template <
typename T1, typename T1,
typename T2, typename T2,
typename T3, typename T3,
...@@ -3958,7 +3960,7 @@ template < ...@@ -3958,7 +3960,7 @@ template <
typename T16, typename T16,
typename T17 typename T17
> >
void call_matlab ( void call_matlab (
const std::string& function_name, const std::string& function_name,
const T1& A1, const T1& A1,
const T2& A2, const T2& A2,
...@@ -3977,8 +3979,8 @@ void call_matlab ( ...@@ -3977,8 +3979,8 @@ void call_matlab (
const T15& A15, const T15& A15,
const T16& A16, const T16& A16,
const T17& A17 const T17& A17
) )
{ {
using namespace mex_binding; using namespace mex_binding;
const int num_args = 17; const int num_args = 17;
mxArray* plhs[num_args] = {0}; mxArray* plhs[num_args] = {0};
...@@ -4026,50 +4028,21 @@ void call_matlab ( ...@@ -4026,50 +4028,21 @@ void call_matlab (
setup_output_args(function_name, plhs[i], A17, i); setup_output_args(function_name, plhs[i], A17, i);
free_callback_resources<T1>(nlhs,plhs,nrhs,prhs); free_callback_resources<T1>(nlhs,plhs,nrhs,prhs);
} }
template < template <
typename T1, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6,
typename T2, typename T7, typename T8, typename T9, typename T10, typename T11, typename T12,
typename T3, typename T13, typename T14, typename T15, typename T16, typename T17, typename T18
typename T4,
typename T5,
typename T6,
typename T7,
typename T8,
typename T9,
typename T10,
typename T11,
typename T12,
typename T13,
typename T14,
typename T15,
typename T16,
typename T17,
typename T18
> >
void call_matlab ( void call_matlab (
const std::string& function_name, const std::string& function_name,
const T1& A1, const T1& A1, const T2& A2, const T3& A3, const T4& A4, const T5& A5, const T6& A6,
const T2& A2, const T7& A7, const T8& A8, const T9& A9, const T10& A10, const T11& A11, const
const T3& A3, T12& A12, const T13& A13, const T14& A14, const T15& A15, const T16& A16, const
const T4& A4, T17& A17, const T18& A18
const T5& A5, )
const T6& A6, {
const T7& A7,
const T8& A8,
const T9& A9,
const T10& A10,
const T11& A11,
const T12& A12,
const T13& A13,
const T14& A14,
const T15& A15,
const T16& A16,
const T17& A17,
const T18& A18
)
{
using namespace mex_binding; using namespace mex_binding;
const int num_args = 18; const int num_args = 18;
mxArray* plhs[num_args] = {0}; mxArray* plhs[num_args] = {0};
...@@ -4119,52 +4092,22 @@ void call_matlab ( ...@@ -4119,52 +4092,22 @@ void call_matlab (
setup_output_args(function_name, plhs[i], A18, i); setup_output_args(function_name, plhs[i], A18, i);
free_callback_resources<T1>(nlhs,plhs,nrhs,prhs); free_callback_resources<T1>(nlhs,plhs,nrhs,prhs);
} }
template < template <
typename T1, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6,
typename T2, typename T7, typename T8, typename T9, typename T10, typename T11, typename T12,
typename T3, typename T13, typename T14, typename T15, typename T16, typename T17, typename T18,
typename T4,
typename T5,
typename T6,
typename T7,
typename T8,
typename T9,
typename T10,
typename T11,
typename T12,
typename T13,
typename T14,
typename T15,
typename T16,
typename T17,
typename T18,
typename T19 typename T19
> >
void call_matlab ( void call_matlab (
const std::string& function_name, const std::string& function_name,
const T1& A1, const T1& A1, const T2& A2, const T3& A3, const T4& A4, const T5& A5, const T6& A6,
const T2& A2, const T7& A7, const T8& A8, const T9& A9, const T10& A10, const T11& A11, const
const T3& A3, T12& A12, const T13& A13, const T14& A14, const T15& A15, const T16& A16, const
const T4& A4, T17& A17, const T18& A18, const T19& A19
const T5& A5, )
const T6& A6, {
const T7& A7,
const T8& A8,
const T9& A9,
const T10& A10,
const T11& A11,
const T12& A12,
const T13& A13,
const T14& A14,
const T15& A15,
const T16& A16,
const T17& A17,
const T18& A18,
const T19& A19
)
{
using namespace mex_binding; using namespace mex_binding;
const int num_args = 19; const int num_args = 19;
mxArray* plhs[num_args] = {0}; mxArray* plhs[num_args] = {0};
...@@ -4216,54 +4159,22 @@ void call_matlab ( ...@@ -4216,54 +4159,22 @@ void call_matlab (
setup_output_args(function_name, plhs[i], A19, i); setup_output_args(function_name, plhs[i], A19, i);
free_callback_resources<T1>(nlhs,plhs,nrhs,prhs); free_callback_resources<T1>(nlhs,plhs,nrhs,prhs);
} }
template < template <
typename T1, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6,
typename T2, typename T7, typename T8, typename T9, typename T10, typename T11, typename T12,
typename T3, typename T13, typename T14, typename T15, typename T16, typename T17, typename T18,
typename T4, typename T19, typename T20
typename T5,
typename T6,
typename T7,
typename T8,
typename T9,
typename T10,
typename T11,
typename T12,
typename T13,
typename T14,
typename T15,
typename T16,
typename T17,
typename T18,
typename T19,
typename T20
> >
void call_matlab ( void call_matlab (
const std::string& function_name, const std::string& function_name,
const T1& A1, const T1& A1, const T2& A2, const T3& A3, const T4& A4, const T5& A5, const T6& A6,
const T2& A2, const T7& A7, const T8& A8, const T9& A9, const T10& A10, const T11& A11, const
const T3& A3, T12& A12, const T13& A13, const T14& A14, const T15& A15, const T16& A16, const
const T4& A4, T17& A17, const T18& A18, const T19& A19, const T20& A20
const T5& A5, )
const T6& A6, {
const T7& A7,
const T8& A8,
const T9& A9,
const T10& A10,
const T11& A11,
const T12& A12,
const T13& A13,
const T14& A14,
const T15& A15,
const T16& A16,
const T17& A17,
const T18& A18,
const T19& A19,
const T20& A20
)
{
using namespace mex_binding; using namespace mex_binding;
const int num_args = 20; const int num_args = 20;
mxArray* plhs[num_args] = {0}; mxArray* plhs[num_args] = {0};
...@@ -4317,22 +4228,22 @@ void call_matlab ( ...@@ -4317,22 +4228,22 @@ void call_matlab (
setup_output_args(function_name, plhs[i], A20, i); setup_output_args(function_name, plhs[i], A20, i);
free_callback_resources<T1>(nlhs,plhs,nrhs,prhs); free_callback_resources<T1>(nlhs,plhs,nrhs,prhs);
} }
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
template <typename T> template <typename T>
matlab_struct::sub::operator T() const matlab_struct::sub::operator T() const
{ {
T item; T item;
get(item); get(item);
return item; return item;
} }
template <typename T> template <typename T>
void matlab_struct::sub::get(T& item) const void matlab_struct::sub::get(T& item) const
{ {
if (struct_handle == 0) if (struct_handle == 0)
throw dlib::error("Attempt to access data in an empty struct."); throw dlib::error("Attempt to access data in an empty struct.");
...@@ -4351,11 +4262,11 @@ void matlab_struct::sub::get(T& item) const ...@@ -4351,11 +4262,11 @@ void matlab_struct::sub::get(T& item) const
<< endl << e.msg; << endl << e.msg;
throw dlib::error(sout.str()); throw dlib::error(sout.str());
} }
} }
const matlab_struct::sub matlab_struct:: const matlab_struct::sub matlab_struct::
operator[] (const std::string& name) const operator[] (const std::string& name) const
{ {
if (struct_handle == 0) if (struct_handle == 0)
throw dlib::error("Struct does not have a field named '" + name + "'."); throw dlib::error("Struct does not have a field named '" + name + "'.");
...@@ -4365,11 +4276,11 @@ operator[] (const std::string& name) const ...@@ -4365,11 +4276,11 @@ operator[] (const std::string& name) const
if (temp.field_idx == -1 ) if (temp.field_idx == -1 )
throw dlib::error("Struct does not have a field named '" + name + "'."); throw dlib::error("Struct does not have a field named '" + name + "'.");
return temp; return temp;
} }
matlab_struct::sub matlab_struct:: matlab_struct::sub matlab_struct::
operator[] (const std::string& name) operator[] (const std::string& name)
{ {
if (struct_handle == 0) if (struct_handle == 0)
{ {
// We make a struct from scratch and mark that we will free it unless it gets // We make a struct from scratch and mark that we will free it unless it gets
...@@ -4393,11 +4304,11 @@ operator[] (const std::string& name) ...@@ -4393,11 +4304,11 @@ operator[] (const std::string& name)
} }
} }
return temp; return temp;
} }
const matlab_struct::sub matlab_struct::sub:: const matlab_struct::sub matlab_struct::sub::
operator[] (const std::string& name) const operator[] (const std::string& name) const
{ {
if (struct_handle == 0) if (struct_handle == 0)
throw dlib::error("Struct does not have a field named '" + name + "'."); throw dlib::error("Struct does not have a field named '" + name + "'.");
...@@ -4413,11 +4324,11 @@ operator[] (const std::string& name) const ...@@ -4413,11 +4324,11 @@ operator[] (const std::string& name) const
if (temp.field_idx == -1 ) if (temp.field_idx == -1 )
throw dlib::error("Struct does not have a field named '" + name + "'."); throw dlib::error("Struct does not have a field named '" + name + "'.");
return temp; return temp;
} }
matlab_struct::sub matlab_struct::sub:: matlab_struct::sub matlab_struct::sub::
operator[] (const std::string& name) operator[] (const std::string& name)
{ {
if (struct_handle == 0) if (struct_handle == 0)
throw dlib::error("Struct does not have a field named '" + name + "'."); throw dlib::error("Struct does not have a field named '" + name + "'.");
...@@ -4447,34 +4358,34 @@ operator[] (const std::string& name) ...@@ -4447,34 +4358,34 @@ operator[] (const std::string& name)
} }
} }
return temp; return temp;
} }
bool matlab_struct::has_field ( bool matlab_struct::has_field (
const std::string& name const std::string& name
) const ) const
{ {
if (struct_handle == 0) if (struct_handle == 0)
return false; return false;
return mxGetFieldNumber((const mxArray*)struct_handle, name.c_str()) != -1; return mxGetFieldNumber((const mxArray*)struct_handle, name.c_str()) != -1;
} }
bool matlab_struct::sub::has_field ( bool matlab_struct::sub::has_field (
const std::string& name const std::string& name
) const ) const
{ {
if (struct_handle == 0) if (struct_handle == 0)
return false; return false;
mxArray* temp = mxGetFieldByNumber((const mxArray*)struct_handle, 0, field_idx); mxArray* temp = mxGetFieldByNumber((const mxArray*)struct_handle, 0, field_idx);
if (temp == 0 || !mxIsStruct(temp)) if (temp == 0 || !mxIsStruct(temp))
return false; return false;
return mxGetFieldNumber(temp, name.c_str()) != -1; return mxGetFieldNumber(temp, name.c_str()) != -1;
} }
template <typename T> template <typename T>
matlab_struct::sub& matlab_struct::sub::operator= ( matlab_struct::sub& matlab_struct::sub::operator= (
const T& new_val const T& new_val
) )
{ {
// Delete anything in the field before we overwrite it // Delete anything in the field before we overwrite it
mxArray* item = mxGetFieldByNumber((mxArray*)struct_handle, 0, field_idx); mxArray* item = mxGetFieldByNumber((mxArray*)struct_handle, 0, field_idx);
if (item != 0) if (item != 0)
...@@ -4488,35 +4399,36 @@ matlab_struct::sub& matlab_struct::sub::operator= ( ...@@ -4488,35 +4399,36 @@ matlab_struct::sub& matlab_struct::sub::operator= (
mxSetFieldByNumber((mxArray*)struct_handle, 0, field_idx, item); mxSetFieldByNumber((mxArray*)struct_handle, 0, field_idx, item);
return *this; return *this;
} }
matlab_struct:: matlab_struct::
~matlab_struct ( ~matlab_struct (
) )
{ {
if (struct_handle && should_free) if (struct_handle && should_free)
{ {
mxDestroyArray((mxArray*)struct_handle); mxDestroyArray((mxArray*)struct_handle);
struct_handle = 0; struct_handle = 0;
} }
} }
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
void call_matlab ( void call_matlab (
const function_handle& funct const function_handle& funct
) )
{ {
call_matlab("feval", funct); call_matlab("feval", funct);
} }
extern "C" bool utIsInterruptPending(); extern "C" bool utIsInterruptPending();
void check_for_ctrl_c( void check_for_matlab_ctrl_c(
) )
{ {
if (utIsInterruptPending()) if (utIsInterruptPending())
throw mex_binding::user_hit_ctrl_c(); 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