From 2ad5a51e741a20af8e06162a095c1cf86d65174d Mon Sep 17 00:00:00 2001 From: dellaert Date: Wed, 12 Nov 2014 15:31:40 +0100 Subject: [PATCH] MAde some method private, and renamed return_type -> str --- wrap/ReturnValue.cpp | 29 +++++++++++++++-------------- wrap/ReturnValue.h | 33 +++++++++++++++++++++------------ 2 files changed, 36 insertions(+), 26 deletions(-) diff --git a/wrap/ReturnValue.cpp b/wrap/ReturnValue.cpp index e760722e8..cd8273731 100644 --- a/wrap/ReturnValue.cpp +++ b/wrap/ReturnValue.cpp @@ -16,13 +16,13 @@ using namespace std; using namespace wrap; /* ************************************************************************* */ -string ReturnType::return_type(bool add_ptr) const { - return maybe_shared_ptr(add_ptr || isPtr, qualifiedName("::"), name); +string ReturnType::str(bool add_ptr) const { + return maybe_shared_ptr(add_ptr && isPtr, qualifiedName("::"), name); } /* ************************************************************************* */ -void ReturnType::wrap_result(const string& result, FileWriter& file, - const TypeAttributesTable& typeAttributes) const { +void ReturnType::wrap_result(const string& out, const string& result, + FileWriter& file, const TypeAttributesTable& typeAttributes) const { string cppType = qualifiedName("::"), matlabType = qualifiedName("."); @@ -41,15 +41,14 @@ void ReturnType::wrap_result(const string& result, FileWriter& file, else objCopy = ptrType + "(new " + cppType + "(" + result + "))"; } - file.oss << " out[0] = wrap_shared_ptr(" << objCopy << ",\"" << matlabType + file.oss << out << " = wrap_shared_ptr(" << objCopy << ",\"" << matlabType << "\", " << (isVirtual ? "true" : "false") << ");\n"; } else if (isPtr) { file.oss << " Shared" << name << "* ret = new Shared" << name << "(" << result << ");" << endl; - file.oss << " out[0] = wrap_shared_ptr(ret,\"" << matlabType << "\");\n"; + file.oss << out << " = wrap_shared_ptr(ret,\"" << matlabType << "\");\n"; } else if (matlabType != "void") - file.oss << " out[0] = wrap< " << return_type(true) << " >(" << result - << ");\n"; + file.oss << out << " = wrap< " << str(false) << " >(" << result << ");\n"; } /* ************************************************************************* */ @@ -61,8 +60,10 @@ void ReturnType::wrapTypeUnwrap(FileWriter& file) const { /* ************************************************************************* */ string ReturnValue::return_type(bool add_ptr) const { - return "pair< " + type1.return_type(add_ptr) + ", " - + type2.return_type(add_ptr) + " >"; + if (isPair) + return "pair< " + type1.str(add_ptr) + ", " + type2.str(add_ptr) + " >"; + else + return type1.str(add_ptr); } /* ************************************************************************* */ @@ -75,12 +76,12 @@ void ReturnValue::wrap_result(const string& result, FileWriter& file, const TypeAttributesTable& typeAttributes) const { if (isPair) { // For a pair, store the returned pair so we do not evaluate the function twice - file.oss << " " << return_type(false) << " pairResult = " << result + file.oss << " " << return_type(true) << " pairResult = " << result << ";\n"; - type1.wrap_result("pairResult.first", file, typeAttributes); - type2.wrap_result("pairResult.second", file, typeAttributes); + type1.wrap_result(" out[0]", "pairResult.first", file, typeAttributes); + type2.wrap_result(" out[1]", "pairResult.second", file, typeAttributes); } else { // Not a pair - type1.wrap_result(result, file, typeAttributes); + type1.wrap_result(" out[0]", result, file, typeAttributes); } } diff --git a/wrap/ReturnValue.h b/wrap/ReturnValue.h index 31f29795b..5b9be18d5 100644 --- a/wrap/ReturnValue.h +++ b/wrap/ReturnValue.h @@ -20,7 +20,7 @@ namespace wrap { /** * Encapsulates return value of a method or function */ -struct ReturnType : Qualified { +struct ReturnType: Qualified { /// the different supported return value categories typedef enum { @@ -30,27 +30,35 @@ struct ReturnType : Qualified { bool isPtr; return_category category; - ReturnType(): isPtr(false), category(CLASS) { + ReturnType() : + isPtr(false), category(CLASS) { } - ReturnType(const Qualified& q): Qualified(q), isPtr(false), category(CLASS) { + ReturnType(const Qualified& q) : + Qualified(q), isPtr(false), category(CLASS) { } - std::string return_type(bool add_ptr) const; - - void wrap_result(const std::string& result, FileWriter& file, - const TypeAttributesTable& typeAttributes) const; - - void wrapTypeUnwrap(FileWriter& wrapperFile) const; - /// Check if this type is in a set of valid types - template + template void verify(TYPES validtypes, const std::string& s) const { std::string key = qualifiedName("::"); if (find(validtypes.begin(), validtypes.end(), key) == validtypes.end()) throw DependencyMissing(key, s); } +private: + + friend struct ReturnValue; + + std::string str(bool add_ptr) const; + + /// Example: out[1] = wrap_shared_ptr(pairResult.second,"Test", false); + void wrap_result(const std::string& out, const std::string& result, + FileWriter& file, const TypeAttributesTable& typeAttributes) const; + + /// Creates typedef + void wrapTypeUnwrap(FileWriter& wrapperFile) const; + }; /** @@ -62,7 +70,8 @@ struct ReturnValue { ReturnType type1, type2; /// Constructor - ReturnValue() : isPair(false) { + ReturnValue() : + isPair(false) { } std::string return_type(bool add_ptr) const;