41#define APF_MEX_ERROR_NO_OUTPUT_SUPPORTED(name) \
44 std::string msg("No output parameters are supported for " \
45 + std::string(name) + "!"); \
46 mexErrMsgTxt(msg.c_str()); }
48#define APF_MEX_ERROR_EXACTLY_ONE_OUTPUT(name) \
51 std::string msg("Exactly one output parameter is supported for " \
52 + std::string(name) + "!"); \
53 mexErrMsgTxt(msg.c_str()); }
55#define APF_MEX_ERROR_ONE_OPTIONAL_OUTPUT(name) \
58 std::string msg("No more than one output parameter is supported for " \
59 + std::string(name) + "!"); \
60 mexErrMsgTxt(msg.c_str()); }
62#define APF_MEX_ERROR_NO_FURTHER_INPUTS(name) \
65 std::string msg("No further input parameters are supported for " \
66 + std::string(name) + "!"); \
67 mexErrMsgTxt(msg.c_str()); }
69#define APF_MEX_ERROR_FURTHER_INPUT_NEEDED(text) \
72 std::string msg(std::string(text) + " needs a further input parameter!"); \
73 mexErrMsgTxt(msg.c_str()); }
75#define APF_MEX_ERROR_NUMERIC_INPUT(text) \
77if (!mxIsNumeric(prhs[0])) { \
78 std::string msg(std::string(text) + " must be a numeric matrix!"); \
79 mexErrMsgTxt(msg.c_str()); }
81#define APF_MEX_ERROR_REAL_INPUT(text) \
83APF_MEX_ERROR_NUMERIC_INPUT(text); \
84if (mxIsComplex(prhs[0])) { \
85 std::string msg(std::string(text) + " must not be complex!"); \
86 mexErrMsgTxt(msg.c_str()); }
88#define APF_MEX_ERROR_SAME_NUMBER_OF_ROWS(value, text) \
90if (static_cast<mwSize>(mxGetM(prhs[0])) != (value)) { \
91 std::string msg("Number of rows must be the same " \
92 + std::string(text) + "!"); \
93 mexErrMsgTxt(msg.c_str()); }
95#define APF_MEX_ERROR_SAME_NUMBER_OF_COLUMNS(value, text) \
97if (static_cast<mwSize>(mxGetN(prhs[0])) != (value)) { \
98 std::string msg("Number of columns must be the same " \
99 + std::string(text) + "!"); \
100 mexErrMsgTxt(msg.c_str()); }
112bool convert(
const mxArray* in, std::string& out)
114 if (!mxIsChar(in))
return false;
115 if (mxGetM(in) != 1 && mxGetN(in) > 0)
return false;
117 char* temp = mxArrayToString(in);
126 if (!mxIsDouble(in) || mxIsComplex(in))
return false;
127 if (mxGetNumberOfElements(in) != 1)
return false;
128 out = mxGetScalar(in);
135 if (!mxIsDouble(in) || mxIsComplex(in))
return false;
136 if (mxGetNumberOfElements(in) != 1)
return false;
137 double temp = mxGetScalar(in);
138 if (temp != std::floor(temp))
return false;
146 if (!mxIsDouble(in) || mxIsComplex(in))
return false;
147 if (mxGetNumberOfElements(in) != 1)
return false;
148 double temp = mxGetScalar(in);
149 if (temp != std::floor(temp))
return false;
157 if (mxIsComplex(in) || (!mxIsLogical(in) && !mxIsNumeric(in)))
return false;
158 if (mxGetNumberOfElements(in) != 1)
return false;
159 out = mxGetScalar(in);
166 if (!mxIsDouble(in) || mxIsComplex(in))
return false;
167 if (mxGetNumberOfElements(in) != 1)
return false;
168 double temp = mxGetScalar(in);
169 if (temp < 0 || temp != std::floor(temp))
return false;
179bool convert(
const mxArray* in, std::map<std::string, std::string>& out)
181 if (!mxIsStruct(in))
return false;
182 if (mxGetNumberOfElements(in) != 1)
return false;
184 for (
int i = 0; i < mxGetNumberOfFields(in); ++i)
186 auto fieldname = std::string(mxGetFieldNameByNumber(in, i));
189 mxArray* field = mxGetFieldByNumber(in, 0, i);
192 std::string stringvalue;
196 if (
convert(field, doublevalue))
200 else if (
convert(field, stringvalue))
206 mexPrintf(
"Trying to convert '%s' ...\n", fieldname.c_str());
207 mexErrMsgTxt(
"Value must be a real scalar number or a string!");
209 out[fieldname] = stringvalue;
217bool convert(
const mxArray* in, std::vector<std::string>& out)
219 if (!mxIsCell(in))
return false;
221 for (
size_t i = 0; i < mxGetNumberOfElements(in); ++i)
223 mxArray* cell = mxGetCell(in, i);
224 std::string stringvalue;
226 if (
convert(cell, stringvalue))
228 out.push_back(stringvalue);
232 mexErrMsgTxt(
"Element of cell array must be a string!");
242template<
bool optional,
typename T>
243bool next_arg_helper(
int& n,
const mxArray**& p, T& data)
245 if (n < 1)
return optional;
246 bool result =
convert(p[0], data);
267 return internal::next_arg_helper<false>(n, p, data);
283 return internal::next_arg_helper<true>(n, p, data);
290void next_arg(
int& n,
const mxArray**& p, T& data,
const std::string& error)
292 if (!
next_arg(n, p, data)) mexErrMsgTxt(error.c_str());
299void next_optarg(
int& n,
const mxArray**& p, T& data,
const std::string& error)
301 if (!
next_optarg(n, p, data)) mexErrMsgTxt(error.c_str());
bool next_arg(int &n, const mxArray **&p, T &data)
Get next argument, converted to T.
bool convert(const mxArray *in, std::string &out)
Convert mxArray to std::string.
bool next_optarg(int &n, const mxArray **&p, T &data)
Get next optional argument, converted to T.
std::string A2S(const T &input)
Converter "Anything to String".
Audio Processing Framework.