CXX extension types question
Greg Landrum
gReGlAnDrUm at earthlink.net
Sat Apr 28 18:55:01 EDT 2001
"Tom" <NoSpam at NoSpam.com> wrote in message
news:T8HG6.20396$HF.4234648 at news4.rdc1.on.home.com...
>
> In args[0] you have a PyObject*.
> If the PyObject is actually one of your PyAtoms, you can cast it as such.
> (PyAtom inherits - I'm assuming - from cxx::PythonExtension<> which
inherits
> from PyObject.)
> Unfortunately, we can't do a safe 'dynamic_cast' because the inheritance
of
> PyObject is non-virtual, so we'll do it the C way:
> assert( thePyObject->ob_type == PyAtom::type_object() ); // or
throw.
> PyAtom* pPyAtom = static_cast< PyAtom* >( thePyObject );
>
> I think this is right, but no guarantees. Tell me if I'm wrong.
>
It was close enough to lead me to something that works:
Py::Object PyBond::GetNbrAtom(const Py::Tuple& args){
PyObject *pyObj=args[0].ptr();
if( pyObj->ob_type != PyAtom::type_object() ){
throw Py::ValueError("argument must be a PyAtom");
}
PyAtom *a = static_cast<PyAtom *>(pyObj);
Thanks for the pointer!
-greg
More information about the Python-list
mailing list