aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cppgenerator.cpp26
-rw-r--r--cppgenerator.h2
2 files changed, 12 insertions, 16 deletions
diff --git a/cppgenerator.cpp b/cppgenerator.cpp
index 49fb4f2ed..5f85149a4 100644
--- a/cppgenerator.cpp
+++ b/cppgenerator.cpp
@@ -1011,7 +1011,7 @@ void CppGenerator::writeInvalidCppObjectCheck(QTextStream& s, QString pyArgName,
}
}
-void CppGenerator::writeTypeCheck(QTextStream& s, const AbstractMetaType* argType, QString argumentName, QString customCheck)
+void CppGenerator::writeTypeCheck(QTextStream& s, const AbstractMetaType* argType, QString argumentName, bool isNumber, QString customType)
{
bool isPairContainer = argType->isContainer()
&& ((ContainerTypeEntry*)argType->typeEntry())->type() == ContainerTypeEntry::PairContainer;
@@ -1025,14 +1025,14 @@ void CppGenerator::writeTypeCheck(QTextStream& s, const AbstractMetaType* argTyp
if (isPairContainer)
s << '(';
- if (!customCheck.isEmpty())
- s << customCheck;
+ if (!customType.isEmpty())
+ s << guessCPythonCheckFunction(customType);
else if (argType->typeEntry()->isFlags())
s << cpythonCheckFunction(((FlagsTypeEntry*) argType->typeEntry())->originator(), true);
else if (argType->isEnum())
s << cpythonCheckFunction(argType, false, true);
- else // Should be treated as a generic number in the case the type is one
- s << cpythonCheckFunction(argType, true);
+ else
+ s << cpythonCheckFunction(argType, isNumber);
s << '(' << argumentName << ')';
@@ -1047,24 +1047,20 @@ void CppGenerator::writeTypeCheck(QTextStream& s, const OverloadData* overloadDa
{
const AbstractMetaType* argType = overloadData->argType();
- int alternativeNumericTypes = 0;
+ QSet<const TypeEntry*> numericTypes;
foreach (OverloadData* pd, overloadData->overloadDataOnPosition(overloadData->argPos())) {
if (!pd->argType()->isPrimitive())
continue;
if (ShibokenGenerator::isNumber(pd->argType()->typeEntry()))
- alternativeNumericTypes++;
+ numericTypes << pd->argType()->typeEntry();
}
// This condition trusts that the OverloadData object will arrange for
// PyInt type to come after the more precise numeric types (e.g. float)
- bool numberType = alternativeNumericTypes == 1 || ShibokenGenerator::isPyInt(argType);
-
- QString customCheck;
- if (overloadData->hasArgumentTypeReplace())
- customCheck = guessCPythonCheckFunction(overloadData->argumentTypeReplaced());
- else if (!numberType)
- customCheck = cpythonCheckFunction(argType, numberType);
- writeTypeCheck(s, argType, argumentName, customCheck);
+ bool numberType = numericTypes.count() == 1 || ShibokenGenerator::isPyInt(argType);
+
+ QString customType = (overloadData->hasArgumentTypeReplace() ? overloadData->argumentTypeReplaced() : "");
+ writeTypeCheck(s, argType, argumentName, numberType, customType);
}
void CppGenerator::writeArgumentConversion(QTextStream& s,
diff --git a/cppgenerator.h b/cppgenerator.h
index 7652719a9..7ed0ee5e5 100644
--- a/cppgenerator.h
+++ b/cppgenerator.h
@@ -65,7 +65,7 @@ private:
* \param type the TypeEntry passed when the validity check must confirm the type of the Python wrapper to be checked
*/
void writeInvalidCppObjectCheck(QTextStream& s, QString pyArgName = "self", const TypeEntry* type = 0);
- void writeTypeCheck(QTextStream& s, const AbstractMetaType* argType, QString argumentName, QString customCheck = "");
+ void writeTypeCheck(QTextStream& s, const AbstractMetaType* argType, QString argumentName, bool isNumber = false, QString customType = "");
void writeTypeCheck(QTextStream& s, const OverloadData* overloadData, QString argumentName);
void writeTypeConverterImpl(QTextStream& s, const TypeEntry* type);