Improved error handling on entry to mex files

This commit is contained in:
hbristow
2013-06-24 12:42:28 -07:00
parent 9b32c6e653
commit da63919811
2 changed files with 76 additions and 19 deletions

View File

@@ -12,6 +12,7 @@
#include "bridge.hpp"
#include <string>
#include <vector>
#include <cassert>
#include <exception>
#include <opencv2/{{includes}}.hpp>
using namespace cv;
@@ -29,9 +30,10 @@ void mexFunction(int nlhs, mxArray* plhs[],
int nrhs, const mxArray* prhs[]) {
// assertions
mxAssert(nrhs >= {{fun.req|length - fun.req|outputs|length}}, "Too few required input arguments specified");
mxAssert(nrhs <= {{fun.req|length + fun.opt|length - fun.req|outputs|length - fun.opt|outputs|length}}, "Too many input arguments specified");
mxAssert(nlhs <= {{ fun.rtp|void|not + fun.req|outputs|length + fun.opt|outputs|length}}, "Too many output arguments specified");
mexPrintf("nrhs: %d, nlhs: %d\n", nrhs, nlhs);
conditionalError(nrhs >= {{fun.req|length - fun.req|outputs|length}}, "Too few required input arguments specified");
conditionalError(nrhs <= {{fun.req|length + fun.opt|length - fun.req|outputs|length - fun.opt|outputs|length}}, "Too many input arguments specified");
conditionalError(nlhs <= {{ fun.rtp|void|not + fun.req|outputs|length + fun.opt|outputs|length}}, "Too many output arguments specified");
// setup
std::vector<Bridge> inputs(plhs, plhs+nrhs);