aboutsummaryrefslogtreecommitdiffstats
path: root/headergenerator.cpp
diff options
context:
space:
mode:
authorHugo Lima <hugo.lima@openbossa.org>2010-03-05 15:43:14 -0300
committerHugo Lima <hugo.lima@openbossa.org>2010-03-18 19:45:07 -0300
commitdc8dcf70f06304105d9a4e6467d98a266dbfe78f (patch)
treeb78dba3e4b94ba3528cdcc7dd7f2e01224b684bf /headergenerator.cpp
parentf52951862649d104abf664da5d456b0e0bb987fd (diff)
Changed the semantic of Converter<T>::isConvertible method.
The new semantic is: Returns true when the type can be converted to T OR the type is T. The old semantic was: Returns true when the type can be converted to T and false if the type is T, however int and float converters did not follow this rule, because they used PyNumber_Check on their isConvertible implementation.
Diffstat (limited to 'headergenerator.cpp')
-rw-r--r--headergenerator.cpp41
1 files changed, 29 insertions, 12 deletions
diff --git a/headergenerator.cpp b/headergenerator.cpp
index ea4666384..670e633f7 100644
--- a/headergenerator.cpp
+++ b/headergenerator.cpp
@@ -164,19 +164,28 @@ void HeaderGenerator::writeTypeConverterDecl(QTextStream& s, const TypeEntry* ty
implicitConvs << func;
}
bool isValueTypeWithImplConversions = type->isValue() && !implicitConvs.isEmpty();
-
- s << "struct Converter<" << type->name() << (isAbstractOrObjectType ? "*" : "") << " > : ";
- if (type->isEnum() || type->isFlags())
- s << "EnumConverter";
- else if (isAbstractOrObjectType)
- s << "ObjectTypeConverter";
- else
- s << "ValueTypeConverter";
- s << '<' << type->name() << " >" << endl;
- s << '{' << endl;
- if (isValueTypeWithImplConversions) {
+ bool hasCustomConversion = type->hasConversionRule();
+ QString typeT = type->name() + (isAbstractOrObjectType ? "*" : "");
+
+ s << "struct Converter<" << typeT << " >";
+ if (!hasCustomConversion) {
+ if (type->isEnum() || type->isFlags())
+ s << " : EnumConverter";
+ else if (isAbstractOrObjectType)
+ s << " : ObjectTypeConverter";
+ else
+ s << " : ValueTypeConverter";
+ s << '<' << type->name() << " >";
+ }
+ s << endl << '{' << endl;
+ if (isValueTypeWithImplConversions || hasCustomConversion) {
s << INDENT << "static " << type->name() << " toCpp(PyObject* pyobj);" << endl;
s << INDENT << "static bool isConvertible(PyObject* pyobj);" << endl;
+ if (hasCustomConversion) {
+ s << INDENT << "static inline PyObject* toPython(void* cppObj) { return toPython(*reinterpret_cast<"
+ << type->name() << (isAbstractOrObjectType ? "" : "*") << " >(cppObj)); }" << endl;
+ s << INDENT << "static PyObject* toPython(const " << type->name() << "& cppObj);" << endl;
+ }
}
s << "};" << endl;
}
@@ -469,6 +478,14 @@ void HeaderGenerator::writeTypeConverterImpl(QTextStream& s, const TypeEntry* ty
// Write Converter<T>::isConvertible
s << "inline bool Shiboken::Converter<" << type->name() << " >::isConvertible(PyObject* pyobj)" << endl;
s << '{' << endl;
+
+ if (type->isValue()) {
+ s << INDENT << "if (ValueTypeConverter<" << type->name() << " >::isConvertible(pyobj))" << endl;
+ Indentation indent(INDENT);
+ s << INDENT << "return true;" << endl;
+ }
+
+
s << INDENT << "SbkBaseWrapperType* shiboType = reinterpret_cast<SbkBaseWrapperType*>(SbkType<";
s << type->name() << " >());" << endl;
s << INDENT << "return ";
@@ -500,7 +517,7 @@ void HeaderGenerator::writeTypeConverterImpl(QTextStream& s, const TypeEntry* ty
{
Indentation indent(INDENT);
s << INDENT << "SbkBaseWrapperType* shiboType = reinterpret_cast<SbkBaseWrapperType*>(SbkType<";
- s << type->name() << ">());" << endl;
+ s << type->name() << " >());" << endl;
}
bool firstImplicitIf = true;
foreach (const AbstractMetaFunction* ctor, implicitConvs) {