48
48
+ std::string(name) + "!"); \
49
49
mexErrMsgTxt(msg.c_str()); }
51
#define APF_MEX_ERROR_ONE_OPTIONAL_OUTPUT(name) \
54
std::string msg("No more than one output parameter is supported for " \
55
+ std::string(name) + "!"); \
56
mexErrMsgTxt(msg.c_str()); }
51
58
#define APF_MEX_ERROR_NO_FURTHER_INPUTS(name) \
100
/// Helper functions for creating MEX files
96
104
// TODO: check if (and how) user-specified overloads of convert() work
97
105
// TODO: use a traits class, if necessary
107
/// Convert @c mxArray to @c std::string
99
108
bool convert(const mxArray* in, std::string& out)
101
110
if (!mxIsChar(in)) return false;
150
/// Convert @c mxArray to a @c std::map of @c std::string%s.
151
/// This expects a scalar structure!
152
/// Values must be real scalar numbers or strings!
153
/// @warning In case of a conversion error, the map may be partially filled!
138
154
// TODO: allow wstring?
139
// This expects a scalar structure!
140
// Values must be real scalar numbers or strings!
141
// WARNING: In case of a conversion error, the map may be partly filled!
142
155
bool convert(const mxArray* in, std::map<std::string, std::string>& out)
144
157
if (!mxIsStruct(in)) return false;
186
199
} // namespace internal
201
/// Get next argument, converted to @p T.
202
/// @param n Number of arguments, typically @c nrhs
203
/// @param p Pointer to arguments, typically @c prhs
204
/// @return @b true if argument was available and if conversion was successful
205
/// @post @p n is decremented, @p p is incremented
188
206
template<typename T>
189
207
bool next_arg(int& n, const mxArray**& p, T& data)
191
209
return internal::next_arg_helper<false>(n, p, data);
212
/// Get next optional argument, converted to @p T.
213
/// @return @b true if no argument available or if conversion was successful
194
215
template<typename T>
195
216
bool next_optarg(int& n, const mxArray**& p, T& data)
197
218
return internal::next_arg_helper<true>(n, p, data);
221
/// Get next argument, converted to @p T.
223
/// @param error Message to be displayed on error
200
224
template<typename T>
201
225
void next_arg(int& n, const mxArray**& p, T& data, const std::string& error)
203
227
if (!next_arg(n, p, data)) mexErrMsgTxt(error.c_str());
230
/// Get next optional argument, converted to @p T.
231
/// @see next_optarg()
232
/// @param error Message to be displayed on error
206
233
template<typename T>
207
234
void next_optarg(int& n, const mxArray**& p, T& data, const std::string& error)