Standard BORG formatting
parent
02c3fe9516
commit
82d6bae4b9
719
wrap/Class.cpp
719
wrap/Class.cpp
|
@ -7,62 +7,62 @@
|
||||||
|
|
||||||
* See LICENSE for the license information
|
* See LICENSE for the license information
|
||||||
|
|
||||||
* -------------------------------------------------------------------------- */
|
* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file Class.cpp
|
* @file Class.cpp
|
||||||
* @author Frank Dellaert
|
* @author Frank Dellaert
|
||||||
* @author Andrew Melim
|
* @author Andrew Melim
|
||||||
* @author Richard Roberts
|
* @author Richard Roberts
|
||||||
**/
|
**/
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
//#include <cstdint> // on Linux GCC: fails with error regarding needing C++0x std flags
|
//#include <cstdint> // on Linux GCC: fails with error regarding needing C++0x std flags
|
||||||
//#include <cinttypes> // same failure as above
|
//#include <cinttypes> // same failure as above
|
||||||
#include <stdint.h> // works on Linux GCC
|
#include <stdint.h> // works on Linux GCC
|
||||||
|
|
||||||
#include <boost/foreach.hpp>
|
#include <boost/foreach.hpp>
|
||||||
#include <boost/lexical_cast.hpp>
|
#include <boost/lexical_cast.hpp>
|
||||||
|
|
||||||
#include "Class.h"
|
#include "Class.h"
|
||||||
#include "utilities.h"
|
#include "utilities.h"
|
||||||
#include "Argument.h"
|
#include "Argument.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace wrap;
|
using namespace wrap;
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
void Class::matlab_proxy(const string& toolboxPath, const string& wrapperName,
|
void Class::matlab_proxy(const string& toolboxPath, const string& wrapperName,
|
||||||
const TypeAttributesTable& typeAttributes,
|
const TypeAttributesTable& typeAttributes, FileWriter& wrapperFile,
|
||||||
FileWriter& wrapperFile, vector<string>& functionNames) const {
|
vector<string>& functionNames) const {
|
||||||
|
|
||||||
// Create namespace folders
|
// Create namespace folders
|
||||||
createNamespaceStructure(namespaces, toolboxPath);
|
createNamespaceStructure(namespaces, toolboxPath);
|
||||||
|
|
||||||
// open destination classFile
|
// open destination classFile
|
||||||
string classFile = toolboxPath;
|
string classFile = toolboxPath;
|
||||||
if(!namespaces.empty())
|
if (!namespaces.empty())
|
||||||
classFile += "/+" + wrap::qualifiedName("/+", namespaces);
|
classFile += "/+" + wrap::qualifiedName("/+", namespaces);
|
||||||
classFile += "/" + name + ".m";
|
classFile += "/" + name + ".m";
|
||||||
FileWriter proxyFile(classFile, verbose_, "%");
|
FileWriter proxyFile(classFile, verbose_, "%");
|
||||||
|
|
||||||
// get the name of actual matlab object
|
// get the name of actual matlab object
|
||||||
const string matlabQualName = qualifiedName("."), matlabUniqueName = qualifiedName(), cppName = qualifiedName("::");
|
const string matlabQualName = qualifiedName("."), matlabUniqueName =
|
||||||
const string matlabBaseName = wrap::qualifiedName(".", qualifiedParent);
|
qualifiedName(), cppName = qualifiedName("::");
|
||||||
const string cppBaseName = wrap::qualifiedName("::", qualifiedParent);
|
const string matlabBaseName = wrap::qualifiedName(".", qualifiedParent);
|
||||||
|
const string cppBaseName = wrap::qualifiedName("::", qualifiedParent);
|
||||||
|
|
||||||
// emit class proxy code
|
// emit class proxy code
|
||||||
// we want our class to inherit the handle class for memory purposes
|
// we want our class to inherit the handle class for memory purposes
|
||||||
const string parent = qualifiedParent.empty() ? "handle" : matlabBaseName;
|
const string parent = qualifiedParent.empty() ? "handle" : matlabBaseName;
|
||||||
comment_fragment(proxyFile);
|
comment_fragment(proxyFile);
|
||||||
proxyFile.oss << "classdef " << name << " < " << parent << endl;
|
proxyFile.oss << "classdef " << name << " < " << parent << endl;
|
||||||
proxyFile.oss << " properties\n";
|
proxyFile.oss << " properties\n";
|
||||||
proxyFile.oss << " ptr_" << matlabUniqueName << " = 0\n";
|
proxyFile.oss << " ptr_" << matlabUniqueName << " = 0\n";
|
||||||
proxyFile.oss << " end\n";
|
proxyFile.oss << " end\n";
|
||||||
proxyFile.oss << " methods\n";
|
proxyFile.oss << " methods\n";
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
proxyFile.oss << " function obj = " << name << "(varargin)\n";
|
proxyFile.oss << " function obj = " << name << "(varargin)\n";
|
||||||
// Special pointer constructors - one in MATLAB to create an object and
|
// Special pointer constructors - one in MATLAB to create an object and
|
||||||
|
@ -72,267 +72,316 @@ void Class::matlab_proxy(const string& toolboxPath, const string& wrapperName,
|
||||||
// other wrap modules - to add these to their collectors the pointer is
|
// other wrap modules - to add these to their collectors the pointer is
|
||||||
// passed from one C++ module into matlab then back into the other C++
|
// passed from one C++ module into matlab then back into the other C++
|
||||||
// module.
|
// module.
|
||||||
pointer_constructor_fragments(proxyFile, wrapperFile, wrapperName, functionNames);
|
pointer_constructor_fragments(proxyFile, wrapperFile, wrapperName,
|
||||||
wrapperFile.oss << "\n";
|
functionNames);
|
||||||
|
wrapperFile.oss << "\n";
|
||||||
// Regular constructors
|
// Regular constructors
|
||||||
BOOST_FOREACH(ArgumentList a, constructor.args_list)
|
BOOST_FOREACH(ArgumentList a, constructor.args_list) {
|
||||||
{
|
const int id = (int) functionNames.size();
|
||||||
const int id = (int)functionNames.size();
|
constructor.proxy_fragment(proxyFile, wrapperName, !qualifiedParent.empty(),
|
||||||
constructor.proxy_fragment(proxyFile, wrapperName, !qualifiedParent.empty(), id, a);
|
id, a);
|
||||||
const string wrapFunctionName = constructor.wrapper_fragment(wrapperFile,
|
const string wrapFunctionName = constructor.wrapper_fragment(wrapperFile,
|
||||||
cppName, matlabUniqueName, cppBaseName, id, a);
|
cppName, matlabUniqueName, cppBaseName, id, a);
|
||||||
wrapperFile.oss << "\n";
|
wrapperFile.oss << "\n";
|
||||||
functionNames.push_back(wrapFunctionName);
|
functionNames.push_back(wrapFunctionName);
|
||||||
}
|
}
|
||||||
proxyFile.oss << " else\n";
|
proxyFile.oss << " else\n";
|
||||||
proxyFile.oss << " error('Arguments do not match any overload of " << matlabQualName << " constructor');\n";
|
proxyFile.oss << " error('Arguments do not match any overload of "
|
||||||
proxyFile.oss << " end\n";
|
<< matlabQualName << " constructor');\n";
|
||||||
if(!qualifiedParent.empty())
|
proxyFile.oss << " end\n";
|
||||||
proxyFile.oss << " obj = obj@" << matlabBaseName << "(uint64(" << ptr_constructor_key << "), base_ptr);\n";
|
if (!qualifiedParent.empty())
|
||||||
proxyFile.oss << " obj.ptr_" << matlabUniqueName << " = my_ptr;\n";
|
proxyFile.oss << " obj = obj@" << matlabBaseName << "(uint64("
|
||||||
proxyFile.oss << " end\n\n";
|
<< ptr_constructor_key << "), base_ptr);\n";
|
||||||
|
proxyFile.oss << " obj.ptr_" << matlabUniqueName << " = my_ptr;\n";
|
||||||
|
proxyFile.oss << " end\n\n";
|
||||||
|
|
||||||
// Deconstructor
|
// Deconstructor
|
||||||
{
|
{
|
||||||
const int id = (int)functionNames.size();
|
const int id = (int) functionNames.size();
|
||||||
deconstructor.proxy_fragment(proxyFile, wrapperName, matlabUniqueName, id);
|
deconstructor.proxy_fragment(proxyFile, wrapperName, matlabUniqueName, id);
|
||||||
proxyFile.oss << "\n";
|
proxyFile.oss << "\n";
|
||||||
const string functionName = deconstructor.wrapper_fragment(wrapperFile, cppName, matlabUniqueName, id);
|
const string functionName = deconstructor.wrapper_fragment(wrapperFile,
|
||||||
wrapperFile.oss << "\n";
|
cppName, matlabUniqueName, id);
|
||||||
functionNames.push_back(functionName);
|
wrapperFile.oss << "\n";
|
||||||
}
|
functionNames.push_back(functionName);
|
||||||
proxyFile.oss << " function display(obj), obj.print(''); end\n %DISPLAY Calls print on the object\n";
|
}
|
||||||
proxyFile.oss << " function disp(obj), obj.display; end\n %DISP Calls print on the object\n";
|
proxyFile.oss
|
||||||
|
<< " function display(obj), obj.print(''); end\n %DISPLAY Calls print on the object\n";
|
||||||
|
proxyFile.oss
|
||||||
|
<< " function disp(obj), obj.display; end\n %DISP Calls print on the object\n";
|
||||||
|
|
||||||
// Methods
|
// Methods
|
||||||
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;
|
||||||
m.proxy_wrapper_fragments(proxyFile, wrapperFile, cppName, matlabQualName, matlabUniqueName, wrapperName, typeAttributes, functionNames);
|
m.proxy_wrapper_fragments(proxyFile, wrapperFile, cppName, matlabQualName,
|
||||||
proxyFile.oss << "\n";
|
matlabUniqueName, wrapperName, typeAttributes, functionNames);
|
||||||
wrapperFile.oss << "\n";
|
proxyFile.oss << "\n";
|
||||||
}
|
wrapperFile.oss << "\n";
|
||||||
|
}
|
||||||
if (hasSerialization)
|
if (hasSerialization)
|
||||||
serialization_fragments(proxyFile, wrapperFile, wrapperName, functionNames);
|
serialization_fragments(proxyFile, wrapperFile, wrapperName, functionNames);
|
||||||
|
|
||||||
proxyFile.oss << " end\n";
|
proxyFile.oss << " end\n";
|
||||||
proxyFile.oss << "\n";
|
proxyFile.oss << "\n";
|
||||||
proxyFile.oss << " methods(Static = true)\n";
|
proxyFile.oss << " methods(Static = true)\n";
|
||||||
|
|
||||||
// Static methods
|
// Static methods
|
||||||
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;
|
||||||
m.proxy_wrapper_fragments(proxyFile, wrapperFile, cppName, matlabQualName, matlabUniqueName, wrapperName, typeAttributes, functionNames);
|
m.proxy_wrapper_fragments(proxyFile, wrapperFile, cppName, matlabQualName,
|
||||||
proxyFile.oss << "\n";
|
matlabUniqueName, wrapperName, typeAttributes, functionNames);
|
||||||
wrapperFile.oss << "\n";
|
proxyFile.oss << "\n";
|
||||||
}
|
wrapperFile.oss << "\n";
|
||||||
|
}
|
||||||
if (hasSerialization)
|
if (hasSerialization)
|
||||||
deserialization_fragments(proxyFile, wrapperFile, wrapperName, functionNames);
|
deserialization_fragments(proxyFile, wrapperFile, wrapperName,
|
||||||
|
functionNames);
|
||||||
|
|
||||||
proxyFile.oss << " end\n";
|
proxyFile.oss << " end\n";
|
||||||
proxyFile.oss << "end\n";
|
proxyFile.oss << "end\n";
|
||||||
|
|
||||||
// Close file
|
// Close file
|
||||||
proxyFile.emit(true);
|
proxyFile.emit(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
string Class::qualifiedName(const string& delim) const {
|
string Class::qualifiedName(const string& delim) const {
|
||||||
return ::wrap::qualifiedName(delim, namespaces, name);
|
return ::wrap::qualifiedName(delim, namespaces, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
void Class::pointer_constructor_fragments(FileWriter& proxyFile, FileWriter& wrapperFile, const string& wrapperName, vector<string>& functionNames) const {
|
void Class::pointer_constructor_fragments(FileWriter& proxyFile,
|
||||||
|
FileWriter& wrapperFile, const string& wrapperName,
|
||||||
const string matlabUniqueName = qualifiedName(), cppName = qualifiedName("::");
|
vector<string>& functionNames) const {
|
||||||
const string baseCppName = wrap::qualifiedName("::", qualifiedParent);
|
|
||||||
|
const string matlabUniqueName = qualifiedName(), cppName = qualifiedName(
|
||||||
const int collectorInsertId = (int)functionNames.size();
|
"::");
|
||||||
const string collectorInsertFunctionName = matlabUniqueName + "_collectorInsertAndMakeBase_" + boost::lexical_cast<string>(collectorInsertId);
|
const string baseCppName = wrap::qualifiedName("::", qualifiedParent);
|
||||||
functionNames.push_back(collectorInsertFunctionName);
|
|
||||||
|
const int collectorInsertId = (int) functionNames.size();
|
||||||
int upcastFromVoidId;
|
const string collectorInsertFunctionName = matlabUniqueName
|
||||||
string upcastFromVoidFunctionName;
|
+ "_collectorInsertAndMakeBase_"
|
||||||
if(isVirtual) {
|
+ boost::lexical_cast<string>(collectorInsertId);
|
||||||
upcastFromVoidId = (int)functionNames.size();
|
functionNames.push_back(collectorInsertFunctionName);
|
||||||
upcastFromVoidFunctionName = matlabUniqueName + "_upcastFromVoid_" + boost::lexical_cast<string>(upcastFromVoidId);
|
|
||||||
functionNames.push_back(upcastFromVoidFunctionName);
|
int upcastFromVoidId;
|
||||||
}
|
string upcastFromVoidFunctionName;
|
||||||
|
if (isVirtual) {
|
||||||
|
upcastFromVoidId = (int) functionNames.size();
|
||||||
|
upcastFromVoidFunctionName = matlabUniqueName + "_upcastFromVoid_"
|
||||||
|
+ boost::lexical_cast<string>(upcastFromVoidId);
|
||||||
|
functionNames.push_back(upcastFromVoidFunctionName);
|
||||||
|
}
|
||||||
|
|
||||||
// MATLAB constructor that assigns pointer to matlab object then calls c++
|
// MATLAB constructor that assigns pointer to matlab object then calls c++
|
||||||
// function to add the object to the collector.
|
// function to add the object to the collector.
|
||||||
if(isVirtual) {
|
if (isVirtual) {
|
||||||
proxyFile.oss << " if (nargin == 2 || (nargin == 3 && strcmp(varargin{3}, 'void')))";
|
proxyFile.oss
|
||||||
} else {
|
<< " if (nargin == 2 || (nargin == 3 && strcmp(varargin{3}, 'void')))";
|
||||||
proxyFile.oss << " if nargin == 2";
|
} else {
|
||||||
}
|
proxyFile.oss << " if nargin == 2";
|
||||||
proxyFile.oss << " && isa(varargin{1}, 'uint64') && varargin{1} == uint64(" << ptr_constructor_key << ")\n";
|
}
|
||||||
if(isVirtual) {
|
proxyFile.oss << " && isa(varargin{1}, 'uint64') && varargin{1} == uint64("
|
||||||
proxyFile.oss << " if nargin == 2\n";
|
<< ptr_constructor_key << ")\n";
|
||||||
proxyFile.oss << " my_ptr = varargin{2};\n";
|
if (isVirtual) {
|
||||||
proxyFile.oss << " else\n";
|
proxyFile.oss << " if nargin == 2\n";
|
||||||
proxyFile.oss << " my_ptr = " << wrapperName << "(" << upcastFromVoidId << ", varargin{2});\n";
|
proxyFile.oss << " my_ptr = varargin{2};\n";
|
||||||
proxyFile.oss << " end\n";
|
proxyFile.oss << " else\n";
|
||||||
} else {
|
proxyFile.oss << " my_ptr = " << wrapperName << "("
|
||||||
proxyFile.oss << " my_ptr = varargin{2};\n";
|
<< upcastFromVoidId << ", varargin{2});\n";
|
||||||
}
|
proxyFile.oss << " end\n";
|
||||||
if(qualifiedParent.empty()) // If this class has a base class, we'll get a base class pointer back
|
} else {
|
||||||
proxyFile.oss << " ";
|
proxyFile.oss << " my_ptr = varargin{2};\n";
|
||||||
else
|
}
|
||||||
proxyFile.oss << " base_ptr = ";
|
if (qualifiedParent.empty()) // If this class has a base class, we'll get a base class pointer back
|
||||||
|
proxyFile.oss << " ";
|
||||||
|
else
|
||||||
|
proxyFile.oss << " base_ptr = ";
|
||||||
proxyFile.oss << wrapperName << "(" << collectorInsertId << ", my_ptr);\n"; // Call collector insert and get base class ptr
|
proxyFile.oss << wrapperName << "(" << collectorInsertId << ", my_ptr);\n"; // Call collector insert and get base class ptr
|
||||||
|
|
||||||
// C++ function to add pointer from MATLAB to collector. The pointer always
|
// C++ function to add pointer from MATLAB to collector. The pointer always
|
||||||
// comes from a C++ return value; this mechanism allows the object to be added
|
// comes from a C++ return value; this mechanism allows the object to be added
|
||||||
// to a collector in a different wrap module. If this class has a base class,
|
// to a collector in a different wrap module. If this class has a base class,
|
||||||
// a new pointer to the base class is allocated and returned.
|
// a new pointer to the base class is allocated and returned.
|
||||||
wrapperFile.oss << "void " << collectorInsertFunctionName << "(int nargout, mxArray *out[], int nargin, const mxArray *in[])\n";
|
wrapperFile.oss << "void " << collectorInsertFunctionName
|
||||||
wrapperFile.oss << "{\n";
|
<< "(int nargout, mxArray *out[], int nargin, const mxArray *in[])\n";
|
||||||
wrapperFile.oss << " mexAtExit(&_deleteAllObjects);\n";
|
wrapperFile.oss << "{\n";
|
||||||
|
wrapperFile.oss << " mexAtExit(&_deleteAllObjects);\n";
|
||||||
// Typedef boost::shared_ptr
|
// Typedef boost::shared_ptr
|
||||||
wrapperFile.oss << " typedef boost::shared_ptr<" << cppName << "> Shared;\n";
|
wrapperFile.oss << " typedef boost::shared_ptr<" << cppName << "> Shared;\n";
|
||||||
wrapperFile.oss << "\n";
|
wrapperFile.oss << "\n";
|
||||||
// Get self pointer passed in
|
// Get self pointer passed in
|
||||||
wrapperFile.oss << " Shared *self = *reinterpret_cast<Shared**> (mxGetData(in[0]));\n";
|
wrapperFile.oss
|
||||||
|
<< " Shared *self = *reinterpret_cast<Shared**> (mxGetData(in[0]));\n";
|
||||||
// Add to collector
|
// Add to collector
|
||||||
wrapperFile.oss << " collector_" << matlabUniqueName << ".insert(self);\n";
|
wrapperFile.oss << " collector_" << matlabUniqueName << ".insert(self);\n";
|
||||||
// If we have a base class, return the base class pointer (MATLAB will call the base class collectorInsertAndMakeBase to add this to the collector and recurse the heirarchy)
|
// If we have a base class, return the base class pointer (MATLAB will call the base class collectorInsertAndMakeBase to add this to the collector and recurse the heirarchy)
|
||||||
if(!qualifiedParent.empty()) {
|
if (!qualifiedParent.empty()) {
|
||||||
wrapperFile.oss << "\n";
|
wrapperFile.oss << "\n";
|
||||||
wrapperFile.oss << " typedef boost::shared_ptr<" << baseCppName << "> SharedBase;\n";
|
wrapperFile.oss << " typedef boost::shared_ptr<" << baseCppName
|
||||||
wrapperFile.oss << " out[0] = mxCreateNumericMatrix(1, 1, mxUINT32OR64_CLASS, mxREAL);\n";
|
<< "> SharedBase;\n";
|
||||||
wrapperFile.oss << " *reinterpret_cast<SharedBase**>(mxGetData(out[0])) = new SharedBase(*self);\n";
|
wrapperFile.oss
|
||||||
}
|
<< " out[0] = mxCreateNumericMatrix(1, 1, mxUINT32OR64_CLASS, mxREAL);\n";
|
||||||
wrapperFile.oss << "}\n";
|
wrapperFile.oss
|
||||||
|
<< " *reinterpret_cast<SharedBase**>(mxGetData(out[0])) = new SharedBase(*self);\n";
|
||||||
|
}
|
||||||
|
wrapperFile.oss << "}\n";
|
||||||
|
|
||||||
// If this is a virtual function, C++ function to dynamic upcast it from a
|
// If this is a virtual function, C++ function to dynamic upcast it from a
|
||||||
// shared_ptr<void>. This mechanism allows automatic dynamic creation of the
|
// shared_ptr<void>. This mechanism allows automatic dynamic creation of the
|
||||||
// real underlying derived-most class when a C++ method returns a virtual
|
// real underlying derived-most class when a C++ method returns a virtual
|
||||||
// base class.
|
// base class.
|
||||||
if(isVirtual)
|
if (isVirtual)
|
||||||
wrapperFile.oss <<
|
wrapperFile.oss << "\n"
|
||||||
"\n"
|
"void " << upcastFromVoidFunctionName
|
||||||
"void " << upcastFromVoidFunctionName << "(int nargout, mxArray *out[], int nargin, const mxArray *in[]) {\n"
|
<< "(int nargout, mxArray *out[], int nargin, const mxArray *in[]) {\n"
|
||||||
" mexAtExit(&_deleteAllObjects);\n"
|
" mexAtExit(&_deleteAllObjects);\n"
|
||||||
" typedef boost::shared_ptr<" << cppName << "> Shared;\n"
|
" typedef boost::shared_ptr<" << cppName
|
||||||
" boost::shared_ptr<void> *asVoid = *reinterpret_cast<boost::shared_ptr<void>**> (mxGetData(in[0]));\n"
|
<< "> Shared;\n"
|
||||||
" out[0] = mxCreateNumericMatrix(1, 1, mxUINT32OR64_CLASS, mxREAL);\n"
|
" boost::shared_ptr<void> *asVoid = *reinterpret_cast<boost::shared_ptr<void>**> (mxGetData(in[0]));\n"
|
||||||
" Shared *self = new Shared(boost::static_pointer_cast<" << cppName << ">(*asVoid));\n"
|
" out[0] = mxCreateNumericMatrix(1, 1, mxUINT32OR64_CLASS, mxREAL);\n"
|
||||||
" *reinterpret_cast<Shared**>(mxGetData(out[0])) = self;\n"
|
" Shared *self = new Shared(boost::static_pointer_cast<" << cppName
|
||||||
"}\n";
|
<< ">(*asVoid));\n"
|
||||||
}
|
" *reinterpret_cast<Shared**>(mxGetData(out[0])) = self;\n"
|
||||||
|
"}\n";
|
||||||
/* ************************************************************************* */
|
}
|
||||||
vector<ArgumentList> expandArgumentListsTemplate(const vector<ArgumentList>& argLists, const string& templateArg, const vector<string>& instName, const std::vector<string>& expandedClassNamespace, const string& expandedClassName) {
|
|
||||||
vector<ArgumentList> result;
|
/* ************************************************************************* */
|
||||||
BOOST_FOREACH(const ArgumentList& argList, argLists) {
|
vector<ArgumentList> expandArgumentListsTemplate(
|
||||||
ArgumentList instArgList;
|
const vector<ArgumentList>& argLists, const string& templateArg,
|
||||||
BOOST_FOREACH(const Argument& arg, argList) {
|
const vector<string>& instName,
|
||||||
Argument instArg = arg;
|
const std::vector<string>& expandedClassNamespace,
|
||||||
if(arg.type == templateArg) {
|
const string& expandedClassName) {
|
||||||
instArg.namespaces.assign(instName.begin(), instName.end()-1);
|
vector<ArgumentList> result;
|
||||||
instArg.type = instName.back();
|
BOOST_FOREACH(const ArgumentList& argList, argLists) {
|
||||||
} else if(arg.type == "This") {
|
ArgumentList instArgList;
|
||||||
instArg.namespaces.assign(expandedClassNamespace.begin(), expandedClassNamespace.end());
|
BOOST_FOREACH(const Argument& arg, argList) {
|
||||||
instArg.type = expandedClassName;
|
Argument instArg = arg;
|
||||||
}
|
if (arg.type == templateArg) {
|
||||||
instArgList.push_back(instArg);
|
instArg.namespaces.assign(instName.begin(), instName.end() - 1);
|
||||||
}
|
instArg.type = instName.back();
|
||||||
result.push_back(instArgList);
|
} else if (arg.type == "This") {
|
||||||
}
|
instArg.namespaces.assign(expandedClassNamespace.begin(),
|
||||||
return result;
|
expandedClassNamespace.end());
|
||||||
}
|
instArg.type = expandedClassName;
|
||||||
|
}
|
||||||
/* ************************************************************************* */
|
instArgList.push_back(instArg);
|
||||||
template<class METHOD>
|
}
|
||||||
map<string, METHOD> expandMethodTemplate(const map<string, METHOD>& methods, const string& templateArg, const vector<string>& instName, const std::vector<string>& expandedClassNamespace, const string& expandedClassName) {
|
result.push_back(instArgList);
|
||||||
map<string, METHOD> result;
|
}
|
||||||
typedef pair<const string, METHOD> Name_Method;
|
return result;
|
||||||
BOOST_FOREACH(const Name_Method& name_method, methods) {
|
}
|
||||||
const METHOD& method = name_method.second;
|
|
||||||
METHOD instMethod = method;
|
/* ************************************************************************* */
|
||||||
instMethod.argLists = expandArgumentListsTemplate(method.argLists, templateArg, instName, expandedClassNamespace, expandedClassName);
|
template<class METHOD>
|
||||||
instMethod.returnVals.clear();
|
map<string, METHOD> expandMethodTemplate(const map<string, METHOD>& methods,
|
||||||
BOOST_FOREACH(const ReturnValue& retVal, method.returnVals) {
|
const string& templateArg, const vector<string>& instName,
|
||||||
ReturnValue instRetVal = retVal;
|
const std::vector<string>& expandedClassNamespace,
|
||||||
if(retVal.type1 == templateArg) {
|
const string& expandedClassName) {
|
||||||
instRetVal.namespaces1.assign(instName.begin(), instName.end()-1);
|
map<string, METHOD> result;
|
||||||
instRetVal.type1 = instName.back();
|
typedef pair<const string, METHOD> Name_Method;
|
||||||
} else if(retVal.type1 == "This") {
|
BOOST_FOREACH(const Name_Method& name_method, methods) {
|
||||||
instRetVal.namespaces1.assign(expandedClassNamespace.begin(), expandedClassNamespace.end());
|
const METHOD& method = name_method.second;
|
||||||
instRetVal.type1 = expandedClassName;
|
METHOD instMethod = method;
|
||||||
}
|
instMethod.argLists = expandArgumentListsTemplate(method.argLists,
|
||||||
if(retVal.type2 == templateArg) {
|
templateArg, instName, expandedClassNamespace, expandedClassName);
|
||||||
instRetVal.namespaces2.assign(instName.begin(), instName.end()-1);
|
instMethod.returnVals.clear();
|
||||||
instRetVal.type2 = instName.back();
|
BOOST_FOREACH(const ReturnValue& retVal, method.returnVals) {
|
||||||
} else if(retVal.type1 == "This") {
|
ReturnValue instRetVal = retVal;
|
||||||
instRetVal.namespaces2.assign(expandedClassNamespace.begin(), expandedClassNamespace.end());
|
if (retVal.type1 == templateArg) {
|
||||||
instRetVal.type2 = expandedClassName;
|
instRetVal.namespaces1.assign(instName.begin(), instName.end() - 1);
|
||||||
}
|
instRetVal.type1 = instName.back();
|
||||||
instMethod.returnVals.push_back(instRetVal);
|
} else if (retVal.type1 == "This") {
|
||||||
}
|
instRetVal.namespaces1.assign(expandedClassNamespace.begin(),
|
||||||
result.insert(make_pair(name_method.first, instMethod));
|
expandedClassNamespace.end());
|
||||||
}
|
instRetVal.type1 = expandedClassName;
|
||||||
return result;
|
}
|
||||||
}
|
if (retVal.type2 == templateArg) {
|
||||||
|
instRetVal.namespaces2.assign(instName.begin(), instName.end() - 1);
|
||||||
/* ************************************************************************* */
|
instRetVal.type2 = instName.back();
|
||||||
Class expandClassTemplate(const Class& cls, const string& templateArg, const vector<string>& instName, const std::vector<string>& expandedClassNamespace, const string& expandedClassName) {
|
} else if (retVal.type1 == "This") {
|
||||||
Class inst;
|
instRetVal.namespaces2.assign(expandedClassNamespace.begin(),
|
||||||
inst.name = cls.name;
|
expandedClassNamespace.end());
|
||||||
inst.templateArgs = cls.templateArgs;
|
instRetVal.type2 = expandedClassName;
|
||||||
inst.typedefName = cls.typedefName;
|
}
|
||||||
inst.isVirtual = cls.isVirtual;
|
instMethod.returnVals.push_back(instRetVal);
|
||||||
|
}
|
||||||
|
result.insert(make_pair(name_method.first, instMethod));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ************************************************************************* */
|
||||||
|
Class expandClassTemplate(const Class& cls, const string& templateArg,
|
||||||
|
const vector<string>& instName,
|
||||||
|
const std::vector<string>& expandedClassNamespace,
|
||||||
|
const string& expandedClassName) {
|
||||||
|
Class inst;
|
||||||
|
inst.name = cls.name;
|
||||||
|
inst.templateArgs = cls.templateArgs;
|
||||||
|
inst.typedefName = cls.typedefName;
|
||||||
|
inst.isVirtual = cls.isVirtual;
|
||||||
inst.isSerializable = cls.isSerializable;
|
inst.isSerializable = cls.isSerializable;
|
||||||
inst.qualifiedParent = cls.qualifiedParent;
|
inst.qualifiedParent = cls.qualifiedParent;
|
||||||
inst.methods = expandMethodTemplate(cls.methods, templateArg, instName, expandedClassNamespace, expandedClassName);
|
inst.methods = expandMethodTemplate(cls.methods, templateArg, instName,
|
||||||
inst.static_methods = expandMethodTemplate(cls.static_methods, templateArg, instName, expandedClassNamespace, expandedClassName);
|
expandedClassNamespace, expandedClassName);
|
||||||
inst.namespaces = cls.namespaces;
|
inst.static_methods = expandMethodTemplate(cls.static_methods, templateArg,
|
||||||
inst.constructor = cls.constructor;
|
instName, expandedClassNamespace, expandedClassName);
|
||||||
inst.constructor.args_list = expandArgumentListsTemplate(cls.constructor.args_list, templateArg, instName, expandedClassNamespace, expandedClassName);
|
inst.namespaces = cls.namespaces;
|
||||||
inst.constructor.name = inst.name;
|
inst.constructor = cls.constructor;
|
||||||
inst.deconstructor = cls.deconstructor;
|
inst.constructor.args_list = expandArgumentListsTemplate(
|
||||||
inst.deconstructor.name = inst.name;
|
cls.constructor.args_list, templateArg, instName, expandedClassNamespace,
|
||||||
inst.verbose_ = cls.verbose_;
|
expandedClassName);
|
||||||
return inst;
|
inst.constructor.name = inst.name;
|
||||||
}
|
inst.deconstructor = cls.deconstructor;
|
||||||
|
inst.deconstructor.name = inst.name;
|
||||||
/* ************************************************************************* */
|
inst.verbose_ = cls.verbose_;
|
||||||
vector<Class> Class::expandTemplate(const string& templateArg, const vector<vector<string> >& instantiations) const {
|
return inst;
|
||||||
vector<Class> result;
|
}
|
||||||
BOOST_FOREACH(const vector<string>& instName, instantiations) {
|
|
||||||
const string expandedName = name + instName.back();
|
/* ************************************************************************* */
|
||||||
Class inst = expandClassTemplate(*this, templateArg, instName, this->namespaces, expandedName);
|
vector<Class> Class::expandTemplate(const string& templateArg,
|
||||||
inst.name = expandedName;
|
const vector<vector<string> >& instantiations) const {
|
||||||
inst.templateArgs.clear();
|
vector<Class> result;
|
||||||
inst.typedefName = qualifiedName("::") + "<" + wrap::qualifiedName("::", instName) + ">";
|
BOOST_FOREACH(const vector<string>& instName, instantiations) {
|
||||||
result.push_back(inst);
|
const string expandedName = name + instName.back();
|
||||||
}
|
Class inst = expandClassTemplate(*this, templateArg, instName,
|
||||||
return result;
|
this->namespaces, expandedName);
|
||||||
}
|
inst.name = expandedName;
|
||||||
|
inst.templateArgs.clear();
|
||||||
/* ************************************************************************* */
|
inst.typedefName = qualifiedName("::") + "<"
|
||||||
Class Class::expandTemplate(const string& templateArg, const vector<string>& instantiation, const std::vector<string>& expandedClassNamespace, const string& expandedClassName) const {
|
+ wrap::qualifiedName("::", instName) + ">";
|
||||||
return expandClassTemplate(*this, templateArg, instantiation, expandedClassNamespace, expandedClassName);
|
result.push_back(inst);
|
||||||
}
|
}
|
||||||
|
return result;
|
||||||
/* ************************************************************************* */
|
}
|
||||||
std::string Class::getTypedef() const {
|
|
||||||
string result;
|
/* ************************************************************************* */
|
||||||
BOOST_FOREACH(const string& namesp, namespaces) {
|
Class Class::expandTemplate(const string& templateArg,
|
||||||
result += ("namespace " + namesp + " { ");
|
const vector<string>& instantiation,
|
||||||
}
|
const std::vector<string>& expandedClassNamespace,
|
||||||
result += ("typedef " + typedefName + " " + name + ";");
|
const string& expandedClassName) const {
|
||||||
for (size_t i = 0; i<namespaces.size(); ++i) {
|
return expandClassTemplate(*this, templateArg, instantiation,
|
||||||
result += " }";
|
expandedClassNamespace, expandedClassName);
|
||||||
}
|
}
|
||||||
return result;
|
|
||||||
}
|
/* ************************************************************************* */
|
||||||
|
std::string Class::getTypedef() const {
|
||||||
/* ************************************************************************* */
|
string result;
|
||||||
|
BOOST_FOREACH(const string& namesp, namespaces) {
|
||||||
|
result += ("namespace " + namesp + " { ");
|
||||||
|
}
|
||||||
|
result += ("typedef " + typedefName + " " + name + ";");
|
||||||
|
for (size_t i = 0; i < namespaces.size(); ++i) {
|
||||||
|
result += " }";
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ************************************************************************* */
|
||||||
|
|
||||||
void Class::comment_fragment(FileWriter& proxyFile) const {
|
void Class::comment_fragment(FileWriter& proxyFile) const {
|
||||||
proxyFile.oss << "%class " << name
|
proxyFile.oss << "%class " << name << ", see Doxygen page for details\n";
|
||||||
<< ", see Doxygen page for details\n";
|
|
||||||
proxyFile.oss
|
proxyFile.oss
|
||||||
<< "%at http://research.cc.gatech.edu/borg/sites/edu.borg/html/index.html\n";
|
<< "%at http://research.cc.gatech.edu/borg/sites/edu.borg/html/index.html\n";
|
||||||
|
|
||||||
|
@ -396,15 +445,17 @@ void Class::comment_fragment(FileWriter& proxyFile) const {
|
||||||
if (hasSerialization) {
|
if (hasSerialization) {
|
||||||
proxyFile.oss << "%\n%-------Serialization Interface-------\n";
|
proxyFile.oss << "%\n%-------Serialization Interface-------\n";
|
||||||
proxyFile.oss << "%string_serialize() : returns string\n";
|
proxyFile.oss << "%string_serialize() : returns string\n";
|
||||||
proxyFile.oss << "%string_deserialize(string serialized) : returns " << this->name << "\n";
|
proxyFile.oss << "%string_deserialize(string serialized) : returns "
|
||||||
|
<< this->name << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
proxyFile.oss << "%\n";
|
proxyFile.oss << "%\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
void Class::serialization_fragments(FileWriter& proxyFile, FileWriter& wrapperFile,
|
void Class::serialization_fragments(FileWriter& proxyFile,
|
||||||
const std::string& wrapperName, std::vector<std::string>& functionNames) const {
|
FileWriter& wrapperFile, const std::string& wrapperName,
|
||||||
|
std::vector<std::string>& functionNames) const {
|
||||||
|
|
||||||
//void Point3_string_serialize_17(int nargout, mxArray *out[], int nargin, const mxArray *in[])
|
//void Point3_string_serialize_17(int nargout, mxArray *out[], int nargin, const mxArray *in[])
|
||||||
//{
|
//{
|
||||||
|
@ -418,30 +469,34 @@ void Class::serialization_fragments(FileWriter& proxyFile, FileWriter& wrapperFi
|
||||||
//}
|
//}
|
||||||
|
|
||||||
int serialize_id = functionNames.size();
|
int serialize_id = functionNames.size();
|
||||||
const string
|
const string matlabQualName = qualifiedName("."), matlabUniqueName =
|
||||||
matlabQualName = qualifiedName("."),
|
qualifiedName(), cppClassName = qualifiedName("::");
|
||||||
matlabUniqueName = qualifiedName(),
|
const string wrapFunctionNameSerialize = matlabUniqueName
|
||||||
cppClassName = qualifiedName("::");
|
+ "_string_serialize_" + boost::lexical_cast<string>(serialize_id);
|
||||||
const string wrapFunctionNameSerialize = matlabUniqueName + "_string_serialize_" + boost::lexical_cast<string>(serialize_id);
|
|
||||||
functionNames.push_back(wrapFunctionNameSerialize);
|
functionNames.push_back(wrapFunctionNameSerialize);
|
||||||
|
|
||||||
// call
|
// call
|
||||||
//void Point3_string_serialize_17(int nargout, mxArray *out[], int nargin, const mxArray *in[])
|
//void Point3_string_serialize_17(int nargout, mxArray *out[], int nargin, const mxArray *in[])
|
||||||
wrapperFile.oss << "void " << wrapFunctionNameSerialize << "(int nargout, mxArray *out[], int nargin, const mxArray *in[])\n";
|
wrapperFile.oss << "void " << wrapFunctionNameSerialize
|
||||||
|
<< "(int nargout, mxArray *out[], int nargin, const mxArray *in[])\n";
|
||||||
wrapperFile.oss << "{\n";
|
wrapperFile.oss << "{\n";
|
||||||
wrapperFile.oss << " typedef boost::shared_ptr<" << cppClassName << "> Shared;" << endl;
|
wrapperFile.oss << " typedef boost::shared_ptr<" << cppClassName
|
||||||
|
<< "> Shared;" << endl;
|
||||||
|
|
||||||
// check arguments - for serialize, no arguments
|
// check arguments - for serialize, no arguments
|
||||||
// example: checkArguments("string_serialize",nargout,nargin-1,0);
|
// example: checkArguments("string_serialize",nargout,nargin-1,0);
|
||||||
wrapperFile.oss << " checkArguments(\"string_serialize\",nargout,nargin-1,0);\n";
|
wrapperFile.oss
|
||||||
|
<< " checkArguments(\"string_serialize\",nargout,nargin-1,0);\n";
|
||||||
|
|
||||||
// get class pointer
|
// get class pointer
|
||||||
// example: Shared obj = unwrap_shared_ptr<Point3>(in[0], "ptr_Point3");
|
// example: Shared obj = unwrap_shared_ptr<Point3>(in[0], "ptr_Point3");
|
||||||
wrapperFile.oss << " Shared obj = unwrap_shared_ptr<" << cppClassName << ">(in[0], \"ptr_" << matlabUniqueName << "\");" << endl;
|
wrapperFile.oss << " Shared obj = unwrap_shared_ptr<" << cppClassName
|
||||||
|
<< ">(in[0], \"ptr_" << matlabUniqueName << "\");" << endl;
|
||||||
|
|
||||||
// Serialization boilerplate
|
// Serialization boilerplate
|
||||||
wrapperFile.oss << " std::ostringstream out_archive_stream;\n";
|
wrapperFile.oss << " std::ostringstream out_archive_stream;\n";
|
||||||
wrapperFile.oss << " boost::archive::text_oarchive out_archive(out_archive_stream);\n";
|
wrapperFile.oss
|
||||||
|
<< " boost::archive::text_oarchive out_archive(out_archive_stream);\n";
|
||||||
wrapperFile.oss << " out_archive << *obj;\n";
|
wrapperFile.oss << " out_archive << *obj;\n";
|
||||||
wrapperFile.oss << " out[0] = wrap< string >(out_archive_stream.str());\n";
|
wrapperFile.oss << " out[0] = wrap< string >(out_archive_stream.str());\n";
|
||||||
|
|
||||||
|
@ -459,13 +514,19 @@ void Class::serialization_fragments(FileWriter& proxyFile, FileWriter& wrapperFi
|
||||||
// end
|
// end
|
||||||
// end
|
// end
|
||||||
|
|
||||||
proxyFile.oss << " function varargout = string_serialize(this, varargin)\n";
|
proxyFile.oss
|
||||||
proxyFile.oss << " % STRING_SERIALIZE usage: string_serialize() : returns string\n";
|
<< " function varargout = string_serialize(this, varargin)\n";
|
||||||
proxyFile.oss << " % Doxygen can be found at http://research.cc.gatech.edu/borg/sites/edu.borg/html/index.html\n";
|
proxyFile.oss
|
||||||
|
<< " % STRING_SERIALIZE usage: string_serialize() : returns string\n";
|
||||||
|
proxyFile.oss
|
||||||
|
<< " % Doxygen can be found at http://research.cc.gatech.edu/borg/sites/edu.borg/html/index.html\n";
|
||||||
proxyFile.oss << " if length(varargin) == 0\n";
|
proxyFile.oss << " if length(varargin) == 0\n";
|
||||||
proxyFile.oss << " varargout{1} = " << wrapperName << "(" << boost::lexical_cast<string>(serialize_id) << ", this, varargin{:});\n";
|
proxyFile.oss << " varargout{1} = " << wrapperName << "("
|
||||||
|
<< boost::lexical_cast<string>(serialize_id) << ", this, varargin{:});\n";
|
||||||
proxyFile.oss << " else\n";
|
proxyFile.oss << " else\n";
|
||||||
proxyFile.oss << " error('Arguments do not match any overload of function " << matlabQualName << ".string_serialize');\n";
|
proxyFile.oss
|
||||||
|
<< " error('Arguments do not match any overload of function "
|
||||||
|
<< matlabQualName << ".string_serialize');\n";
|
||||||
proxyFile.oss << " end\n";
|
proxyFile.oss << " end\n";
|
||||||
proxyFile.oss << " end\n\n";
|
proxyFile.oss << " end\n\n";
|
||||||
|
|
||||||
|
@ -476,14 +537,16 @@ void Class::serialization_fragments(FileWriter& proxyFile, FileWriter& wrapperFi
|
||||||
// end
|
// end
|
||||||
|
|
||||||
proxyFile.oss << " function sobj = saveobj(obj)\n";
|
proxyFile.oss << " function sobj = saveobj(obj)\n";
|
||||||
proxyFile.oss << " % SAVEOBJ Saves the object to a matlab-readable format\n";
|
proxyFile.oss
|
||||||
|
<< " % SAVEOBJ Saves the object to a matlab-readable format\n";
|
||||||
proxyFile.oss << " sobj = obj.string_serialize();\n";
|
proxyFile.oss << " sobj = obj.string_serialize();\n";
|
||||||
proxyFile.oss << " end\n";
|
proxyFile.oss << " end\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
void Class::deserialization_fragments(FileWriter& proxyFile, FileWriter& wrapperFile,
|
void Class::deserialization_fragments(FileWriter& proxyFile,
|
||||||
const std::string& wrapperName, std::vector<std::string>& functionNames) const {
|
FileWriter& wrapperFile, const std::string& wrapperName,
|
||||||
|
std::vector<std::string>& functionNames) const {
|
||||||
//void Point3_string_deserialize_18(int nargout, mxArray *out[], int nargin, const mxArray *in[])
|
//void Point3_string_deserialize_18(int nargout, mxArray *out[], int nargin, const mxArray *in[])
|
||||||
//{
|
//{
|
||||||
// typedef boost::shared_ptr<Point3> Shared;
|
// typedef boost::shared_ptr<Point3> Shared;
|
||||||
|
@ -495,32 +558,36 @@ void Class::deserialization_fragments(FileWriter& proxyFile, FileWriter& wrapper
|
||||||
// in_archive >> *output;
|
// in_archive >> *output;
|
||||||
// out[0] = wrap_shared_ptr(output,"Point3", false);
|
// out[0] = wrap_shared_ptr(output,"Point3", false);
|
||||||
//}
|
//}
|
||||||
int deserialize_id = functionNames.size();
|
int deserialize_id = functionNames.size();
|
||||||
const string
|
const string matlabQualName = qualifiedName("."), matlabUniqueName =
|
||||||
matlabQualName = qualifiedName("."),
|
qualifiedName(), cppClassName = qualifiedName("::");
|
||||||
matlabUniqueName = qualifiedName(),
|
const string wrapFunctionNameDeserialize = matlabUniqueName
|
||||||
cppClassName = qualifiedName("::");
|
+ "_string_deserialize_" + boost::lexical_cast<string>(deserialize_id);
|
||||||
const string wrapFunctionNameDeserialize = matlabUniqueName + "_string_deserialize_" + boost::lexical_cast<string>(deserialize_id);
|
functionNames.push_back(wrapFunctionNameDeserialize);
|
||||||
functionNames.push_back(wrapFunctionNameDeserialize);
|
|
||||||
|
|
||||||
// call
|
// call
|
||||||
wrapperFile.oss << "void " << wrapFunctionNameDeserialize << "(int nargout, mxArray *out[], int nargin, const mxArray *in[])\n";
|
wrapperFile.oss << "void " << wrapFunctionNameDeserialize
|
||||||
wrapperFile.oss << "{\n";
|
<< "(int nargout, mxArray *out[], int nargin, const mxArray *in[])\n";
|
||||||
wrapperFile.oss << " typedef boost::shared_ptr<" << cppClassName << "> Shared;" << endl;
|
wrapperFile.oss << "{\n";
|
||||||
|
wrapperFile.oss << " typedef boost::shared_ptr<" << cppClassName
|
||||||
|
<< "> Shared;" << endl;
|
||||||
|
|
||||||
// check arguments - for deserialize, 1 string argument
|
// check arguments - for deserialize, 1 string argument
|
||||||
wrapperFile.oss << " checkArguments(\"" << matlabUniqueName << ".string_deserialize\",nargout,nargin,1);\n";
|
wrapperFile.oss << " checkArguments(\"" << matlabUniqueName
|
||||||
|
<< ".string_deserialize\",nargout,nargin,1);\n";
|
||||||
|
|
||||||
// string argument with deserialization boilerplate
|
// string argument with deserialization boilerplate
|
||||||
wrapperFile.oss << " string serialized = unwrap< string >(in[0]);\n";
|
wrapperFile.oss << " string serialized = unwrap< string >(in[0]);\n";
|
||||||
wrapperFile.oss << " std::istringstream in_archive_stream(serialized);\n";
|
wrapperFile.oss << " std::istringstream in_archive_stream(serialized);\n";
|
||||||
wrapperFile.oss << " boost::archive::text_iarchive in_archive(in_archive_stream);\n";
|
wrapperFile.oss
|
||||||
wrapperFile.oss << " Shared output(new " << cppClassName << "());\n";
|
<< " boost::archive::text_iarchive in_archive(in_archive_stream);\n";
|
||||||
wrapperFile.oss << " in_archive >> *output;\n";
|
wrapperFile.oss << " Shared output(new " << cppClassName << "());\n";
|
||||||
wrapperFile.oss << " out[0] = wrap_shared_ptr(output,\"" << matlabQualName << "\", false);\n";
|
wrapperFile.oss << " in_archive >> *output;\n";
|
||||||
wrapperFile.oss << "}\n";
|
wrapperFile.oss << " out[0] = wrap_shared_ptr(output,\"" << matlabQualName
|
||||||
|
<< "\", false);\n";
|
||||||
|
wrapperFile.oss << "}\n";
|
||||||
|
|
||||||
// Generate matlab function
|
// Generate matlab function
|
||||||
// function varargout = string_deserialize(varargin)
|
// function varargout = string_deserialize(varargin)
|
||||||
// % STRING_DESERIALIZE usage: string_deserialize() : returns Point3
|
// % STRING_DESERIALIZE usage: string_deserialize() : returns Point3
|
||||||
// % 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
|
||||||
|
@ -531,32 +598,40 @@ void Class::deserialization_fragments(FileWriter& proxyFile, FileWriter& wrapper
|
||||||
// end
|
// end
|
||||||
// end
|
// end
|
||||||
|
|
||||||
proxyFile.oss << " function varargout = string_deserialize(varargin)\n";
|
proxyFile.oss << " function varargout = string_deserialize(varargin)\n";
|
||||||
proxyFile.oss << " % STRING_DESERIALIZE usage: string_deserialize() : returns " << matlabQualName << "\n";
|
proxyFile.oss
|
||||||
proxyFile.oss << " % Doxygen can be found at http://research.cc.gatech.edu/borg/sites/edu.borg/html/index.html\n";
|
<< " % STRING_DESERIALIZE usage: string_deserialize() : returns "
|
||||||
proxyFile.oss << " if length(varargin) == 1\n";
|
<< matlabQualName << "\n";
|
||||||
proxyFile.oss << " varargout{1} = " << wrapperName << "(" << boost::lexical_cast<string>(deserialize_id) << ", varargin{:});\n";
|
proxyFile.oss
|
||||||
proxyFile.oss << " else\n";
|
<< " % Doxygen can be found at http://research.cc.gatech.edu/borg/sites/edu.borg/html/index.html\n";
|
||||||
proxyFile.oss << " error('Arguments do not match any overload of function " << matlabQualName << ".string_deserialize');\n";
|
proxyFile.oss << " if length(varargin) == 1\n";
|
||||||
proxyFile.oss << " end\n";
|
proxyFile.oss << " varargout{1} = " << wrapperName << "("
|
||||||
proxyFile.oss << " end\n\n";
|
<< boost::lexical_cast<string>(deserialize_id) << ", varargin{:});\n";
|
||||||
|
proxyFile.oss << " else\n";
|
||||||
|
proxyFile.oss
|
||||||
|
<< " error('Arguments do not match any overload of function "
|
||||||
|
<< matlabQualName << ".string_deserialize');\n";
|
||||||
|
proxyFile.oss << " end\n";
|
||||||
|
proxyFile.oss << " end\n\n";
|
||||||
|
|
||||||
|
// Generate matlab load function
|
||||||
// Generate matlab load function
|
|
||||||
// function obj = loadobj(sobj)
|
// function obj = loadobj(sobj)
|
||||||
// % LOADOBJ Saves the object to a matlab-readable format
|
// % LOADOBJ Saves the object to a matlab-readable format
|
||||||
// obj = Point3.string_deserialize(sobj);
|
// obj = Point3.string_deserialize(sobj);
|
||||||
// end
|
// end
|
||||||
|
|
||||||
proxyFile.oss << " function obj = loadobj(sobj)\n";
|
proxyFile.oss << " function obj = loadobj(sobj)\n";
|
||||||
proxyFile.oss << " % LOADOBJ Saves the object to a matlab-readable format\n";
|
proxyFile.oss
|
||||||
proxyFile.oss << " obj = " << matlabQualName << ".string_deserialize(sobj);\n";
|
<< " % LOADOBJ Saves the object to a matlab-readable format\n";
|
||||||
proxyFile.oss << " end" << endl;
|
proxyFile.oss << " obj = " << matlabQualName
|
||||||
|
<< ".string_deserialize(sobj);\n";
|
||||||
|
proxyFile.oss << " end" << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
std::string Class::getSerializationExport() const {
|
std::string Class::getSerializationExport() const {
|
||||||
//BOOST_CLASS_EXPORT_GUID(gtsam::SharedDiagonal, "gtsamSharedDiagonal");
|
//BOOST_CLASS_EXPORT_GUID(gtsam::SharedDiagonal, "gtsamSharedDiagonal");
|
||||||
return "BOOST_CLASS_EXPORT_GUID(" + qualifiedName("::") + ", \"" + qualifiedName() + "\");";
|
return "BOOST_CLASS_EXPORT_GUID(" + qualifiedName("::") + ", \""
|
||||||
|
+ qualifiedName() + "\");";
|
||||||
}
|
}
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
|
|
|
@ -28,7 +28,6 @@
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace wrap;
|
using namespace wrap;
|
||||||
|
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
void StaticMethod::addOverload(bool verbose, const std::string& name,
|
void StaticMethod::addOverload(bool verbose, const std::string& name,
|
||||||
const ArgumentList& args, const ReturnValue& retVal) {
|
const ArgumentList& args, const ReturnValue& retVal) {
|
||||||
|
@ -39,144 +38,149 @@ void StaticMethod::addOverload(bool verbose, const std::string& name,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
void StaticMethod::proxy_wrapper_fragments(FileWriter& proxyFile, FileWriter& wrapperFile,
|
void StaticMethod::proxy_wrapper_fragments(FileWriter& proxyFile,
|
||||||
const string& cppClassName,
|
FileWriter& wrapperFile, const string& cppClassName,
|
||||||
const std::string& matlabQualName,
|
const std::string& matlabQualName, const std::string& matlabUniqueName,
|
||||||
const std::string& matlabUniqueName,
|
const string& wrapperName, const TypeAttributesTable& typeAttributes,
|
||||||
const string& wrapperName,
|
vector<string>& functionNames) const {
|
||||||
const TypeAttributesTable& typeAttributes,
|
|
||||||
vector<string>& functionNames) const {
|
|
||||||
|
|
||||||
string upperName = name; upperName[0] = std::toupper(upperName[0], std::locale());
|
string upperName = name;
|
||||||
|
upperName[0] = std::toupper(upperName[0], std::locale());
|
||||||
|
|
||||||
proxyFile.oss << " function varargout = " << upperName << "(varargin)\n";
|
proxyFile.oss << " function varargout = " << upperName << "(varargin)\n";
|
||||||
//Comments for documentation
|
//Comments for documentation
|
||||||
string up_name = boost::to_upper_copy(name);
|
string up_name = boost::to_upper_copy(name);
|
||||||
proxyFile.oss << " % " << up_name << " usage:";
|
proxyFile.oss << " % " << up_name << " usage:";
|
||||||
unsigned int argLCount = 0;
|
unsigned int argLCount = 0;
|
||||||
BOOST_FOREACH(ArgumentList argList, argLists)
|
BOOST_FOREACH(ArgumentList argList, argLists) {
|
||||||
{
|
proxyFile.oss << " " << name << "(";
|
||||||
proxyFile.oss << " " << name << "(";
|
unsigned int i = 0;
|
||||||
unsigned int i = 0;
|
BOOST_FOREACH(const Argument& arg, argList) {
|
||||||
BOOST_FOREACH(const Argument& arg, argList)
|
if (i != argList.size() - 1)
|
||||||
{
|
proxyFile.oss << arg.type << " " << arg.name << ", ";
|
||||||
if(i != argList.size()-1)
|
else
|
||||||
proxyFile.oss << arg.type << " " << arg.name << ", ";
|
proxyFile.oss << arg.type << " " << arg.name;
|
||||||
else
|
i++;
|
||||||
proxyFile.oss << arg.type << " " << arg.name;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
if(argLCount != argLists.size()-1)
|
|
||||||
proxyFile.oss << "), ";
|
|
||||||
else
|
|
||||||
proxyFile.oss << ") : returns " << returnVals[0].return_type(false, returnVals[0].pair) << endl;
|
|
||||||
argLCount++;
|
|
||||||
}
|
}
|
||||||
|
if (argLCount != argLists.size() - 1)
|
||||||
|
proxyFile.oss << "), ";
|
||||||
|
else
|
||||||
|
proxyFile.oss << ") : returns "
|
||||||
|
<< returnVals[0].return_type(false, returnVals[0].pair) << endl;
|
||||||
|
argLCount++;
|
||||||
|
}
|
||||||
|
|
||||||
proxyFile.oss << " % " << "Doxygen can be found at http://research.cc.gatech.edu/borg/sites/edu.borg/html/index.html" << endl;
|
proxyFile.oss << " % "
|
||||||
|
<< "Doxygen can be found at http://research.cc.gatech.edu/borg/sites/edu.borg/html/index.html"
|
||||||
|
<< endl;
|
||||||
proxyFile.oss << " % " << "" << endl;
|
proxyFile.oss << " % " << "" << endl;
|
||||||
proxyFile.oss << " % " << "Usage" << endl;
|
proxyFile.oss << " % " << "Usage" << endl;
|
||||||
BOOST_FOREACH(ArgumentList argList, argLists)
|
BOOST_FOREACH(ArgumentList argList, argLists) {
|
||||||
{
|
proxyFile.oss << " % " << up_name << "(";
|
||||||
proxyFile.oss << " % " << up_name << "(";
|
unsigned int i = 0;
|
||||||
unsigned int i = 0;
|
BOOST_FOREACH(const Argument& arg, argList) {
|
||||||
BOOST_FOREACH(const Argument& arg, argList)
|
if (i != argList.size() - 1)
|
||||||
{
|
proxyFile.oss << arg.type << " " << arg.name << ", ";
|
||||||
if(i != argList.size()-1)
|
else
|
||||||
proxyFile.oss << arg.type << " " << arg.name << ", ";
|
proxyFile.oss << arg.type << " " << arg.name;
|
||||||
else
|
i++;
|
||||||
proxyFile.oss << arg.type << " " << arg.name;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
proxyFile.oss << ")" << endl;
|
|
||||||
}
|
}
|
||||||
|
proxyFile.oss << ")" << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (size_t overload = 0; overload < argLists.size(); ++overload) {
|
||||||
for(size_t overload = 0; overload < argLists.size(); ++overload) {
|
|
||||||
const ArgumentList& args = argLists[overload];
|
const ArgumentList& args = argLists[overload];
|
||||||
const ReturnValue& returnVal = returnVals[overload];
|
const ReturnValue& returnVal = returnVals[overload];
|
||||||
size_t nrArgs = args.size();
|
size_t nrArgs = args.size();
|
||||||
|
|
||||||
const int id = (int)functionNames.size();
|
const int id = (int) functionNames.size();
|
||||||
|
|
||||||
// Output proxy matlab code
|
// Output proxy matlab code
|
||||||
|
|
||||||
// check for number of arguments...
|
// check for number of arguments...
|
||||||
proxyFile.oss << " " << (overload==0?"":"else") << "if length(varargin) == " << nrArgs;
|
proxyFile.oss << " " << (overload == 0 ? "" : "else")
|
||||||
if (nrArgs>0) proxyFile.oss << " && ";
|
<< "if length(varargin) == " << nrArgs;
|
||||||
|
if (nrArgs > 0)
|
||||||
|
proxyFile.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) proxyFile.oss << " && ";
|
if (!first)
|
||||||
proxyFile.oss << "isa(varargin{" << i+1 << "},'" << args[i].matlabClass(".") << "')";
|
proxyFile.oss << " && ";
|
||||||
first=false;
|
proxyFile.oss << "isa(varargin{" << i + 1 << "},'"
|
||||||
|
<< args[i].matlabClass(".") << "')";
|
||||||
|
first = false;
|
||||||
}
|
}
|
||||||
proxyFile.oss << "\n";
|
proxyFile.oss << "\n";
|
||||||
|
|
||||||
// output call to C++ wrapper
|
// output call to C++ wrapper
|
||||||
string output;
|
string output;
|
||||||
if(returnVal.isPair)
|
if (returnVal.isPair)
|
||||||
output = "[ varargout{1} varargout{2} ] = ";
|
output = "[ varargout{1} varargout{2} ] = ";
|
||||||
else if(returnVal.category1 == ReturnValue::VOID)
|
else if (returnVal.category1 == ReturnValue::VOID)
|
||||||
output = "";
|
output = "";
|
||||||
else
|
else
|
||||||
output = "varargout{1} = ";
|
output = "varargout{1} = ";
|
||||||
proxyFile.oss << " " << output << wrapperName << "(" << id << ", varargin{:});\n";
|
proxyFile.oss << " " << output << wrapperName << "(" << id
|
||||||
|
<< ", varargin{:});\n";
|
||||||
|
|
||||||
// Output C++ wrapper code
|
// Output C++ wrapper code
|
||||||
|
|
||||||
const string wrapFunctionName = wrapper_fragment(
|
const string wrapFunctionName = wrapper_fragment(wrapperFile, cppClassName,
|
||||||
wrapperFile, cppClassName, matlabUniqueName, (int)overload, id, typeAttributes);
|
matlabUniqueName, (int) overload, id, typeAttributes);
|
||||||
|
|
||||||
// Add to function list
|
// Add to function list
|
||||||
functionNames.push_back(wrapFunctionName);
|
functionNames.push_back(wrapFunctionName);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
proxyFile.oss << " else\n";
|
proxyFile.oss << " else\n";
|
||||||
proxyFile.oss << " error('Arguments do not match any overload of function " <<
|
proxyFile.oss
|
||||||
matlabQualName << "." << upperName << "');" << endl;
|
<< " error('Arguments do not match any overload of function "
|
||||||
|
<< matlabQualName << "." << upperName << "');" << endl;
|
||||||
|
|
||||||
proxyFile.oss << " end\n";
|
proxyFile.oss << " end\n";
|
||||||
proxyFile.oss << " end\n";
|
proxyFile.oss << " end\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
string StaticMethod::wrapper_fragment(FileWriter& file,
|
string StaticMethod::wrapper_fragment(FileWriter& file,
|
||||||
const string& cppClassName,
|
const string& cppClassName, const string& matlabUniqueName, int overload,
|
||||||
const string& matlabUniqueName,
|
int id, const TypeAttributesTable& typeAttributes) const {
|
||||||
int overload,
|
|
||||||
int id,
|
|
||||||
const TypeAttributesTable& typeAttributes) const {
|
|
||||||
|
|
||||||
// generate code
|
// generate code
|
||||||
|
|
||||||
const string wrapFunctionName = matlabUniqueName + "_" + name + "_" + boost::lexical_cast<string>(id);
|
const string wrapFunctionName = matlabUniqueName + "_" + name + "_"
|
||||||
|
+ boost::lexical_cast<string>(id);
|
||||||
|
|
||||||
const ArgumentList& args = argLists[overload];
|
const ArgumentList& args = argLists[overload];
|
||||||
const ReturnValue& returnVal = returnVals[overload];
|
const ReturnValue& returnVal = returnVals[overload];
|
||||||
|
|
||||||
// call
|
// call
|
||||||
file.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
|
||||||
file.oss << "{\n";
|
file.oss << "{\n";
|
||||||
|
|
||||||
returnVal.wrapTypeUnwrap(file);
|
returnVal.wrapTypeUnwrap(file);
|
||||||
|
|
||||||
file.oss << " typedef boost::shared_ptr<" << cppClassName << "> Shared;" << endl;
|
file.oss << " typedef boost::shared_ptr<" << cppClassName << "> Shared;"
|
||||||
|
<< endl;
|
||||||
|
|
||||||
// check arguments
|
// check arguments
|
||||||
// NOTE: for static functions, there is no object passed
|
// NOTE: for static functions, there is no object passed
|
||||||
file.oss << " checkArguments(\"" << matlabUniqueName << "." << name << "\",nargout,nargin," << args.size() << ");\n";
|
file.oss << " checkArguments(\"" << matlabUniqueName << "." << name
|
||||||
|
<< "\",nargout,nargin," << args.size() << ");\n";
|
||||||
|
|
||||||
// unwrap arguments, see Argument.cpp
|
// unwrap arguments, see Argument.cpp
|
||||||
args.matlab_unwrap(file,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(cppClassName+"::"+name+"("+args.names()+")", file, typeAttributes);
|
returnVal.wrap_result(cppClassName + "::" + name + "(" + args.names() + ")",
|
||||||
|
file, typeAttributes);
|
||||||
else
|
else
|
||||||
file.oss << cppClassName+"::"+name+"("+args.names()+");\n";
|
file.oss << cppClassName + "::" + name + "(" + args.names() + ");\n";
|
||||||
|
|
||||||
// finish
|
// finish
|
||||||
file.oss << "}\n";
|
file.oss << "}\n";
|
||||||
|
|
Loading…
Reference in New Issue