Movatterモバイル変換


[0]ホーム

URL:


CXX extension types question

Greg LandrumgReGlAnDrUm at earthlink.net
Sat Apr 28 18:55:01 EDT 2001


"Tom" <NoSpam at NoSpam.com> wrote in messagenews: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<> whichinherits> from PyObject.)> Unfortunately, we can't do a safe 'dynamic_cast' because the inheritanceof> PyObject is non-virtual, so we'll do it the C way:>     assert( thePyObject->ob_type == PyAtom::type_object() );    // orthrow.>     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-listmailing list

[8]ページ先頭

©2009-2025 Movatter.jp