standardize function name to emit_cython_[pxd/pyx]. Remove first level namespace from Cython object names.

Examples: gtsam_Point3 --> Point3, gtsam_noiseModel_Base --> noiseModel_Base
release/4.3a0
Duy-Nguyen Ta 2016-09-09 12:01:51 -04:00
parent f137ae1d9c
commit 2d3d6d99f9
6 changed files with 31 additions and 17 deletions

View File

@ -672,8 +672,8 @@ void Class::python_wrapper(FileWriter& wrapperFile) const {
}
/* ************************************************************************* */
void Class::cython_wrapper(FileWriter& pxdFile, FileWriter& pyxFile) const {
string cythonClassName = qualifiedName("_");
void Class::emit_cython_pxd(FileWriter& pxdFile) const {
string cythonClassName = qualifiedName("_", 1);
pxdFile.oss << "cdef extern from \"" << includeFile << "\" namespace \""
<< qualifiedNamespaces("::") << "\":" << endl;
pxdFile.oss << "\tcdef cppclass " << cythonClassName << " \"" << qualifiedName("::") << "\"";
@ -688,13 +688,7 @@ void Class::cython_wrapper(FileWriter& pxdFile, FileWriter& pyxFile) const {
if (parentClass) pxdFile.oss << "(" << parentClass->qualifiedName("_") << ")";
pxdFile.oss << ":\n";
pyxFile.oss << "cdef class " << name();
if (parentClass) pyxFile.oss << "(" << parentClass->name() << ")";
pyxFile.oss << ":\n";
pyxFile.oss << "\tcdef shared_ptr[" << cythonClassName << "] "
<< "gt" << name() << "_\n";
constructor.cython_wrapper(pxdFile, pyxFile, cythonClassName);
constructor.emit_cython_pxd(pxdFile, cythonClassName);
if (constructor.nrOverloads()>0) pxdFile.oss << "\n";
for(const StaticMethod& m: static_methods | boost::adaptors::map_values)
@ -710,6 +704,17 @@ void Class::cython_wrapper(FileWriter& pxdFile, FileWriter& pyxFile) const {
if (numMethods == 0)
pxdFile.oss << "\t\tpass";
pxdFile.oss << "\n\n";
}
void Class::emit_cython_pyx(FileWriter& pyxFile) const {
string cythonClassName = qualifiedName("_", 1);
pyxFile.oss << "cdef class " << name();
if (parentClass) pyxFile.oss << "(" << parentClass->name() << ")";
pyxFile.oss << ":\n";
pyxFile.oss << "\tcdef shared_ptr[" << cythonClassName << "] "
<< "gt" << name() << "_\n";
constructor.emit_cython_pyx(pyxFile, cythonClassName);
pyxFile.oss << "\n";
}

View File

@ -148,7 +148,8 @@ public:
void python_wrapper(FileWriter& wrapperFile) const;
// emit cython wrapper
void cython_wrapper(FileWriter& pxdFile, FileWriter& pyxFile) const;
void emit_cython_pxd(FileWriter& pxdFile) const;
void emit_cython_pyx(FileWriter& pyxFile) const;
friend std::ostream& operator<<(std::ostream& os, const Class& cls) {
os << "class " << cls.name() << "{\n";

View File

@ -121,7 +121,7 @@ void Constructor::python_wrapper(FileWriter& wrapperFile, Str className) const {
}
/* ************************************************************************* */
void Constructor::cython_wrapper(FileWriter& pxdFile, FileWriter& pyxFile, Str className) const {
void Constructor::emit_cython_pxd(FileWriter& pxdFile, Str className) const {
for (size_t i = 0; i < nrOverloads(); i++) {
ArgumentList args = argumentList(i);
pxdFile.oss << "\t\t" << className << "(";
@ -131,3 +131,7 @@ void Constructor::cython_wrapper(FileWriter& pxdFile, FileWriter& pyxFile, Str c
}
/* ************************************************************************* */
void Constructor::emit_cython_pyx(FileWriter& pyxFile, Str className) const {
}
/* ************************************************************************* */

View File

@ -79,7 +79,8 @@ struct Constructor: public OverloadedFunction {
void python_wrapper(FileWriter& wrapperFile, Str className) const;
// emit cython wrapper
void cython_wrapper(FileWriter& pxdFile, FileWriter& pyxFile, Str className) const;
void emit_cython_pxd(FileWriter& pxdFile, Str className) const;
void emit_cython_pyx(FileWriter& pyxFile, Str className) const;
friend std::ostream& operator<<(std::ostream& os, const Constructor& m) {
for (size_t i = 0; i < m.nrOverloads(); i++)

View File

@ -294,13 +294,16 @@ void Module::cython_code(const string& toolboxPath) const {
FileWriter pxdFile(pxdFileName, verbose, "#");
FileWriter pyxFile(pyxFileName, verbose, "#");
// create proxy class and wrapper code
// create cython pxd file
for(const Class& cls: uninstantiatedClasses)
cls.cython_wrapper(pxdFile, pyxFile);
cls.emit_cython_pxd(pxdFile);
// finish wrapper file
pxdFile.oss << "\n";
pxdFile.emit(true);
// create cython pyx file
for(const Class& cls: uninstantiatedClasses)
cls.emit_cython_pyx(pyxFile);
pyxFile.oss << "\n";
pyxFile.emit(true);
}

View File

@ -137,9 +137,9 @@ public:
}
/// Return a qualified string using given delimiter
std::string qualifiedName(const std::string& delimiter = "") const {
std::string qualifiedName(const std::string& delimiter = "", size_t fromLevel = 0) const {
std::string result;
for (std::size_t i = 0; i < namespaces_.size(); ++i)
for (std::size_t i = fromLevel; i < namespaces_.size(); ++i)
result += (namespaces_[i] + delimiter);
result += name_;
return result;