Code cleanup and comments
parent
c3ed90c792
commit
ce12f3d255
|
@ -13,6 +13,7 @@
|
|||
* @file Argument.ccp
|
||||
* @author Frank Dellaert
|
||||
* @author Andrew Melim
|
||||
* @author Richard Roberts
|
||||
**/
|
||||
|
||||
#include <iostream>
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
* @brief arguments to constructors and methods
|
||||
* @author Frank Dellaert
|
||||
* @author Andrew Melim
|
||||
* @author Richard Roberts
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
* @file Class.cpp
|
||||
* @author Frank Dellaert
|
||||
* @author Andrew Melim
|
||||
* @author Richard Roberts
|
||||
**/
|
||||
|
||||
#include <vector>
|
||||
|
@ -34,7 +35,7 @@ using namespace wrap;
|
|||
|
||||
/* ************************************************************************* */
|
||||
void Class::matlab_proxy(const string& classFile, const string& wrapperName,
|
||||
const ReturnValue::TypeAttributesTable& typeAttributes,
|
||||
const TypeAttributesTable& typeAttributes,
|
||||
FileWriter& wrapperFile, vector<string>& functionNames) const {
|
||||
// open destination classFile
|
||||
FileWriter proxyFile(classFile, verbose_, "%");
|
||||
|
@ -68,7 +69,7 @@ void Class::matlab_proxy(const string& classFile, const string& wrapperName,
|
|||
// Regular constructors
|
||||
BOOST_FOREACH(ArgumentList a, constructor.args_list)
|
||||
{
|
||||
const int id = functionNames.size();
|
||||
const int id = (int)functionNames.size();
|
||||
constructor.proxy_fragment(proxyFile, wrapperName, matlabName, matlabBaseName, id, a);
|
||||
const string wrapFunctionName = constructor.wrapper_fragment(wrapperFile,
|
||||
cppName, matlabName, cppBaseName, id, using_namespaces, a);
|
||||
|
@ -85,7 +86,7 @@ void Class::matlab_proxy(const string& classFile, const string& wrapperName,
|
|||
|
||||
// Deconstructor
|
||||
{
|
||||
const int id = functionNames.size();
|
||||
const int id = (int)functionNames.size();
|
||||
deconstructor.proxy_fragment(proxyFile, wrapperName, matlabName, id);
|
||||
proxyFile.oss << "\n";
|
||||
const string functionName = deconstructor.wrapper_fragment(wrapperFile, cppName, matlabName, id, using_namespaces);
|
||||
|
@ -134,14 +135,14 @@ void Class::pointer_constructor_fragments(FileWriter& proxyFile, FileWriter& wra
|
|||
const string baseMatlabName = wrap::qualifiedName("", qualifiedParent);
|
||||
const string baseCppName = wrap::qualifiedName("::", qualifiedParent);
|
||||
|
||||
const int collectorInsertId = functionNames.size();
|
||||
const int collectorInsertId = (int)functionNames.size();
|
||||
const string collectorInsertFunctionName = matlabName + "_collectorInsertAndMakeBase_" + boost::lexical_cast<string>(collectorInsertId);
|
||||
functionNames.push_back(collectorInsertFunctionName);
|
||||
|
||||
int upcastFromVoidId;
|
||||
string upcastFromVoidFunctionName;
|
||||
if(isVirtual) {
|
||||
upcastFromVoidId = functionNames.size();
|
||||
upcastFromVoidId = (int)functionNames.size();
|
||||
upcastFromVoidFunctionName = matlabName + "_upcastFromVoid_" + boost::lexical_cast<string>(upcastFromVoidId);
|
||||
functionNames.push_back(upcastFromVoidFunctionName);
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
* @brief describe the C++ class that is being wrapped
|
||||
* @author Frank Dellaert
|
||||
* @author Andrew Melim
|
||||
* @author Richard Roberts
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
@ -25,6 +26,7 @@
|
|||
#include "Deconstructor.h"
|
||||
#include "Method.h"
|
||||
#include "StaticMethod.h"
|
||||
#include "TypeAttributesTable.h"
|
||||
|
||||
namespace wrap {
|
||||
|
||||
|
@ -52,7 +54,7 @@ struct Class {
|
|||
bool verbose_; ///< verbose flag
|
||||
|
||||
// And finally MATLAB code is emitted, methods below called by Module::matlab_code
|
||||
void matlab_proxy(const std::string& classFile, const std::string& wrapperName, const ReturnValue::TypeAttributesTable& typeAttributes,
|
||||
void matlab_proxy(const std::string& classFile, const std::string& wrapperName, const TypeAttributesTable& typeAttributes,
|
||||
FileWriter& wrapperFile, std::vector<std::string>& functionNames) const; ///< emit proxy class
|
||||
std::string qualifiedName(const std::string& delim = "") const; ///< creates a namespace-qualified name, optional delimiter
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
* @file Constructor.ccp
|
||||
* @author Frank Dellaert
|
||||
* @author Andrew Melim
|
||||
* @author Richard Roberts
|
||||
**/
|
||||
|
||||
#include <iostream>
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
* @file Constructor.h
|
||||
* @brief class describing a constructor + code generation
|
||||
* @author Frank Dellaert
|
||||
* @author Richard Roberts
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
* @file Deconstructor.ccp
|
||||
* @author Frank Dellaert
|
||||
* @author Andrew Melim
|
||||
* @author Richard Roberts
|
||||
**/
|
||||
|
||||
#include <iostream>
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
* @brief class describing a constructor + code generation
|
||||
* @author Frank Dellaert
|
||||
* @author Andrew Melim
|
||||
* @author Richard Roberts
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
/**
|
||||
* @file Method.ccp
|
||||
* @author Frank Dellaert
|
||||
* @author Richard Roberts
|
||||
**/
|
||||
|
||||
#include <iostream>
|
||||
|
@ -41,7 +42,7 @@ void Method::proxy_wrapper_fragments(FileWriter& proxyFile, FileWriter& wrapperF
|
|||
const string& matlabClassName,
|
||||
const string& wrapperName,
|
||||
const vector<string>& using_namespaces,
|
||||
const ReturnValue::TypeAttributesTable& typeAttributes,
|
||||
const TypeAttributesTable& typeAttributes,
|
||||
vector<string>& functionNames) const {
|
||||
|
||||
proxyFile.oss << " function varargout = " << name << "(this, varargin)\n";
|
||||
|
@ -102,7 +103,7 @@ string Method::wrapper_fragment(FileWriter& file,
|
|||
int overload,
|
||||
int id,
|
||||
const vector<string>& using_namespaces,
|
||||
const ReturnValue::TypeAttributesTable& typeAttributes) const {
|
||||
const TypeAttributesTable& typeAttributes) const {
|
||||
|
||||
// generate code
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
* @file Method.h
|
||||
* @brief describes and generates code for methods
|
||||
* @author Frank Dellaert
|
||||
* @author Richard Roberts
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
@ -22,6 +23,7 @@
|
|||
|
||||
#include "Argument.h"
|
||||
#include "ReturnValue.h"
|
||||
#include "TypeAttributesTable.h"
|
||||
|
||||
namespace wrap {
|
||||
|
||||
|
@ -50,7 +52,7 @@ struct Method {
|
|||
void proxy_wrapper_fragments(FileWriter& proxyFile, FileWriter& wrapperFile,
|
||||
const std::string& cppClassName, const std::string& matlabClassName,
|
||||
const std::string& wrapperName, const std::vector<std::string>& using_namespaces,
|
||||
const ReturnValue::TypeAttributesTable& typeAttributes,
|
||||
const TypeAttributesTable& typeAttributes,
|
||||
std::vector<std::string>& functionNames) const;
|
||||
|
||||
private:
|
||||
|
@ -60,7 +62,7 @@ private:
|
|||
int overload,
|
||||
int id,
|
||||
const std::vector<std::string>& using_namespaces,
|
||||
const ReturnValue::TypeAttributesTable& typeAttributes) const; ///< cpp wrapper
|
||||
const TypeAttributesTable& typeAttributes) const; ///< cpp wrapper
|
||||
};
|
||||
|
||||
} // \namespace wrap
|
||||
|
|
237
wrap/Module.cpp
237
wrap/Module.cpp
|
@ -14,10 +14,12 @@
|
|||
* @author Frank Dellaert
|
||||
* @author Alex Cunningham
|
||||
* @author Andrew Melim
|
||||
* @author Richard Roberts
|
||||
**/
|
||||
|
||||
#include "Module.h"
|
||||
#include "FileWriter.h"
|
||||
#include "TypeAttributesTable.h"
|
||||
#include "utilities.h"
|
||||
#include "spirit_actors.h"
|
||||
|
||||
|
@ -88,7 +90,7 @@ Module::Module(const string& interfacePath,
|
|||
string templateArgument;
|
||||
vector<string> templateInstantiationNamespace;
|
||||
vector<vector<string> > templateInstantiations;
|
||||
TemplateSingleInstantiation singleInstantiation, singleInstantiation0;
|
||||
TemplateInstantiationTypedef singleInstantiation, singleInstantiation0;
|
||||
string include_path = "";
|
||||
const string null_str = "";
|
||||
|
||||
|
@ -167,7 +169,7 @@ Module::Module(const string& interfacePath,
|
|||
className_p[assign_a(singleInstantiation.name)] >>
|
||||
';')
|
||||
[assign_a(singleInstantiation.namespaces, namespaces)]
|
||||
[push_back_a(singleInstantiations, singleInstantiation)]
|
||||
[push_back_a(templateInstantiationTypedefs, singleInstantiation)]
|
||||
[assign_a(singleInstantiation, singleInstantiation0)];
|
||||
|
||||
Rule templateList_p =
|
||||
|
@ -335,7 +337,7 @@ Module::Module(const string& interfacePath,
|
|||
parse_info<const char*> info = parse(contents.c_str(), module_p, space_p);
|
||||
if(!info.full) {
|
||||
printf("parsing stopped at \n%.20s\n",info.stop);
|
||||
throw ParseFailed(info.length);
|
||||
throw ParseFailed((int)info.length);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -413,49 +415,19 @@ void Module::matlab_code(const string& toolboxPath, const string& headerPath) co
|
|||
wrapperFile.oss << "#include <boost/foreach.hpp>\n";
|
||||
wrapperFile.oss << "\n";
|
||||
|
||||
// Expand templates
|
||||
vector<Class> expandedClasses = expandTemplates();
|
||||
// Expand templates - This is done first so that template instantiations are
|
||||
// counted in the list of valid types, have their attributes and dependencies
|
||||
// checked, etc.
|
||||
vector<Class> expandedClasses = ExpandTypedefInstantiations(classes, templateInstantiationTypedefs);
|
||||
|
||||
// Dependency check list
|
||||
vector<string> validTypes;
|
||||
BOOST_FOREACH(const ForwardDeclaration& fwDec, forward_declarations) {
|
||||
validTypes.push_back(fwDec.name);
|
||||
}
|
||||
validTypes.push_back("void");
|
||||
validTypes.push_back("string");
|
||||
validTypes.push_back("int");
|
||||
validTypes.push_back("bool");
|
||||
validTypes.push_back("char");
|
||||
validTypes.push_back("unsigned char");
|
||||
validTypes.push_back("size_t");
|
||||
validTypes.push_back("double");
|
||||
validTypes.push_back("Vector");
|
||||
validTypes.push_back("Matrix");
|
||||
//Create a list of parsed classes for dependency checking
|
||||
BOOST_FOREACH(const Class& cls, expandedClasses) {
|
||||
validTypes.push_back(cls.qualifiedName("::"));
|
||||
}
|
||||
vector<string> validTypes = GenerateValidTypes(expandedClasses, forward_declarations);
|
||||
|
||||
// Create type attributes table
|
||||
ReturnValue::TypeAttributesTable typeAttributes;
|
||||
BOOST_FOREACH(const ForwardDeclaration& fwDec, forward_declarations) {
|
||||
if(!typeAttributes.insert(make_pair(fwDec.name, ReturnValue::TypeAttributes(fwDec.isVirtual))).second)
|
||||
throw DuplicateDefinition("class " + fwDec.name);
|
||||
}
|
||||
BOOST_FOREACH(const Class& cls, expandedClasses) {
|
||||
if(!typeAttributes.insert(make_pair(cls.qualifiedName("::"), ReturnValue::TypeAttributes(cls.isVirtual))).second)
|
||||
throw DuplicateDefinition("class " + cls.qualifiedName("::"));
|
||||
}
|
||||
// Check attributes
|
||||
BOOST_FOREACH(const Class& cls, expandedClasses) {
|
||||
// Check that class is virtual if it has a parent
|
||||
if(!cls.qualifiedParent.empty() && !cls.isVirtual)
|
||||
throw AttributeError(cls.qualifiedName("::"), "Has a base class so needs to be declared virtual, change to 'virtual class "+cls.name+" ...'");
|
||||
// Check that parent is virtual as well
|
||||
if(!cls.qualifiedParent.empty() && !typeAttributes.at(wrap::qualifiedName("::", cls.qualifiedParent)).isVirtual)
|
||||
throw AttributeError(wrap::qualifiedName("::", cls.qualifiedParent),
|
||||
"Is the base class of " + cls.qualifiedName("::") + ", so needs to be declared virtual");
|
||||
}
|
||||
// Create type attributes table and check validity
|
||||
TypeAttributesTable typeAttributes;
|
||||
typeAttributes.addClasses(expandedClasses);
|
||||
typeAttributes.addForwardDeclarations(forward_declarations);
|
||||
typeAttributes.checkValidity(expandedClasses);
|
||||
|
||||
// Check that all classes have been defined somewhere
|
||||
BOOST_FOREACH(const Class& cls, expandedClasses) {
|
||||
|
@ -472,69 +444,18 @@ void Module::matlab_code(const string& toolboxPath, const string& headerPath) co
|
|||
// Generate includes while avoiding redundant includes
|
||||
generateIncludes(wrapperFile);
|
||||
|
||||
// create typedef classes
|
||||
// create typedef classes - we put this at the top of the wrap file so that collectors and method arguments can use these typedefs
|
||||
BOOST_FOREACH(const Class& cls, expandedClasses) {
|
||||
if(!cls.typedefName.empty())
|
||||
wrapperFile.oss << cls.getTypedef() << "\n";
|
||||
}
|
||||
wrapperFile.oss << "\n";
|
||||
|
||||
// Generate all collectors
|
||||
BOOST_FOREACH(const Class& cls, expandedClasses) {
|
||||
const string matlabName = cls.qualifiedName(), cppName = cls.qualifiedName("::");
|
||||
wrapperFile.oss << "typedef std::set<boost::shared_ptr<" << cppName << ">*> "
|
||||
<< "Collector_" << matlabName << ";\n";
|
||||
wrapperFile.oss << "static Collector_" << matlabName <<
|
||||
" collector_" << matlabName << ";\n";
|
||||
}
|
||||
|
||||
// generate mexAtExit cleanup function
|
||||
wrapperFile.oss << "\nvoid _deleteAllObjects()\n";
|
||||
wrapperFile.oss << "{\n";
|
||||
BOOST_FOREACH(const Class& cls, expandedClasses) {
|
||||
const string matlabName = cls.qualifiedName();
|
||||
const string cppName = cls.qualifiedName("::");
|
||||
const string collectorType = "Collector_" + matlabName;
|
||||
const string collectorName = "collector_" + matlabName;
|
||||
wrapperFile.oss << " for(" << collectorType << "::iterator iter = " << collectorName << ".begin();\n";
|
||||
wrapperFile.oss << " iter != " << collectorName << ".end(); ) {\n";
|
||||
wrapperFile.oss << " delete *iter;\n";
|
||||
wrapperFile.oss << " " << collectorName << ".erase(iter++);\n";
|
||||
wrapperFile.oss << " }\n";
|
||||
}
|
||||
wrapperFile.oss << "}\n\n";
|
||||
// Generate collectors and cleanup function to be called from mexAtExit
|
||||
WriteCollectorsAndCleanupFcn(wrapperFile, name, expandedClasses);
|
||||
|
||||
// generate RTTI registry (for returning derived-most types)
|
||||
{
|
||||
wrapperFile.oss <<
|
||||
"static bool _RTTIRegister_" << name << "_done = false;\n"
|
||||
"void _" << name << "_RTTIRegister() {\n"
|
||||
" std::map<std::string, std::string> types;\n";
|
||||
BOOST_FOREACH(const Class& cls, expandedClasses) {
|
||||
if(cls.isVirtual)
|
||||
wrapperFile.oss <<
|
||||
" types.insert(std::make_pair(typeid(" << cls.qualifiedName("::") << ").name(), \"" << cls.qualifiedName() << "\"));\n";
|
||||
}
|
||||
wrapperFile.oss << "\n";
|
||||
|
||||
wrapperFile.oss <<
|
||||
" mxArray *registry = mexGetVariable(\"global\", \"gtsamwrap_rttiRegistry\");\n"
|
||||
" if(!registry)\n"
|
||||
" registry = mxCreateStructMatrix(1, 1, 0, NULL);\n"
|
||||
" typedef std::pair<std::string, std::string> StringPair;\n"
|
||||
" BOOST_FOREACH(const StringPair& rtti_matlab, types) {\n"
|
||||
" int fieldId = mxAddField(registry, rtti_matlab.first.c_str());\n"
|
||||
" if(fieldId < 0)\n"
|
||||
" mexErrMsgTxt(\"gtsam wrap: Error indexing RTTI types, inheritance will not work correctly\");\n"
|
||||
" mxArray *matlabName = mxCreateString(rtti_matlab.second.c_str());\n"
|
||||
" mxSetFieldByNumber(registry, 0, fieldId, matlabName);\n"
|
||||
" }\n"
|
||||
" if(mexPutVariable(\"global\", \"gtsamwrap_rttiRegistry\", registry) != 0)\n"
|
||||
" mexErrMsgTxt(\"gtsam wrap: Error indexing RTTI types, inheritance will not work correctly\");\n"
|
||||
" mxDestroyArray(registry);\n"
|
||||
"}\n"
|
||||
"\n";
|
||||
}
|
||||
WriteRTTIRegistry(wrapperFile, name, expandedClasses);
|
||||
|
||||
// create proxy class and wrapper code
|
||||
BOOST_FOREACH(const Class& cls, expandedClasses) {
|
||||
|
@ -573,43 +494,13 @@ void Module::matlab_code(const string& toolboxPath, const string& headerPath) co
|
|||
}
|
||||
|
||||
/* ************************************************************************* */
|
||||
vector<Class> Module::expandTemplates() const {
|
||||
vector<Class> Module::ExpandTypedefInstantiations(const vector<Class>& classes, const vector<TemplateInstantiationTypedef> instantiations) {
|
||||
|
||||
vector<Class> expandedClasses = classes;
|
||||
|
||||
BOOST_FOREACH(const TemplateSingleInstantiation& inst, singleInstantiations) {
|
||||
// Find matching class
|
||||
std::vector<Class>::iterator clsIt = expandedClasses.end();
|
||||
for(std::vector<Class>::iterator it = expandedClasses.begin(); it != expandedClasses.end(); ++it) {
|
||||
if(it->name == inst.className && it->namespaces == inst.classNamespaces && it->templateArgs.size() == inst.typeList.size()) {
|
||||
clsIt = it;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(clsIt == expandedClasses.end())
|
||||
throw DependencyMissing(wrap::qualifiedName("::", inst.classNamespaces, inst.className),
|
||||
"instantiation into typedef name " + wrap::qualifiedName("::", inst.namespaces, inst.name) +
|
||||
". Ensure that the typedef provides the correct number of template arguments.");
|
||||
|
||||
// Instantiate it
|
||||
Class classInst = *clsIt;
|
||||
for(size_t i = 0; i < inst.typeList.size(); ++i)
|
||||
classInst = classInst.expandTemplate(classInst.templateArgs[i], inst.typeList[i]);
|
||||
|
||||
// Fix class properties
|
||||
classInst.name = inst.name;
|
||||
classInst.templateArgs.clear();
|
||||
classInst.typedefName = clsIt->qualifiedName("::") + "<";
|
||||
if(inst.typeList.size() > 0)
|
||||
classInst.typedefName += wrap::qualifiedName("::", inst.typeList[0]);
|
||||
for(size_t i = 1; i < inst.typeList.size(); ++i)
|
||||
classInst.typedefName += (", " + wrap::qualifiedName("::", inst.typeList[i]));
|
||||
classInst.typedefName += ">";
|
||||
classInst.namespaces = inst.namespaces;
|
||||
|
||||
BOOST_FOREACH(const TemplateInstantiationTypedef& inst, instantiations) {
|
||||
// Add the new class to the list
|
||||
expandedClasses.push_back(classInst);
|
||||
expandedClasses.push_back(inst.findAndExpand(classes));
|
||||
}
|
||||
|
||||
// Remove all template classes
|
||||
|
@ -623,3 +514,87 @@ vector<Class> Module::expandTemplates() const {
|
|||
}
|
||||
|
||||
/* ************************************************************************* */
|
||||
vector<string> Module::GenerateValidTypes(const vector<Class>& classes, const vector<ForwardDeclaration> forwardDeclarations) {
|
||||
vector<string> validTypes;
|
||||
BOOST_FOREACH(const ForwardDeclaration& fwDec, forwardDeclarations) {
|
||||
validTypes.push_back(fwDec.name);
|
||||
}
|
||||
validTypes.push_back("void");
|
||||
validTypes.push_back("string");
|
||||
validTypes.push_back("int");
|
||||
validTypes.push_back("bool");
|
||||
validTypes.push_back("char");
|
||||
validTypes.push_back("unsigned char");
|
||||
validTypes.push_back("size_t");
|
||||
validTypes.push_back("double");
|
||||
validTypes.push_back("Vector");
|
||||
validTypes.push_back("Matrix");
|
||||
//Create a list of parsed classes for dependency checking
|
||||
BOOST_FOREACH(const Class& cls, classes) {
|
||||
validTypes.push_back(cls.qualifiedName("::"));
|
||||
}
|
||||
|
||||
return validTypes;
|
||||
}
|
||||
|
||||
/* ************************************************************************* */
|
||||
void Module::WriteCollectorsAndCleanupFcn(FileWriter& wrapperFile, const std::string& moduleName, const std::vector<Class>& classes) {
|
||||
// Generate all collectors
|
||||
BOOST_FOREACH(const Class& cls, classes) {
|
||||
const string matlabName = cls.qualifiedName(), cppName = cls.qualifiedName("::");
|
||||
wrapperFile.oss << "typedef std::set<boost::shared_ptr<" << cppName << ">*> "
|
||||
<< "Collector_" << matlabName << ";\n";
|
||||
wrapperFile.oss << "static Collector_" << matlabName <<
|
||||
" collector_" << matlabName << ";\n";
|
||||
}
|
||||
|
||||
// generate mexAtExit cleanup function
|
||||
wrapperFile.oss << "\nvoid _deleteAllObjects()\n";
|
||||
wrapperFile.oss << "{\n";
|
||||
BOOST_FOREACH(const Class& cls, classes) {
|
||||
const string matlabName = cls.qualifiedName();
|
||||
const string cppName = cls.qualifiedName("::");
|
||||
const string collectorType = "Collector_" + matlabName;
|
||||
const string collectorName = "collector_" + matlabName;
|
||||
wrapperFile.oss << " for(" << collectorType << "::iterator iter = " << collectorName << ".begin();\n";
|
||||
wrapperFile.oss << " iter != " << collectorName << ".end(); ) {\n";
|
||||
wrapperFile.oss << " delete *iter;\n";
|
||||
wrapperFile.oss << " " << collectorName << ".erase(iter++);\n";
|
||||
wrapperFile.oss << " }\n";
|
||||
}
|
||||
wrapperFile.oss << "}\n\n";
|
||||
}
|
||||
|
||||
/* ************************************************************************* */
|
||||
void Module::WriteRTTIRegistry(FileWriter& wrapperFile, const std::string& moduleName, const std::vector<Class>& classes) {
|
||||
wrapperFile.oss <<
|
||||
"static bool _RTTIRegister_" << moduleName << "_done = false;\n"
|
||||
"void _" << moduleName << "_RTTIRegister() {\n"
|
||||
" std::map<std::string, std::string> types;\n";
|
||||
BOOST_FOREACH(const Class& cls, classes) {
|
||||
if(cls.isVirtual)
|
||||
wrapperFile.oss <<
|
||||
" types.insert(std::make_pair(typeid(" << cls.qualifiedName("::") << ").name(), \"" << cls.qualifiedName() << "\"));\n";
|
||||
}
|
||||
wrapperFile.oss << "\n";
|
||||
|
||||
wrapperFile.oss <<
|
||||
" mxArray *registry = mexGetVariable(\"global\", \"gtsamwrap_rttiRegistry\");\n"
|
||||
" if(!registry)\n"
|
||||
" registry = mxCreateStructMatrix(1, 1, 0, NULL);\n"
|
||||
" typedef std::pair<std::string, std::string> StringPair;\n"
|
||||
" BOOST_FOREACH(const StringPair& rtti_matlab, types) {\n"
|
||||
" int fieldId = mxAddField(registry, rtti_matlab.first.c_str());\n"
|
||||
" if(fieldId < 0)\n"
|
||||
" mexErrMsgTxt(\"gtsam wrap: Error indexing RTTI types, inheritance will not work correctly\");\n"
|
||||
" mxArray *matlabName = mxCreateString(rtti_matlab.second.c_str());\n"
|
||||
" mxSetFieldByNumber(registry, 0, fieldId, matlabName);\n"
|
||||
" }\n"
|
||||
" if(mexPutVariable(\"global\", \"gtsamwrap_rttiRegistry\", registry) != 0)\n"
|
||||
" mexErrMsgTxt(\"gtsam wrap: Error indexing RTTI types, inheritance will not work correctly\");\n"
|
||||
" mxDestroyArray(registry);\n"
|
||||
"}\n"
|
||||
"\n";
|
||||
}
|
||||
|
||||
/* ************************************************************************* */
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
* @file Module.h
|
||||
* @brief describes module to be wrapped
|
||||
* @author Frank Dellaert
|
||||
* @author Richard Roberts
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
@ -22,6 +23,8 @@
|
|||
#include <map>
|
||||
|
||||
#include "Class.h"
|
||||
#include "TemplateInstantiationTypedef.h"
|
||||
#include "ForwardDeclaration.h"
|
||||
|
||||
namespace wrap {
|
||||
|
||||
|
@ -30,23 +33,9 @@ namespace wrap {
|
|||
*/
|
||||
struct Module {
|
||||
|
||||
struct ForwardDeclaration {
|
||||
std::string name;
|
||||
bool isVirtual;
|
||||
ForwardDeclaration() : isVirtual(false) {}
|
||||
};
|
||||
|
||||
struct TemplateSingleInstantiation {
|
||||
std::vector<std::string> classNamespaces;
|
||||
std::string className;
|
||||
std::vector<std::string> namespaces;
|
||||
std::string name;
|
||||
std::vector<std::vector<std::string> > typeList;
|
||||
};
|
||||
|
||||
std::string name; ///< module name
|
||||
std::vector<Class> classes; ///< list of classes
|
||||
std::vector<TemplateSingleInstantiation> singleInstantiations; ///< list of template instantiations
|
||||
std::vector<TemplateInstantiationTypedef> templateInstantiationTypedefs; ///< list of template instantiations
|
||||
bool verbose; ///< verbose flag
|
||||
// std::vector<std::string> using_namespaces; ///< all default namespaces
|
||||
std::vector<ForwardDeclaration> forward_declarations;
|
||||
|
@ -66,7 +55,10 @@ struct Module {
|
|||
void generateIncludes(FileWriter& file) const;
|
||||
|
||||
private:
|
||||
std::vector<Class> expandTemplates() const;
|
||||
static std::vector<Class> ExpandTypedefInstantiations(const std::vector<Class>& classes, const std::vector<TemplateInstantiationTypedef> instantiations);
|
||||
static std::vector<std::string> GenerateValidTypes(const std::vector<Class>& classes, const std::vector<ForwardDeclaration> forwardDeclarations);
|
||||
static void WriteCollectorsAndCleanupFcn(FileWriter& wrapperFile, const std::string& moduleName, const std::vector<Class>& classes);
|
||||
static void WriteRTTIRegistry(FileWriter& wrapperFile, const std::string& moduleName, const std::vector<Class>& classes);
|
||||
};
|
||||
|
||||
} // \namespace wrap
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
* @date Dec 1, 2011
|
||||
* @author Alex Cunningham
|
||||
* @author Andrew Melim
|
||||
* @author Richard Roberts
|
||||
*/
|
||||
|
||||
#include <boost/foreach.hpp>
|
||||
|
|
|
@ -5,12 +5,14 @@
|
|||
*
|
||||
* @date Dec 1, 2011
|
||||
* @author Alex Cunningham
|
||||
* @author Richard Roberts
|
||||
*/
|
||||
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
#include "FileWriter.h"
|
||||
#include "TypeAttributesTable.h"
|
||||
|
||||
#pragma once
|
||||
|
||||
|
@ -18,14 +20,6 @@ namespace wrap {
|
|||
|
||||
struct ReturnValue {
|
||||
|
||||
struct TypeAttributes {
|
||||
bool isVirtual;
|
||||
TypeAttributes() : isVirtual(false) {}
|
||||
TypeAttributes(bool isVirtual) : isVirtual(isVirtual) {}
|
||||
};
|
||||
|
||||
typedef std::map<std::string, TypeAttributes> TypeAttributesTable;
|
||||
|
||||
typedef enum {
|
||||
CLASS,
|
||||
EIGEN,
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
* @file StaticMethod.ccp
|
||||
* @author Frank Dellaert
|
||||
* @author Andrew Melim
|
||||
* @author Richard Roberts
|
||||
**/
|
||||
|
||||
#include <iostream>
|
||||
|
@ -42,7 +43,7 @@ void StaticMethod::proxy_wrapper_fragments(FileWriter& proxyFile, FileWriter& wr
|
|||
const string& matlabClassName,
|
||||
const string& wrapperName,
|
||||
const vector<string>& using_namespaces,
|
||||
const ReturnValue::TypeAttributesTable& typeAttributes,
|
||||
const TypeAttributesTable& typeAttributes,
|
||||
vector<string>& functionNames) const {
|
||||
|
||||
string upperName = name; upperName[0] = std::toupper(upperName[0], std::locale());
|
||||
|
@ -105,7 +106,7 @@ string StaticMethod::wrapper_fragment(FileWriter& file,
|
|||
int overload,
|
||||
int id,
|
||||
const vector<string>& using_namespaces,
|
||||
const ReturnValue::TypeAttributesTable& typeAttributes) const {
|
||||
const TypeAttributesTable& typeAttributes) const {
|
||||
|
||||
// generate code
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
* @brief describes and generates code for static methods
|
||||
* @author Frank Dellaert
|
||||
* @author Alex Cunningham
|
||||
* @author Richard Roberts
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
@ -23,6 +24,7 @@
|
|||
|
||||
#include "Argument.h"
|
||||
#include "ReturnValue.h"
|
||||
#include "TypeAttributesTable.h"
|
||||
|
||||
namespace wrap {
|
||||
|
||||
|
@ -50,7 +52,7 @@ struct StaticMethod {
|
|||
void proxy_wrapper_fragments(FileWriter& proxyFile, FileWriter& wrapperFile,
|
||||
const std::string& cppClassName, const std::string& matlabClassName,
|
||||
const std::string& wrapperName, const std::vector<std::string>& using_namespaces,
|
||||
const ReturnValue::TypeAttributesTable& typeAttributes,
|
||||
const TypeAttributesTable& typeAttributes,
|
||||
std::vector<std::string>& functionNames) const;
|
||||
|
||||
private:
|
||||
|
@ -60,7 +62,7 @@ private:
|
|||
int overload,
|
||||
int id,
|
||||
const std::vector<std::string>& using_namespaces,
|
||||
const ReturnValue::TypeAttributesTable& typeAttributes) const; ///< cpp wrapper
|
||||
const TypeAttributesTable& typeAttributes) const; ///< cpp wrapper
|
||||
};
|
||||
|
||||
} // \namespace wrap
|
||||
|
|
|
@ -14,6 +14,9 @@
|
|||
* @brief header file to be included in MATLAB wrappers
|
||||
* @date 2008
|
||||
* @author Frank Dellaert
|
||||
* @author Alex Cunningham
|
||||
* @author Andrew Melim
|
||||
* @author Richard Roberts
|
||||
*
|
||||
* wrapping and unwrapping is done using specialized templates, see
|
||||
* http://www.cplusplus.com/doc/tutorial/templates.html
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
* @file utilities.ccp
|
||||
* @author Frank Dellaert
|
||||
* @author Andrew Melim
|
||||
* @author Richard Roberts
|
||||
**/
|
||||
|
||||
#include <iostream>
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
* @file utilities.h
|
||||
* @author Frank Dellaert
|
||||
* @author Andrew Melim
|
||||
* @author Richard Roberts
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
|
Loading…
Reference in New Issue