aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cppgenerator.cpp50
-rw-r--r--cppgenerator.h4
2 files changed, 54 insertions, 0 deletions
diff --git a/cppgenerator.cpp b/cppgenerator.cpp
index f5cdad8ca..84e7e9e25 100644
--- a/cppgenerator.cpp
+++ b/cppgenerator.cpp
@@ -1673,6 +1673,56 @@ void CppGenerator::writeSpecialCastFunction(QTextStream& s, const AbstractMetaCl
s << "}\n\n";
}
+void CppGenerator::writeExtendedIsConvertibleFunction(QTextStream& s, const TypeEntry* externalType, const QList<const AbstractMetaClass*>& conversions)
+{
+ s << "static bool " << extendedIsConvertibleFunctionName(externalType) << "(PyObject* pyobj)" << endl;
+ s << '{' << endl;
+ s << INDENT << "return ";
+ bool isFirst = true;
+ foreach (const AbstractMetaClass* metaClass, conversions) {
+ Indentation indent(INDENT);
+ if (isFirst)
+ isFirst = false;
+ else
+ s << endl << INDENT << " || ";
+ s << cpythonCheckFunction(metaClass->typeEntry()) << "(pyobj)";
+ }
+ s << ';' << endl;
+ s << '}' << endl;
+}
+
+void CppGenerator::writeExtendedToCppFunction(QTextStream& s, const TypeEntry* externalType, const QList<const AbstractMetaClass*>& conversions)
+{
+ s << "static void* " << extendedToCppFunctionName(externalType) << "(PyObject* pyobj)" << endl;
+ s << '{' << endl;
+ s << INDENT << "void* cptr = 0;" << endl;
+ bool isFirst = true;
+ foreach (const AbstractMetaClass* metaClass, conversions) {
+ s << INDENT;
+ if (isFirst)
+ isFirst = false;
+ else
+ s << "else ";
+ s << "if (" << cpythonCheckFunction(metaClass->typeEntry()) << "(pyobj))" << endl;
+ Indentation indent(INDENT);
+ s << INDENT << "cptr = new " << externalType->name() << '(';
+ writeToCppConversion(s, metaClass, "pyobj");
+ s << ");" << endl;
+ }
+ s << INDENT << "return cptr;" << endl;
+ s << '}' << endl;
+}
+
+void CppGenerator::writeExtendedConverterInitialization(QTextStream& s, const TypeEntry* externalType, const QList<const AbstractMetaClass*>& conversions)
+{
+ s << INDENT << "// Extended implicit conversions for " << externalType->targetLangPackage() << '.' << externalType->name() << endl;
+ s << INDENT << "shiboType = reinterpret_cast<Shiboken::SbkBaseWrapperType*>(";
+ s << cppApiVariableName(externalType->targetLangPackage()) << '[';
+ s << getTypeIndexVariableName(externalType) << "]);" << endl;
+ s << INDENT << "shiboType->ext_isconvertible = " << extendedIsConvertibleFunctionName(externalType) << ';' << endl;
+ s << INDENT << "shiboType->ext_tocpp = " << extendedToCppFunctionName(externalType) << ';' << endl;
+}
+
QString CppGenerator::multipleInheritanceInitializerFunctionName(const AbstractMetaClass* metaClass)
{
if (!hasMultipleInheritanceInAncestry(metaClass))
diff --git a/cppgenerator.h b/cppgenerator.h
index 2230d6ba2..1df870d81 100644
--- a/cppgenerator.h
+++ b/cppgenerator.h
@@ -149,6 +149,10 @@ private:
/// Writes the implementation of special cast functions, used when we need to cast a class with mulltiple inheritance.
void writeSpecialCastFunction(QTextStream& s, const AbstractMetaClass* metaClass);
+ void writeExtendedIsConvertibleFunction(QTextStream& s, const TypeEntry* externalType, const QList<const AbstractMetaClass*>& conversions);
+ void writeExtendedToCppFunction(QTextStream& s, const TypeEntry* externalType, const QList<const AbstractMetaClass*>& conversions);
+ void writeExtendedConverterInitialization(QTextStream& s, const TypeEntry* externalType, const QList<const AbstractMetaClass*>& conversions);
+
void writeParentChildManagement(QTextStream& s, const AbstractMetaFunction* func);
void writeReturnValueHeuristics(QTextStream& s, const AbstractMetaFunction* func, const QString& self = "self");
/**