Standard BORG formatting
parent
d8235d0c2a
commit
05a38ca263
|
@ -17,7 +17,8 @@ using namespace std;
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
void GlobalFunction::addOverload(bool verbose, const std::string& name,
|
void GlobalFunction::addOverload(bool verbose, const std::string& name,
|
||||||
const ArgumentList& args, const ReturnValue& retVal, const StrVec& ns_stack) {
|
const ArgumentList& args, const ReturnValue& retVal,
|
||||||
|
const StrVec& ns_stack) {
|
||||||
this->verbose_ = verbose;
|
this->verbose_ = verbose;
|
||||||
this->name = name;
|
this->name = name;
|
||||||
this->argLists.push_back(args);
|
this->argLists.push_back(args);
|
||||||
|
@ -26,9 +27,9 @@ void GlobalFunction::addOverload(bool verbose, const std::string& name,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
void GlobalFunction::matlab_proxy(const std::string& toolboxPath, const std::string& wrapperName,
|
void GlobalFunction::matlab_proxy(const std::string& toolboxPath,
|
||||||
const TypeAttributesTable& typeAttributes, FileWriter& wrapperFile,
|
const std::string& wrapperName, const TypeAttributesTable& typeAttributes,
|
||||||
std::vector<std::string>& functionNames) const {
|
FileWriter& file, std::vector<std::string>& functionNames) const {
|
||||||
|
|
||||||
// cluster overloads with same namespace
|
// cluster overloads with same namespace
|
||||||
// create new GlobalFunction structures around namespaces - same namespaces and names are overloads
|
// create new GlobalFunction structures around namespaces - same namespaces and names are overloads
|
||||||
|
@ -51,16 +52,17 @@ void GlobalFunction::matlab_proxy(const std::string& toolboxPath, const std::str
|
||||||
|
|
||||||
size_t lastcheck = grouped_functions.size();
|
size_t lastcheck = grouped_functions.size();
|
||||||
BOOST_FOREACH(const GlobalFunctionMap::value_type& p, grouped_functions) {
|
BOOST_FOREACH(const GlobalFunctionMap::value_type& p, grouped_functions) {
|
||||||
p.second.generateSingleFunction(toolboxPath, wrapperName, typeAttributes, wrapperFile, functionNames);
|
p.second.generateSingleFunction(toolboxPath, wrapperName, typeAttributes,
|
||||||
|
file, functionNames);
|
||||||
if (--lastcheck != 0)
|
if (--lastcheck != 0)
|
||||||
wrapperFile.oss << endl;
|
file.oss << endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
void GlobalFunction::generateSingleFunction(const std::string& toolboxPath, const std::string& wrapperName,
|
void GlobalFunction::generateSingleFunction(const std::string& toolboxPath,
|
||||||
const TypeAttributesTable& typeAttributes, FileWriter& wrapperFile,
|
const std::string& wrapperName, const TypeAttributesTable& typeAttributes,
|
||||||
std::vector<std::string>& functionNames) const {
|
FileWriter& file, std::vector<std::string>& functionNames) const {
|
||||||
|
|
||||||
// create the folder for the namespace
|
// create the folder for the namespace
|
||||||
const StrVec& ns = namespaces.front();
|
const StrVec& ns = namespaces.front();
|
||||||
|
@ -74,10 +76,8 @@ void GlobalFunction::generateSingleFunction(const std::string& toolboxPath, cons
|
||||||
FileWriter mfunctionFile(mfunctionFileName, verbose_, "%");
|
FileWriter mfunctionFile(mfunctionFileName, verbose_, "%");
|
||||||
|
|
||||||
// get the name of actual matlab object
|
// get the name of actual matlab object
|
||||||
const string
|
const string matlabQualName = qualifiedName(".", ns, name), matlabUniqueName =
|
||||||
matlabQualName = qualifiedName(".", ns, name),
|
qualifiedName("", ns, name), cppName = qualifiedName("::", ns, name);
|
||||||
matlabUniqueName = qualifiedName("", ns, name),
|
|
||||||
cppName = qualifiedName("::", ns, name);
|
|
||||||
|
|
||||||
mfunctionFile.oss << "function varargout = " << name << "(varargin)\n";
|
mfunctionFile.oss << "function varargout = " << name << "(varargin)\n";
|
||||||
|
|
||||||
|
@ -91,13 +91,17 @@ void GlobalFunction::generateSingleFunction(const std::string& toolboxPath, cons
|
||||||
// Output proxy matlab code
|
// Output proxy matlab code
|
||||||
|
|
||||||
// check for number of arguments...
|
// check for number of arguments...
|
||||||
mfunctionFile.oss << (overload==0?"":"else") << "if length(varargin) == " << nrArgs;
|
mfunctionFile.oss << (overload == 0 ? "" : "else")
|
||||||
if (nrArgs>0) mfunctionFile.oss << " && ";
|
<< "if length(varargin) == " << nrArgs;
|
||||||
|
if (nrArgs > 0)
|
||||||
|
mfunctionFile.oss << " && ";
|
||||||
// ...and their types
|
// ...and their types
|
||||||
bool first = true;
|
bool first = true;
|
||||||
for (size_t i = 0; i < nrArgs; i++) {
|
for (size_t i = 0; i < nrArgs; i++) {
|
||||||
if (!first) mfunctionFile.oss << " && ";
|
if (!first)
|
||||||
mfunctionFile.oss << "isa(varargin{" << i+1 << "},'" << args[i].matlabClass(".") << "')";
|
mfunctionFile.oss << " && ";
|
||||||
|
mfunctionFile.oss << "isa(varargin{" << i + 1 << "},'"
|
||||||
|
<< args[i].matlabClass(".") << "')";
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
mfunctionFile.oss << "\n";
|
mfunctionFile.oss << "\n";
|
||||||
|
@ -109,37 +113,43 @@ void GlobalFunction::generateSingleFunction(const std::string& toolboxPath, cons
|
||||||
|
|
||||||
// Output C++ wrapper code
|
// Output C++ wrapper code
|
||||||
|
|
||||||
const string wrapFunctionName = matlabUniqueName + "_" + boost::lexical_cast<string>(id);
|
const string wrapFunctionName = matlabUniqueName + "_"
|
||||||
|
+ boost::lexical_cast<string>(id);
|
||||||
|
|
||||||
// call
|
// call
|
||||||
wrapperFile.oss << "void " << wrapFunctionName << "(int nargout, mxArray *out[], int nargin, const mxArray *in[])\n";
|
file.oss << "void " << wrapFunctionName
|
||||||
|
<< "(int nargout, mxArray *out[], int nargin, const mxArray *in[])\n";
|
||||||
// start
|
// start
|
||||||
wrapperFile.oss << "{\n";
|
file.oss << "{\n";
|
||||||
|
|
||||||
returnVal.wrapTypeUnwrap(wrapperFile);
|
returnVal.wrapTypeUnwrap(file);
|
||||||
|
|
||||||
// check arguments
|
// check arguments
|
||||||
// NOTE: for static functions, there is no object passed
|
// NOTE: for static functions, there is no object passed
|
||||||
wrapperFile.oss << " checkArguments(\"" << matlabUniqueName << "\",nargout,nargin," << args.size() << ");\n";
|
file.oss << " checkArguments(\"" << matlabUniqueName
|
||||||
|
<< "\",nargout,nargin," << args.size() << ");\n";
|
||||||
|
|
||||||
// unwrap arguments, see Argument.cpp
|
// unwrap arguments, see Argument.cpp
|
||||||
args.matlab_unwrap(wrapperFile,0); // We start at 0 because there is no self object
|
args.matlab_unwrap(file, 0); // We start at 0 because there is no self object
|
||||||
|
|
||||||
// call method with default type and wrap result
|
// call method with default type and wrap result
|
||||||
if (returnVal.type1 != "void")
|
if (returnVal.type1 != "void")
|
||||||
returnVal.wrap_result(cppName+"("+args.names()+")", wrapperFile, typeAttributes);
|
returnVal.wrap_result(cppName + "(" + args.names() + ")", file,
|
||||||
|
typeAttributes);
|
||||||
else
|
else
|
||||||
wrapperFile.oss << cppName+"("+args.names()+");\n";
|
file.oss << cppName + "(" + args.names() + ");\n";
|
||||||
|
|
||||||
// finish
|
// finish
|
||||||
wrapperFile.oss << "}\n";
|
file.oss << "}\n";
|
||||||
|
|
||||||
// Add to function list
|
// Add to function list
|
||||||
functionNames.push_back(wrapFunctionName);
|
functionNames.push_back(wrapFunctionName);
|
||||||
}
|
}
|
||||||
|
|
||||||
mfunctionFile.oss << "else\n";
|
mfunctionFile.oss << "else\n";
|
||||||
mfunctionFile.oss << " error('Arguments do not match any overload of function " << matlabQualName << "');" << endl;
|
mfunctionFile.oss
|
||||||
|
<< " error('Arguments do not match any overload of function "
|
||||||
|
<< matlabQualName << "');" << endl;
|
||||||
mfunctionFile.oss << "end" << endl;
|
mfunctionFile.oss << "end" << endl;
|
||||||
|
|
||||||
// Close file
|
// Close file
|
||||||
|
@ -148,9 +158,5 @@ void GlobalFunction::generateSingleFunction(const std::string& toolboxPath, cons
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
|
|
||||||
|
|
||||||
} // \namespace wrap
|
} // \namespace wrap
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -27,32 +27,33 @@ struct GlobalFunction {
|
||||||
std::vector<StrVec> namespaces; ///< Stack of namespaces
|
std::vector<StrVec> namespaces; ///< Stack of namespaces
|
||||||
|
|
||||||
// Constructor only used in Module
|
// Constructor only used in Module
|
||||||
GlobalFunction(bool verbose = true) : verbose_(verbose) {}
|
GlobalFunction(bool verbose = true) :
|
||||||
|
verbose_(verbose) {
|
||||||
|
}
|
||||||
|
|
||||||
// Used to reconstruct
|
// Used to reconstruct
|
||||||
GlobalFunction(const std::string& name_, bool verbose = true)
|
GlobalFunction(const std::string& name_, bool verbose = true) :
|
||||||
: verbose_(verbose), name(name_) {}
|
verbose_(verbose), name(name_) {
|
||||||
|
}
|
||||||
|
|
||||||
// adds an overloaded version of this function
|
// adds an overloaded version of this function
|
||||||
void addOverload(bool verbose, const std::string& name,
|
void addOverload(bool verbose, const std::string& name,
|
||||||
const ArgumentList& args, const ReturnValue& retVal, const StrVec& ns_stack);
|
const ArgumentList& args, const ReturnValue& retVal,
|
||||||
|
const StrVec& ns_stack);
|
||||||
|
|
||||||
// codegen function called from Module to build the cpp and matlab versions of the function
|
// codegen function called from Module to build the cpp and matlab versions of the function
|
||||||
void matlab_proxy(const std::string& toolboxPath, const std::string& wrapperName,
|
void matlab_proxy(const std::string& toolboxPath,
|
||||||
const TypeAttributesTable& typeAttributes, FileWriter& wrapperFile,
|
const std::string& wrapperName, const TypeAttributesTable& typeAttributes,
|
||||||
std::vector<std::string>& functionNames) const;
|
FileWriter& file, std::vector<std::string>& functionNames) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
// Creates a single global function - all in same namespace
|
// Creates a single global function - all in same namespace
|
||||||
void generateSingleFunction(const std::string& toolboxPath, const std::string& wrapperName,
|
void generateSingleFunction(const std::string& toolboxPath,
|
||||||
const TypeAttributesTable& typeAttributes, FileWriter& wrapperFile,
|
const std::string& wrapperName, const TypeAttributesTable& typeAttributes,
|
||||||
std::vector<std::string>& functionNames) const;
|
FileWriter& file, std::vector<std::string>& functionNames) const;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // \namespace wrap
|
} // \namespace wrap
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue