On 2012-02-23 11:50, Holger Joukl wrote: > Hi, > > what's the recommended way to check if an object instance is an instance of > my extension class > in C++ code? > > I'm currently doing a very ugly > > #define isMyExtensionClass(pyobj) (strcmp(pyobj->ob_type->tp_name, > "MyExtensionClass") == 0) > > on PyObj* pyobj. > > I bet there is a better way but just can't seem to find it.
bpl::extract<MyExtensionClass> e(pyobj); if (e.check()) ... Note that you may want to use a reference type as template argument to the boost::python::extract type, if you want to retrieve the object by reference instead of by value. See http://www.boost.org/doc/libs/1_40_0/libs/python/doc/v2/extract.html for details. HTH, Stefan -- ...ich hab' noch einen Koffer in Berlin... _______________________________________________ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig