From 98ed4d78502fdc746a68024a0e0af25b0202e326 Mon Sep 17 00:00:00 2001 From: Frank Dellaert Date: Tue, 19 Mar 2019 12:09:00 -0400 Subject: [PATCH] Only create typedef to SharedXXX where really needed. --- wrap/GlobalFunction.cpp | 2 -- wrap/Method.cpp | 4 ++-- wrap/MethodBase.cpp | 5 ----- wrap/ReturnType.cpp | 21 ++++++++++----------- wrap/ReturnType.h | 3 --- wrap/ReturnValue.cpp | 8 +------- wrap/ReturnValue.h | 2 -- 7 files changed, 13 insertions(+), 32 deletions(-) diff --git a/wrap/GlobalFunction.cpp b/wrap/GlobalFunction.cpp index c8482f2c4..123511dfa 100644 --- a/wrap/GlobalFunction.cpp +++ b/wrap/GlobalFunction.cpp @@ -94,8 +94,6 @@ void GlobalFunction::generateSingleFunction(const string& toolboxPath, // start file.oss << "{\n"; - returnVal.wrapTypeUnwrap(file); - // check arguments // NOTE: for static functions, there is no object passed file.oss << " checkArguments(\"" << matlabUniqueName diff --git a/wrap/Method.cpp b/wrap/Method.cpp index 8f0ef17b9..f7247341c 100644 --- a/wrap/Method.cpp +++ b/wrap/Method.cpp @@ -64,8 +64,8 @@ string Method::wrapper_call(FileWriter& wrapperFile, Str cppClassName, << "\",nargout,nargin-1," << args.size() << ");\n"; // get class pointer - // example: shared_ptr = unwrap_shared_ptr< Test >(in[0], "Test"); - wrapperFile.oss << " Shared obj = unwrap_shared_ptr<" << cppClassName + // example: auto obj = unwrap_shared_ptr< Test >(in[0], "Test"); + wrapperFile.oss << " auto obj = unwrap_shared_ptr<" << cppClassName << ">(in[0], \"ptr_" << matlabUniqueName << "\");" << endl; // unwrap arguments, see Argument.cpp, we start at 1 as first is obj diff --git a/wrap/MethodBase.cpp b/wrap/MethodBase.cpp index ef169d989..a2ed68780 100644 --- a/wrap/MethodBase.cpp +++ b/wrap/MethodBase.cpp @@ -108,11 +108,6 @@ string MethodBase::wrapper_fragment( // start wrapperFile.oss << "{\n"; - returnVal.wrapTypeUnwrap(wrapperFile); - - wrapperFile.oss << " typedef boost::shared_ptr<" << cppClassName - << "> Shared;" << endl; - // get call // for static methods: cppClassName::staticMethod // for instance methods: obj->instanceMethod diff --git a/wrap/ReturnType.cpp b/wrap/ReturnType.cpp index 506e7d471..a97b1cf31 100644 --- a/wrap/ReturnType.cpp +++ b/wrap/ReturnType.cpp @@ -23,6 +23,7 @@ void ReturnType::wrap_result(const string& out, const string& result, const TypeAttributesTable& typeAttributes) const { string cppType = qualifiedName("::"), matlabType = qualifiedName("."); + const string sharedType = "Shared" + name(); if (category == CLASS) { // Handle Classes 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 // returned objCopy = result + ".clone()"; - else + else { // ...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); wrapperFile.oss << out << " = wrap_shared_ptr(" << objCopy << ",\"" @@ -46,8 +50,10 @@ void ReturnType::wrap_result(const string& out, const string& result, } else if (isPtr) { // Handle shared pointer case for BASIS/EIGEN/VOID - wrapperFile.oss << " {\n Shared" << name() << "* ret = new Shared" - << name() << "(" << result << ");" << endl; + wrapperFile.oss << " typedef boost::shared_ptr<" << qualifiedName("::") + << "> " << sharedType << ";" << endl; + wrapperFile.oss << " {\n auto ret = new " << sharedType << "(" << result + << ");" << endl; wrapperFile.oss << out << " = wrap_shared_ptr(ret,\"" << matlabType << "\");\n }\n"; @@ -58,13 +64,6 @@ void ReturnType::wrap_result(const string& out, const string& result, << ");\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( FileWriter& file, const std::string& className, diff --git a/wrap/ReturnType.h b/wrap/ReturnType.h index de1835f28..e4b5b193f 100644 --- a/wrap/ReturnType.h +++ b/wrap/ReturnType.h @@ -60,9 +60,6 @@ private: void wrap_result(const std::string& out, const std::string& result, FileWriter& wrapperFile, const TypeAttributesTable& typeAttributes) const; - - /// Creates typedef - void wrapTypeUnwrap(FileWriter& wrapperFile) const; }; //****************************************************************************** diff --git a/wrap/ReturnValue.cpp b/wrap/ReturnValue.cpp index 3f318eddc..9bdd9f5fb 100644 --- a/wrap/ReturnValue.cpp +++ b/wrap/ReturnValue.cpp @@ -40,7 +40,7 @@ void ReturnValue::wrap_result(const string& result, FileWriter& wrapperFile, if (isPair) { // For a pair, store the returned pair so we do not evaluate the function // twice - wrapperFile.oss << " " << return_type(true) << " pairResult = " << result + wrapperFile.oss << " auto pairResult = " << result << ";\n"; type1.wrap_result(" out[0]", "pairResult.first", wrapperFile, 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 { string output; diff --git a/wrap/ReturnValue.h b/wrap/ReturnValue.h index 589db5bd6..3e3ca1cc7 100644 --- a/wrap/ReturnValue.h +++ b/wrap/ReturnValue.h @@ -70,8 +70,6 @@ struct ReturnValue { void wrap_result(const std::string& result, FileWriter& wrapperFile, const TypeAttributesTable& typeAttributes) const; - void wrapTypeUnwrap(FileWriter& wrapperFile) const; - void emit_matlab(FileWriter& proxyFile) const; /// @param className the actual class name to use when "This" is specified