aboutsummaryrefslogtreecommitdiffstats
path: root/headergenerator.cpp
diff options
context:
space:
mode:
authorMarcelo Lira <marcelo.lira@openbossa.org>2009-10-28 17:47:49 -0300
committerMarcelo Lira <marcelo.lira@openbossa.org>2009-10-30 14:24:20 -0300
commit2c70b9c40a49dd18bc390783464ef20ed088486d (patch)
tree7fc7ed1288fe3f8949f34772346c76ada4abb69c /headergenerator.cpp
parentb01f0b159a5edf42de817fada68e9852a65e8bc9 (diff)
modified Converter<T>::isConvertible(PyObject*) to check only if the given
Python object is convertible to the C++ type T, and not if it is of the same type as T (this is done by the standard PyTYPENAME_Check macros)
Diffstat (limited to 'headergenerator.cpp')
-rw-r--r--headergenerator.cpp31
1 files changed, 23 insertions, 8 deletions
diff --git a/headergenerator.cpp b/headergenerator.cpp
index dcdfa948c..bd671012e 100644
--- a/headergenerator.cpp
+++ b/headergenerator.cpp
@@ -188,9 +188,10 @@ void HeaderGenerator::writeTypeConverterDecl(QTextStream& s, const TypeEntry* ty
s << "template<>" << endl;
s << "struct Converter< " << cppName << " >" << endl << '{' << endl;
- s << INDENT << "static bool isConvertible(const PyObject* pyObj);\n";
- s << INDENT << "static PyObject* toPython(const " << cppName << " cppobj);\n";
- s << INDENT << "static " << cppName << " toCpp(PyObject* pyobj);\n";
+ if (implicitConversions(type).size() > 0)
+ s << INDENT << "static bool isConvertible(PyObject* pyObj);" << endl;
+ s << INDENT << "static PyObject* toPython(const " << cppName << " cppobj);" << endl;
+ s << INDENT << "static " << cppName << " toCpp(PyObject* pyobj);" << endl;
s << "};" << endl;
}
@@ -204,10 +205,24 @@ void HeaderGenerator::writeTypeConverterImpl(QTextStream& s, const TypeEntry* ty
cppName.append('*');
// write isConvertible function
- s << "inline bool Converter<" << cppName << " >::isConvertible(const PyObject* pyObj)\n";
- s << "{\n";
- s << INDENT << "return PyObject_TypeCheck(pyObj, &" << pyTypeName << ");\n";
- s << "}\n";
+ AbstractMetaFunctionList implicitConvs = implicitConversions(type);
+ if (implicitConvs.size() > 0) {
+ s << "inline bool Converter<" << cppName << " >::isConvertible(PyObject* pyObj)" << endl;
+ s << '{' << endl;
+ s << INDENT << "return ";
+ bool isFirst = true;
+ foreach (const AbstractMetaFunction* ctor, implicitConvs) {
+ Indentation indent(INDENT);
+ if (isFirst)
+ isFirst = false;
+ else
+ s << endl << INDENT << " || ";
+ s << cpythonCheckFunction(ctor->arguments().first()->type());
+ s << "(pyObj)";
+ }
+ s << ';' << endl;
+ s << '}' << endl;
+ }
// write toPython function
s << "inline PyObject* Converter<" << cppName << " >::toPython(const " << cppName << " cppobj)\n";
@@ -269,7 +284,7 @@ void HeaderGenerator::writeTypeConverterImpl(QTextStream& s, const TypeEntry* ty
firstImplicitIf = false;
else
s << "else ";
- s << "if (" << cpythonIsConvertibleFunction(argType) << "(pyobj))" << endl;
+ s << "if (" << cpythonCheckFunction(argType) << "(pyobj))" << endl;
{
Indentation indent(INDENT);
s << INDENT << "return " << cppName << '(';