Code cleanup and comments

release/4.3a0
Richard Roberts 2012-07-12 22:28:28 +00:00
parent c3ed90c792
commit ce12f3d255
19 changed files with 151 additions and 169 deletions

View File

@ -13,6 +13,7 @@
* @file Argument.ccp * @file Argument.ccp
* @author Frank Dellaert * @author Frank Dellaert
* @author Andrew Melim * @author Andrew Melim
* @author Richard Roberts
**/ **/
#include <iostream> #include <iostream>

View File

@ -14,6 +14,7 @@
* @brief arguments to constructors and methods * @brief arguments to constructors and methods
* @author Frank Dellaert * @author Frank Dellaert
* @author Andrew Melim * @author Andrew Melim
* @author Richard Roberts
**/ **/
#pragma once #pragma once

View File

@ -13,6 +13,7 @@
* @file Class.cpp * @file Class.cpp
* @author Frank Dellaert * @author Frank Dellaert
* @author Andrew Melim * @author Andrew Melim
* @author Richard Roberts
**/ **/
#include <vector> #include <vector>
@ -34,7 +35,7 @@ using namespace wrap;
/* ************************************************************************* */ /* ************************************************************************* */
void Class::matlab_proxy(const string& classFile, const string& wrapperName, void Class::matlab_proxy(const string& classFile, const string& wrapperName,
const ReturnValue::TypeAttributesTable& typeAttributes, const TypeAttributesTable& typeAttributes,
FileWriter& wrapperFile, vector<string>& functionNames) const { FileWriter& wrapperFile, vector<string>& functionNames) const {
// open destination classFile // open destination classFile
FileWriter proxyFile(classFile, verbose_, "%"); FileWriter proxyFile(classFile, verbose_, "%");
@ -68,7 +69,7 @@ void Class::matlab_proxy(const string& classFile, const string& wrapperName,
// Regular constructors // Regular constructors
BOOST_FOREACH(ArgumentList a, constructor.args_list) 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); constructor.proxy_fragment(proxyFile, wrapperName, matlabName, matlabBaseName, id, a);
const string wrapFunctionName = constructor.wrapper_fragment(wrapperFile, const string wrapFunctionName = constructor.wrapper_fragment(wrapperFile,
cppName, matlabName, cppBaseName, id, using_namespaces, a); cppName, matlabName, cppBaseName, id, using_namespaces, a);
@ -85,7 +86,7 @@ void Class::matlab_proxy(const string& classFile, const string& wrapperName,
// Deconstructor // Deconstructor
{ {
const int id = functionNames.size(); const int id = (int)functionNames.size();
deconstructor.proxy_fragment(proxyFile, wrapperName, matlabName, id); deconstructor.proxy_fragment(proxyFile, wrapperName, matlabName, id);
proxyFile.oss << "\n"; proxyFile.oss << "\n";
const string functionName = deconstructor.wrapper_fragment(wrapperFile, cppName, matlabName, id, using_namespaces); 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 baseMatlabName = wrap::qualifiedName("", qualifiedParent);
const string baseCppName = 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); const string collectorInsertFunctionName = matlabName + "_collectorInsertAndMakeBase_" + boost::lexical_cast<string>(collectorInsertId);
functionNames.push_back(collectorInsertFunctionName); functionNames.push_back(collectorInsertFunctionName);
int upcastFromVoidId; int upcastFromVoidId;
string upcastFromVoidFunctionName; string upcastFromVoidFunctionName;
if(isVirtual) { if(isVirtual) {
upcastFromVoidId = functionNames.size(); upcastFromVoidId = (int)functionNames.size();
upcastFromVoidFunctionName = matlabName + "_upcastFromVoid_" + boost::lexical_cast<string>(upcastFromVoidId); upcastFromVoidFunctionName = matlabName + "_upcastFromVoid_" + boost::lexical_cast<string>(upcastFromVoidId);
functionNames.push_back(upcastFromVoidFunctionName); functionNames.push_back(upcastFromVoidFunctionName);
} }

View File

@ -14,6 +14,7 @@
* @brief describe the C++ class that is being wrapped * @brief describe the C++ class that is being wrapped
* @author Frank Dellaert * @author Frank Dellaert
* @author Andrew Melim * @author Andrew Melim
* @author Richard Roberts
**/ **/
#pragma once #pragma once
@ -25,6 +26,7 @@
#include "Deconstructor.h" #include "Deconstructor.h"
#include "Method.h" #include "Method.h"
#include "StaticMethod.h" #include "StaticMethod.h"
#include "TypeAttributesTable.h"
namespace wrap { namespace wrap {
@ -52,7 +54,7 @@ struct Class {
bool verbose_; ///< verbose flag bool verbose_; ///< verbose flag
// And finally MATLAB code is emitted, methods below called by Module::matlab_code // 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 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 std::string qualifiedName(const std::string& delim = "") const; ///< creates a namespace-qualified name, optional delimiter

View File

@ -13,6 +13,7 @@
* @file Constructor.ccp * @file Constructor.ccp
* @author Frank Dellaert * @author Frank Dellaert
* @author Andrew Melim * @author Andrew Melim
* @author Richard Roberts
**/ **/
#include <iostream> #include <iostream>

View File

@ -13,6 +13,7 @@
* @file Constructor.h * @file Constructor.h
* @brief class describing a constructor + code generation * @brief class describing a constructor + code generation
* @author Frank Dellaert * @author Frank Dellaert
* @author Richard Roberts
**/ **/
#pragma once #pragma once

View File

@ -13,6 +13,7 @@
* @file Deconstructor.ccp * @file Deconstructor.ccp
* @author Frank Dellaert * @author Frank Dellaert
* @author Andrew Melim * @author Andrew Melim
* @author Richard Roberts
**/ **/
#include <iostream> #include <iostream>

View File

@ -14,6 +14,7 @@
* @brief class describing a constructor + code generation * @brief class describing a constructor + code generation
* @author Frank Dellaert * @author Frank Dellaert
* @author Andrew Melim * @author Andrew Melim
* @author Richard Roberts
**/ **/
#pragma once #pragma once

View File

@ -12,6 +12,7 @@
/** /**
* @file Method.ccp * @file Method.ccp
* @author Frank Dellaert * @author Frank Dellaert
* @author Richard Roberts
**/ **/
#include <iostream> #include <iostream>
@ -41,7 +42,7 @@ void Method::proxy_wrapper_fragments(FileWriter& proxyFile, FileWriter& wrapperF
const string& matlabClassName, const string& matlabClassName,
const string& wrapperName, const string& wrapperName,
const vector<string>& using_namespaces, const vector<string>& using_namespaces,
const ReturnValue::TypeAttributesTable& typeAttributes, const TypeAttributesTable& typeAttributes,
vector<string>& functionNames) const { vector<string>& functionNames) const {
proxyFile.oss << " function varargout = " << name << "(this, varargin)\n"; proxyFile.oss << " function varargout = " << name << "(this, varargin)\n";
@ -102,7 +103,7 @@ string Method::wrapper_fragment(FileWriter& file,
int overload, int overload,
int id, int id,
const vector<string>& using_namespaces, const vector<string>& using_namespaces,
const ReturnValue::TypeAttributesTable& typeAttributes) const { const TypeAttributesTable& typeAttributes) const {
// generate code // generate code

View File

@ -13,6 +13,7 @@
* @file Method.h * @file Method.h
* @brief describes and generates code for methods * @brief describes and generates code for methods
* @author Frank Dellaert * @author Frank Dellaert
* @author Richard Roberts
**/ **/
#pragma once #pragma once
@ -22,6 +23,7 @@
#include "Argument.h" #include "Argument.h"
#include "ReturnValue.h" #include "ReturnValue.h"
#include "TypeAttributesTable.h"
namespace wrap { namespace wrap {
@ -50,7 +52,7 @@ struct Method {
void proxy_wrapper_fragments(FileWriter& proxyFile, FileWriter& wrapperFile, void proxy_wrapper_fragments(FileWriter& proxyFile, FileWriter& wrapperFile,
const std::string& cppClassName, const std::string& matlabClassName, const std::string& cppClassName, const std::string& matlabClassName,
const std::string& wrapperName, const std::vector<std::string>& using_namespaces, const std::string& wrapperName, const std::vector<std::string>& using_namespaces,
const ReturnValue::TypeAttributesTable& typeAttributes, const TypeAttributesTable& typeAttributes,
std::vector<std::string>& functionNames) const; std::vector<std::string>& functionNames) const;
private: private:
@ -60,7 +62,7 @@ private:
int overload, int overload,
int id, int id,
const std::vector<std::string>& using_namespaces, const std::vector<std::string>& using_namespaces,
const ReturnValue::TypeAttributesTable& typeAttributes) const; ///< cpp wrapper const TypeAttributesTable& typeAttributes) const; ///< cpp wrapper
}; };
} // \namespace wrap } // \namespace wrap

View File

@ -14,10 +14,12 @@
* @author Frank Dellaert * @author Frank Dellaert
* @author Alex Cunningham * @author Alex Cunningham
* @author Andrew Melim * @author Andrew Melim
* @author Richard Roberts
**/ **/
#include "Module.h" #include "Module.h"
#include "FileWriter.h" #include "FileWriter.h"
#include "TypeAttributesTable.h"
#include "utilities.h" #include "utilities.h"
#include "spirit_actors.h" #include "spirit_actors.h"
@ -88,7 +90,7 @@ Module::Module(const string& interfacePath,
string templateArgument; string templateArgument;
vector<string> templateInstantiationNamespace; vector<string> templateInstantiationNamespace;
vector<vector<string> > templateInstantiations; vector<vector<string> > templateInstantiations;
TemplateSingleInstantiation singleInstantiation, singleInstantiation0; TemplateInstantiationTypedef singleInstantiation, singleInstantiation0;
string include_path = ""; string include_path = "";
const string null_str = ""; const string null_str = "";
@ -167,7 +169,7 @@ Module::Module(const string& interfacePath,
className_p[assign_a(singleInstantiation.name)] >> className_p[assign_a(singleInstantiation.name)] >>
';') ';')
[assign_a(singleInstantiation.namespaces, namespaces)] [assign_a(singleInstantiation.namespaces, namespaces)]
[push_back_a(singleInstantiations, singleInstantiation)] [push_back_a(templateInstantiationTypedefs, singleInstantiation)]
[assign_a(singleInstantiation, singleInstantiation0)]; [assign_a(singleInstantiation, singleInstantiation0)];
Rule templateList_p = 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); parse_info<const char*> info = parse(contents.c_str(), module_p, space_p);
if(!info.full) { if(!info.full) {
printf("parsing stopped at \n%.20s\n",info.stop); 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 << "#include <boost/foreach.hpp>\n";
wrapperFile.oss << "\n"; wrapperFile.oss << "\n";
// Expand templates // Expand templates - This is done first so that template instantiations are
vector<Class> expandedClasses = expandTemplates(); // counted in the list of valid types, have their attributes and dependencies
// checked, etc.
vector<Class> expandedClasses = ExpandTypedefInstantiations(classes, templateInstantiationTypedefs);
// Dependency check list // Dependency check list
vector<string> validTypes; vector<string> validTypes = GenerateValidTypes(expandedClasses, forward_declarations);
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("::"));
}
// Create type attributes table // Create type attributes table and check validity
ReturnValue::TypeAttributesTable typeAttributes; TypeAttributesTable typeAttributes;
BOOST_FOREACH(const ForwardDeclaration& fwDec, forward_declarations) { typeAttributes.addClasses(expandedClasses);
if(!typeAttributes.insert(make_pair(fwDec.name, ReturnValue::TypeAttributes(fwDec.isVirtual))).second) typeAttributes.addForwardDeclarations(forward_declarations);
throw DuplicateDefinition("class " + fwDec.name); typeAttributes.checkValidity(expandedClasses);
}
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");
}
// Check that all classes have been defined somewhere // Check that all classes have been defined somewhere
BOOST_FOREACH(const Class& cls, expandedClasses) { 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 // Generate includes while avoiding redundant includes
generateIncludes(wrapperFile); 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) { BOOST_FOREACH(const Class& cls, expandedClasses) {
if(!cls.typedefName.empty()) if(!cls.typedefName.empty())
wrapperFile.oss << cls.getTypedef() << "\n"; wrapperFile.oss << cls.getTypedef() << "\n";
} }
wrapperFile.oss << "\n"; wrapperFile.oss << "\n";
// Generate all collectors // Generate collectors and cleanup function to be called from mexAtExit
BOOST_FOREACH(const Class& cls, expandedClasses) { WriteCollectorsAndCleanupFcn(wrapperFile, name, 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 RTTI registry (for returning derived-most types) // generate RTTI registry (for returning derived-most types)
{ WriteRTTIRegistry(wrapperFile, name, expandedClasses);
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";
}
// create proxy class and wrapper code // create proxy class and wrapper code
BOOST_FOREACH(const Class& cls, expandedClasses) { 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; vector<Class> expandedClasses = classes;
BOOST_FOREACH(const TemplateSingleInstantiation& inst, singleInstantiations) { BOOST_FOREACH(const TemplateInstantiationTypedef& inst, instantiations) {
// 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;
// Add the new class to the list // Add the new class to the list
expandedClasses.push_back(classInst); expandedClasses.push_back(inst.findAndExpand(classes));
} }
// Remove all template 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";
}
/* ************************************************************************* */

View File

@ -13,6 +13,7 @@
* @file Module.h * @file Module.h
* @brief describes module to be wrapped * @brief describes module to be wrapped
* @author Frank Dellaert * @author Frank Dellaert
* @author Richard Roberts
**/ **/
#pragma once #pragma once
@ -22,6 +23,8 @@
#include <map> #include <map>
#include "Class.h" #include "Class.h"
#include "TemplateInstantiationTypedef.h"
#include "ForwardDeclaration.h"
namespace wrap { namespace wrap {
@ -30,23 +33,9 @@ namespace wrap {
*/ */
struct Module { 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::string name; ///< module name
std::vector<Class> classes; ///< list of classes 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 bool verbose; ///< verbose flag
// std::vector<std::string> using_namespaces; ///< all default namespaces // std::vector<std::string> using_namespaces; ///< all default namespaces
std::vector<ForwardDeclaration> forward_declarations; std::vector<ForwardDeclaration> forward_declarations;
@ -66,7 +55,10 @@ struct Module {
void generateIncludes(FileWriter& file) const; void generateIncludes(FileWriter& file) const;
private: 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 } // \namespace wrap

View File

@ -4,6 +4,7 @@
* @date Dec 1, 2011 * @date Dec 1, 2011
* @author Alex Cunningham * @author Alex Cunningham
* @author Andrew Melim * @author Andrew Melim
* @author Richard Roberts
*/ */
#include <boost/foreach.hpp> #include <boost/foreach.hpp>

View File

@ -5,12 +5,14 @@
* *
* @date Dec 1, 2011 * @date Dec 1, 2011
* @author Alex Cunningham * @author Alex Cunningham
* @author Richard Roberts
*/ */
#include <vector> #include <vector>
#include <map> #include <map>
#include "FileWriter.h" #include "FileWriter.h"
#include "TypeAttributesTable.h"
#pragma once #pragma once
@ -18,14 +20,6 @@ namespace wrap {
struct ReturnValue { struct ReturnValue {
struct TypeAttributes {
bool isVirtual;
TypeAttributes() : isVirtual(false) {}
TypeAttributes(bool isVirtual) : isVirtual(isVirtual) {}
};
typedef std::map<std::string, TypeAttributes> TypeAttributesTable;
typedef enum { typedef enum {
CLASS, CLASS,
EIGEN, EIGEN,

View File

@ -13,6 +13,7 @@
* @file StaticMethod.ccp * @file StaticMethod.ccp
* @author Frank Dellaert * @author Frank Dellaert
* @author Andrew Melim * @author Andrew Melim
* @author Richard Roberts
**/ **/
#include <iostream> #include <iostream>
@ -42,7 +43,7 @@ void StaticMethod::proxy_wrapper_fragments(FileWriter& proxyFile, FileWriter& wr
const string& matlabClassName, const string& matlabClassName,
const string& wrapperName, const string& wrapperName,
const vector<string>& using_namespaces, const vector<string>& using_namespaces,
const ReturnValue::TypeAttributesTable& typeAttributes, const TypeAttributesTable& typeAttributes,
vector<string>& functionNames) const { 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());
@ -105,7 +106,7 @@ string StaticMethod::wrapper_fragment(FileWriter& file,
int overload, int overload,
int id, int id,
const vector<string>& using_namespaces, const vector<string>& using_namespaces,
const ReturnValue::TypeAttributesTable& typeAttributes) const { const TypeAttributesTable& typeAttributes) const {
// generate code // generate code

View File

@ -14,6 +14,7 @@
* @brief describes and generates code for static methods * @brief describes and generates code for static methods
* @author Frank Dellaert * @author Frank Dellaert
* @author Alex Cunningham * @author Alex Cunningham
* @author Richard Roberts
**/ **/
#pragma once #pragma once
@ -23,6 +24,7 @@
#include "Argument.h" #include "Argument.h"
#include "ReturnValue.h" #include "ReturnValue.h"
#include "TypeAttributesTable.h"
namespace wrap { namespace wrap {
@ -50,7 +52,7 @@ struct StaticMethod {
void proxy_wrapper_fragments(FileWriter& proxyFile, FileWriter& wrapperFile, void proxy_wrapper_fragments(FileWriter& proxyFile, FileWriter& wrapperFile,
const std::string& cppClassName, const std::string& matlabClassName, const std::string& cppClassName, const std::string& matlabClassName,
const std::string& wrapperName, const std::vector<std::string>& using_namespaces, const std::string& wrapperName, const std::vector<std::string>& using_namespaces,
const ReturnValue::TypeAttributesTable& typeAttributes, const TypeAttributesTable& typeAttributes,
std::vector<std::string>& functionNames) const; std::vector<std::string>& functionNames) const;
private: private:
@ -60,7 +62,7 @@ private:
int overload, int overload,
int id, int id,
const std::vector<std::string>& using_namespaces, const std::vector<std::string>& using_namespaces,
const ReturnValue::TypeAttributesTable& typeAttributes) const; ///< cpp wrapper const TypeAttributesTable& typeAttributes) const; ///< cpp wrapper
}; };
} // \namespace wrap } // \namespace wrap

View File

@ -14,6 +14,9 @@
* @brief header file to be included in MATLAB wrappers * @brief header file to be included in MATLAB wrappers
* @date 2008 * @date 2008
* @author Frank Dellaert * @author Frank Dellaert
* @author Alex Cunningham
* @author Andrew Melim
* @author Richard Roberts
* *
* wrapping and unwrapping is done using specialized templates, see * wrapping and unwrapping is done using specialized templates, see
* http://www.cplusplus.com/doc/tutorial/templates.html * http://www.cplusplus.com/doc/tutorial/templates.html

View File

@ -13,6 +13,7 @@
* @file utilities.ccp * @file utilities.ccp
* @author Frank Dellaert * @author Frank Dellaert
* @author Andrew Melim * @author Andrew Melim
* @author Richard Roberts
**/ **/
#include <iostream> #include <iostream>

View File

@ -13,6 +13,7 @@
* @file utilities.h * @file utilities.h
* @author Frank Dellaert * @author Frank Dellaert
* @author Andrew Melim * @author Andrew Melim
* @author Richard Roberts
**/ **/
#pragma once #pragma once