New TemplateSubstitution object simplifies a lot
parent
a5e0adb7e6
commit
b451e97f6f
|
@ -29,24 +29,21 @@ using namespace std;
|
||||||
using namespace wrap;
|
using namespace wrap;
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
Argument Argument::expandTemplate(const string& templateArg,
|
Argument Argument::expandTemplate(const TemplateSubstitution& ts) const {
|
||||||
const Qualified& qualifiedType, const Qualified& expandedClass) const {
|
|
||||||
Argument instArg = *this;
|
Argument instArg = *this;
|
||||||
if (type.name == templateArg) {
|
if (type.name == ts.templateArg) {
|
||||||
instArg.type = qualifiedType;
|
instArg.type = ts.qualifiedType;
|
||||||
} else if (type.name == "This") {
|
} else if (type.name == "This") {
|
||||||
instArg.type = expandedClass;
|
instArg.type = ts.expandedClass;
|
||||||
}
|
}
|
||||||
return instArg;
|
return instArg;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
ArgumentList ArgumentList::expandTemplate(const string& templateArg,
|
ArgumentList ArgumentList::expandTemplate(const TemplateSubstitution& ts) const {
|
||||||
const Qualified& qualifiedType, const Qualified& expandedClass) const {
|
|
||||||
ArgumentList instArgList;
|
ArgumentList instArgList;
|
||||||
BOOST_FOREACH(const Argument& arg, *this) {
|
BOOST_FOREACH(const Argument& arg, *this) {
|
||||||
Argument instArg = arg.expandTemplate(templateArg, qualifiedType,
|
Argument instArg = arg.expandTemplate(ts);
|
||||||
expandedClass);
|
|
||||||
instArgList.push_back(instArg);
|
instArgList.push_back(instArg);
|
||||||
}
|
}
|
||||||
return instArgList;
|
return instArgList;
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Qualified.h"
|
#include "TemplateSubstitution.h"
|
||||||
#include "FileWriter.h"
|
#include "FileWriter.h"
|
||||||
#include "ReturnValue.h"
|
#include "ReturnValue.h"
|
||||||
|
|
||||||
|
@ -35,8 +35,7 @@ struct Argument {
|
||||||
is_const(false), is_ref(false), is_ptr(false) {
|
is_const(false), is_ref(false), is_ptr(false) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Argument expandTemplate(const std::string& templateArg,
|
Argument expandTemplate(const TemplateSubstitution& ts) const;
|
||||||
const Qualified& qualifiedType, const Qualified& expandedClass) const;
|
|
||||||
|
|
||||||
/// return MATLAB class for use in isa(x,class)
|
/// return MATLAB class for use in isa(x,class)
|
||||||
std::string matlabClass(const std::string& delim = "") const;
|
std::string matlabClass(const std::string& delim = "") const;
|
||||||
|
@ -63,8 +62,7 @@ struct ArgumentList: public std::vector<Argument> {
|
||||||
/// Check if all arguments scalar
|
/// Check if all arguments scalar
|
||||||
bool allScalar() const;
|
bool allScalar() const;
|
||||||
|
|
||||||
ArgumentList expandTemplate(const std::string& templateArg,
|
ArgumentList expandTemplate(const TemplateSubstitution& ts) const;
|
||||||
const Qualified& qualifiedType, const Qualified& expandedClass) const;
|
|
||||||
|
|
||||||
// MATLAB code generation:
|
// MATLAB code generation:
|
||||||
|
|
||||||
|
@ -110,14 +108,7 @@ inline void verifyArguments(const std::vector<std::string>& validArgs,
|
||||||
typedef typename std::map<std::string, T>::value_type NamedMethod;
|
typedef typename std::map<std::string, T>::value_type NamedMethod;
|
||||||
BOOST_FOREACH(const NamedMethod& namedMethod, vt) {
|
BOOST_FOREACH(const NamedMethod& namedMethod, vt) {
|
||||||
const T& t = namedMethod.second;
|
const T& t = namedMethod.second;
|
||||||
BOOST_FOREACH(const ArgumentList& argList, t.argLists) {
|
t.verifyArguments(validArgs,t.name_);
|
||||||
BOOST_FOREACH(Argument arg, argList) {
|
|
||||||
std::string fullType = arg.type.qualifiedName("::");
|
|
||||||
if (find(validArgs.begin(), validArgs.end(), fullType)
|
|
||||||
== validArgs.end())
|
|
||||||
throw DependencyMissing(fullType, t.name_);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -240,15 +240,11 @@ void Class::pointer_constructor_fragments(FileWriter& proxyFile,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
Class Class::expandTemplate(const string& templateArg,
|
Class Class::expandTemplate(const TemplateSubstitution& ts) const {
|
||||||
const Qualified& instName, const Qualified& expandedClass) const {
|
|
||||||
Class inst = *this;
|
Class inst = *this;
|
||||||
inst.methods = expandMethodTemplate(methods, templateArg, instName,
|
inst.methods = expandMethodTemplate(methods, ts);
|
||||||
expandedClass);
|
inst.static_methods = expandMethodTemplate(static_methods, ts);
|
||||||
inst.static_methods = expandMethodTemplate(static_methods, templateArg,
|
inst.constructor.args_list = inst.constructor.expandArgumentListsTemplate(ts);
|
||||||
instName, expandedClass);
|
|
||||||
inst.constructor.args_list = inst.constructor.expandArgumentListsTemplate(
|
|
||||||
templateArg, instName, expandedClass);
|
|
||||||
inst.constructor.name = inst.name;
|
inst.constructor.name = inst.name;
|
||||||
inst.deconstructor.name = inst.name;
|
inst.deconstructor.name = inst.name;
|
||||||
return inst;
|
return inst;
|
||||||
|
@ -261,7 +257,8 @@ vector<Class> Class::expandTemplate(const string& templateArg,
|
||||||
BOOST_FOREACH(const Qualified& instName, instantiations) {
|
BOOST_FOREACH(const Qualified& instName, instantiations) {
|
||||||
Qualified expandedClass = (Qualified) (*this);
|
Qualified expandedClass = (Qualified) (*this);
|
||||||
expandedClass.name += instName.name;
|
expandedClass.name += instName.name;
|
||||||
Class inst = expandTemplate(templateArg, instName, expandedClass);
|
const TemplateSubstitution ts(templateArg, instName, expandedClass);
|
||||||
|
Class inst = expandTemplate(ts);
|
||||||
inst.name = expandedClass.name;
|
inst.name = expandedClass.name;
|
||||||
inst.templateArgs.clear();
|
inst.templateArgs.clear();
|
||||||
inst.typedefName = qualifiedName("::") + "<" + instName.qualifiedName("::")
|
inst.typedefName = qualifiedName("::") + "<" + instName.qualifiedName("::")
|
||||||
|
@ -282,13 +279,12 @@ void Class::addMethod(bool verbose, bool is_const, const string& name,
|
||||||
BOOST_FOREACH(const Qualified& instName, templateArgValues) {
|
BOOST_FOREACH(const Qualified& instName, templateArgValues) {
|
||||||
string expandedName = name + instName.name;
|
string expandedName = name + instName.name;
|
||||||
// substitute template in arguments
|
// substitute template in arguments
|
||||||
ArgumentList expandedArgs = args.expandTemplate(templateArgName, instName,
|
const TemplateSubstitution ts(templateArgName, instName, name);
|
||||||
name);
|
ArgumentList expandedArgs = args.expandTemplate(ts);
|
||||||
// do the same for return types
|
// do the same for return types
|
||||||
ReturnValue expandedRetVal = retVal.expandTemplate(templateArgName,
|
ReturnValue expandedRetVal = retVal.expandTemplate(ts);
|
||||||
instName, name);
|
methods[expandedName].addOverload(verbose, is_const, name, expandedArgs,
|
||||||
methods[expandedName].addOverload(verbose, is_const, expandedName,
|
expandedRetVal, instName);
|
||||||
expandedArgs, expandedRetVal, instName);
|
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
// just add overload
|
// just add overload
|
||||||
|
@ -390,24 +386,14 @@ void Class::comment_fragment(FileWriter& proxyFile) const {
|
||||||
proxyFile.oss << "%\n%-------Methods-------\n";
|
proxyFile.oss << "%\n%-------Methods-------\n";
|
||||||
BOOST_FOREACH(const Methods::value_type& name_m, methods) {
|
BOOST_FOREACH(const Methods::value_type& name_m, methods) {
|
||||||
const Method& m = name_m.second;
|
const Method& m = name_m.second;
|
||||||
BOOST_FOREACH(ArgumentList argList, m.argLists) {
|
m.comment_fragment(proxyFile, m.name_);
|
||||||
proxyFile.oss << "%";
|
|
||||||
argList.emit_prototype(proxyFile, m.name_);
|
|
||||||
proxyFile.oss << " : returns " << m.returnVals[0].return_type(false)
|
|
||||||
<< endl;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!static_methods.empty())
|
if (!static_methods.empty())
|
||||||
proxyFile.oss << "%\n%-------Static Methods-------\n";
|
proxyFile.oss << "%\n%-------Static Methods-------\n";
|
||||||
BOOST_FOREACH(const StaticMethods::value_type& name_m, static_methods) {
|
BOOST_FOREACH(const StaticMethods::value_type& name_m, static_methods) {
|
||||||
const StaticMethod& m = name_m.second;
|
const StaticMethod& m = name_m.second;
|
||||||
BOOST_FOREACH(ArgumentList argList, m.argLists) {
|
m.comment_fragment(proxyFile, m.name_);
|
||||||
proxyFile.oss << "%";
|
|
||||||
argList.emit_prototype(proxyFile, m.name_);
|
|
||||||
proxyFile.oss << " : returns " << m.returnVals[0].return_type(false)
|
|
||||||
<< endl;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasSerialization) {
|
if (hasSerialization) {
|
||||||
|
|
|
@ -67,8 +67,7 @@ public:
|
||||||
const std::string& wrapperName, const TypeAttributesTable& typeAttributes,
|
const std::string& wrapperName, const TypeAttributesTable& typeAttributes,
|
||||||
FileWriter& wrapperFile, std::vector<std::string>& functionNames) const; ///< emit proxy class
|
FileWriter& wrapperFile, std::vector<std::string>& functionNames) const; ///< emit proxy class
|
||||||
|
|
||||||
Class expandTemplate(const std::string& templateArg,
|
Class expandTemplate(const TemplateSubstitution& ts) const;
|
||||||
const Qualified& instantiation, const Qualified& expandedClass) const;
|
|
||||||
|
|
||||||
std::vector<Class> expandTemplate(const std::string& templateArg,
|
std::vector<Class> expandTemplate(const std::string& templateArg,
|
||||||
const std::vector<Qualified>& instantiations) const;
|
const std::vector<Qualified>& instantiations) const;
|
||||||
|
|
|
@ -38,12 +38,10 @@ string Constructor::matlab_wrapper_name(const string& className) const {
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
vector<ArgumentList> Constructor::expandArgumentListsTemplate(
|
vector<ArgumentList> Constructor::expandArgumentListsTemplate(
|
||||||
const string& templateArg, const Qualified& qualifiedType,
|
const TemplateSubstitution& ts) const {
|
||||||
const Qualified& expandedClass) const {
|
|
||||||
vector<ArgumentList> result;
|
vector<ArgumentList> result;
|
||||||
BOOST_FOREACH(const ArgumentList& argList, args_list) {
|
BOOST_FOREACH(const ArgumentList& argList, args_list) {
|
||||||
ArgumentList instArgList = argList.expandTemplate(templateArg,
|
ArgumentList instArgList = argList.expandTemplate(ts);
|
||||||
qualifiedType, expandedClass);
|
|
||||||
result.push_back(instArgList);
|
result.push_back(instArgList);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -40,8 +40,7 @@ struct Constructor {
|
||||||
|
|
||||||
// TODO eliminate copy/paste with function
|
// TODO eliminate copy/paste with function
|
||||||
std::vector<ArgumentList> expandArgumentListsTemplate(
|
std::vector<ArgumentList> expandArgumentListsTemplate(
|
||||||
const std::string& templateArg, const Qualified& qualifiedType,
|
const TemplateSubstitution& ts) const;
|
||||||
const Qualified& expandedClass) const;
|
|
||||||
|
|
||||||
// MATLAB code generation
|
// MATLAB code generation
|
||||||
// toolboxPath is main toolbox directory, e.g., ../matlab
|
// toolboxPath is main toolbox directory, e.g., ../matlab
|
||||||
|
|
|
@ -30,7 +30,6 @@ using namespace wrap;
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
void Function::addOverload(bool verbose, const std::string& name,
|
void Function::addOverload(bool verbose, const std::string& name,
|
||||||
const ArgumentList& args, const ReturnValue& retVal,
|
|
||||||
const Qualified& instName) {
|
const Qualified& instName) {
|
||||||
|
|
||||||
// Check if this overload is give to the correct method
|
// Check if this overload is give to the correct method
|
||||||
|
@ -51,18 +50,14 @@ void Function::addOverload(bool verbose, const std::string& name,
|
||||||
+ templateArgValue_.qualifiedName(":"));
|
+ templateArgValue_.qualifiedName(":"));
|
||||||
|
|
||||||
verbose_ = verbose;
|
verbose_ = verbose;
|
||||||
argLists.push_back(args);
|
|
||||||
returnVals.push_back(retVal);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
vector<ArgumentList> Function::expandArgumentListsTemplate(
|
vector<ArgumentList> ArgumentOverloads::expandArgumentListsTemplate(
|
||||||
const string& templateArg, const Qualified& qualifiedType,
|
const TemplateSubstitution& ts) const {
|
||||||
const Qualified& expandedClass) const {
|
|
||||||
vector<ArgumentList> result;
|
vector<ArgumentList> result;
|
||||||
BOOST_FOREACH(const ArgumentList& argList, argLists) {
|
BOOST_FOREACH(const ArgumentList& argList, argLists_) {
|
||||||
ArgumentList instArgList = argList.expandTemplate(templateArg,
|
ArgumentList instArgList = argList.expandTemplate(ts);
|
||||||
qualifiedType, expandedClass);
|
|
||||||
result.push_back(instArgList);
|
result.push_back(instArgList);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|
171
wrap/Function.h
171
wrap/Function.h
|
@ -42,66 +42,163 @@ struct Function {
|
||||||
bool verbose_;
|
bool verbose_;
|
||||||
std::string name_; ///< name of method
|
std::string name_; ///< name of method
|
||||||
Qualified templateArgValue_; ///< value of template argument if applicable
|
Qualified templateArgValue_; ///< value of template argument if applicable
|
||||||
std::vector<ArgumentList> argLists;
|
|
||||||
std::vector<ReturnValue> returnVals;
|
|
||||||
|
|
||||||
// The first time this function is called, it initializes the class members
|
// The first time this function is called, it initializes the class members
|
||||||
// with those in rhs, but in subsequent calls it adds additional argument
|
// with those in rhs, but in subsequent calls it adds additional argument
|
||||||
// lists as function overloads.
|
// lists as function overloads.
|
||||||
void addOverload(bool verbose, const std::string& name,
|
void addOverload(bool verbose, const std::string& name,
|
||||||
const ArgumentList& args, const ReturnValue& retVal,
|
|
||||||
const Qualified& instName = Qualified());
|
const Qualified& instName = Qualified());
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ArgumentList Overloads
|
||||||
|
*/
|
||||||
|
class ArgumentOverloads {
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
std::vector<ArgumentList> argLists_;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
size_t nrOverloads() const {
|
||||||
|
return argLists_.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
const ArgumentList& argumentList(size_t i) const {
|
||||||
|
return argLists_.at(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
void addOverload(const ArgumentList& args) {
|
||||||
|
argLists_.push_back(args);
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<ArgumentList> expandArgumentListsTemplate(
|
std::vector<ArgumentList> expandArgumentListsTemplate(
|
||||||
const std::string& templateArg, const Qualified& qualifiedType,
|
const TemplateSubstitution& ts) const;
|
||||||
const Qualified& expandedClass) const;
|
|
||||||
|
/// Expand templates, imperative !
|
||||||
|
virtual void ExpandTemplate(const TemplateSubstitution& ts) {
|
||||||
|
argLists_ = expandArgumentListsTemplate(ts);
|
||||||
|
}
|
||||||
|
|
||||||
|
void verifyArguments(const std::vector<std::string>& validArgs,
|
||||||
|
const std::string s) const {
|
||||||
|
BOOST_FOREACH(const ArgumentList& argList, argLists_) {
|
||||||
|
BOOST_FOREACH(Argument arg, argList) {
|
||||||
|
std::string fullType = arg.type.qualifiedName("::");
|
||||||
|
if (find(validArgs.begin(), validArgs.end(), fullType)
|
||||||
|
== validArgs.end())
|
||||||
|
throw DependencyMissing(fullType, s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Signature Overload (including return value)
|
||||||
|
*/
|
||||||
|
class SignatureOverloads: public ArgumentOverloads {
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
std::vector<ReturnValue> returnVals_;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
const ReturnValue& returnValue(size_t i) const {
|
||||||
|
return returnVals_.at(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
void addOverload(const ArgumentList& args, const ReturnValue& retVal) {
|
||||||
|
argLists_.push_back(args);
|
||||||
|
returnVals_.push_back(retVal);
|
||||||
|
}
|
||||||
|
|
||||||
|
void verifyReturnTypes(const std::vector<std::string>& validtypes,
|
||||||
|
const std::string& s) const {
|
||||||
|
BOOST_FOREACH(const ReturnValue& retval, returnVals_) {
|
||||||
|
retval.type1.verify(validtypes, s);
|
||||||
|
if (retval.isPair)
|
||||||
|
retval.type2.verify(validtypes, s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO use transform ?
|
||||||
|
std::vector<ReturnValue> ExpandReturnValuesTemplate(
|
||||||
|
const TemplateSubstitution& ts) const {
|
||||||
|
std::vector<ReturnValue> result;
|
||||||
|
BOOST_FOREACH(const ReturnValue& retVal, returnVals_) {
|
||||||
|
ReturnValue instRetVal = retVal.expandTemplate(ts);
|
||||||
|
result.push_back(instRetVal);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Expand templates, imperative !
|
||||||
|
void expandTemplate(const TemplateSubstitution& ts) {
|
||||||
|
// substitute template in arguments
|
||||||
|
argLists_ = expandArgumentListsTemplate(ts);
|
||||||
|
// do the same for return types
|
||||||
|
returnVals_ = ExpandReturnValuesTemplate(ts);
|
||||||
|
}
|
||||||
|
|
||||||
|
// emit a list of comments, one for each overload
|
||||||
|
void usage_fragment(FileWriter& proxyFile, const std::string& name) const {
|
||||||
|
unsigned int argLCount = 0;
|
||||||
|
BOOST_FOREACH(ArgumentList argList, argLists_) {
|
||||||
|
argList.emit_prototype(proxyFile, name);
|
||||||
|
if (argLCount != nrOverloads() - 1)
|
||||||
|
proxyFile.oss << ", ";
|
||||||
|
else
|
||||||
|
proxyFile.oss << " : returns " << returnValue(0).return_type(false)
|
||||||
|
<< std::endl;
|
||||||
|
argLCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// emit a list of comments, one for each overload
|
||||||
|
void comment_fragment(FileWriter& proxyFile, const std::string& name) const {
|
||||||
|
size_t i = 0;
|
||||||
|
BOOST_FOREACH(ArgumentList argList, argLists_) {
|
||||||
|
proxyFile.oss << "%";
|
||||||
|
argList.emit_prototype(proxyFile, name);
|
||||||
|
proxyFile.oss << " : returns " << returnVals_[i++].return_type(false)
|
||||||
|
<< std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Templated checking functions
|
// Templated checking functions
|
||||||
// TODO: do this via polymorphism ?
|
// TODO: do this via polymorphism ?
|
||||||
|
|
||||||
template<class FUNCTION>
|
template<class F>
|
||||||
FUNCTION expandMethodTemplate(const FUNCTION& method,
|
F expandMethodTemplate(F& method, const TemplateSubstitution& ts) {
|
||||||
const std::string& templateArg, const Qualified& qualifiedType,
|
F instMethod = method;
|
||||||
const Qualified& expandedClass) {
|
method.expandTemplate(ts);
|
||||||
// Create new instance
|
|
||||||
FUNCTION instMethod = method;
|
|
||||||
// substitute template in arguments
|
|
||||||
instMethod.argLists = method.expandArgumentListsTemplate(templateArg,
|
|
||||||
qualifiedType, expandedClass);
|
|
||||||
// do the same for return types
|
|
||||||
instMethod.returnVals = ReturnValue::ExpandTemplate(method.returnVals,
|
|
||||||
templateArg, qualifiedType, expandedClass);
|
|
||||||
// return new method
|
|
||||||
return instMethod;
|
return instMethod;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO use transform
|
// TODO use transform
|
||||||
template<class FUNCTION>
|
template<class F>
|
||||||
static std::map<std::string, FUNCTION> expandMethodTemplate(
|
static std::map<std::string, F> expandMethodTemplate(
|
||||||
const std::map<std::string, FUNCTION>& methods,
|
const std::map<std::string, F>& methods, const TemplateSubstitution& ts) {
|
||||||
const std::string& templateArg, const Qualified& qualifiedType,
|
std::map<std::string, F> result;
|
||||||
const Qualified& expandedClass) {
|
typedef std::pair<const std::string, F> NamedMethod;
|
||||||
std::map<std::string, FUNCTION> result;
|
|
||||||
typedef std::pair<const std::string, FUNCTION> NamedMethod;
|
|
||||||
BOOST_FOREACH(NamedMethod namedMethod, methods) {
|
BOOST_FOREACH(NamedMethod namedMethod, methods) {
|
||||||
namedMethod.second = expandMethodTemplate(namedMethod.second, templateArg,
|
namedMethod.second = expandMethodTemplate(namedMethod.second, ts);
|
||||||
qualifiedType, expandedClass);
|
|
||||||
result.insert(namedMethod);
|
result.insert(namedMethod);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
template<class T>
|
template<class F>
|
||||||
inline void verifyReturnTypes(const std::vector<std::string>& validtypes,
|
inline void verifyReturnTypes(const std::vector<std::string>& validTypes,
|
||||||
const std::map<std::string, T>& vt) {
|
const std::map<std::string, F>& vt) {
|
||||||
typedef typename std::map<std::string, T>::value_type NamedMethod;
|
typedef typename std::map<std::string, F>::value_type NamedMethod;
|
||||||
BOOST_FOREACH(const NamedMethod& namedMethod, vt) {
|
BOOST_FOREACH(const NamedMethod& namedMethod, vt) {
|
||||||
const T& t = namedMethod.second;
|
const F& t = namedMethod.second;
|
||||||
BOOST_FOREACH(const ReturnValue& retval, t.returnVals) {
|
t.verifyReturnTypes(validTypes, t.name_);
|
||||||
retval.type1.verify(validtypes, t.name_);
|
|
||||||
if (retval.isPair)
|
|
||||||
retval.type2.verify(validtypes, t.name_);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,8 @@ using namespace std;
|
||||||
void GlobalFunction::addOverload(bool verbose, const Qualified& overload,
|
void GlobalFunction::addOverload(bool verbose, const Qualified& overload,
|
||||||
const ArgumentList& args, const ReturnValue& retVal,
|
const ArgumentList& args, const ReturnValue& retVal,
|
||||||
const Qualified& instName) {
|
const Qualified& instName) {
|
||||||
Function::addOverload(verbose, overload.name, args, retVal, instName);
|
Function::addOverload(verbose, overload.name, instName);
|
||||||
|
SignatureOverloads::addOverload(args, retVal);
|
||||||
overloads.push_back(overload);
|
overloads.push_back(overload);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,15 +38,10 @@ void GlobalFunction::matlab_proxy(const std::string& toolboxPath,
|
||||||
Qualified overload = overloads.at(i);
|
Qualified overload = overloads.at(i);
|
||||||
// use concatenated namespaces as key
|
// use concatenated namespaces as key
|
||||||
string str_ns = qualifiedName("", overload.namespaces);
|
string str_ns = qualifiedName("", overload.namespaces);
|
||||||
ReturnValue ret = returnVals.at(i);
|
const ReturnValue& ret = returnValue(i);
|
||||||
ArgumentList args = argLists.at(i);
|
const ArgumentList& args = argumentList(i);
|
||||||
|
grouped_functions[str_ns].addOverload(verbose_, overload, args, ret,
|
||||||
if (!grouped_functions.count(str_ns))
|
templateArgValue_);
|
||||||
grouped_functions[str_ns] = GlobalFunction(name_, verbose_);
|
|
||||||
|
|
||||||
grouped_functions[str_ns].argLists.push_back(args);
|
|
||||||
grouped_functions[str_ns].returnVals.push_back(ret);
|
|
||||||
grouped_functions[str_ns].overloads.push_back(overload);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t lastcheck = grouped_functions.size();
|
size_t lastcheck = grouped_functions.size();
|
||||||
|
@ -77,16 +73,15 @@ void GlobalFunction::generateSingleFunction(const std::string& toolboxPath,
|
||||||
|
|
||||||
mfunctionFile.oss << "function varargout = " << name_ << "(varargin)\n";
|
mfunctionFile.oss << "function varargout = " << name_ << "(varargin)\n";
|
||||||
|
|
||||||
for (size_t overload = 0; overload < argLists.size(); ++overload) {
|
for (size_t i = 0; i < nrOverloads(); ++i) {
|
||||||
const ArgumentList& args = argLists[overload];
|
const ArgumentList& args = argumentList(i);
|
||||||
const ReturnValue& returnVal = returnVals[overload];
|
const ReturnValue& returnVal = returnValue(i);
|
||||||
|
|
||||||
const int id = functionNames.size();
|
const int id = functionNames.size();
|
||||||
|
|
||||||
// Output proxy matlab code
|
// Output proxy matlab code
|
||||||
mfunctionFile.oss << " " << (overload == 0 ? "" : "else");
|
mfunctionFile.oss << " " << (i == 0 ? "" : "else");
|
||||||
argLists[overload].emit_conditional_call(mfunctionFile,
|
args.emit_conditional_call(mfunctionFile, returnVal, wrapperName, id, true); // true omits "this"
|
||||||
returnVals[overload], wrapperName, id, true); // true omits "this"
|
|
||||||
|
|
||||||
// Output C++ wrapper code
|
// Output C++ wrapper code
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
|
|
||||||
namespace wrap {
|
namespace wrap {
|
||||||
|
|
||||||
struct GlobalFunction: public Function {
|
struct GlobalFunction: public Function, public SignatureOverloads {
|
||||||
|
|
||||||
std::vector<Qualified> overloads; ///< Stack of qualified names
|
std::vector<Qualified> overloads; ///< Stack of qualified names
|
||||||
|
|
||||||
|
|
126
wrap/Method.cpp
126
wrap/Method.cpp
|
@ -29,123 +29,24 @@ using namespace std;
|
||||||
using namespace wrap;
|
using namespace wrap;
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
void Method::addOverload(bool verbose, bool is_const, const std::string& name_,
|
void Method::addOverload(bool verbose, bool is_const, const std::string& name,
|
||||||
const ArgumentList& args, const ReturnValue& retVal,
|
const ArgumentList& args, const ReturnValue& retVal,
|
||||||
const Qualified& instName) {
|
const Qualified& instName) {
|
||||||
|
|
||||||
Function::addOverload(verbose, name_, args, retVal);
|
StaticMethod::addOverload(verbose, name, args, retVal, instName);
|
||||||
is_const_ = is_const;
|
is_const_ = is_const;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
void Method::proxy_wrapper_fragments(FileWriter& proxyFile,
|
void Method::proxy_header(FileWriter& proxyFile) const {
|
||||||
FileWriter& wrapperFile, const string& cppClassName,
|
|
||||||
const std::string& matlabQualName, const std::string& matlabUniqueName,
|
|
||||||
const string& wrapperName, const TypeAttributesTable& typeAttributes,
|
|
||||||
vector<string>& functionNames) const {
|
|
||||||
|
|
||||||
// Create function header
|
|
||||||
proxyFile.oss << " function varargout = " << name_ << "(this, varargin)\n";
|
proxyFile.oss << " function varargout = " << name_ << "(this, varargin)\n";
|
||||||
|
|
||||||
// Emit comments for documentation
|
|
||||||
string up_name = boost::to_upper_copy(name_);
|
|
||||||
proxyFile.oss << " % " << up_name << " usage: ";
|
|
||||||
unsigned int argLCount = 0;
|
|
||||||
BOOST_FOREACH(ArgumentList argList, argLists) {
|
|
||||||
argList.emit_prototype(proxyFile, name_);
|
|
||||||
if (argLCount != argLists.size() - 1)
|
|
||||||
proxyFile.oss << ", ";
|
|
||||||
else
|
|
||||||
proxyFile.oss << " : returns " << returnVals[0].return_type(false)
|
|
||||||
<< endl;
|
|
||||||
argLCount++;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Emit URL to Doxygen page
|
|
||||||
proxyFile.oss << " % "
|
|
||||||
<< "Doxygen can be found at http://research.cc.gatech.edu/borg/sites/edu.borg/html/index.html"
|
|
||||||
<< endl;
|
|
||||||
|
|
||||||
// Document all overloads, if any
|
|
||||||
if (argLists.size() > 1) {
|
|
||||||
proxyFile.oss << " % " << "" << endl;
|
|
||||||
proxyFile.oss << " % " << "Method Overloads" << endl;
|
|
||||||
BOOST_FOREACH(ArgumentList argList, argLists) {
|
|
||||||
proxyFile.oss << " % ";
|
|
||||||
argList.emit_prototype(proxyFile, name_);
|
|
||||||
proxyFile.oss << endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle special case of single overload with all numeric arguments
|
|
||||||
if (argLists.size() == 1 && argLists[0].allScalar()) {
|
|
||||||
// Output proxy matlab code
|
|
||||||
proxyFile.oss << " ";
|
|
||||||
const int id = (int) functionNames.size();
|
|
||||||
argLists[0].emit_call(proxyFile, returnVals[0], wrapperName, id);
|
|
||||||
|
|
||||||
// Output C++ wrapper code
|
|
||||||
const string wrapFunctionName = wrapper_fragment(wrapperFile, cppClassName,
|
|
||||||
matlabUniqueName, 0, id, typeAttributes, templateArgValue_);
|
|
||||||
|
|
||||||
// Add to function list
|
|
||||||
functionNames.push_back(wrapFunctionName);
|
|
||||||
} else {
|
|
||||||
// Check arguments for all overloads
|
|
||||||
for (size_t overload = 0; overload < argLists.size(); ++overload) {
|
|
||||||
|
|
||||||
// Output proxy matlab code
|
|
||||||
proxyFile.oss << " " << (overload == 0 ? "" : "else");
|
|
||||||
const int id = (int) functionNames.size();
|
|
||||||
string expanded = wrapperName;
|
|
||||||
if (!templateArgValue_.empty())
|
|
||||||
expanded += templateArgValue_.name;
|
|
||||||
argLists[overload].emit_conditional_call(proxyFile, returnVals[overload],
|
|
||||||
expanded, id);
|
|
||||||
|
|
||||||
// Output C++ wrapper code
|
|
||||||
const string wrapFunctionName = wrapper_fragment(wrapperFile,
|
|
||||||
cppClassName, matlabUniqueName, overload, id, typeAttributes,
|
|
||||||
templateArgValue_);
|
|
||||||
|
|
||||||
// Add to function list
|
|
||||||
functionNames.push_back(wrapFunctionName);
|
|
||||||
}
|
|
||||||
proxyFile.oss << " else\n";
|
|
||||||
proxyFile.oss
|
|
||||||
<< " error('Arguments do not match any overload of function "
|
|
||||||
<< matlabQualName << "." << name_ << "');" << endl;
|
|
||||||
proxyFile.oss << " end\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
proxyFile.oss << " end\n";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
string Method::wrapper_fragment(FileWriter& wrapperFile,
|
string Method::wrapper_call(FileWriter& wrapperFile, const string& cppClassName,
|
||||||
const string& cppClassName, const string& matlabUniqueName, int overload,
|
const string& matlabUniqueName, const ArgumentList& args,
|
||||||
int id, const TypeAttributesTable& typeAttributes,
|
const ReturnValue& returnVal, const TypeAttributesTable& typeAttributes,
|
||||||
const Qualified& instName) const {
|
const Qualified& instName) const {
|
||||||
|
|
||||||
// generate code
|
|
||||||
|
|
||||||
const string wrapFunctionName = matlabUniqueName + "_" + name_ + "_"
|
|
||||||
+ boost::lexical_cast<string>(id);
|
|
||||||
|
|
||||||
const ArgumentList& args = argLists[overload];
|
|
||||||
const ReturnValue& returnVal = returnVals[overload];
|
|
||||||
|
|
||||||
// call
|
|
||||||
wrapperFile.oss << "void " << wrapFunctionName
|
|
||||||
<< "(int nargout, mxArray *out[], int nargin, const mxArray *in[])\n";
|
|
||||||
// start
|
|
||||||
wrapperFile.oss << "{\n";
|
|
||||||
|
|
||||||
returnVal.wrapTypeUnwrap(wrapperFile);
|
|
||||||
|
|
||||||
wrapperFile.oss << " typedef boost::shared_ptr<" << cppClassName
|
|
||||||
<< "> Shared;" << endl;
|
|
||||||
|
|
||||||
// check arguments
|
// check arguments
|
||||||
// extra argument obj -> nargin-1 is passed !
|
// extra argument obj -> nargin-1 is passed !
|
||||||
// example: checkArguments("equals",nargout,nargin-1,2);
|
// example: checkArguments("equals",nargout,nargin-1,2);
|
||||||
|
@ -156,24 +57,17 @@ string Method::wrapper_fragment(FileWriter& wrapperFile,
|
||||||
// example: shared_ptr<Test> = unwrap_shared_ptr< Test >(in[0], "Test");
|
// example: shared_ptr<Test> = unwrap_shared_ptr< Test >(in[0], "Test");
|
||||||
wrapperFile.oss << " Shared obj = unwrap_shared_ptr<" << cppClassName
|
wrapperFile.oss << " Shared obj = unwrap_shared_ptr<" << cppClassName
|
||||||
<< ">(in[0], \"ptr_" << matlabUniqueName << "\");" << endl;
|
<< ">(in[0], \"ptr_" << matlabUniqueName << "\");" << endl;
|
||||||
// unwrap arguments, see Argument.cpp
|
|
||||||
|
// unwrap arguments, see Argument.cpp, we start at 1 as first is obj
|
||||||
args.matlab_unwrap(wrapperFile, 1);
|
args.matlab_unwrap(wrapperFile, 1);
|
||||||
|
|
||||||
// call method and wrap result
|
// call method and wrap result
|
||||||
// example: out[0]=wrap<bool>(self->return_field(t));
|
// example: out[0]=wrap<bool>(obj->return_field(t));
|
||||||
string expanded = "obj->" + name_;
|
string expanded = "obj->" + name_;
|
||||||
if (!instName.empty())
|
if (!instName.empty())
|
||||||
expanded += ("<" + instName.qualifiedName("::") + ">");
|
expanded += ("<" + instName.qualifiedName("::") + ">");
|
||||||
expanded += ("(" + args.names() + ")");
|
|
||||||
if (returnVal.type1.name != "void")
|
|
||||||
returnVal.wrap_result(expanded, wrapperFile, typeAttributes);
|
|
||||||
else
|
|
||||||
wrapperFile.oss << " " + expanded + ";\n";
|
|
||||||
|
|
||||||
// finish
|
return expanded;
|
||||||
wrapperFile.oss << "}\n";
|
|
||||||
|
|
||||||
return wrapFunctionName;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
|
|
|
@ -18,16 +18,16 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Function.h"
|
#include "StaticMethod.h"
|
||||||
|
|
||||||
namespace wrap {
|
namespace wrap {
|
||||||
|
|
||||||
/// Method class
|
/// Method class
|
||||||
struct Method : public Function {
|
struct Method: public StaticMethod {
|
||||||
|
|
||||||
/// Constructor creates empty object
|
/// Constructor creates empty object
|
||||||
Method(bool verbose = true) :
|
Method(bool verbose = true) :
|
||||||
Function(verbose), is_const_(false) {
|
StaticMethod(verbose), is_const_(false) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_const_;
|
bool is_const_;
|
||||||
|
@ -39,21 +39,16 @@ struct Method : public Function {
|
||||||
const ArgumentList& args, const ReturnValue& retVal,
|
const ArgumentList& args, const ReturnValue& retVal,
|
||||||
const Qualified& instName = Qualified());
|
const Qualified& instName = Qualified());
|
||||||
|
|
||||||
// MATLAB code generation
|
|
||||||
// classPath is class directory, e.g., ../matlab/@Point2
|
|
||||||
void proxy_wrapper_fragments(FileWriter& proxyFile, FileWriter& wrapperFile,
|
|
||||||
const std::string& cppClassName, const std::string& matlabQualName,
|
|
||||||
const std::string& matlabUniqueName, const std::string& wrapperName,
|
|
||||||
const TypeAttributesTable& typeAttributes,
|
|
||||||
std::vector<std::string>& functionNames) const;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
/// Emit C++ code
|
// Emit method header
|
||||||
std::string wrapper_fragment(FileWriter& wrapperFile,
|
void proxy_header(FileWriter& proxyFile) const;
|
||||||
|
|
||||||
|
std::string wrapper_call(FileWriter& wrapperFile,
|
||||||
const std::string& cppClassName, const std::string& matlabUniqueName,
|
const std::string& cppClassName, const std::string& matlabUniqueName,
|
||||||
int overload, int id, const TypeAttributesTable& typeAttributes,
|
const ArgumentList& args, const ReturnValue& returnVal,
|
||||||
const Qualified& instName) const; ///< cpp wrapper
|
const TypeAttributesTable& typeAttributes,
|
||||||
|
const Qualified& instName) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // \namespace wrap
|
} // \namespace wrap
|
||||||
|
|
|
@ -59,18 +59,17 @@ void ReturnType::wrapTypeUnwrap(FileWriter& wrapperFile) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
ReturnValue ReturnValue::expandTemplate(const string& templateArg,
|
ReturnValue ReturnValue::expandTemplate(const TemplateSubstitution& ts) const {
|
||||||
const Qualified& qualifiedType, const Qualified& expandedClass) const {
|
|
||||||
ReturnValue instRetVal = *this;
|
ReturnValue instRetVal = *this;
|
||||||
if (type1.name == templateArg) {
|
if (type1.name == ts.templateArg) {
|
||||||
instRetVal.type1.rename(qualifiedType);
|
instRetVal.type1.rename(ts.qualifiedType);
|
||||||
} else if (type1.name == "This") {
|
} else if (type1.name == "This") {
|
||||||
instRetVal.type1.rename(expandedClass);
|
instRetVal.type1.rename(ts.expandedClass);
|
||||||
}
|
}
|
||||||
if (type2.name == templateArg) {
|
if (type2.name == ts.templateArg) {
|
||||||
instRetVal.type2.rename(qualifiedType);
|
instRetVal.type2.rename(ts.qualifiedType);
|
||||||
} else if (type2.name == "This") {
|
} else if (type2.name == "This") {
|
||||||
instRetVal.type2.rename(expandedClass);
|
instRetVal.type2.rename(ts.expandedClass);
|
||||||
}
|
}
|
||||||
return instRetVal;
|
return instRetVal;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
* @author Richard Roberts
|
* @author Richard Roberts
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "Qualified.h"
|
#include "TemplateSubstitution.h"
|
||||||
#include "FileWriter.h"
|
#include "FileWriter.h"
|
||||||
#include "TypeAttributesTable.h"
|
#include "TypeAttributesTable.h"
|
||||||
#include "utilities.h"
|
#include "utilities.h"
|
||||||
|
@ -86,21 +86,7 @@ struct ReturnValue {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Substitute template argument
|
/// Substitute template argument
|
||||||
ReturnValue expandTemplate(const std::string& templateArg,
|
ReturnValue expandTemplate(const TemplateSubstitution& ts) const;
|
||||||
const Qualified& qualifiedType, const Qualified& expandedClass) const;
|
|
||||||
|
|
||||||
// TODO use transform ?
|
|
||||||
static std::vector<ReturnValue> ExpandTemplate(
|
|
||||||
std::vector<ReturnValue> returnVals, const std::string& templateArg,
|
|
||||||
const Qualified& qualifiedType, const Qualified& expandedClass) {
|
|
||||||
std::vector<ReturnValue> result;
|
|
||||||
BOOST_FOREACH(const ReturnValue& retVal, returnVals) {
|
|
||||||
ReturnValue instRetVal = retVal.expandTemplate(templateArg,
|
|
||||||
qualifiedType, expandedClass);
|
|
||||||
result.push_back(instRetVal);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string return_type(bool add_ptr) const;
|
std::string return_type(bool add_ptr) const;
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
* @author Richard Roberts
|
* @author Richard Roberts
|
||||||
**/
|
**/
|
||||||
|
|
||||||
#include "StaticMethod.h"
|
#include "Method.h"
|
||||||
#include "utilities.h"
|
#include "utilities.h"
|
||||||
|
|
||||||
#include <boost/foreach.hpp>
|
#include <boost/foreach.hpp>
|
||||||
|
@ -30,108 +30,148 @@ using namespace std;
|
||||||
using namespace wrap;
|
using namespace wrap;
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
void StaticMethod::proxy_wrapper_fragments(FileWriter& file,
|
void StaticMethod::addOverload(bool verbose, const std::string& name,
|
||||||
|
const ArgumentList& args, const ReturnValue& retVal,
|
||||||
|
const Qualified& instName) {
|
||||||
|
|
||||||
|
Function::addOverload(verbose, name, instName);
|
||||||
|
SignatureOverloads::addOverload(args, retVal);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ************************************************************************* */
|
||||||
|
void StaticMethod::proxy_header(FileWriter& proxyFile) const {
|
||||||
|
string upperName = name_;
|
||||||
|
upperName[0] = std::toupper(upperName[0], std::locale());
|
||||||
|
proxyFile.oss << " function varargout = " << upperName << "(varargin)\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ************************************************************************* */
|
||||||
|
void StaticMethod::proxy_wrapper_fragments(FileWriter& proxyFile,
|
||||||
FileWriter& wrapperFile, const string& cppClassName,
|
FileWriter& wrapperFile, const string& cppClassName,
|
||||||
const std::string& matlabQualName, const std::string& matlabUniqueName,
|
const std::string& matlabQualName, const std::string& matlabUniqueName,
|
||||||
const string& wrapperName, const TypeAttributesTable& typeAttributes,
|
const string& wrapperName, const TypeAttributesTable& typeAttributes,
|
||||||
vector<string>& functionNames) const {
|
vector<string>& functionNames) const {
|
||||||
|
|
||||||
string upperName = name_;
|
proxy_header(proxyFile);
|
||||||
upperName[0] = std::toupper(upperName[0], std::locale());
|
|
||||||
|
|
||||||
file.oss << " function varargout = " << upperName << "(varargin)\n";
|
// Emit comments for documentation
|
||||||
//Comments for documentation
|
|
||||||
string up_name = boost::to_upper_copy(name_);
|
string up_name = boost::to_upper_copy(name_);
|
||||||
file.oss << " % " << up_name << " usage: ";
|
proxyFile.oss << " % " << up_name << " usage: ";
|
||||||
unsigned int argLCount = 0;
|
usage_fragment(proxyFile, name_);
|
||||||
BOOST_FOREACH(ArgumentList argList, argLists) {
|
|
||||||
argList.emit_prototype(file, name_);
|
|
||||||
if (argLCount != argLists.size() - 1)
|
|
||||||
file.oss << ", ";
|
|
||||||
else
|
|
||||||
file.oss << " : returns "
|
|
||||||
<< returnVals[0].return_type(false) << endl;
|
|
||||||
argLCount++;
|
|
||||||
}
|
|
||||||
|
|
||||||
file.oss << " % "
|
// Emit URL to Doxygen page
|
||||||
|
proxyFile.oss << " % "
|
||||||
<< "Doxygen can be found at http://research.cc.gatech.edu/borg/sites/edu.borg/html/index.html"
|
<< "Doxygen can be found at http://research.cc.gatech.edu/borg/sites/edu.borg/html/index.html"
|
||||||
<< endl;
|
<< endl;
|
||||||
file.oss << " % " << "" << endl;
|
|
||||||
file.oss << " % " << "Usage" << endl;
|
|
||||||
BOOST_FOREACH(ArgumentList argList, argLists) {
|
|
||||||
file.oss << " % ";
|
|
||||||
argList.emit_prototype(file, up_name);
|
|
||||||
file.oss << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check arguments for all overloads
|
|
||||||
for (size_t overload = 0; overload < argLists.size(); ++overload) {
|
|
||||||
|
|
||||||
|
// Handle special case of single overload with all numeric arguments
|
||||||
|
if (nrOverloads() == 1 && argumentList(0).allScalar()) {
|
||||||
// Output proxy matlab code
|
// Output proxy matlab code
|
||||||
file.oss << " " << (overload == 0 ? "" : "else");
|
proxyFile.oss << " ";
|
||||||
const int id = (int) functionNames.size();
|
const int id = (int) functionNames.size();
|
||||||
argLists[overload].emit_conditional_call(file, returnVals[overload],
|
argumentList(0).emit_call(proxyFile, returnValue(0), wrapperName, id);
|
||||||
wrapperName, id, true); // last bool is to indicate static !
|
|
||||||
|
|
||||||
// Output C++ wrapper code
|
// Output C++ wrapper code
|
||||||
const string wrapFunctionName = wrapper_fragment(wrapperFile, cppClassName,
|
const string wrapFunctionName = wrapper_fragment(wrapperFile, cppClassName,
|
||||||
matlabUniqueName, (int) overload, id, typeAttributes);
|
matlabUniqueName, 0, id, typeAttributes, templateArgValue_);
|
||||||
|
|
||||||
// Add to function list
|
// Add to function list
|
||||||
functionNames.push_back(wrapFunctionName);
|
functionNames.push_back(wrapFunctionName);
|
||||||
}
|
} else {
|
||||||
file.oss << " else\n";
|
// Check arguments for all overloads
|
||||||
file.oss << " error('Arguments do not match any overload of function "
|
for (size_t i = 0; i < nrOverloads(); ++i) {
|
||||||
<< matlabQualName << "." << upperName << "');" << endl;
|
|
||||||
file.oss << " end\n";
|
|
||||||
|
|
||||||
file.oss << " end\n";
|
// Output proxy matlab code
|
||||||
|
proxyFile.oss << " " << (i == 0 ? "" : "else");
|
||||||
|
const int id = (int) functionNames.size();
|
||||||
|
string expanded = wrapperName;
|
||||||
|
if (!templateArgValue_.empty())
|
||||||
|
expanded += templateArgValue_.name;
|
||||||
|
argumentList(i).emit_conditional_call(proxyFile, returnValue(i), expanded,
|
||||||
|
id);
|
||||||
|
|
||||||
|
// Output C++ wrapper code
|
||||||
|
const string wrapFunctionName = wrapper_fragment(wrapperFile,
|
||||||
|
cppClassName, matlabUniqueName, i, id, typeAttributes,
|
||||||
|
templateArgValue_);
|
||||||
|
|
||||||
|
// Add to function list
|
||||||
|
functionNames.push_back(wrapFunctionName);
|
||||||
|
}
|
||||||
|
proxyFile.oss << " else\n";
|
||||||
|
proxyFile.oss
|
||||||
|
<< " error('Arguments do not match any overload of function "
|
||||||
|
<< matlabQualName << "." << name_ << "');" << endl;
|
||||||
|
proxyFile.oss << " end\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
proxyFile.oss << " end\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
string StaticMethod::wrapper_fragment(FileWriter& file,
|
string StaticMethod::wrapper_fragment(FileWriter& wrapperFile,
|
||||||
const string& cppClassName, const string& matlabUniqueName, int overload,
|
const string& cppClassName, const string& matlabUniqueName, int overload,
|
||||||
int id, const TypeAttributesTable& typeAttributes) const {
|
int id, const TypeAttributesTable& typeAttributes,
|
||||||
|
const Qualified& instName) const {
|
||||||
|
|
||||||
// generate code
|
// generate code
|
||||||
|
|
||||||
const string wrapFunctionName = matlabUniqueName + "_" + name_ + "_"
|
const string wrapFunctionName = matlabUniqueName + "_" + name_ + "_"
|
||||||
+ boost::lexical_cast<string>(id);
|
+ boost::lexical_cast<string>(id);
|
||||||
|
|
||||||
const ArgumentList& args = argLists[overload];
|
const ArgumentList& args = argumentList(overload);
|
||||||
const ReturnValue& returnVal = returnVals[overload];
|
const ReturnValue& returnVal = returnValue(overload);
|
||||||
|
|
||||||
// call
|
// call
|
||||||
file.oss << "void " << wrapFunctionName
|
wrapperFile.oss << "void " << wrapFunctionName
|
||||||
<< "(int nargout, mxArray *out[], int nargin, const mxArray *in[])\n";
|
<< "(int nargout, mxArray *out[], int nargin, const mxArray *in[])\n";
|
||||||
// start
|
// start
|
||||||
file.oss << "{\n";
|
wrapperFile.oss << "{\n";
|
||||||
|
|
||||||
returnVal.wrapTypeUnwrap(file);
|
returnVal.wrapTypeUnwrap(wrapperFile);
|
||||||
|
|
||||||
file.oss << " typedef boost::shared_ptr<" << cppClassName << "> Shared;"
|
wrapperFile.oss << " typedef boost::shared_ptr<" << cppClassName
|
||||||
<< endl;
|
<< "> Shared;" << endl;
|
||||||
|
|
||||||
// check arguments
|
// get call
|
||||||
// NOTE: for static functions, there is no object passed
|
// for static methods: cppClassName::staticMethod<TemplateVal>
|
||||||
file.oss << " checkArguments(\"" << matlabUniqueName << "." << name_
|
// for instance methods: obj->instanceMethod<TemplateVal>
|
||||||
<< "\",nargout,nargin," << args.size() << ");\n";
|
string expanded = wrapper_call(wrapperFile, cppClassName, matlabUniqueName,
|
||||||
|
args, returnVal, typeAttributes, instName);
|
||||||
|
|
||||||
// unwrap arguments, see Argument.cpp
|
expanded += ("(" + args.names() + ")");
|
||||||
args.matlab_unwrap(file, 0); // We start at 0 because there is no self object
|
|
||||||
|
|
||||||
// call method with default type and wrap result
|
|
||||||
if (returnVal.type1.name != "void")
|
if (returnVal.type1.name != "void")
|
||||||
returnVal.wrap_result(cppClassName + "::" + name_ + "(" + args.names() + ")",
|
returnVal.wrap_result(expanded, wrapperFile, typeAttributes);
|
||||||
file, typeAttributes);
|
|
||||||
else
|
else
|
||||||
file.oss << cppClassName + "::" + name_ + "(" + args.names() + ");\n";
|
wrapperFile.oss << " " + expanded + ";\n";
|
||||||
|
|
||||||
// finish
|
// finish
|
||||||
file.oss << "}\n";
|
wrapperFile.oss << "}\n";
|
||||||
|
|
||||||
return wrapFunctionName;
|
return wrapFunctionName;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
|
string StaticMethod::wrapper_call(FileWriter& wrapperFile,
|
||||||
|
const string& cppClassName, const string& matlabUniqueName,
|
||||||
|
const ArgumentList& args, const ReturnValue& returnVal,
|
||||||
|
const TypeAttributesTable& typeAttributes,
|
||||||
|
const Qualified& instName) const {
|
||||||
|
// check arguments
|
||||||
|
// NOTE: for static functions, there is no object passed
|
||||||
|
wrapperFile.oss << " checkArguments(\"" << matlabUniqueName << "." << name_
|
||||||
|
<< "\",nargout,nargin," << args.size() << ");\n";
|
||||||
|
|
||||||
|
// unwrap arguments, see Argument.cpp
|
||||||
|
args.matlab_unwrap(wrapperFile, 0); // We start at 0 because there is no self object
|
||||||
|
|
||||||
|
// call method and wrap result
|
||||||
|
// example: out[0]=wrap<bool>(staticMethod(t));
|
||||||
|
string expanded = cppClassName + "::" + name_;
|
||||||
|
if (!instName.empty())
|
||||||
|
expanded += ("<" + instName.qualifiedName("::") + ">");
|
||||||
|
|
||||||
|
return expanded;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ************************************************************************* */
|
||||||
|
|
|
@ -24,13 +24,17 @@
|
||||||
namespace wrap {
|
namespace wrap {
|
||||||
|
|
||||||
/// StaticMethod class
|
/// StaticMethod class
|
||||||
struct StaticMethod: public Function {
|
struct StaticMethod: public Function, public SignatureOverloads {
|
||||||
|
|
||||||
/// Constructor creates empty object
|
/// Constructor creates empty object
|
||||||
StaticMethod(bool verbosity = true) :
|
StaticMethod(bool verbosity = true) :
|
||||||
Function(verbosity) {
|
Function(verbosity) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void addOverload(bool verbose, const std::string& name,
|
||||||
|
const ArgumentList& args, const ReturnValue& retVal,
|
||||||
|
const Qualified& instName);
|
||||||
|
|
||||||
// MATLAB code generation
|
// MATLAB code generation
|
||||||
// classPath is class directory, e.g., ../matlab/@Point2
|
// classPath is class directory, e.g., ../matlab/@Point2
|
||||||
void proxy_wrapper_fragments(FileWriter& proxyFile, FileWriter& wrapperFile,
|
void proxy_wrapper_fragments(FileWriter& proxyFile, FileWriter& wrapperFile,
|
||||||
|
@ -39,10 +43,20 @@ struct StaticMethod: public Function {
|
||||||
const TypeAttributesTable& typeAttributes,
|
const TypeAttributesTable& typeAttributes,
|
||||||
std::vector<std::string>& functionNames) const;
|
std::vector<std::string>& functionNames) const;
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
std::string wrapper_fragment(FileWriter& file,
|
|
||||||
|
virtual void proxy_header(FileWriter& proxyFile) const;
|
||||||
|
|
||||||
|
std::string wrapper_fragment(FileWriter& wrapperFile,
|
||||||
const std::string& cppClassName, const std::string& matlabUniqueName,
|
const std::string& cppClassName, const std::string& matlabUniqueName,
|
||||||
int overload, int id, const TypeAttributesTable& typeAttributes) const; ///< cpp wrapper
|
int overload, int id, const TypeAttributesTable& typeAttributes,
|
||||||
|
const Qualified& instName = Qualified()) const; ///< cpp wrapper
|
||||||
|
|
||||||
|
virtual std::string wrapper_call(FileWriter& wrapperFile,
|
||||||
|
const std::string& cppClassName, const std::string& matlabUniqueName,
|
||||||
|
const ArgumentList& args, const ReturnValue& returnVal,
|
||||||
|
const TypeAttributesTable& typeAttributes,
|
||||||
|
const Qualified& instName) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // \namespace wrap
|
} // \namespace wrap
|
||||||
|
|
|
@ -46,8 +46,10 @@ Class TemplateInstantiationTypedef::findAndExpand(
|
||||||
|
|
||||||
// Instantiate it
|
// Instantiate it
|
||||||
Class classInst = *matchedClass;
|
Class classInst = *matchedClass;
|
||||||
for (size_t i = 0; i < typeList.size(); ++i)
|
for (size_t i = 0; i < typeList.size(); ++i) {
|
||||||
classInst = classInst.expandTemplate(classInst.templateArgs[i], typeList[i], *this);
|
TemplateSubstitution ts(classInst.templateArgs[i], typeList[i], *this);
|
||||||
|
classInst = classInst.expandTemplate(ts);
|
||||||
|
}
|
||||||
|
|
||||||
// Fix class properties
|
// Fix class properties
|
||||||
classInst.name = name;
|
classInst.name = name;
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
/* ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
* GTSAM Copyright 2010, Georgia Tech Research Corporation,
|
||||||
|
* Atlanta, Georgia 30332-0415
|
||||||
|
* All Rights Reserved
|
||||||
|
* Authors: Frank Dellaert, et al. (see THANKS for the full author list)
|
||||||
|
|
||||||
|
* See LICENSE for the license information
|
||||||
|
|
||||||
|
* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file TemplateSubstitution.h
|
||||||
|
* @brief Auxiliary class for template sunstitutions
|
||||||
|
* @author Frank Dellaert
|
||||||
|
* @date Nov 13, 2014
|
||||||
|
**/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Qualified.h"
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace wrap {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* e.g. TemplateSubstitution("T", gtsam::Point2, gtsam::PriorFactorPoint2)
|
||||||
|
*/
|
||||||
|
struct TemplateSubstitution {
|
||||||
|
TemplateSubstitution(const std::string& a, const Qualified& t,
|
||||||
|
const Qualified& e) :
|
||||||
|
templateArg(a), qualifiedType(t), expandedClass(e) {
|
||||||
|
}
|
||||||
|
std::string templateArg;
|
||||||
|
Qualified qualifiedType, expandedClass;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // \namespace wrap
|
||||||
|
|
|
@ -0,0 +1,90 @@
|
||||||
|
%class Point2, see Doxygen page for details
|
||||||
|
%at http://research.cc.gatech.edu/borg/sites/edu.borg/html/index.html
|
||||||
|
%
|
||||||
|
%-------Constructors-------
|
||||||
|
%Point2()
|
||||||
|
%Point2(double x, double y)
|
||||||
|
%
|
||||||
|
%-------Methods-------
|
||||||
|
%argChar(char a) : returns void
|
||||||
|
%argUChar(unsigned char a) : returns void
|
||||||
|
%dim() : returns int
|
||||||
|
%returnChar() : returns char
|
||||||
|
%vectorConfusion() : returns VectorNotEigen
|
||||||
|
%x() : returns double
|
||||||
|
%y() : returns double
|
||||||
|
%
|
||||||
|
classdef Point2 < handle
|
||||||
|
properties
|
||||||
|
ptr_gtsamPoint2 = 0
|
||||||
|
end
|
||||||
|
methods
|
||||||
|
function obj = Point2(varargin)
|
||||||
|
if nargin == 2 && isa(varargin{1}, 'uint64') && varargin{1} == uint64(5139824614673773682)
|
||||||
|
my_ptr = varargin{2};
|
||||||
|
geometry_wrapper(0, my_ptr);
|
||||||
|
elseif nargin == 0
|
||||||
|
my_ptr = geometry_wrapper(1);
|
||||||
|
elseif nargin == 2 && isa(varargin{1},'double') && isa(varargin{2},'double')
|
||||||
|
my_ptr = geometry_wrapper(2, varargin{1}, varargin{2});
|
||||||
|
else
|
||||||
|
error('Arguments do not match any overload of gtsam.Point2 constructor');
|
||||||
|
end
|
||||||
|
obj.ptr_gtsamPoint2 = my_ptr;
|
||||||
|
end
|
||||||
|
|
||||||
|
function delete(obj)
|
||||||
|
geometry_wrapper(3, obj.ptr_gtsamPoint2);
|
||||||
|
end
|
||||||
|
|
||||||
|
function display(obj), obj.print(''); end
|
||||||
|
%DISPLAY Calls print on the object
|
||||||
|
function disp(obj), obj.display; end
|
||||||
|
%DISP Calls print on the object
|
||||||
|
function varargout = argChar(this, varargin)
|
||||||
|
% ARGCHAR usage: argChar(char a) : returns void
|
||||||
|
% Doxygen can be found at http://research.cc.gatech.edu/borg/sites/edu.borg/html/index.html
|
||||||
|
geometry_wrapper(4, this, varargin{:});
|
||||||
|
end
|
||||||
|
|
||||||
|
function varargout = argUChar(this, varargin)
|
||||||
|
% ARGUCHAR usage: argUChar(unsigned char a) : returns void
|
||||||
|
% Doxygen can be found at http://research.cc.gatech.edu/borg/sites/edu.borg/html/index.html
|
||||||
|
geometry_wrapper(5, this, varargin{:});
|
||||||
|
end
|
||||||
|
|
||||||
|
function varargout = dim(this, varargin)
|
||||||
|
% DIM usage: dim() : returns int
|
||||||
|
% Doxygen can be found at http://research.cc.gatech.edu/borg/sites/edu.borg/html/index.html
|
||||||
|
varargout{1} = geometry_wrapper(6, this, varargin{:});
|
||||||
|
end
|
||||||
|
|
||||||
|
function varargout = returnChar(this, varargin)
|
||||||
|
% RETURNCHAR usage: returnChar() : returns char
|
||||||
|
% Doxygen can be found at http://research.cc.gatech.edu/borg/sites/edu.borg/html/index.html
|
||||||
|
varargout{1} = geometry_wrapper(7, this, varargin{:});
|
||||||
|
end
|
||||||
|
|
||||||
|
function varargout = vectorConfusion(this, varargin)
|
||||||
|
% VECTORCONFUSION usage: vectorConfusion() : returns VectorNotEigen
|
||||||
|
% Doxygen can be found at http://research.cc.gatech.edu/borg/sites/edu.borg/html/index.html
|
||||||
|
varargout{1} = geometry_wrapper(8, this, varargin{:});
|
||||||
|
end
|
||||||
|
|
||||||
|
function varargout = x(this, varargin)
|
||||||
|
% X usage: x() : returns double
|
||||||
|
% Doxygen can be found at http://research.cc.gatech.edu/borg/sites/edu.borg/html/index.html
|
||||||
|
varargout{1} = geometry_wrapper(9, this, varargin{:});
|
||||||
|
end
|
||||||
|
|
||||||
|
function varargout = y(this, varargin)
|
||||||
|
% Y usage: y() : returns double
|
||||||
|
% Doxygen can be found at http://research.cc.gatech.edu/borg/sites/edu.borg/html/index.html
|
||||||
|
varargout{1} = geometry_wrapper(10, this, varargin{:});
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
methods(Static = true)
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,75 @@
|
||||||
|
%class Point3, see Doxygen page for details
|
||||||
|
%at http://research.cc.gatech.edu/borg/sites/edu.borg/html/index.html
|
||||||
|
%
|
||||||
|
%-------Constructors-------
|
||||||
|
%Point3(double x, double y, double z)
|
||||||
|
%
|
||||||
|
%-------Methods-------
|
||||||
|
%norm() : returns double
|
||||||
|
%
|
||||||
|
%-------Static Methods-------
|
||||||
|
%StaticFunctionRet(double z) : returns gtsam::Point3
|
||||||
|
%staticFunction() : returns double
|
||||||
|
%
|
||||||
|
classdef Point3 < handle
|
||||||
|
properties
|
||||||
|
ptr_gtsamPoint3 = 0
|
||||||
|
end
|
||||||
|
methods
|
||||||
|
function obj = Point3(varargin)
|
||||||
|
if nargin == 2 && isa(varargin{1}, 'uint64') && varargin{1} == uint64(5139824614673773682)
|
||||||
|
my_ptr = varargin{2};
|
||||||
|
geometry_wrapper(11, my_ptr);
|
||||||
|
elseif nargin == 3 && isa(varargin{1},'double') && isa(varargin{2},'double') && isa(varargin{3},'double')
|
||||||
|
my_ptr = geometry_wrapper(12, varargin{1}, varargin{2}, varargin{3});
|
||||||
|
else
|
||||||
|
error('Arguments do not match any overload of gtsam.Point3 constructor');
|
||||||
|
end
|
||||||
|
obj.ptr_gtsamPoint3 = my_ptr;
|
||||||
|
end
|
||||||
|
|
||||||
|
function delete(obj)
|
||||||
|
geometry_wrapper(13, obj.ptr_gtsamPoint3);
|
||||||
|
end
|
||||||
|
|
||||||
|
function display(obj), obj.print(''); end
|
||||||
|
%DISPLAY Calls print on the object
|
||||||
|
function disp(obj), obj.display; end
|
||||||
|
%DISP Calls print on the object
|
||||||
|
function varargout = norm(this, varargin)
|
||||||
|
% NORM usage: norm() : returns double
|
||||||
|
% Doxygen can be found at http://research.cc.gatech.edu/borg/sites/edu.borg/html/index.html
|
||||||
|
varargout{1} = geometry_wrapper(14, this, varargin{:});
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
methods(Static = true)
|
||||||
|
function varargout = StaticFunctionRet(varargin)
|
||||||
|
% STATICFUNCTIONRET usage: StaticFunctionRet(double z) : returns gtsam::Point3
|
||||||
|
% Doxygen can be found at http://research.cc.gatech.edu/borg/sites/edu.borg/html/index.html
|
||||||
|
%
|
||||||
|
% Usage
|
||||||
|
% STATICFUNCTIONRET(double z)
|
||||||
|
if length(varargin) == 1 && isa(varargin{1},'double')
|
||||||
|
varargout{1} = geometry_wrapper(15, varargin{:});
|
||||||
|
else
|
||||||
|
error('Arguments do not match any overload of function gtsam.Point3.StaticFunctionRet');
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function varargout = StaticFunction(varargin)
|
||||||
|
% STATICFUNCTION usage: staticFunction() : returns double
|
||||||
|
% Doxygen can be found at http://research.cc.gatech.edu/borg/sites/edu.borg/html/index.html
|
||||||
|
%
|
||||||
|
% Usage
|
||||||
|
% STATICFUNCTION()
|
||||||
|
if length(varargin) == 0
|
||||||
|
varargout{1} = geometry_wrapper(16, varargin{:});
|
||||||
|
else
|
||||||
|
error('Arguments do not match any overload of function gtsam.Point3.StaticFunction');
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
|
@ -65,14 +65,7 @@ classdef ClassA < handle
|
||||||
function varargout = Afunction(varargin)
|
function varargout = Afunction(varargin)
|
||||||
% AFUNCTION usage: afunction() : returns double
|
% AFUNCTION usage: afunction() : returns double
|
||||||
% Doxygen can be found at http://research.cc.gatech.edu/borg/sites/edu.borg/html/index.html
|
% Doxygen can be found at http://research.cc.gatech.edu/borg/sites/edu.borg/html/index.html
|
||||||
%
|
varargout{1} = testNamespaces_wrapper(12, this, varargin{:});
|
||||||
% Usage
|
|
||||||
% AFUNCTION()
|
|
||||||
if length(varargin) == 0
|
|
||||||
varargout{1} = testNamespaces_wrapper(12, varargin{:});
|
|
||||||
else
|
|
||||||
error('Arguments do not match any overload of function ns2.ClassA.Afunction');
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -99,10 +99,9 @@ TEST( wrap, Small ) {
|
||||||
Method m1 = cls.method("x");
|
Method m1 = cls.method("x");
|
||||||
EXPECT(assert_equal("x", m1.name_));
|
EXPECT(assert_equal("x", m1.name_));
|
||||||
EXPECT(m1.is_const_);
|
EXPECT(m1.is_const_);
|
||||||
LONGS_EQUAL(1, m1.argLists.size());
|
LONGS_EQUAL(1, m1.nrOverloads());
|
||||||
LONGS_EQUAL(1, m1.returnVals.size());
|
|
||||||
|
|
||||||
ReturnValue rv1 = m1.returnVals.front();
|
ReturnValue rv1 = m1.returnValue(0);
|
||||||
EXPECT(!rv1.isPair);
|
EXPECT(!rv1.isPair);
|
||||||
EXPECT(!rv1.type1.isPtr);
|
EXPECT(!rv1.type1.isPtr);
|
||||||
EXPECT(assert_equal("double", rv1.type1.name));
|
EXPECT(assert_equal("double", rv1.type1.name));
|
||||||
|
@ -112,10 +111,9 @@ TEST( wrap, Small ) {
|
||||||
Method m2 = cls.method("returnMatrix");
|
Method m2 = cls.method("returnMatrix");
|
||||||
EXPECT(assert_equal("returnMatrix", m2.name_));
|
EXPECT(assert_equal("returnMatrix", m2.name_));
|
||||||
EXPECT(m2.is_const_);
|
EXPECT(m2.is_const_);
|
||||||
LONGS_EQUAL(1, m2.argLists.size());
|
LONGS_EQUAL(1, m2.nrOverloads());
|
||||||
LONGS_EQUAL(1, m2.returnVals.size());
|
|
||||||
|
|
||||||
ReturnValue rv2 = m2.returnVals.front();
|
ReturnValue rv2 = m2.returnValue(0);
|
||||||
EXPECT(!rv2.isPair);
|
EXPECT(!rv2.isPair);
|
||||||
EXPECT(!rv2.type1.isPtr);
|
EXPECT(!rv2.type1.isPtr);
|
||||||
EXPECT(assert_equal("Matrix", rv2.type1.name));
|
EXPECT(assert_equal("Matrix", rv2.type1.name));
|
||||||
|
@ -125,10 +123,9 @@ TEST( wrap, Small ) {
|
||||||
Method m3 = cls.method("returnPoint2");
|
Method m3 = cls.method("returnPoint2");
|
||||||
EXPECT(assert_equal("returnPoint2", m3.name_));
|
EXPECT(assert_equal("returnPoint2", m3.name_));
|
||||||
EXPECT(m3.is_const_);
|
EXPECT(m3.is_const_);
|
||||||
LONGS_EQUAL(1, m3.argLists.size());
|
LONGS_EQUAL(1, m3.nrOverloads());
|
||||||
LONGS_EQUAL(1, m3.returnVals.size());
|
|
||||||
|
|
||||||
ReturnValue rv3 = m3.returnVals.front();
|
ReturnValue rv3 = m3.returnValue(0);
|
||||||
EXPECT(!rv3.isPair);
|
EXPECT(!rv3.isPair);
|
||||||
EXPECT(!rv3.type1.isPtr);
|
EXPECT(!rv3.type1.isPtr);
|
||||||
EXPECT(assert_equal("Point2", rv3.type1.name));
|
EXPECT(assert_equal("Point2", rv3.type1.name));
|
||||||
|
@ -138,10 +135,9 @@ TEST( wrap, Small ) {
|
||||||
// static Vector returnVector();
|
// static Vector returnVector();
|
||||||
StaticMethod sm1 = cls.static_methods.at("returnVector");
|
StaticMethod sm1 = cls.static_methods.at("returnVector");
|
||||||
EXPECT(assert_equal("returnVector", sm1.name_));
|
EXPECT(assert_equal("returnVector", sm1.name_));
|
||||||
LONGS_EQUAL(1, sm1.argLists.size());
|
LONGS_EQUAL(1, sm1.nrOverloads());
|
||||||
LONGS_EQUAL(1, sm1.returnVals.size());
|
|
||||||
|
|
||||||
ReturnValue rv4 = sm1.returnVals.front();
|
ReturnValue rv4 = sm1.returnValue(0);
|
||||||
EXPECT(!rv4.isPair);
|
EXPECT(!rv4.isPair);
|
||||||
EXPECT(!rv4.type1.isPtr);
|
EXPECT(!rv4.type1.isPtr);
|
||||||
EXPECT(assert_equal("Vector", rv4.type1.name));
|
EXPECT(assert_equal("Vector", rv4.type1.name));
|
||||||
|
@ -195,13 +191,13 @@ TEST( wrap, Geometry ) {
|
||||||
// char returnChar() const;
|
// char returnChar() const;
|
||||||
CHECK(cls.exists("returnChar"));
|
CHECK(cls.exists("returnChar"));
|
||||||
Method m1 = cls.method("returnChar");
|
Method m1 = cls.method("returnChar");
|
||||||
LONGS_EQUAL(1, m1.returnVals.size());
|
LONGS_EQUAL(1, m1.nrOverloads());
|
||||||
EXPECT(assert_equal("char", m1.returnVals.front().type1.name));
|
EXPECT(assert_equal("char", m1.returnValue(0).type1.name));
|
||||||
EXPECT_LONGS_EQUAL(ReturnType::BASIS, m1.returnVals.front().type1.category);
|
EXPECT_LONGS_EQUAL(ReturnType::BASIS, m1.returnValue(0).type1.category);
|
||||||
EXPECT(!m1.returnVals.front().isPair);
|
EXPECT(!m1.returnValue(0).isPair);
|
||||||
EXPECT(assert_equal("returnChar", m1.name_));
|
EXPECT(assert_equal("returnChar", m1.name_));
|
||||||
LONGS_EQUAL(1, m1.argLists.size());
|
LONGS_EQUAL(1, m1.nrOverloads());
|
||||||
EXPECT_LONGS_EQUAL(0, m1.argLists.front().size());
|
EXPECT_LONGS_EQUAL(0, m1.argumentList(0).size());
|
||||||
EXPECT(m1.is_const_);
|
EXPECT(m1.is_const_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -209,13 +205,13 @@ TEST( wrap, Geometry ) {
|
||||||
// VectorNotEigen vectorConfusion();
|
// VectorNotEigen vectorConfusion();
|
||||||
CHECK(cls.exists("vectorConfusion"));
|
CHECK(cls.exists("vectorConfusion"));
|
||||||
Method m1 = cls.method("vectorConfusion");
|
Method m1 = cls.method("vectorConfusion");
|
||||||
LONGS_EQUAL(1, m1.returnVals.size());
|
LONGS_EQUAL(1, m1.nrOverloads());
|
||||||
EXPECT(assert_equal("VectorNotEigen", m1.returnVals.front().type1.name));
|
EXPECT(assert_equal("VectorNotEigen", m1.returnValue(0).type1.name));
|
||||||
EXPECT_LONGS_EQUAL(ReturnType::CLASS, m1.returnVals.front().type1.category);
|
EXPECT_LONGS_EQUAL(ReturnType::CLASS, m1.returnValue(0).type1.category);
|
||||||
EXPECT(!m1.returnVals.front().isPair);
|
EXPECT(!m1.returnValue(0).isPair);
|
||||||
EXPECT(assert_equal("vectorConfusion", m1.name_));
|
EXPECT(assert_equal("vectorConfusion", m1.name_));
|
||||||
LONGS_EQUAL(1, m1.argLists.size());
|
LONGS_EQUAL(1, m1.nrOverloads());
|
||||||
EXPECT_LONGS_EQUAL(0, m1.argLists.front().size());
|
EXPECT_LONGS_EQUAL(0, m1.argumentList(0).size());
|
||||||
EXPECT(!m1.is_const_);
|
EXPECT(!m1.is_const_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -252,12 +248,12 @@ TEST( wrap, Geometry ) {
|
||||||
// check method
|
// check method
|
||||||
CHECK(cls.exists("norm"));
|
CHECK(cls.exists("norm"));
|
||||||
Method m1 = cls.method("norm");
|
Method m1 = cls.method("norm");
|
||||||
LONGS_EQUAL(1, m1.returnVals.size());
|
LONGS_EQUAL(1, m1.nrOverloads());
|
||||||
EXPECT(assert_equal("double", m1.returnVals.front().type1.name));
|
EXPECT(assert_equal("double", m1.returnValue(0).type1.name));
|
||||||
EXPECT_LONGS_EQUAL(ReturnType::BASIS, m1.returnVals.front().type1.category);
|
EXPECT_LONGS_EQUAL(ReturnType::BASIS, m1.returnValue(0).type1.category);
|
||||||
EXPECT(assert_equal("norm", m1.name_));
|
EXPECT(assert_equal("norm", m1.name_));
|
||||||
LONGS_EQUAL(1, m1.argLists.size());
|
LONGS_EQUAL(1, m1.nrOverloads());
|
||||||
EXPECT_LONGS_EQUAL(0, m1.argLists.front().size());
|
EXPECT_LONGS_EQUAL(0, m1.argumentList(0).size());
|
||||||
EXPECT(m1.is_const_);
|
EXPECT(m1.is_const_);
|
||||||
|
|
||||||
#ifndef WRAP_DISABLE_SERIALIZE
|
#ifndef WRAP_DISABLE_SERIALIZE
|
||||||
|
@ -278,19 +274,19 @@ TEST( wrap, Geometry ) {
|
||||||
// function to parse: pair<Vector,Matrix> return_pair (Vector v, Matrix A) const;
|
// function to parse: pair<Vector,Matrix> return_pair (Vector v, Matrix A) const;
|
||||||
CHECK(testCls.exists("return_pair"));
|
CHECK(testCls.exists("return_pair"));
|
||||||
Method m2 = testCls.method("return_pair");
|
Method m2 = testCls.method("return_pair");
|
||||||
LONGS_EQUAL(1, m2.returnVals.size());
|
LONGS_EQUAL(1, m2.nrOverloads());
|
||||||
EXPECT(m2.returnVals.front().isPair);
|
EXPECT(m2.returnValue(0).isPair);
|
||||||
EXPECT_LONGS_EQUAL(ReturnType::EIGEN, m2.returnVals.front().type1.category);
|
EXPECT_LONGS_EQUAL(ReturnType::EIGEN, m2.returnValue(0).type1.category);
|
||||||
EXPECT(assert_equal("Vector", m2.returnVals.front().type1.name));
|
EXPECT(assert_equal("Vector", m2.returnValue(0).type1.name));
|
||||||
EXPECT_LONGS_EQUAL(ReturnType::EIGEN, m2.returnVals.front().type2.category);
|
EXPECT_LONGS_EQUAL(ReturnType::EIGEN, m2.returnValue(0).type2.category);
|
||||||
EXPECT(assert_equal("Matrix", m2.returnVals.front().type2.name));
|
EXPECT(assert_equal("Matrix", m2.returnValue(0).type2.name));
|
||||||
|
|
||||||
// checking pointer args and return values
|
// checking pointer args and return values
|
||||||
// pair<Test*,Test*> return_ptrs (Test* p1, Test* p2) const;
|
// pair<Test*,Test*> return_ptrs (Test* p1, Test* p2) const;
|
||||||
CHECK(testCls.exists("return_ptrs"));
|
CHECK(testCls.exists("return_ptrs"));
|
||||||
Method m3 = testCls.method("return_ptrs");
|
Method m3 = testCls.method("return_ptrs");
|
||||||
LONGS_EQUAL(1, m3.argLists.size());
|
LONGS_EQUAL(1, m3.nrOverloads());
|
||||||
ArgumentList args = m3.argLists.front();
|
ArgumentList args = m3.argumentList(0);
|
||||||
LONGS_EQUAL(2, args.size());
|
LONGS_EQUAL(2, args.size());
|
||||||
|
|
||||||
Argument arg1 = args.at(0);
|
Argument arg1 = args.at(0);
|
||||||
|
@ -317,9 +313,9 @@ TEST( wrap, Geometry ) {
|
||||||
{
|
{
|
||||||
GlobalFunction gfunc = module.global_functions.at("aGlobalFunction");
|
GlobalFunction gfunc = module.global_functions.at("aGlobalFunction");
|
||||||
EXPECT(assert_equal("aGlobalFunction", gfunc.name_));
|
EXPECT(assert_equal("aGlobalFunction", gfunc.name_));
|
||||||
LONGS_EQUAL(1, gfunc.returnVals.size());
|
LONGS_EQUAL(1, gfunc.nrOverloads());
|
||||||
EXPECT(assert_equal("Vector", gfunc.returnVals.front().type1.name));
|
EXPECT(assert_equal("Vector", gfunc.returnValue(0).type1.name));
|
||||||
EXPECT_LONGS_EQUAL(1, gfunc.argLists.size());
|
EXPECT_LONGS_EQUAL(1, gfunc.nrOverloads());
|
||||||
LONGS_EQUAL(1, gfunc.overloads.size());
|
LONGS_EQUAL(1, gfunc.overloads.size());
|
||||||
EXPECT(gfunc.overloads.front().namespaces.empty());
|
EXPECT(gfunc.overloads.front().namespaces.empty());
|
||||||
}
|
}
|
||||||
|
@ -391,9 +387,8 @@ TEST( wrap, parse_namespaces ) {
|
||||||
{
|
{
|
||||||
GlobalFunction gfunc = module.global_functions.at("aGlobalFunction");
|
GlobalFunction gfunc = module.global_functions.at("aGlobalFunction");
|
||||||
EXPECT(assert_equal("aGlobalFunction", gfunc.name_));
|
EXPECT(assert_equal("aGlobalFunction", gfunc.name_));
|
||||||
LONGS_EQUAL(2, gfunc.returnVals.size());
|
LONGS_EQUAL(2, gfunc.nrOverloads());
|
||||||
EXPECT(assert_equal("Vector", gfunc.returnVals.front().type1.name));
|
EXPECT(assert_equal("Vector", gfunc.returnValue(0).type1.name));
|
||||||
EXPECT_LONGS_EQUAL(2, gfunc.argLists.size());
|
|
||||||
|
|
||||||
// check namespaces
|
// check namespaces
|
||||||
LONGS_EQUAL(2, gfunc.overloads.size());
|
LONGS_EQUAL(2, gfunc.overloads.size());
|
||||||
|
|
Loading…
Reference in New Issue