diff --git a/wrap/Class.cpp b/wrap/Class.cpp index d1ffe0eb2..e70d745cd 100644 --- a/wrap/Class.cpp +++ b/wrap/Class.cpp @@ -736,7 +736,6 @@ void Class::emit_cython_pyx(FileWriter& pyxFile, const std::vector& allCl "\t\tself." << pyxCythonObj() << " = " << pyxSharedCythonClass() << "(new " << pyxCythonClass() << "())\n"; pyxInitParentObj(pyxFile, "\t\tself", "self." + pyxCythonObj(), allClasses); - pyxFile.oss << "\n"; pyxFile.oss << "\t@staticmethod\n"; pyxFile.oss << "\tcdef " << pythonClassName() << " cyCreate(" << pyxSharedCythonClass() << " other):\n" @@ -744,13 +743,14 @@ void Class::emit_cython_pyx(FileWriter& pyxFile, const std::vector& allCl << "\t\tret." << pyxCythonObj() << " = other\n"; pyxInitParentObj(pyxFile, "\t\tret", "other", allClasses); pyxFile.oss << "\t\treturn ret" << "\n"; + pyxFile.oss << "\n"; constructor.emit_cython_pyx(pyxFile, *this); - // if (constructor.nrOverloads()>0) pyxFile.oss << "\n"; + if (constructor.nrOverloads()>0) pyxFile.oss << "\n"; - // for(const StaticMethod& m: static_methods | boost::adaptors::map_values) - // m.emit_cython_pxd(pyxFile); - // if (static_methods.size()>0) pyxFile.oss << "\n"; + for(const StaticMethod& m: static_methods | boost::adaptors::map_values) + m.emit_cython_pyx(pyxFile, *this); + if (static_methods.size()>0) pyxFile.oss << "\n"; // for(const Method& m: nontemplateMethods_ | boost::adaptors::map_values) // m.emit_cython_pxd(pyxFile); diff --git a/wrap/ReturnValue.h b/wrap/ReturnValue.h index 5a6fe24ec..fba4fc6b9 100644 --- a/wrap/ReturnValue.h +++ b/wrap/ReturnValue.h @@ -48,6 +48,10 @@ struct ReturnValue { isPair = false; } + bool isVoid() const { + return !isPair && !type1.isPtr && (type1.name() == "void"); + } + bool operator==(const ReturnValue& other) const { return isPair == other.isPair && type1 == other.type1 && type2 == other.type2; diff --git a/wrap/StaticMethod.cpp b/wrap/StaticMethod.cpp index e612f4353..6b7d98894 100644 --- a/wrap/StaticMethod.cpp +++ b/wrap/StaticMethod.cpp @@ -18,6 +18,7 @@ #include "StaticMethod.h" #include "utilities.h" +#include "Class.h" #include #include @@ -59,15 +60,31 @@ string StaticMethod::wrapper_call(FileWriter& wrapperFile, Str cppClassName, void StaticMethod::emit_cython_pxd(FileWriter& file) const { // don't support overloads for static method :-( for(size_t i = 0; i < nrOverloads(); ++i) { - if (i>0) file.oss << "# "; file.oss << "\t\t@staticmethod\n"; - if (i>0) file.oss << "# "; file.oss << "\t\t"; returnVals_[i].emit_cython_pxd(file); - file.oss << name_ << "("; + file.oss << name_ << ((i>0)?to_string(i):"") << "("; argumentList(i).emit_cython_pxd(file); file.oss << ")\n"; } } /* ************************************************************************* */ +void StaticMethod::emit_cython_pyx(FileWriter& file, const Class& cls) const { + // don't support overloads for static method :-( + for(size_t i = 0; i < nrOverloads(); ++i) { + file.oss << "\t@staticmethod\n"; + file.oss << "\tdef " << name_ << "("; + argumentList(i).emit_cython_pyx(file); + file.oss << "):\n"; + file.oss << "\t\t"; + if (!returnVals_[i].isVoid()) file.oss << "return "; + file.oss << cls.pythonClassName() << ".cyCreate(" + << cls.pyxCythonClass() << "." << name_ + << "("; + argumentList(i).emit_cython_pyx_asParams(file); + file.oss << "))\n"; + } +} + +/* ************************************************************************* */ diff --git a/wrap/StaticMethod.h b/wrap/StaticMethod.h index 2c69459a0..c04408daf 100644 --- a/wrap/StaticMethod.h +++ b/wrap/StaticMethod.h @@ -23,6 +23,9 @@ namespace wrap { +// Forward declaration +class Class; + /// StaticMethod class struct StaticMethod: public MethodBase { @@ -35,6 +38,7 @@ struct StaticMethod: public MethodBase { } void emit_cython_pxd(FileWriter& file) const; + void emit_cython_pyx(FileWriter& file, const Class& cls) const; protected: