aboutsummaryrefslogtreecommitdiffstats
path: root/generator
diff options
context:
space:
mode:
authorMarcelo Lira <marcelo.lira@openbossa.org>2011-07-28 00:51:45 -0300
committerHugo Parente Lima <hugo.pl@gmail.com>2012-03-08 16:17:05 -0300
commitdbdcbdffa21b754faf6bab309126684427df7ac6 (patch)
tree040647860d3675967fae761dde14be5c7b7b423d /generator
parent0eb50de5faccf1a87f6f4686c8e214dcdb677aa5 (diff)
Improved readability of CppGenerator::writeCopyFunction() method.
The indentation, and everything else about it, was terrible.
Diffstat (limited to 'generator')
-rw-r--r--generator/cppgenerator.cpp50
1 files changed, 18 insertions, 32 deletions
diff --git a/generator/cppgenerator.cpp b/generator/cppgenerator.cpp
index fbe58dcf8..e9cf136df 100644
--- a/generator/cppgenerator.cpp
+++ b/generator/cppgenerator.cpp
@@ -2831,43 +2831,29 @@ void CppGenerator::writeTpClearFunction(QTextStream& s, const AbstractMetaClass*
void CppGenerator::writeCopyFunction(QTextStream& s, const AbstractMetaClass *metaClass)
{
- QString className = cpythonTypeName(metaClass).replace(QRegExp("_Type$"), "");
-
- Indentation indent(INDENT);
-
- s << "static PyObject *" << className << "___copy__(PyObject *self)" << endl;
- s << "{" << endl;
- s << INDENT << "::" << metaClass->qualifiedCppName() << "* " CPP_SELF_VAR " = 0;" << endl;
- s << INDENT << "if (!Shiboken::Object::isValid(self))" << endl;
- {
- Indentation indent(INDENT);
- s << INDENT << "return 0;" << endl;
- }
-
- s << INDENT << "cppSelf = Shiboken::Converter< ::" << metaClass->qualifiedCppName() << "*>::toCpp(self);" << endl;
- s << INDENT << "PyObject* " PYTHON_RETURN_VAR " = 0;" << endl;
-
- s << INDENT << "::" << metaClass->qualifiedCppName() << "* copy = new ::" << metaClass->qualifiedCppName();
- s << "(*cppSelf);" << endl;
- s << INDENT << PYTHON_RETURN_VAR " = Shiboken::Converter< ::" << metaClass->qualifiedCppName();
- s << "*>::toPython(copy);" << endl;
+ QString className = cpythonTypeName(metaClass).replace(QRegExp("_Type$"), "");
+ s << "static PyObject* " << className << "___copy__(PyObject* self)" << endl;
+ s << "{" << endl;
- s << INDENT << "Shiboken::Object::getOwnership(" PYTHON_RETURN_VAR ");" << endl;
+ writeCppSelfDefinition(s, metaClass);
- s << endl;
+ s << INDENT << "PyObject* " << PYTHON_RETURN_VAR << " = ";
+ s << "Shiboken::Converter< ::" << metaClass->qualifiedCppName() << " >::toPython(*";
+ s << CPP_SELF_VAR << ");" << endl;
- s << INDENT << "if (PyErr_Occurred() || !" PYTHON_RETURN_VAR ") {" << endl;
- {
- Indentation indent(INDENT);
- s << INDENT << "Py_XDECREF(" PYTHON_RETURN_VAR ");" << endl;
- s << INDENT << "return 0;" << endl;
- }
+ s << endl;
- s << INDENT << "}" << endl;
+ s << INDENT << "if (PyErr_Occurred() || !" PYTHON_RETURN_VAR ") {" << endl;
+ {
+ Indentation indent(INDENT);
+ s << INDENT << "Py_XDECREF(" PYTHON_RETURN_VAR ");" << endl;
+ s << INDENT << "return 0;" << endl;
+ }
+ s << INDENT << "}" << endl;
- s << INDENT << "return " PYTHON_RETURN_VAR ";" << endl;
- s << "}" << endl;
- s << endl;
+ s << INDENT << "return " PYTHON_RETURN_VAR ";" << endl;
+ s << "}" << endl;
+ s << endl;
}
void CppGenerator::writeGetterFunction(QTextStream& s, const AbstractMetaField* metaField)