diff options
author | Hugo Lima <hugo.lima@openbossa.org> | 2010-03-17 14:11:02 -0300 |
---|---|---|
committer | Hugo Lima <hugo.lima@openbossa.org> | 2010-03-18 19:45:08 -0300 |
commit | 1c1002df611d9f0283379a94e943c0563a9f8804 (patch) | |
tree | e0f341f560fa601666c407d727c92446ee37a350 /libshiboken/conversions.h | |
parent | ca2febda4080bb7ea2bd94aa9c8bf3ce18dccac0 (diff) |
Added ObjectTypeReferenceConverter, so object-types can be used as references.
Diffstat (limited to 'libshiboken/conversions.h')
-rw-r--r-- | libshiboken/conversions.h | 13 |
1 files changed, 13 insertions, 0 deletions
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*> |