Moved wrapper class signature to Class.cpp

release/4.3a0
dellaert 2017-08-06 12:21:26 -07:00
parent 74a33ff222
commit 6068166d2b
3 changed files with 36 additions and 32 deletions

View File

@ -764,6 +764,19 @@ void Class::emit_cython_pxd(FileWriter& pxdFile) const {
if (numMethods == 0)
pxdFile.oss << " pass\n";
}
/* ************************************************************************* */
void Class::emit_cython_wrapper_pxd(FileWriter& pxdFile) const {
pxdFile.oss << "cdef class " << pyxClassName();
if (getParent())
pxdFile.oss << "(" << getParent()->pyxClassName() << ")";
pxdFile.oss << ":\n";
pxdFile.oss << " cdef " << shared_pxd_class_in_pyx() << " "
<< shared_pxd_obj_in_pyx() << "\n";
// cyCreateFromShared
pxdFile.oss << " @staticmethod\n";
pxdFile.oss << " cdef " << pyxClassName() << " cyCreateFromShared(const "
<< shared_pxd_class_in_pyx() << "& other)\n";
}
/* ************************************************************************* */
void Class::pyxInitParentObj(FileWriter& pyxFile, const std::string& pyObj,

View File

@ -165,6 +165,7 @@ public:
// emit cython wrapper
void emit_cython_pxd(FileWriter& pxdFile) const;
void emit_cython_wrapper_pxd(FileWriter& pxdFile) const;
void emit_cython_pyx(FileWriter& pyxFile,
const std::vector<Class>& allClasses) const;
void pyxInitParentObj(FileWriter& pyxFile, const std::string& pyObj,

View File

@ -357,41 +357,31 @@ void Module::emit_cython_pxd(FileWriter& pxdFile) const {
//... wrap all classes
for (const Class& cls : uninstantiatedClasses) {
cls.emit_cython_pxd(pxdFile);
cls.emit_cython_pxd(pxdFile);
for (const Class& expCls : expandedClasses) {
//... ctypedef for template instantiations
if (expCls.templateClass &&
expCls.templateClass->pxdClassName() == cls.pxdClassName()) {
pxdFile.oss << "ctypedef " << expCls.templateClass->pxdClassName()
<< "[";
for (size_t i = 0; i < expCls.templateInstTypeList.size(); ++i)
pxdFile.oss << expCls.templateInstTypeList[i].pxdClassName()
<< ((i == expCls.templateInstTypeList.size() - 1)
? ""
: ", ");
pxdFile.oss << "] " << expCls.pxdClassName() << "\n";
}
for (const Class& expanded : expandedClasses) {
bool matchingNonTemplated = !expanded.templateClass
&& expanded.pxdClassName() == cls.pxdClassName();
bool isTemplatedFromCls = expanded.templateClass
&& expanded.templateClass->pxdClassName() == cls.pxdClassName();
if ((!expCls.templateClass &&
expCls.pxdClassName() == cls.pxdClassName()) ||
(expCls.templateClass &&
expCls.templateClass->pxdClassName() == cls.pxdClassName())) {
pxdFile.oss << "\n";
pxdFile.oss << "cdef class " << expCls.pyxClassName();
if (expCls.getParent())
pxdFile.oss << "(" << expCls.getParent()->pyxClassName() << ")";
pxdFile.oss << ":\n";
pxdFile.oss << " cdef " << expCls.shared_pxd_class_in_pyx()
<< " " << expCls.shared_pxd_obj_in_pyx() << "\n";
// cyCreateFromShared
pxdFile.oss << " @staticmethod\n";
pxdFile.oss << " cdef " << expCls.pyxClassName()
<< " cyCreateFromShared(const "
<< expCls.shared_pxd_class_in_pyx() << "& other)\n";
}
// ctypedef for template instantiations
if (isTemplatedFromCls) {
pxdFile.oss << "\n";
pxdFile.oss << "ctypedef " << expanded.templateClass->pxdClassName()
<< "[";
for (size_t i = 0; i < expanded.templateInstTypeList.size(); ++i)
pxdFile.oss << expanded.templateInstTypeList[i].pxdClassName()
<< ((i == expanded.templateInstTypeList.size() - 1) ? "" : ", ");
pxdFile.oss << "] " << expanded.pxdClassName() << "\n";
}
pxdFile.oss << "\n\n";
// Python wrapper class
if (isTemplatedFromCls || matchingNonTemplated) {
expanded.emit_cython_wrapper_pxd(pxdFile);
}
}
pxdFile.oss << "\n\n";
}
//... wrap global functions