Merged in fix/matlab_wrapper_scalar_references (pull request #287)
Fixed unwrapping of scalar references.release/4.3a0
commit
687ae3d251
|
@ -75,16 +75,22 @@ void Argument::matlab_unwrap(FileWriter& file, const string& matlabName) const {
|
||||||
|
|
||||||
string cppType = type.qualifiedName("::");
|
string cppType = type.qualifiedName("::");
|
||||||
string matlabUniqueType = type.qualifiedName();
|
string matlabUniqueType = type.qualifiedName();
|
||||||
|
bool isNotScalar = !Argument::isScalar();
|
||||||
|
|
||||||
|
// We cannot handle scalar non const references
|
||||||
|
if (!isNotScalar && is_ref && !is_const) {
|
||||||
|
throw std::runtime_error("Cannot unwrap a scalar non-const reference");
|
||||||
|
}
|
||||||
|
|
||||||
if (is_ptr && type.category != Qualified::EIGEN)
|
if (is_ptr && type.category != Qualified::EIGEN)
|
||||||
// A pointer: emit an "unwrap_shared_ptr" call which returns a pointer
|
// A pointer: emit an "unwrap_shared_ptr" call which returns a pointer
|
||||||
file.oss << "boost::shared_ptr<" << cppType << "> " << name
|
file.oss << "boost::shared_ptr<" << cppType << "> " << name
|
||||||
<< " = unwrap_shared_ptr< ";
|
<< " = unwrap_shared_ptr< ";
|
||||||
else if (is_ref && type.category != Qualified::EIGEN)
|
else if (is_ref && isNotScalar && type.category != Qualified::EIGEN)
|
||||||
// A reference: emit an "unwrap_shared_ptr" call and de-reference the pointer
|
// A reference: emit an "unwrap_shared_ptr" call and de-reference the pointer
|
||||||
file.oss << cppType << "& " << name << " = *unwrap_shared_ptr< ";
|
file.oss << cppType << "& " << name << " = *unwrap_shared_ptr< ";
|
||||||
else
|
else
|
||||||
// Not a pointer or a reference: emit an "unwrap" call
|
// Not a pointer, or a reference to a scalar type. Therefore, emit an "unwrap" call
|
||||||
// unwrap is specified in matlab.h as a series of template specializations
|
// unwrap is specified in matlab.h as a series of template specializations
|
||||||
// that know how to unpack the expected MATLAB object
|
// that know how to unpack the expected MATLAB object
|
||||||
// example: double tol = unwrap< double >(in[2]);
|
// example: double tol = unwrap< double >(in[2]);
|
||||||
|
@ -92,7 +98,7 @@ void Argument::matlab_unwrap(FileWriter& file, const string& matlabName) const {
|
||||||
file.oss << cppType << " " << name << " = unwrap< ";
|
file.oss << cppType << " " << name << " = unwrap< ";
|
||||||
|
|
||||||
file.oss << cppType << " >(" << matlabName;
|
file.oss << cppType << " >(" << matlabName;
|
||||||
if( (is_ptr || is_ref) && type.category != Qualified::EIGEN)
|
if( (is_ptr || is_ref) && isNotScalar && type.category != Qualified::EIGEN)
|
||||||
file.oss << ", \"ptr_" << matlabUniqueType << "\"";
|
file.oss << ", \"ptr_" << matlabUniqueType << "\"";
|
||||||
file.oss << ");" << endl;
|
file.oss << ");" << endl;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue