Undo unrelated changes
parent
3bbea0f301
commit
c5a0f1a839
140
wrap/Class.cpp
140
wrap/Class.cpp
|
@ -176,7 +176,7 @@ void Class::matlab_proxy(Str toolboxPath, Str wrapperName,
|
|||
proxyFile.oss << " methods(Static = true)\n";
|
||||
|
||||
// Static methods
|
||||
for(const StaticMethods::value_type& name_m: static_methods_) {
|
||||
for(const StaticMethods::value_type& name_m: static_methods) {
|
||||
const StaticMethod& m = name_m.second;
|
||||
m.proxy_wrapper_fragments(proxyFile, wrapperFile, cppName, matlabQualName,
|
||||
matlabUniqueName, wrapperName, typeAttributes, functionNames);
|
||||
|
@ -295,7 +295,7 @@ void Class::pointer_constructor_fragments(FileWriter& proxyFile,
|
|||
Class Class::expandTemplate(const TemplateSubstitution& ts) const {
|
||||
Class inst = *this;
|
||||
inst.methods_ = expandMethodTemplate(methods_, ts);
|
||||
inst.static_methods_ = expandMethodTemplate(static_methods_, ts);
|
||||
inst.static_methods = expandMethodTemplate(static_methods, ts);
|
||||
inst.constructor = constructor.expandTemplate(ts);
|
||||
inst.deconstructor.name = inst.name();
|
||||
return inst;
|
||||
|
@ -409,11 +409,11 @@ void Class::verifyAll(vector<string>& validTypes, bool& hasSerialiable) const {
|
|||
|
||||
// verify all of the function arguments
|
||||
//TODO:verifyArguments<ArgumentList>(validTypes, constructor.args_list);
|
||||
verifyArguments<StaticMethod>(validTypes, static_methods_);
|
||||
verifyArguments<StaticMethod>(validTypes, static_methods);
|
||||
verifyArguments<Method>(validTypes, methods_);
|
||||
|
||||
// verify function return types
|
||||
verifyReturnTypes<StaticMethod>(validTypes, static_methods_);
|
||||
verifyReturnTypes<StaticMethod>(validTypes, static_methods);
|
||||
verifyReturnTypes<Method>(validTypes, methods_);
|
||||
|
||||
// verify parents
|
||||
|
@ -517,9 +517,9 @@ void Class::comment_fragment(FileWriter& proxyFile) const {
|
|||
for(const Methods::value_type& name_m: methods_)
|
||||
name_m.second.comment_fragment(proxyFile);
|
||||
|
||||
if (!static_methods_.empty())
|
||||
if (!static_methods.empty())
|
||||
proxyFile.oss << "%\n%-------Static Methods-------\n";
|
||||
for(const StaticMethods::value_type& name_m: static_methods_)
|
||||
for(const StaticMethods::value_type& name_m: static_methods)
|
||||
name_m.second.comment_fragment(proxyFile);
|
||||
|
||||
if (hasSerialization) {
|
||||
|
@ -721,7 +721,7 @@ string Class::getSerializationExport() const {
|
|||
void Class::python_wrapper(FileWriter& wrapperFile) const {
|
||||
wrapperFile.oss << "class_<" << name() << ">(\"" << name() << "\")\n";
|
||||
constructor.python_wrapper(wrapperFile, name());
|
||||
for(const StaticMethod& m: static_methods_ | boost::adaptors::map_values)
|
||||
for(const StaticMethod& m: static_methods | boost::adaptors::map_values)
|
||||
m.python_wrapper(wrapperFile, name());
|
||||
for(const Method& m: methods_ | boost::adaptors::map_values)
|
||||
m.python_wrapper(wrapperFile, name());
|
||||
|
@ -729,64 +729,64 @@ void Class::python_wrapper(FileWriter& wrapperFile) const {
|
|||
}
|
||||
|
||||
/* ************************************************************************* */
|
||||
void Class::emit_cython_pxd(FileWriter& file) const {
|
||||
file.oss << "cdef extern from \"" << includeFile << "\"";
|
||||
void Class::emit_cython_pxd(FileWriter& pxdFile) const {
|
||||
pxdFile.oss << "cdef extern from \"" << includeFile << "\"";
|
||||
string ns = qualifiedNamespaces("::");
|
||||
if (!ns.empty())
|
||||
file.oss << " namespace \"" << ns << "\"";
|
||||
file.oss << ":" << endl;
|
||||
file.oss << " cdef cppclass " << pxdClassName() << " \"" << qualifiedName("::") << "\"";
|
||||
pxdFile.oss << " namespace \"" << ns << "\"";
|
||||
pxdFile.oss << ":" << endl;
|
||||
pxdFile.oss << " cdef cppclass " << pxdClassName() << " \"" << qualifiedName("::") << "\"";
|
||||
if (templateArgs.size()>0) {
|
||||
file.oss << "[";
|
||||
pxdFile.oss << "[";
|
||||
for(size_t i = 0; i<templateArgs.size(); ++i) {
|
||||
file.oss << templateArgs[i];
|
||||
if (i<templateArgs.size()-1) file.oss << ",";
|
||||
pxdFile.oss << templateArgs[i];
|
||||
if (i<templateArgs.size()-1) pxdFile.oss << ",";
|
||||
}
|
||||
file.oss << "]";
|
||||
pxdFile.oss << "]";
|
||||
}
|
||||
if (parentClass) file.oss << "(" << parentClass->pxdClassName() << ")";
|
||||
file.oss << ":\n";
|
||||
if (parentClass) pxdFile.oss << "(" << parentClass->pxdClassName() << ")";
|
||||
pxdFile.oss << ":\n";
|
||||
|
||||
constructor.emit_cython_pxd(file, *this);
|
||||
if (constructor.nrOverloads()>0) file.oss << "\n";
|
||||
constructor.emit_cython_pxd(pxdFile, *this);
|
||||
if (constructor.nrOverloads()>0) pxdFile.oss << "\n";
|
||||
|
||||
for(const StaticMethod& m: static_methods_ | boost::adaptors::map_values)
|
||||
m.emit_cython_pxd(file, *this);
|
||||
if (static_methods_.size()>0) file.oss << "\n";
|
||||
for(const StaticMethod& m: static_methods | boost::adaptors::map_values)
|
||||
m.emit_cython_pxd(pxdFile, *this);
|
||||
if (static_methods.size()>0) pxdFile.oss << "\n";
|
||||
|
||||
for(const Method& m: nontemplateMethods_ | boost::adaptors::map_values)
|
||||
m.emit_cython_pxd(file, *this);
|
||||
m.emit_cython_pxd(pxdFile, *this);
|
||||
|
||||
for(const TemplateMethod& m: templateMethods_ | boost::adaptors::map_values)
|
||||
m.emit_cython_pxd(file, *this);
|
||||
size_t numMethods = constructor.nrOverloads() + static_methods_.size() +
|
||||
m.emit_cython_pxd(pxdFile, *this);
|
||||
size_t numMethods = constructor.nrOverloads() + static_methods.size() +
|
||||
methods_.size() + templateMethods_.size();
|
||||
if (numMethods == 0)
|
||||
file.oss << " pass\n";
|
||||
pxdFile.oss << " pass\n";
|
||||
}
|
||||
/* ************************************************************************* */
|
||||
void Class::emit_cython_wrapper_pxd(FileWriter& file) const {
|
||||
file.oss << "\ncdef class " << pyxClassName();
|
||||
void Class::emit_cython_wrapper_pxd(FileWriter& pxdFile) const {
|
||||
pxdFile.oss << "\ncdef class " << pyxClassName();
|
||||
if (getParent())
|
||||
file.oss << "(" << getParent()->pyxClassName() << ")";
|
||||
file.oss << ":\n";
|
||||
file.oss << " cdef " << shared_pxd_class_in_pyx() << " "
|
||||
pxdFile.oss << "(" << getParent()->pyxClassName() << ")";
|
||||
pxdFile.oss << ":\n";
|
||||
pxdFile.oss << " cdef " << shared_pxd_class_in_pyx() << " "
|
||||
<< shared_pxd_obj_in_pyx() << "\n";
|
||||
// cyCreateFromShared
|
||||
file.oss << " @staticmethod\n";
|
||||
file.oss << " cdef " << pyxClassName() << " cyCreateFromShared(const "
|
||||
pxdFile.oss << " @staticmethod\n";
|
||||
pxdFile.oss << " cdef " << pyxClassName() << " cyCreateFromShared(const "
|
||||
<< shared_pxd_class_in_pyx() << "& other)\n";
|
||||
for(const StaticMethod& m: static_methods_ | boost::adaptors::map_values)
|
||||
m.emit_cython_wrapper_pxd(file, *this);
|
||||
if (static_methods_.size()>0) file.oss << "\n";
|
||||
for(const StaticMethod& m: static_methods | boost::adaptors::map_values)
|
||||
m.emit_cython_wrapper_pxd(pxdFile, *this);
|
||||
if (static_methods.size()>0) pxdFile.oss << "\n";
|
||||
}
|
||||
|
||||
/* ************************************************************************* */
|
||||
void Class::pyxInitParentObj(FileWriter& file, const std::string& pyObj,
|
||||
void Class::pyxInitParentObj(FileWriter& pyxFile, const std::string& pyObj,
|
||||
const std::string& cySharedObj,
|
||||
const std::vector<Class>& allClasses) const {
|
||||
if (parentClass) {
|
||||
file.oss << pyObj << "." << parentClass->shared_pxd_obj_in_pyx() << " = "
|
||||
pyxFile.oss << pyObj << "." << parentClass->shared_pxd_obj_in_pyx() << " = "
|
||||
<< "<" << parentClass->shared_pxd_class_in_pyx() << ">("
|
||||
<< cySharedObj << ")\n";
|
||||
// Find the parent class with name "parentClass" and point its cython obj
|
||||
|
@ -800,27 +800,27 @@ void Class::pyxInitParentObj(FileWriter& file, const std::string& pyObj,
|
|||
cerr << "Can't find parent class: " << parentClass->pxdClassName();
|
||||
throw std::runtime_error("Parent class not found!");
|
||||
}
|
||||
parent_it->pyxInitParentObj(file, pyObj, cySharedObj, allClasses);
|
||||
parent_it->pyxInitParentObj(pyxFile, pyObj, cySharedObj, allClasses);
|
||||
}
|
||||
}
|
||||
|
||||
/* ************************************************************************* */
|
||||
void Class::pyxDynamicCast(FileWriter& file, const Class& curLevel,
|
||||
void Class::pyxDynamicCast(FileWriter& pyxFile, const Class& curLevel,
|
||||
const std::vector<Class>& allClasses) const {
|
||||
std::string me = this->pyxClassName(), sharedMe = this->shared_pxd_class_in_pyx();
|
||||
if (curLevel.parentClass) {
|
||||
std::string parent = curLevel.parentClass->pyxClassName(),
|
||||
parentObj = curLevel.parentClass->shared_pxd_obj_in_pyx(),
|
||||
parentCythonClass = curLevel.parentClass->pxd_class_in_pyx();
|
||||
file.oss << "def dynamic_cast_" << me << "_" << parent << "(" << parent
|
||||
pyxFile.oss << "def dynamic_cast_" << me << "_" << parent << "(" << parent
|
||||
<< " parent):\n";
|
||||
file.oss << " try:\n";
|
||||
file.oss << " return " << me << ".cyCreateFromShared(<" << sharedMe
|
||||
pyxFile.oss << " try:\n";
|
||||
pyxFile.oss << " return " << me << ".cyCreateFromShared(<" << sharedMe
|
||||
<< ">dynamic_pointer_cast[" << pxd_class_in_pyx() << ","
|
||||
<< parentCythonClass << "](parent." << parentObj
|
||||
<< "))\n";
|
||||
file.oss << " except:\n";
|
||||
file.oss << " raise TypeError('dynamic cast failed!')\n";
|
||||
pyxFile.oss << " except:\n";
|
||||
pyxFile.oss << " raise TypeError('dynamic cast failed!')\n";
|
||||
// Move up higher to one level: Find the parent class with name "parentClass"
|
||||
auto parent_it = find_if(allClasses.begin(), allClasses.end(),
|
||||
[&curLevel](const Class& cls) {
|
||||
|
@ -831,51 +831,51 @@ void Class::pyxDynamicCast(FileWriter& file, const Class& curLevel,
|
|||
cerr << "Can't find parent class: " << parentClass->pxdClassName();
|
||||
throw std::runtime_error("Parent class not found!");
|
||||
}
|
||||
pyxDynamicCast(file, *parent_it, allClasses);
|
||||
pyxDynamicCast(pyxFile, *parent_it, allClasses);
|
||||
}
|
||||
}
|
||||
|
||||
/* ************************************************************************* */
|
||||
void Class::emit_cython_pyx(FileWriter& file, const std::vector<Class>& allClasses) const {
|
||||
file.oss << "cdef class " << pyxClassName();
|
||||
if (parentClass) file.oss << "(" << parentClass->pyxClassName() << ")";
|
||||
file.oss << ":\n";
|
||||
void Class::emit_cython_pyx(FileWriter& pyxFile, const std::vector<Class>& allClasses) const {
|
||||
pyxFile.oss << "cdef class " << pyxClassName();
|
||||
if (parentClass) pyxFile.oss << "(" << parentClass->pyxClassName() << ")";
|
||||
pyxFile.oss << ":\n";
|
||||
|
||||
// __init___
|
||||
file.oss << " def __init__(self, *args, **kwargs):\n";
|
||||
file.oss << " cdef list __params\n";
|
||||
file.oss << " self." << shared_pxd_obj_in_pyx() << " = " << shared_pxd_class_in_pyx() << "()\n";
|
||||
file.oss << " if len(args)==0 and len(kwargs)==1 and kwargs.has_key('cyCreateFromShared'):\n return\n";
|
||||
pyxFile.oss << " def __init__(self, *args, **kwargs):\n";
|
||||
pyxFile.oss << " cdef list __params\n";
|
||||
pyxFile.oss << " self." << shared_pxd_obj_in_pyx() << " = " << shared_pxd_class_in_pyx() << "()\n";
|
||||
pyxFile.oss << " if len(args)==0 and len(kwargs)==1 and kwargs.has_key('cyCreateFromShared'):\n return\n";
|
||||
|
||||
// Constructors
|
||||
constructor.emit_cython_pyx(file, *this);
|
||||
file.oss << " if (self." << shared_pxd_obj_in_pyx() << ".use_count()==0):\n";
|
||||
file.oss << " raise TypeError('" << pyxClassName()
|
||||
constructor.emit_cython_pyx(pyxFile, *this);
|
||||
pyxFile.oss << " if (self." << shared_pxd_obj_in_pyx() << ".use_count()==0):\n";
|
||||
pyxFile.oss << " raise TypeError('" << pyxClassName()
|
||||
<< " construction failed!')\n";
|
||||
pyxInitParentObj(file, " self", "self." + shared_pxd_obj_in_pyx(), allClasses);
|
||||
file.oss << "\n";
|
||||
pyxInitParentObj(pyxFile, " self", "self." + shared_pxd_obj_in_pyx(), allClasses);
|
||||
pyxFile.oss << "\n";
|
||||
|
||||
// cyCreateFromShared
|
||||
file.oss << " @staticmethod\n";
|
||||
file.oss << " cdef " << pyxClassName() << " cyCreateFromShared(const "
|
||||
pyxFile.oss << " @staticmethod\n";
|
||||
pyxFile.oss << " cdef " << pyxClassName() << " cyCreateFromShared(const "
|
||||
<< shared_pxd_class_in_pyx() << "& other):\n"
|
||||
<< " if other.get() == NULL:\n"
|
||||
<< " raise RuntimeError('Cannot create object from a nullptr!')\n"
|
||||
<< " cdef " << pyxClassName() << " return_value = " << pyxClassName() << "(cyCreateFromShared=True)\n"
|
||||
<< " return_value." << shared_pxd_obj_in_pyx() << " = other\n";
|
||||
pyxInitParentObj(file, " return_value", "other", allClasses);
|
||||
file.oss << " return return_value" << "\n\n";
|
||||
pyxInitParentObj(pyxFile, " return_value", "other", allClasses);
|
||||
pyxFile.oss << " return return_value" << "\n\n";
|
||||
|
||||
for(const StaticMethod& m: static_methods_ | boost::adaptors::map_values)
|
||||
m.emit_cython_pyx(file, *this);
|
||||
if (static_methods_.size()>0) file.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: methods_ | boost::adaptors::map_values)
|
||||
m.emit_cython_pyx(file, *this);
|
||||
m.emit_cython_pyx(pyxFile, *this);
|
||||
|
||||
pyxDynamicCast(file, *this, allClasses);
|
||||
pyxDynamicCast(pyxFile, *this, allClasses);
|
||||
|
||||
file.oss << "\n\n";
|
||||
pyxFile.oss << "\n\n";
|
||||
}
|
||||
|
||||
/* ************************************************************************* */
|
||||
|
|
|
@ -67,7 +67,7 @@ private:
|
|||
|
||||
public:
|
||||
|
||||
StaticMethods static_methods_; ///< Static methods
|
||||
StaticMethods static_methods; ///< Static methods
|
||||
|
||||
// Then the instance variables are set directly by the Module constructor
|
||||
std::vector<std::string> templateArgs; ///< Template arguments
|
||||
|
@ -177,7 +177,7 @@ public:
|
|||
friend std::ostream& operator<<(std::ostream& os, const Class& cls) {
|
||||
os << "class " << cls.name() << "{\n";
|
||||
os << cls.constructor << ";\n";
|
||||
for(const StaticMethod& m: cls.static_methods_ | boost::adaptors::map_values)
|
||||
for(const StaticMethod& m: cls.static_methods | boost::adaptors::map_values)
|
||||
os << m << ";\n";
|
||||
for(const Method& m: cls.methods_ | boost::adaptors::map_values)
|
||||
os << m << ";\n";
|
||||
|
@ -272,7 +272,7 @@ struct ClassGrammar: public classic::grammar<ClassGrammar> {
|
|||
>> staticMethodName_p[assign_a(methodName)] >> argumentList_g >> ';'
|
||||
>> *comments_p) //
|
||||
[bl::bind(&StaticMethod::addOverload,
|
||||
bl::var(self.cls_.static_methods_)[bl::var(methodName)],
|
||||
bl::var(self.cls_.static_methods)[bl::var(methodName)],
|
||||
bl::var(methodName), bl::var(args), bl::var(retVal), boost::none,
|
||||
verbose)] //
|
||||
[assign_a(retVal, retVal0)][clear_a(args)];
|
||||
|
|
|
@ -129,31 +129,31 @@ bool Constructor::hasDefaultConstructor() const {
|
|||
}
|
||||
|
||||
/* ************************************************************************* */
|
||||
void Constructor::emit_cython_pxd(FileWriter& file, const Class& cls) const {
|
||||
void Constructor::emit_cython_pxd(FileWriter& pxdFile, const Class& cls) const {
|
||||
for (size_t i = 0; i < nrOverloads(); i++) {
|
||||
ArgumentList args = argumentList(i);
|
||||
|
||||
// generate the constructor
|
||||
file.oss << " " << cls.pxdClassName() << "(";
|
||||
args.emit_cython_pxd(file, cls.pxdClassName(), cls.templateArgs);
|
||||
file.oss << ") " << "except +\n";
|
||||
pxdFile.oss << " " << cls.pxdClassName() << "(";
|
||||
args.emit_cython_pxd(pxdFile, cls.pxdClassName(), cls.templateArgs);
|
||||
pxdFile.oss << ") " << "except +\n";
|
||||
}
|
||||
}
|
||||
|
||||
/* ************************************************************************* */
|
||||
void Constructor::emit_cython_pyx(FileWriter& file, const Class& cls) const {
|
||||
void Constructor::emit_cython_pyx(FileWriter& pyxFile, const Class& cls) const {
|
||||
for (size_t i = 0; i < nrOverloads(); i++) {
|
||||
ArgumentList args = argumentList(i);
|
||||
file.oss << " try:\n";
|
||||
file.oss << pyx_resolveOverloadParams(args, true, 3);
|
||||
file.oss
|
||||
pyxFile.oss << " try:\n";
|
||||
pyxFile.oss << pyx_resolveOverloadParams(args, true, 3);
|
||||
pyxFile.oss
|
||||
<< argumentList(i).pyx_convertEigenTypeAndStorageOrder(" ");
|
||||
|
||||
file.oss << " self." << cls.shared_pxd_obj_in_pyx() << " = "
|
||||
pyxFile.oss << " self." << cls.shared_pxd_obj_in_pyx() << " = "
|
||||
<< cls.shared_pxd_class_in_pyx() << "(new " << cls.pxd_class_in_pyx()
|
||||
<< "(" << args.pyx_asParams() << "))\n";
|
||||
file.oss << " except:\n";
|
||||
file.oss << " pass\n";
|
||||
pyxFile.oss << " except:\n";
|
||||
pyxFile.oss << " pass\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -360,26 +360,26 @@ void Module::emit_cython_pxd(FileWriter& pxdFile) const {
|
|||
for (const Class& cls : uninstantiatedClasses) {
|
||||
cls.emit_cython_pxd(pxdFile);
|
||||
|
||||
for (const Class& expanded : expandedClasses) {
|
||||
bool matchingNonTemplated = !expanded.templateClass
|
||||
&& expanded.pxdClassName() == cls.pxdClassName();
|
||||
bool isTemplatedFromCls = expanded.templateClass
|
||||
&& expanded.templateClass->pxdClassName() == cls.pxdClassName();
|
||||
for (const Class& expCls : expandedClasses) {
|
||||
bool matchingNonTemplated = !expCls.templateClass
|
||||
&& expCls.pxdClassName() == cls.pxdClassName();
|
||||
bool isTemplatedFromCls = expCls.templateClass
|
||||
&& expCls.templateClass->pxdClassName() == cls.pxdClassName();
|
||||
|
||||
// ctypedef for template instantiations
|
||||
if (isTemplatedFromCls) {
|
||||
pxdFile.oss << "\n";
|
||||
pxdFile.oss << "ctypedef " << expanded.templateClass->pxdClassName()
|
||||
pxdFile.oss << "ctypedef " << expCls.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";
|
||||
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";
|
||||
}
|
||||
|
||||
// Python wrapper class
|
||||
if (isTemplatedFromCls || matchingNonTemplated) {
|
||||
expanded.emit_cython_wrapper_pxd(pxdFile);
|
||||
expCls.emit_cython_wrapper_pxd(pxdFile);
|
||||
}
|
||||
}
|
||||
pxdFile.oss << "\n\n";
|
||||
|
|
Loading…
Reference in New Issue