aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHugo Lima <hugo.lima@openbossa.org>2010-03-17 14:11:02 -0300
committerHugo Lima <hugo.lima@openbossa.org>2010-03-18 19:45:08 -0300
commit1c1002df611d9f0283379a94e943c0563a9f8804 (patch)
treee0f341f560fa601666c407d727c92446ee37a350
parentca2febda4080bb7ea2bd94aa9c8bf3ce18dccac0 (diff)
Added ObjectTypeReferenceConverter, so object-types can be used as references.
-rw-r--r--headergenerator.cpp7
-rw-r--r--libshiboken/conversions.h13
2 files changed, 20 insertions, 0 deletions
diff --git a/headergenerator.cpp b/headergenerator.cpp
index 670e633f7..a44e53ed0 100644
--- a/headergenerator.cpp
+++ b/headergenerator.cpp
@@ -188,6 +188,13 @@ void HeaderGenerator::writeTypeConverterDecl(QTextStream& s, const TypeEntry* ty
}
}
s << "};" << endl;
+
+ // write value-type like converter to object-types
+ if (isAbstractOrObjectType) {
+ s << endl << "template<>" << endl;
+ s << "struct Converter<" << type->name() << "& > : ObjectTypeReferenceConverter<" << type->name() << " >" << endl << '{' << endl;
+ s << "};" << endl << endl;
+ }
}
void HeaderGenerator::writeTypeIndexDefineLine(QTextStream& s, const TypeEntry* typeEntry, int& idx)
diff --git a/libshiboken/conversions.h b/libshiboken/conversions.h
index 600280c9f..97c73fd7d 100644
--- a/libshiboken/conversions.h
+++ b/libshiboken/conversions.h
@@ -270,6 +270,19 @@ struct ObjectTypeConverter
}
};
+template <typename T>
+struct ObjectTypeReferenceConverter : ObjectTypeConverter<T>
+{
+ static inline bool isConvertible(PyObject* pyObj) { return PyObject_TypeCheck(pyObj, SbkType<T>()); }
+ static inline PyObject* toPython(const T& cppobj) { return Converter<T*>::toPython(&cppobj); }
+ static inline T& toCpp(PyObject* pyobj)
+ {
+ T* t = Converter<T*>::toCpp(pyobj);
+ assert(t);
+ return *t;
+ }
+};
+
// PyObject* specialization to avoid converting what doesn't need to be converted.
template<>
struct Converter<PyObject*> : ObjectTypeConverter<PyObject*>