emit template class to Cython pxd with test

Cython allows template class.
release/4.3a0
Duy-Nguyen Ta 2016-09-09 07:28:13 -04:00
parent 40da298f68
commit b9880d4257
3 changed files with 28 additions and 10 deletions

View File

@ -45,8 +45,10 @@ namespace fs = boost::filesystem;
/* ************************************************************************* */ /* ************************************************************************* */
// If a number of template arguments were given, generate a number of expanded // If a number of template arguments were given, generate a number of expanded
// class names, e.g., PriorFactor -> PriorFactorPose2, and add those classes // class names, e.g., PriorFactor -> PriorFactorPose2, and add those classes
static void handle_possible_template(vector<Class>& classes, const Class& cls, static void handle_possible_template(vector<Class>& classes,
const Template& t) { vector<Class>& uninstantiatedClasses,
const Class& cls, const Template& t) {
uninstantiatedClasses.push_back(cls);
if (cls.templateArgs.empty() || t.empty()) { if (cls.templateArgs.empty() || t.empty()) {
classes.push_back(cls); classes.push_back(cls);
} else { } else {
@ -108,10 +110,10 @@ void Module::parseMarkup(const std::string& data) {
ClassGrammar class_g(cls,classTemplate); ClassGrammar class_g(cls,classTemplate);
Rule class_p = class_g // Rule class_p = class_g //
[assign_a(cls.namespaces_, namespaces)] [assign_a(cls.namespaces_, namespaces)]
[assign_a(cls.includeFile, currentInclude)] [assign_a(cls.includeFile, currentInclude)][bl::bind(
[bl::bind(&handle_possible_template, bl::var(classes), bl::var(cls), &handle_possible_template, bl::var(classes),
bl::var(classTemplate))] bl::var(uninstantiatedClasses), bl::var(cls),
[clear_a(classTemplate)] // bl::var(classTemplate))][clear_a(classTemplate)] //
[assign_a(cls, cls0)]; [assign_a(cls, cls0)];
// parse "gtsam::Pose2" and add to singleInstantiation.typeList // parse "gtsam::Pose2" and add to singleInstantiation.typeList
@ -184,6 +186,9 @@ void Module::parseMarkup(const std::string& data) {
for(Class& cls: classes) for(Class& cls: classes)
cls.erase_serialization(); cls.erase_serialization();
for(Class& cls: uninstantiatedClasses)
cls.erase_serialization();
// Explicitly add methods to the classes from parents so it shows in documentation // Explicitly add methods to the classes from parents so it shows in documentation
for(Class& cls: classes) for(Class& cls: classes)
cls.appendInheritedMethods(cls, classes); cls.appendInheritedMethods(cls, classes);
@ -290,7 +295,7 @@ void Module::cython_code(const string& toolboxPath) const {
FileWriter pyxFile(pyxFileName, verbose, "#"); FileWriter pyxFile(pyxFileName, verbose, "#");
// create proxy class and wrapper code // create proxy class and wrapper code
for(const Class& cls: expandedClasses) for(const Class& cls: uninstantiatedClasses)
cls.cython_wrapper(pxdFile, pyxFile); cls.cython_wrapper(pxdFile, pyxFile);
// finish wrapper file // finish wrapper file
@ -483,8 +488,10 @@ void Module::python_wrapper(const string& toolboxPath) const {
wrapperFile.oss << "{\n"; wrapperFile.oss << "{\n";
// write out classes // write out classes
for(const Class& cls: expandedClasses) for(const Class& cls: classes) {
cout << "tmpl args:" << cls.templateArgs.size() << endl;
cls.python_wrapper(wrapperFile); cls.python_wrapper(wrapperFile);
}
// write out global functions // write out global functions
for(const GlobalFunctions::value_type& p: global_functions) for(const GlobalFunctions::value_type& p: global_functions)

View File

@ -38,6 +38,7 @@ struct Module {
std::string name; ///< module name std::string name; ///< module name
bool verbose; ///< verbose flag bool verbose; ///< verbose flag
std::vector<Class> classes; ///< list of classes std::vector<Class> classes; ///< list of classes
std::vector<Class> uninstantiatedClasses; ///< list of template classes after instantiated
std::vector<TemplateInstantiationTypedef> templateInstantiationTypedefs; ///< list of template instantiations std::vector<TemplateInstantiationTypedef> templateInstantiationTypedefs; ///< list of template instantiations
std::vector<ForwardDeclaration> forward_declarations; std::vector<ForwardDeclaration> forward_declarations;
std::vector<std::string> includes; ///< Include statements std::vector<std::string> includes; ///< Include statements

View File

@ -320,6 +320,16 @@ virtual class BetweenFactor : gtsam::NoiseModelFactor {
void serialize() const; void serialize() const;
}; };
#include <gtsam/sam/BearingFactor.h>
template<POSE, POINT, BEARING>
virtual class BearingFactor : gtsam::NoiseModelFactor {
BearingFactor(size_t key1, size_t key2, const BEARING& measured, const gtsam::noiseModel::Base* noiseModel);
// enabling serialization functionality
void serialize() const;
};
typedef gtsam::BearingFactor<gtsam::Pose2, gtsam::Point2, gtsam::Rot2> BearingFactor2D;
} }