check if default constructor exists. Autogenerate copy constructor by default
parent
8944f02401
commit
2496de85a9
|
@ -121,10 +121,29 @@ void Constructor::python_wrapper(FileWriter& wrapperFile, Str className) const {
|
||||||
<< ");\n";
|
<< ");\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ************************************************************************* */
|
||||||
|
bool Constructor::hasDefaultConstructor() const {
|
||||||
|
for (size_t i = 0; i < nrOverloads(); i++) {
|
||||||
|
if (argumentList(i).size() == 0) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
void Constructor::emit_cython_pxd(FileWriter& pxdFile, Str className) const {
|
void Constructor::emit_cython_pxd(FileWriter& pxdFile, Str className) const {
|
||||||
|
// if it can ever be constructed, add the default copy constructor by default
|
||||||
|
if (nrOverloads() > 0) {
|
||||||
|
pxdFile.oss << "\t\t" << className << "(const " << className
|
||||||
|
<< "&) except +\n";
|
||||||
|
}
|
||||||
|
|
||||||
for (size_t i = 0; i < nrOverloads(); i++) {
|
for (size_t i = 0; i < nrOverloads(); i++) {
|
||||||
ArgumentList args = argumentList(i);
|
ArgumentList args = argumentList(i);
|
||||||
|
// ignore copy constructor, it's generated by default above
|
||||||
|
if (args.size() == 1 && args[0].is_const && args[0].is_ref &&
|
||||||
|
!args[0].is_ptr && args[0].type.cythonClassName() == className)
|
||||||
|
continue;
|
||||||
|
// generate the constructor
|
||||||
pxdFile.oss << "\t\t" << className << "(";
|
pxdFile.oss << "\t\t" << className << "(";
|
||||||
args.emit_cython_pxd(pxdFile);
|
args.emit_cython_pxd(pxdFile);
|
||||||
pxdFile.oss << ") " << "except +\n";
|
pxdFile.oss << ") " << "except +\n";
|
||||||
|
|
|
@ -45,6 +45,9 @@ struct Constructor: public OverloadedFunction {
|
||||||
return inst;
|
return inst;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// return true if the default constructor exists
|
||||||
|
bool hasDefaultConstructor() const;
|
||||||
|
|
||||||
// MATLAB code generation
|
// MATLAB code generation
|
||||||
// toolboxPath is main toolbox directory, e.g., ../matlab
|
// toolboxPath is main toolbox directory, e.g., ../matlab
|
||||||
// classFile is class proxy file, e.g., ../matlab/@Point2/Point2.m
|
// classFile is class proxy file, e.g., ../matlab/@Point2/Point2.m
|
||||||
|
|
Loading…
Reference in New Issue