Only create typedef to SharedXXX where really needed.
parent
6b20b888a2
commit
98ed4d7850
|
@ -94,8 +94,6 @@ void GlobalFunction::generateSingleFunction(const string& toolboxPath,
|
||||||
// start
|
// start
|
||||||
file.oss << "{\n";
|
file.oss << "{\n";
|
||||||
|
|
||||||
returnVal.wrapTypeUnwrap(file);
|
|
||||||
|
|
||||||
// check arguments
|
// check arguments
|
||||||
// NOTE: for static functions, there is no object passed
|
// NOTE: for static functions, there is no object passed
|
||||||
file.oss << " checkArguments(\"" << matlabUniqueName
|
file.oss << " checkArguments(\"" << matlabUniqueName
|
||||||
|
|
|
@ -64,8 +64,8 @@ string Method::wrapper_call(FileWriter& wrapperFile, Str cppClassName,
|
||||||
<< "\",nargout,nargin-1," << args.size() << ");\n";
|
<< "\",nargout,nargin-1," << args.size() << ");\n";
|
||||||
|
|
||||||
// get class pointer
|
// get class pointer
|
||||||
// example: shared_ptr<Test> = unwrap_shared_ptr< Test >(in[0], "Test");
|
// example: auto obj = unwrap_shared_ptr< Test >(in[0], "Test");
|
||||||
wrapperFile.oss << " Shared obj = unwrap_shared_ptr<" << cppClassName
|
wrapperFile.oss << " auto obj = unwrap_shared_ptr<" << cppClassName
|
||||||
<< ">(in[0], \"ptr_" << matlabUniqueName << "\");" << endl;
|
<< ">(in[0], \"ptr_" << matlabUniqueName << "\");" << endl;
|
||||||
|
|
||||||
// unwrap arguments, see Argument.cpp, we start at 1 as first is obj
|
// unwrap arguments, see Argument.cpp, we start at 1 as first is obj
|
||||||
|
|
|
@ -108,11 +108,6 @@ string MethodBase::wrapper_fragment(
|
||||||
// start
|
// start
|
||||||
wrapperFile.oss << "{\n";
|
wrapperFile.oss << "{\n";
|
||||||
|
|
||||||
returnVal.wrapTypeUnwrap(wrapperFile);
|
|
||||||
|
|
||||||
wrapperFile.oss << " typedef boost::shared_ptr<" << cppClassName
|
|
||||||
<< "> Shared;" << endl;
|
|
||||||
|
|
||||||
// get call
|
// get call
|
||||||
// for static methods: cppClassName::staticMethod<TemplateVal>
|
// for static methods: cppClassName::staticMethod<TemplateVal>
|
||||||
// for instance methods: obj->instanceMethod<TemplateVal>
|
// for instance methods: obj->instanceMethod<TemplateVal>
|
||||||
|
|
|
@ -23,6 +23,7 @@ void ReturnType::wrap_result(const string& out, const string& result,
|
||||||
const TypeAttributesTable& typeAttributes) const {
|
const TypeAttributesTable& typeAttributes) const {
|
||||||
string cppType = qualifiedName("::"), matlabType = qualifiedName(".");
|
string cppType = qualifiedName("::"), matlabType = qualifiedName(".");
|
||||||
|
|
||||||
|
const string sharedType = "Shared" + name();
|
||||||
if (category == CLASS) {
|
if (category == CLASS) {
|
||||||
// Handle Classes
|
// Handle Classes
|
||||||
string objCopy, ptrType;
|
string objCopy, ptrType;
|
||||||
|
@ -35,9 +36,12 @@ void ReturnType::wrap_result(const string& out, const string& result,
|
||||||
// A virtual class needs to be cloned, so the whole hierarchy is
|
// A virtual class needs to be cloned, so the whole hierarchy is
|
||||||
// returned
|
// returned
|
||||||
objCopy = result + ".clone()";
|
objCopy = result + ".clone()";
|
||||||
else
|
else {
|
||||||
// ...but a non-virtual class can just be copied
|
// ...but a non-virtual class can just be copied
|
||||||
objCopy = "Shared" + name() + "(new " + cppType + "(" + result + "))";
|
wrapperFile.oss << " typedef boost::shared_ptr<" << qualifiedName("::")
|
||||||
|
<< "> " << sharedType << ";" << endl;
|
||||||
|
objCopy = sharedType + "(new " + cppType + "(" + result + "))";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// e.g. out[1] = wrap_shared_ptr(pairResult.second,"gtsam.Point3", false);
|
// e.g. out[1] = wrap_shared_ptr(pairResult.second,"gtsam.Point3", false);
|
||||||
wrapperFile.oss << out << " = wrap_shared_ptr(" << objCopy << ",\""
|
wrapperFile.oss << out << " = wrap_shared_ptr(" << objCopy << ",\""
|
||||||
|
@ -46,8 +50,10 @@ void ReturnType::wrap_result(const string& out, const string& result,
|
||||||
|
|
||||||
} else if (isPtr) {
|
} else if (isPtr) {
|
||||||
// Handle shared pointer case for BASIS/EIGEN/VOID
|
// Handle shared pointer case for BASIS/EIGEN/VOID
|
||||||
wrapperFile.oss << " {\n Shared" << name() << "* ret = new Shared"
|
wrapperFile.oss << " typedef boost::shared_ptr<" << qualifiedName("::")
|
||||||
<< name() << "(" << result << ");" << endl;
|
<< "> " << sharedType << ";" << endl;
|
||||||
|
wrapperFile.oss << " {\n auto ret = new " << sharedType << "(" << result
|
||||||
|
<< ");" << endl;
|
||||||
wrapperFile.oss << out << " = wrap_shared_ptr(ret,\"" << matlabType
|
wrapperFile.oss << out << " = wrap_shared_ptr(ret,\"" << matlabType
|
||||||
<< "\");\n }\n";
|
<< "\");\n }\n";
|
||||||
|
|
||||||
|
@ -58,13 +64,6 @@ void ReturnType::wrap_result(const string& out, const string& result,
|
||||||
<< ");\n";
|
<< ");\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
|
||||||
void ReturnType::wrapTypeUnwrap(FileWriter& wrapperFile) const {
|
|
||||||
if (category == CLASS)
|
|
||||||
wrapperFile.oss << " typedef boost::shared_ptr<" << qualifiedName("::")
|
|
||||||
<< "> Shared" << name() << ";" << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
void ReturnType::emit_cython_pxd(
|
void ReturnType::emit_cython_pxd(
|
||||||
FileWriter& file, const std::string& className,
|
FileWriter& file, const std::string& className,
|
||||||
|
|
|
@ -60,9 +60,6 @@ private:
|
||||||
void wrap_result(const std::string& out, const std::string& result,
|
void wrap_result(const std::string& out, const std::string& result,
|
||||||
FileWriter& wrapperFile,
|
FileWriter& wrapperFile,
|
||||||
const TypeAttributesTable& typeAttributes) const;
|
const TypeAttributesTable& typeAttributes) const;
|
||||||
|
|
||||||
/// Creates typedef
|
|
||||||
void wrapTypeUnwrap(FileWriter& wrapperFile) const;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//******************************************************************************
|
//******************************************************************************
|
||||||
|
|
|
@ -40,7 +40,7 @@ void ReturnValue::wrap_result(const string& result, FileWriter& wrapperFile,
|
||||||
if (isPair) {
|
if (isPair) {
|
||||||
// For a pair, store the returned pair so we do not evaluate the function
|
// For a pair, store the returned pair so we do not evaluate the function
|
||||||
// twice
|
// twice
|
||||||
wrapperFile.oss << " " << return_type(true) << " pairResult = " << result
|
wrapperFile.oss << " auto pairResult = " << result
|
||||||
<< ";\n";
|
<< ";\n";
|
||||||
type1.wrap_result(" out[0]", "pairResult.first", wrapperFile,
|
type1.wrap_result(" out[0]", "pairResult.first", wrapperFile,
|
||||||
typeAttributes);
|
typeAttributes);
|
||||||
|
@ -51,12 +51,6 @@ void ReturnValue::wrap_result(const string& result, FileWriter& wrapperFile,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
|
||||||
void ReturnValue::wrapTypeUnwrap(FileWriter& wrapperFile) const {
|
|
||||||
type1.wrapTypeUnwrap(wrapperFile);
|
|
||||||
if (isPair) type2.wrapTypeUnwrap(wrapperFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
void ReturnValue::emit_matlab(FileWriter& proxyFile) const {
|
void ReturnValue::emit_matlab(FileWriter& proxyFile) const {
|
||||||
string output;
|
string output;
|
||||||
|
|
|
@ -70,8 +70,6 @@ struct ReturnValue {
|
||||||
void wrap_result(const std::string& result, FileWriter& wrapperFile,
|
void wrap_result(const std::string& result, FileWriter& wrapperFile,
|
||||||
const TypeAttributesTable& typeAttributes) const;
|
const TypeAttributesTable& typeAttributes) const;
|
||||||
|
|
||||||
void wrapTypeUnwrap(FileWriter& wrapperFile) const;
|
|
||||||
|
|
||||||
void emit_matlab(FileWriter& proxyFile) const;
|
void emit_matlab(FileWriter& proxyFile) const;
|
||||||
|
|
||||||
/// @param className the actual class name to use when "This" is specified
|
/// @param className the actual class name to use when "This" is specified
|
||||||
|
|
Loading…
Reference in New Issue