Re-factoring ReturnValue
parent
9b9d9a6b54
commit
443b710a8d
|
@ -99,10 +99,7 @@ Module::Module(const string& interfacePath,
|
||||||
void Module::parseMarkup(const std::string& data) {
|
void Module::parseMarkup(const std::string& data) {
|
||||||
// these variables will be imperatively updated to gradually build [cls]
|
// these variables will be imperatively updated to gradually build [cls]
|
||||||
// The one with postfix 0 are used to reset the variables after parse.
|
// The one with postfix 0 are used to reset the variables after parse.
|
||||||
bool isConst, isConst0 = false;
|
|
||||||
ReturnValue retVal0, retVal;
|
|
||||||
Argument arg0, arg;
|
Argument arg0, arg;
|
||||||
ArgumentList args;
|
|
||||||
vector<string> arg_dup; ///keep track of duplicates
|
vector<string> arg_dup; ///keep track of duplicates
|
||||||
Constructor constructor0(verbose), constructor(verbose);
|
Constructor constructor0(verbose), constructor(verbose);
|
||||||
Deconstructor deconstructor0(verbose), deconstructor(verbose);
|
Deconstructor deconstructor0(verbose), deconstructor(verbose);
|
||||||
|
@ -210,6 +207,7 @@ void Module::parseMarkup(const std::string& data) {
|
||||||
'>');
|
'>');
|
||||||
|
|
||||||
// NOTE: allows for pointers to all types
|
// NOTE: allows for pointers to all types
|
||||||
|
ArgumentList args;
|
||||||
Rule argument_p =
|
Rule argument_p =
|
||||||
((basisType_p[assign_a(arg.type.name)] | argEigenType_p | eigenRef_p | classArg_p)
|
((basisType_p[assign_a(arg.type.name)] | argEigenType_p | eigenRef_p | classArg_p)
|
||||||
>> !ch_p('*')[assign_a(arg.is_ptr,true)]
|
>> !ch_p('*')[assign_a(arg.is_ptr,true)]
|
||||||
|
@ -223,10 +221,6 @@ void Module::parseMarkup(const std::string& data) {
|
||||||
(className_p >> '(' >> argumentList_p >> ')' >> ';' >> !comments_p)
|
(className_p >> '(' >> argumentList_p >> ')' >> ';' >> !comments_p)
|
||||||
[push_back_a(constructor.args_list, args)]
|
[push_back_a(constructor.args_list, args)]
|
||||||
[clear_a(args)];
|
[clear_a(args)];
|
||||||
//[assign_a(constructor.args,args)]
|
|
||||||
//[assign_a(constructor.name,cls.name)]
|
|
||||||
//[push_back_a(cls.constructors, constructor)]
|
|
||||||
//[assign_a(constructor,constructor0)];
|
|
||||||
|
|
||||||
Rule namespace_ret_p = namespace_name_p[push_back_a(namespaces_return)] >> str_p("::");
|
Rule namespace_ret_p = namespace_name_p[push_back_a(namespaces_return)] >> str_p("::");
|
||||||
|
|
||||||
|
@ -236,6 +230,8 @@ void Module::parseMarkup(const std::string& data) {
|
||||||
static const ReturnValue::return_category RETURN_CLASS = ReturnValue::CLASS;
|
static const ReturnValue::return_category RETURN_CLASS = ReturnValue::CLASS;
|
||||||
static const ReturnValue::return_category RETURN_VOID = ReturnValue::VOID;
|
static const ReturnValue::return_category RETURN_VOID = ReturnValue::VOID;
|
||||||
|
|
||||||
|
// TODO, eliminate copy/paste
|
||||||
|
ReturnValue retVal0, retVal;
|
||||||
Rule returnType1_p =
|
Rule returnType1_p =
|
||||||
(basisType_p[assign_a(retVal.type1.name)][assign_a(retVal.category1, RETURN_BASIS)]) |
|
(basisType_p[assign_a(retVal.type1.name)][assign_a(retVal.category1, RETURN_BASIS)]) |
|
||||||
((*namespace_ret_p)[assign_a(retVal.type1.namespaces, namespaces_return)][clear_a(namespaces_return)]
|
((*namespace_ret_p)[assign_a(retVal.type1.namespaces, namespaces_return)][clear_a(namespaces_return)]
|
||||||
|
@ -262,6 +258,7 @@ void Module::parseMarkup(const std::string& data) {
|
||||||
|
|
||||||
// gtsam::Values retract(const gtsam::VectorValues& delta) const;
|
// gtsam::Values retract(const gtsam::VectorValues& delta) const;
|
||||||
string methodName;
|
string methodName;
|
||||||
|
bool isConst, isConst0 = false;
|
||||||
vector<Qualified> methodInstantiations;
|
vector<Qualified> methodInstantiations;
|
||||||
Rule method_p =
|
Rule method_p =
|
||||||
!templateArgValues_p
|
!templateArgValues_p
|
||||||
|
@ -272,9 +269,9 @@ void Module::parseMarkup(const std::string& data) {
|
||||||
[bl::bind(&Method::addOverload,
|
[bl::bind(&Method::addOverload,
|
||||||
bl::var(cls.methods)[bl::var(methodName)], verbose,
|
bl::var(cls.methods)[bl::var(methodName)], verbose,
|
||||||
bl::var(isConst), bl::var(methodName), bl::var(args), bl::var(retVal))]
|
bl::var(isConst), bl::var(methodName), bl::var(args), bl::var(retVal))]
|
||||||
[assign_a(isConst,isConst0)]
|
[assign_a(retVal,retVal0)]
|
||||||
[clear_a(args)]
|
[clear_a(args)]
|
||||||
[assign_a(retVal,retVal0)];
|
[assign_a(isConst,isConst0)];
|
||||||
|
|
||||||
Rule staticMethodName_p = lexeme_d[(upper_p | lower_p) >> *(alnum_p | '_')];
|
Rule staticMethodName_p = lexeme_d[(upper_p | lower_p) >> *(alnum_p | '_')];
|
||||||
|
|
||||||
|
@ -283,18 +280,16 @@ void Module::parseMarkup(const std::string& data) {
|
||||||
'(' >> argumentList_p >> ')' >> ';' >> *comments_p)
|
'(' >> argumentList_p >> ')' >> ';' >> *comments_p)
|
||||||
[bl::bind(&StaticMethod::addOverload,
|
[bl::bind(&StaticMethod::addOverload,
|
||||||
bl::var(cls.static_methods)[bl::var(methodName)],
|
bl::var(cls.static_methods)[bl::var(methodName)],
|
||||||
verbose,
|
verbose, bl::var(methodName), bl::var(args), bl::var(retVal))]
|
||||||
bl::var(methodName),
|
[assign_a(retVal,retVal0)]
|
||||||
bl::var(args),
|
[clear_a(args)];
|
||||||
bl::var(retVal))]
|
|
||||||
[clear_a(args)]
|
|
||||||
[assign_a(retVal,retVal0)];
|
|
||||||
|
|
||||||
Rule functions_p = constructor_p | method_p | static_method_p;
|
Rule functions_p = constructor_p | method_p | static_method_p;
|
||||||
|
|
||||||
|
// parse a full class
|
||||||
vector<Qualified> templateInstantiations;
|
vector<Qualified> templateInstantiations;
|
||||||
Rule class_p =
|
Rule class_p =
|
||||||
(str_p("")[assign_a(cls,cls0)])
|
eps_p[assign_a(cls,cls0)]
|
||||||
>> (!(templateArgValues_p
|
>> (!(templateArgValues_p
|
||||||
[push_back_a(cls.templateArgs, templateArgName)]
|
[push_back_a(cls.templateArgs, templateArgName)]
|
||||||
[assign_a(templateInstantiations,templateArgValues)]
|
[assign_a(templateInstantiations,templateArgValues)]
|
||||||
|
@ -313,11 +308,12 @@ void Module::parseMarkup(const std::string& data) {
|
||||||
[assign_a(cls.deconstructor, deconstructor)]
|
[assign_a(cls.deconstructor, deconstructor)]
|
||||||
[bl::bind(&handle_possible_template, bl::var(classes), bl::var(cls),
|
[bl::bind(&handle_possible_template, bl::var(classes), bl::var(cls),
|
||||||
bl::var(templateArgName), bl::var(templateInstantiations))]
|
bl::var(templateArgName), bl::var(templateInstantiations))]
|
||||||
|
[clear_a(templateInstantiations)]
|
||||||
[assign_a(deconstructor,deconstructor0)]
|
[assign_a(deconstructor,deconstructor0)]
|
||||||
[assign_a(constructor, constructor0)]
|
[assign_a(constructor, constructor0)]
|
||||||
[assign_a(cls,cls0)]
|
[assign_a(cls,cls0)];
|
||||||
[clear_a(templateInstantiations)];
|
|
||||||
|
|
||||||
|
// parse a global function
|
||||||
Qualified globalFunction;
|
Qualified globalFunction;
|
||||||
Rule global_function_p =
|
Rule global_function_p =
|
||||||
(returnType_p >> staticMethodName_p[assign_a(globalFunction.name)] >>
|
(returnType_p >> staticMethodName_p[assign_a(globalFunction.name)] >>
|
||||||
|
@ -325,13 +321,10 @@ void Module::parseMarkup(const std::string& data) {
|
||||||
[assign_a(globalFunction.namespaces,namespaces)]
|
[assign_a(globalFunction.namespaces,namespaces)]
|
||||||
[bl::bind(&GlobalFunction::addOverload,
|
[bl::bind(&GlobalFunction::addOverload,
|
||||||
bl::var(global_functions)[bl::var(globalFunction.name)],
|
bl::var(global_functions)[bl::var(globalFunction.name)],
|
||||||
verbose,
|
verbose, bl::var(globalFunction), bl::var(args), bl::var(retVal))]
|
||||||
bl::var(globalFunction),
|
[assign_a(retVal,retVal0)]
|
||||||
bl::var(args),
|
|
||||||
bl::var(retVal))]
|
|
||||||
[clear_a(globalFunction)]
|
[clear_a(globalFunction)]
|
||||||
[clear_a(args)]
|
[clear_a(args)];
|
||||||
[assign_a(retVal,retVal0)];
|
|
||||||
|
|
||||||
Rule include_p = str_p("#include") >> ch_p('<') >> (*(anychar_p - '>'))[push_back_a(includes)] >> ch_p('>');
|
Rule include_p = str_p("#include") >> ch_p('<') >> (*(anychar_p - '>'))[push_back_a(includes)] >> ch_p('>');
|
||||||
|
|
||||||
|
|
|
@ -19,13 +19,13 @@ using namespace wrap;
|
||||||
string ReturnValue::return_type(bool add_ptr, pairing p) const {
|
string ReturnValue::return_type(bool add_ptr, pairing p) const {
|
||||||
if (p == pair && isPair) {
|
if (p == pair && isPair) {
|
||||||
string str = "pair< "
|
string str = "pair< "
|
||||||
+ maybe_shared_ptr(add_ptr || isPtr1, qualifiedType1("::"), type1.name)
|
+ maybe_shared_ptr(add_ptr || type1.isPtr, qualifiedType1("::"), type1.name)
|
||||||
+ ", "
|
+ ", "
|
||||||
+ maybe_shared_ptr(add_ptr || isPtr2, qualifiedType2("::"), type2.name)
|
+ maybe_shared_ptr(add_ptr || type2.isPtr, qualifiedType2("::"), type2.name)
|
||||||
+ " >";
|
+ " >";
|
||||||
return str;
|
return str;
|
||||||
} else
|
} else
|
||||||
return maybe_shared_ptr(add_ptr && isPtr1,
|
return maybe_shared_ptr(add_ptr && type1.isPtr,
|
||||||
(p == arg2) ? qualifiedType2("::") : qualifiedType1("::"),
|
(p == arg2) ? qualifiedType2("::") : qualifiedType1("::"),
|
||||||
(p == arg2) ? type2.name : type1.name);
|
(p == arg2) ? type2.name : type1.name);
|
||||||
}
|
}
|
||||||
|
@ -45,6 +45,101 @@ string ReturnValue::qualifiedType2(const string& delim) const {
|
||||||
return type2.qualifiedName(delim);
|
return type2.qualifiedName(delim);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ************************************************************************* */
|
||||||
|
void ReturnType::wrap_result(const string& result, FileWriter& file,
|
||||||
|
const TypeAttributesTable& typeAttributes) const {
|
||||||
|
string cppType1 = qualifiedType1("::"), matlabType1 = qualifiedType1(".");
|
||||||
|
string cppType2 = qualifiedType2("::"), matlabType2 = qualifiedType2(".");
|
||||||
|
|
||||||
|
if (isPair) {
|
||||||
|
// For a pair, store the returned pair so we do not evaluate the function twice
|
||||||
|
file.oss << " " << return_type(false, pair) << " pairResult = " << result
|
||||||
|
<< ";\n";
|
||||||
|
|
||||||
|
// first return value in pair
|
||||||
|
if (type1.category == ReturnValue::CLASS) { // if we are going to make one
|
||||||
|
string objCopy, ptrType;
|
||||||
|
ptrType = "Shared" + type1.name;
|
||||||
|
const bool isVirtual = typeAttributes.at(cppType1).isVirtual;
|
||||||
|
if (isVirtual) {
|
||||||
|
if (type1.isPtr)
|
||||||
|
objCopy = "pairResult.first";
|
||||||
|
else
|
||||||
|
objCopy = "pairResult.first.clone()";
|
||||||
|
} else {
|
||||||
|
if (type1.isPtr)
|
||||||
|
objCopy = "pairResult.first";
|
||||||
|
else
|
||||||
|
objCopy = ptrType + "(new " + cppType1 + "(pairResult.first))";
|
||||||
|
}
|
||||||
|
file.oss << " out[0] = wrap_shared_ptr(" << objCopy << ",\""
|
||||||
|
<< matlabType1 << "\", " << (isVirtual ? "true" : "false") << ");\n";
|
||||||
|
} else if (type1.isPtr) {
|
||||||
|
file.oss << " Shared" << type1.name << "* ret = new Shared" << type1.name
|
||||||
|
<< "(pairResult.first);" << endl;
|
||||||
|
file.oss << " out[0] = wrap_shared_ptr(ret,\"" << matlabType1
|
||||||
|
<< "\", false);\n";
|
||||||
|
} else
|
||||||
|
// if basis type
|
||||||
|
file.oss << " out[0] = wrap< " << return_type(true, arg1)
|
||||||
|
<< " >(pairResult.first);\n";
|
||||||
|
|
||||||
|
// second return value in pair
|
||||||
|
if (type2.category == ReturnValue::CLASS) { // if we are going to make one
|
||||||
|
string objCopy, ptrType;
|
||||||
|
ptrType = "Shared" + type2.name;
|
||||||
|
const bool isVirtual = typeAttributes.at(cppType2).isVirtual;
|
||||||
|
if (isVirtual) {
|
||||||
|
if (type2.isPtr)
|
||||||
|
objCopy = "pairResult.second";
|
||||||
|
else
|
||||||
|
objCopy = "pairResult.second.clone()";
|
||||||
|
} else {
|
||||||
|
if (type2.isPtr)
|
||||||
|
objCopy = "pairResult.second";
|
||||||
|
else
|
||||||
|
objCopy = ptrType + "(new " + cppType2 + "(pairResult.second))";
|
||||||
|
}
|
||||||
|
file.oss << " out[1] = wrap_shared_ptr(" << objCopy << ",\""
|
||||||
|
<< matlabType2 << "\", " << (isVirtual ? "true" : "false") << ");\n";
|
||||||
|
} else if (type2.isPtr) {
|
||||||
|
file.oss << " Shared" << type2.name << "* ret = new Shared" << type2.name
|
||||||
|
<< "(pairResult.second);" << endl;
|
||||||
|
file.oss << " out[1] = wrap_shared_ptr(ret,\"" << matlabType2
|
||||||
|
<< "\");\n";
|
||||||
|
} else
|
||||||
|
file.oss << " out[1] = wrap< " << return_type(true, arg2)
|
||||||
|
<< " >(pairResult.second);\n";
|
||||||
|
} else { // Not a pair
|
||||||
|
|
||||||
|
if (type1.category == ReturnValue::CLASS) {
|
||||||
|
string objCopy, ptrType;
|
||||||
|
ptrType = "Shared" + type1.name;
|
||||||
|
const bool isVirtual = typeAttributes.at(cppType1).isVirtual;
|
||||||
|
if (isVirtual) {
|
||||||
|
if (type1.isPtr)
|
||||||
|
objCopy = result;
|
||||||
|
else
|
||||||
|
objCopy = result + ".clone()";
|
||||||
|
} else {
|
||||||
|
if (type1.isPtr)
|
||||||
|
objCopy = result;
|
||||||
|
else
|
||||||
|
objCopy = ptrType + "(new " + cppType1 + "(" + result + "))";
|
||||||
|
}
|
||||||
|
file.oss << " out[0] = wrap_shared_ptr(" << objCopy << ",\""
|
||||||
|
<< matlabType1 << "\", " << (isVirtual ? "true" : "false") << ");\n";
|
||||||
|
} else if (type1.isPtr) {
|
||||||
|
file.oss << " Shared" << type1.name << "* ret = new Shared" << type1.name
|
||||||
|
<< "(" << result << ");" << endl;
|
||||||
|
file.oss << " out[0] = wrap_shared_ptr(ret,\"" << matlabType1
|
||||||
|
<< "\");\n";
|
||||||
|
} else if (matlabType1 != "void")
|
||||||
|
file.oss << " out[0] = wrap< " << return_type(true, arg1) << " >("
|
||||||
|
<< result << ");\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
//TODO:Fix this
|
//TODO:Fix this
|
||||||
void ReturnValue::wrap_result(const string& result, FileWriter& file, const TypeAttributesTable& typeAttributes) const {
|
void ReturnValue::wrap_result(const string& result, FileWriter& file, const TypeAttributesTable& typeAttributes) const {
|
||||||
|
@ -56,69 +151,69 @@ void ReturnValue::wrap_result(const string& result, FileWriter& file, const Type
|
||||||
file.oss << " " << return_type(false, pair) << " pairResult = " << result << ";\n";
|
file.oss << " " << return_type(false, pair) << " pairResult = " << result << ";\n";
|
||||||
|
|
||||||
// first return value in pair
|
// first return value in pair
|
||||||
if (category1 == ReturnValue::CLASS) { // if we are going to make one
|
if (type1.category == ReturnValue::CLASS) { // if we are going to make one
|
||||||
string objCopy, ptrType;
|
string objCopy, ptrType;
|
||||||
ptrType = "Shared" + type1.name;
|
ptrType = "Shared" + type1.name;
|
||||||
const bool isVirtual = typeAttributes.at(cppType1).isVirtual;
|
const bool isVirtual = typeAttributes.at(cppType1).isVirtual;
|
||||||
if(isVirtual) {
|
if(isVirtual) {
|
||||||
if(isPtr1)
|
if(type1.isPtr)
|
||||||
objCopy = "pairResult.first";
|
objCopy = "pairResult.first";
|
||||||
else
|
else
|
||||||
objCopy = "pairResult.first.clone()";
|
objCopy = "pairResult.first.clone()";
|
||||||
} else {
|
} else {
|
||||||
if(isPtr1)
|
if(type1.isPtr)
|
||||||
objCopy = "pairResult.first";
|
objCopy = "pairResult.first";
|
||||||
else
|
else
|
||||||
objCopy = ptrType + "(new " + cppType1 + "(pairResult.first))";
|
objCopy = ptrType + "(new " + cppType1 + "(pairResult.first))";
|
||||||
}
|
}
|
||||||
file.oss << " out[0] = wrap_shared_ptr(" << objCopy << ",\"" << matlabType1 << "\", " << (isVirtual ? "true" : "false") << ");\n";
|
file.oss << " out[0] = wrap_shared_ptr(" << objCopy << ",\"" << matlabType1 << "\", " << (isVirtual ? "true" : "false") << ");\n";
|
||||||
} else if(isPtr1) {
|
} else if(type1.isPtr) {
|
||||||
file.oss << " Shared" << type1.name <<"* ret = new Shared" << type1.name << "(pairResult.first);" << endl;
|
file.oss << " Shared" << type1.name <<"* ret = new Shared" << type1.name << "(pairResult.first);" << endl;
|
||||||
file.oss << " out[0] = wrap_shared_ptr(ret,\"" << matlabType1 << "\", false);\n";
|
file.oss << " out[0] = wrap_shared_ptr(ret,\"" << matlabType1 << "\", false);\n";
|
||||||
} else // if basis type
|
} else // if basis type
|
||||||
file.oss << " out[0] = wrap< " << return_type(true,arg1) << " >(pairResult.first);\n";
|
file.oss << " out[0] = wrap< " << return_type(true,arg1) << " >(pairResult.first);\n";
|
||||||
|
|
||||||
// second return value in pair
|
// second return value in pair
|
||||||
if (category2 == ReturnValue::CLASS) { // if we are going to make one
|
if (type2.category == ReturnValue::CLASS) { // if we are going to make one
|
||||||
string objCopy, ptrType;
|
string objCopy, ptrType;
|
||||||
ptrType = "Shared" + type2.name;
|
ptrType = "Shared" + type2.name;
|
||||||
const bool isVirtual = typeAttributes.at(cppType2).isVirtual;
|
const bool isVirtual = typeAttributes.at(cppType2).isVirtual;
|
||||||
if(isVirtual) {
|
if(isVirtual) {
|
||||||
if(isPtr2)
|
if(type2.isPtr)
|
||||||
objCopy = "pairResult.second";
|
objCopy = "pairResult.second";
|
||||||
else
|
else
|
||||||
objCopy = "pairResult.second.clone()";
|
objCopy = "pairResult.second.clone()";
|
||||||
} else {
|
} else {
|
||||||
if(isPtr2)
|
if(type2.isPtr)
|
||||||
objCopy = "pairResult.second";
|
objCopy = "pairResult.second";
|
||||||
else
|
else
|
||||||
objCopy = ptrType + "(new " + cppType2 + "(pairResult.second))";
|
objCopy = ptrType + "(new " + cppType2 + "(pairResult.second))";
|
||||||
}
|
}
|
||||||
file.oss << " out[1] = wrap_shared_ptr(" << objCopy << ",\"" << matlabType2 << "\", " << (isVirtual ? "true" : "false") << ");\n";
|
file.oss << " out[1] = wrap_shared_ptr(" << objCopy << ",\"" << matlabType2 << "\", " << (isVirtual ? "true" : "false") << ");\n";
|
||||||
} else if(isPtr2) {
|
} else if(type2.isPtr) {
|
||||||
file.oss << " Shared" << type2.name <<"* ret = new Shared" << type2.name << "(pairResult.second);" << endl;
|
file.oss << " Shared" << type2.name <<"* ret = new Shared" << type2.name << "(pairResult.second);" << endl;
|
||||||
file.oss << " out[1] = wrap_shared_ptr(ret,\"" << matlabType2 << "\");\n";
|
file.oss << " out[1] = wrap_shared_ptr(ret,\"" << matlabType2 << "\");\n";
|
||||||
} else
|
} else
|
||||||
file.oss << " out[1] = wrap< " << return_type(true,arg2) << " >(pairResult.second);\n";
|
file.oss << " out[1] = wrap< " << return_type(true,arg2) << " >(pairResult.second);\n";
|
||||||
} else { // Not a pair
|
} else { // Not a pair
|
||||||
|
|
||||||
if (category1 == ReturnValue::CLASS) {
|
if (type1.category == ReturnValue::CLASS) {
|
||||||
string objCopy, ptrType;
|
string objCopy, ptrType;
|
||||||
ptrType = "Shared" + type1.name;
|
ptrType = "Shared" + type1.name;
|
||||||
const bool isVirtual = typeAttributes.at(cppType1).isVirtual;
|
const bool isVirtual = typeAttributes.at(cppType1).isVirtual;
|
||||||
if(isVirtual) {
|
if(isVirtual) {
|
||||||
if(isPtr1)
|
if(type1.isPtr)
|
||||||
objCopy = result;
|
objCopy = result;
|
||||||
else
|
else
|
||||||
objCopy = result + ".clone()";
|
objCopy = result + ".clone()";
|
||||||
} else {
|
} else {
|
||||||
if(isPtr1)
|
if(type1.isPtr)
|
||||||
objCopy = result;
|
objCopy = result;
|
||||||
else
|
else
|
||||||
objCopy = ptrType + "(new " + cppType1 + "(" + result + "))";
|
objCopy = ptrType + "(new " + cppType1 + "(" + result + "))";
|
||||||
}
|
}
|
||||||
file.oss << " out[0] = wrap_shared_ptr(" << objCopy << ",\"" << matlabType1 << "\", " << (isVirtual ? "true" : "false") << ");\n";
|
file.oss << " out[0] = wrap_shared_ptr(" << objCopy << ",\"" << matlabType1 << "\", " << (isVirtual ? "true" : "false") << ");\n";
|
||||||
} else if(isPtr1) {
|
} else if(type1.isPtr) {
|
||||||
file.oss << " Shared" << type1.name <<"* ret = new Shared" << type1.name << "(" << result << ");" << endl;
|
file.oss << " Shared" << type1.name <<"* ret = new Shared" << type1.name << "(" << result << ");" << endl;
|
||||||
file.oss << " out[0] = wrap_shared_ptr(ret,\"" << matlabType1 << "\");\n";
|
file.oss << " out[0] = wrap_shared_ptr(ret,\"" << matlabType1 << "\");\n";
|
||||||
} else if (matlabType1!="void")
|
} else if (matlabType1!="void")
|
||||||
|
@ -130,13 +225,13 @@ void ReturnValue::wrap_result(const string& result, FileWriter& file, const Type
|
||||||
void ReturnValue::wrapTypeUnwrap(FileWriter& wrapperFile) const {
|
void ReturnValue::wrapTypeUnwrap(FileWriter& wrapperFile) const {
|
||||||
if(isPair)
|
if(isPair)
|
||||||
{
|
{
|
||||||
if(category1 == ReturnValue::CLASS)
|
if(type1.category == ReturnValue::CLASS)
|
||||||
wrapperFile.oss << " typedef boost::shared_ptr<" << qualifiedType1("::") << "> Shared" << type1.name << ";"<< endl;
|
wrapperFile.oss << " typedef boost::shared_ptr<" << qualifiedType1("::") << "> Shared" << type1.name << ";"<< endl;
|
||||||
if(category2 == ReturnValue::CLASS)
|
if(type2.category == ReturnValue::CLASS)
|
||||||
wrapperFile.oss << " typedef boost::shared_ptr<" << qualifiedType2("::") << "> Shared" << type2.name << ";"<< endl;
|
wrapperFile.oss << " typedef boost::shared_ptr<" << qualifiedType2("::") << "> Shared" << type2.name << ";"<< endl;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (category1 == ReturnValue::CLASS)
|
if (type1.category == ReturnValue::CLASS)
|
||||||
wrapperFile.oss << " typedef boost::shared_ptr<" << qualifiedType1("::") << "> Shared" << type1.name << ";"<< endl;
|
wrapperFile.oss << " typedef boost::shared_ptr<" << qualifiedType1("::") << "> Shared" << type1.name << ";"<< endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -145,7 +240,7 @@ void ReturnValue::emit_matlab(FileWriter& file) const {
|
||||||
string output;
|
string output;
|
||||||
if (isPair)
|
if (isPair)
|
||||||
file.oss << "[ varargout{1} varargout{2} ] = ";
|
file.oss << "[ varargout{1} varargout{2} ] = ";
|
||||||
else if (category1 != ReturnValue::VOID)
|
else if (type1.category != ReturnValue::VOID)
|
||||||
file.oss << "varargout{1} = ";
|
file.oss << "varargout{1} = ";
|
||||||
}
|
}
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
|
|
|
@ -19,21 +19,33 @@ namespace wrap {
|
||||||
/**
|
/**
|
||||||
* Encapsulates return value of a method or function
|
* Encapsulates return value of a method or function
|
||||||
*/
|
*/
|
||||||
struct ReturnValue {
|
struct ReturnType : Qualified {
|
||||||
|
|
||||||
|
ReturnType(): isPtr(false), category(CLASS) {
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnType(const Qualified& q): Qualified(q), isPtr(false), category(CLASS) {
|
||||||
|
}
|
||||||
|
|
||||||
/// the different supported return value categories
|
/// the different supported return value categories
|
||||||
typedef enum {
|
typedef enum {
|
||||||
CLASS = 1, EIGEN = 2, BASIS = 3, VOID = 4
|
CLASS = 1, EIGEN = 2, BASIS = 3, VOID = 4
|
||||||
} return_category;
|
} return_category;
|
||||||
|
|
||||||
bool isPtr1, isPtr2, isPair;
|
bool isPtr;
|
||||||
return_category category1, category2;
|
return_category category;
|
||||||
Qualified type1, type2;
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encapsulates return value of a method or function, possibly a pair
|
||||||
|
*/
|
||||||
|
struct ReturnValue {
|
||||||
|
|
||||||
|
bool isPair;
|
||||||
|
ReturnType type1, type2;
|
||||||
|
|
||||||
/// Constructor
|
/// Constructor
|
||||||
ReturnValue() :
|
ReturnValue() : isPair(false) {
|
||||||
isPtr1(false), isPtr2(false), isPair(false), category1(CLASS), category2(
|
|
||||||
CLASS) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
|
Loading…
Reference in New Issue