collect typedefs of basic (non-class) types to treat them as basic types

release/4.3a0
Duy-Nguyen Ta 2016-11-14 00:08:42 -05:00
parent 709417b36d
commit d38c51b533
4 changed files with 31 additions and 9 deletions

View File

@ -372,8 +372,12 @@ void Module::emit_cython_pyx(FileWriter& pyxFile) const {
string pxdHeader = name + "_wrapper";
pyxFile.oss << "cimport numpy as np\n"
"cimport " << pxdHeader << " as " << name << "\n"
"from "<< pxdHeader << " cimport shared_ptr\n"
"from eigency.core cimport *\n"
"from "<< pxdHeader << " cimport shared_ptr\n";
// import all typedefs, e.g. from gtsam cimport Key, so we don't need to say gtsam.Key
for(const Qualified& q: Qualified::BasicTypedefs) {
pyxFile.oss << "from " << pxdHeader << " cimport " << q.cythonClass() << "\n";
}
pyxFile.oss << "from eigency.core cimport *\n"
"from libcpp cimport bool\n\n"
"from libcpp.pair cimport pair\n"
"from libcpp.string cimport string\n"

5
wrap/Qualified.cpp Normal file
View File

@ -0,0 +1,5 @@
#include <wrap/Qualified.h>
namespace wrap {
std::vector<Qualified> Qualified::BasicTypedefs;
}

View File

@ -1,6 +1,6 @@
/* ----------------------------------------------------------------------------
* GTSAM Copyright 2010, Georgia Tech Research Corporation,
* GTSAM Copyright 2010, Georgia Tech Research Corporation,
* Atlanta, Georgia 30332-0415
* All Rights Reserved
* Authors: Frank Dellaert, et al. (see THANKS for the full author list)
@ -22,7 +22,7 @@
#include <string>
#include <vector>
#include <iostream>
namespace wrap {
/**
@ -35,6 +35,7 @@ public:
std::vector<std::string> namespaces_; ///< Stack of namespaces
std::string name_; ///< type name
static std::vector<Qualified> BasicTypedefs;
friend struct TypeGrammar;
friend class TemplateSubstitution;
@ -128,8 +129,15 @@ public:
return name() == "Vector" || name() == "Matrix";
}
bool isBasicTypedef() const {
return std::find(Qualified::BasicTypedefs.begin(),
Qualified::BasicTypedefs.end(),
*this) != Qualified::BasicTypedefs.end();
}
bool isNonBasicType() const {
return !isString() && !isScalar() && !isEigen() && !isVoid();
return !isString() && !isScalar() && !isEigen() && !isVoid() &&
!isBasicTypedef();
}
public:
@ -219,7 +227,6 @@ public:
os << q.qualifiedName("::");
return os;
}
};
/* ************************************************************************* */

View File

@ -8,9 +8,15 @@ struct TypedefPair {
std::string includeFile;
TypedefPair() {}
TypedefPair(const Qualified& oldType, const Qualified& newType,
TypedefPair(const Qualified& _oldType, const Qualified& _newType,
const std::string& includeFile)
: oldType(oldType), newType(newType), includeFile(includeFile) {}
: oldType(_oldType), newType(_newType), includeFile(includeFile) {
if (!oldType.isNonBasicType() &&
std::find(Qualified::BasicTypedefs.begin(),
Qualified::BasicTypedefs.end(),
newType) == Qualified::BasicTypedefs.end())
Qualified::BasicTypedefs.push_back(newType);
}
void emit_cython_pxd(FileWriter& file) const {
file.oss << "cdef extern from \"" << includeFile << "\" namespace \""
@ -19,4 +25,4 @@ struct TypedefPair {
<< newType.cythonClass() << "\n";
}
};
}
}