Drake
|
Go to the source code of this file.
Macros | |
#define | NOEXCEPT noexcept |
Typedefs | |
template<typename T > | |
using | FromMexType = typename std::remove_cv< typename std::remove_reference< T >::type >::type |
Functions that make it easy to create a mex file that calls a std::function. More... | |
Functions | |
template<typename R > | |
void | mexCallFunctionUnsafe (std::function< R(void)> func, int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) |
mexCallFunctionUnsafe Converts arguments and calls function without checking whether arguments are convertible first. More... | |
template<> | |
void | mexCallFunctionUnsafe (std::function< void(void)> func, int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) |
template<typename R , typename Arg0 , typename... Args> | |
void | mexCallFunctionUnsafe (std::function< R(Arg0, Args...)> func, int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) |
bool | areArgumentsConvertibleFromMex (int nrhs, const mxArray *prhs[], int arg_num, std::ostream *log) NOEXCEPT |
areArgumentsConvertibleFromMex Checks whether the Matlab input arguments match the function signature When the log argument is not a nullptr, writes diagnostic message to log upon failure. More... | |
template<typename Arg0 , typename... Args> | |
bool | areArgumentsConvertibleFromMex (int nrhs, const mxArray *prhs[], int arg_num, std::ostream *log, Arg0 *, Args *...tail) NOEXCEPT |
template<typename R , typename... Args> | |
bool | mexCallFunction (int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[], bool throw_on_error, std::function< R(Args...)> func) |
mexCallFunction checks whether arguments are convertible, and then calls mexCallFunctionUnsafe. More... | |
void | collectMexTryCallFunctionsErrorDiagnostics (int nrhs, const mxArray *prhs[], std::ostream &log, int function_num) |
collectMexTryCallFunctionsErrorDiagnostics write diagnostic information to log; called after mexTryToCallFunctions has exhausted all options More... | |
template<typename R0 , typename... Args0, typename... Funcs> | |
void | collectMexTryCallFunctionsErrorDiagnostics (int nrhs, const mxArray *prhs[], std::ostream &log, int function_num, std::function< R0(Args0...)> function0, Funcs...functions) |
bool | mexTryToCallFunctions (int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[], bool throw_on_error) |
mexTryToCallFunctions keep trying functions in order until one is called without error. More... | |
template<typename Func0 , typename... Funcs> | |
bool | mexTryToCallFunctions (int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[], bool throw_on_error, Func0 function0, Funcs...functions) |
template<typename T > | |
auto | fromMex (const mxArray *source, T *trigger_type) -> decltype(fromMexUnsafe(source, trigger_type)) |
fromMex For if you only want to convert a single argument. More... | |
#define NOEXCEPT noexcept |
using FromMexType = typename std::remove_cv<typename std::remove_reference<T>::type>::type |
Functions that make it easy to create a mex file that calls a std::function.
Example: Calling a C++ function with signature
bool foo(int arg)
can be done by creating a mex function with body
function<bool(int)> func = mexCallFunction(func, nlhs, plhs, nrhs, prhs);
Overloads for isConvertibleFromMex and fromMexUnsafe should be provided for each argument type. isConvertibleFromMex and fromMexUnsafe functions should be of the form
bool isConvertibleFromMex(const mxArray* source, TriggerType*, std::ostream* log) NOEXCEPT ArgumentType fromMexUnsafe(const mxArray* source, TriggerType*)
where TriggerType is the type of the argument currently being processed according to the signature of the std::function that was passed in (with cv qualifiers and reference removed) and ArgumentType is the type that will actually be passed into the function (which may or may not be the same as TriggerType). isConvertibleFromMex functions should do minimal work when the log argument is a nullptr. If it is not null, they should provide a helpful error message.
toMex functions should be of the form
int toMex(const SourceType& source, mxArray* dest[], int nlhs)
where SourceType is such that the return type of the std::function can be converted to it. The toMex function should return the number of Matlab output arguments it has set.
bool areArgumentsConvertibleFromMex | ( | int | nrhs, |
const mxArray * | prhs[], | ||
int | arg_num, | ||
std::ostream * | log | ||
) |
areArgumentsConvertibleFromMex Checks whether the Matlab input arguments match the function signature When the log argument is not a nullptr, writes diagnostic message to log upon failure.
bool areArgumentsConvertibleFromMex | ( | int | nrhs, |
const mxArray * | prhs[], | ||
int | arg_num, | ||
std::ostream * | log, | ||
Arg0 * | , | ||
Args *... | tail | ||
) |
void collectMexTryCallFunctionsErrorDiagnostics | ( | int | nrhs, |
const mxArray * | prhs[], | ||
std::ostream & | log, | ||
int | function_num | ||
) |
collectMexTryCallFunctionsErrorDiagnostics write diagnostic information to log; called after mexTryToCallFunctions has exhausted all options
void collectMexTryCallFunctionsErrorDiagnostics | ( | int | nrhs, |
const mxArray * | prhs[], | ||
std::ostream & | log, | ||
int | function_num, | ||
std::function< R0(Args0...)> | function0, | ||
Funcs... | functions | ||
) |
auto fromMex | ( | const mxArray * | source, |
T * | trigger_type | ||
) | -> decltype(fromMexUnsafe(source, trigger_type)) |
fromMex For if you only want to convert a single argument.
First calls isConvertible, then calls fromMexUnsafe. Throws a runtime_error if not convertible.
bool mexCallFunction | ( | int | nlhs, |
mxArray * | plhs[], | ||
int | nrhs, | ||
const mxArray * | prhs[], | ||
bool | throw_on_error, | ||
std::function< R(Args...)> | func | ||
) |
mexCallFunction checks whether arguments are convertible, and then calls mexCallFunctionUnsafe.
throws a runtime_error with a diagnostic message upon failure
void mexCallFunctionUnsafe | ( | std::function< R(void)> | func, |
int | nlhs, | ||
mxArray * | plhs[], | ||
int | nrhs, | ||
const mxArray * | prhs[] | ||
) |
mexCallFunctionUnsafe Converts arguments and calls function without checking whether arguments are convertible first.
void mexCallFunctionUnsafe | ( | std::function< void(void)> | func, |
int | nlhs, | ||
mxArray * | plhs[], | ||
int | nrhs, | ||
const mxArray * | prhs[] | ||
) |
void mexCallFunctionUnsafe | ( | std::function< R(Arg0, Args...)> | func, |
int | nlhs, | ||
mxArray * | plhs[], | ||
int | nrhs, | ||
const mxArray * | prhs[] | ||
) |
bool mexTryToCallFunctions | ( | int | nlhs, |
mxArray * | plhs[], | ||
int | nrhs, | ||
const mxArray * | prhs[], | ||
bool | throw_on_error | ||
) |
mexTryToCallFunctions keep trying functions in order until one is called without error.
throws a runtime_error with a diagnostic message upon failure
bool mexTryToCallFunctions | ( | int | nlhs, |
mxArray * | plhs[], | ||
int | nrhs, | ||
const mxArray * | prhs[], | ||
bool | throw_on_error, | ||
Func0 | function0, | ||
Funcs... | functions | ||
) |