Isolated argument check

release/4.3a0
dellaert 2014-11-29 21:11:13 +01:00
parent 0261c59063
commit 370f2c6763
3 changed files with 19 additions and 7 deletions

View File

@ -36,7 +36,8 @@ Argument Argument::expandTemplate(const TemplateSubstitution& ts) const {
}
/* ************************************************************************* */
ArgumentList ArgumentList::expandTemplate(const TemplateSubstitution& ts) const {
ArgumentList ArgumentList::expandTemplate(
const TemplateSubstitution& ts) const {
ArgumentList instArgList;
BOOST_FOREACH(const Argument& arg, *this) {
Argument instArg = arg.expandTemplate(ts);
@ -97,6 +98,12 @@ void Argument::matlab_unwrap(FileWriter& file, const string& matlabName) const {
file.oss << ");" << endl;
}
/* ************************************************************************* */
void Argument::proxy_check(FileWriter& proxyFile, size_t sequenceNr) const {
proxyFile.oss << "isa(varargin{" << sequenceNr << "},'" << matlabClass(".")
<< "')";
}
/* ************************************************************************* */
string ArgumentList::types() const {
string str;
@ -177,7 +184,7 @@ void ArgumentList::emit_prototype(FileWriter& file, const string& name) const {
}
/* ************************************************************************* */
void ArgumentList::proxy_check_arguments(FileWriter& proxyFile) const {
void ArgumentList::proxy_check(FileWriter& proxyFile) const {
// Check nr of arguments
proxyFile.oss << "if length(varargin) == " << size();
if (size() > 0)
@ -187,11 +194,11 @@ void ArgumentList::proxy_check_arguments(FileWriter& proxyFile) const {
for (size_t i = 0; i < size(); i++) {
if (!first)
proxyFile.oss << " && ";
proxyFile.oss << "isa(varargin{" << i + 1 << "},'"
<< (*this)[i].matlabClass(".") << "')";
(*this)[i].proxy_check(proxyFile, i + 1);
first = false;
}
proxyFile.oss << "\n";
}
/* ************************************************************************* */

View File

@ -46,6 +46,12 @@ struct Argument {
/// MATLAB code generation, MATLAB to C++
void matlab_unwrap(FileWriter& file, const std::string& matlabName) const;
/**
* emit checking argument to MATLAB proxy
* @param proxyFile output stream
*/
void proxy_check(FileWriter& proxyFile, size_t sequenceNr) const;
friend std::ostream& operator<<(std::ostream& os, const Argument& arg) {
os << (arg.is_const ? "const " : "") << arg.type << (arg.is_ptr ? "*" : "")
<< (arg.is_ref ? "&" : "");
@ -91,7 +97,7 @@ struct ArgumentList: public std::vector<Argument> {
* emit checking arguments to MATLAB proxy
* @param proxyFile output stream
*/
void proxy_check_arguments(FileWriter& proxyFile) const;
void proxy_check(FileWriter& proxyFile) const;
/// Output stream operator
friend std::ostream& operator<<(std::ostream& os,
@ -106,7 +112,6 @@ struct ArgumentList: public std::vector<Argument> {
return os;
}
};
} // \namespace wrap

View File

@ -69,7 +69,7 @@ void Function::emit_conditional_call(FileWriter& proxyFile,
const string& wrapperName, int id) const {
// Check all arguments
args.proxy_check_arguments(proxyFile);
args.proxy_check(proxyFile);
// output call to C++ wrapper
proxyFile.oss << " ";