Loading ...
Sorry, an error occurred while loading the content.

boost python and smart pointers

Expand Messages
  • Martin Strubel
    Hello, I ve lately experimented with Boost.Python and found it pretty useful. Though I ve run into one thing which I couldn t figure out by the documentation,
    Message 1 of 1 , Feb 1, 2002
    • 0 Attachment
      Hello,

      I've lately experimented with Boost.Python and found it pretty useful.
      Though I've run into one thing which I couldn't figure out by
      the documentation, I hope someone can give me a hint there:

      I have a function returning a pointer to an 'owned' structure,
      i.e. its container takes care of creation and deletion.
      In Python, I want to wrap this pointer into a direct reference
      to the struct, i.e. no copying. To guard the access and make sure
      the object can't be accessed after the deletion, I want to wrap
      the smart pointer AS a python object.

      for example, a C++ function returning an 'owned' face from a mesh:

      FaceSmartPtr Mesh::addFace() { .. }

      should be wrapped for access in Python like:

      f = mesh.addFace()

      with subsequent calls for face manipulation like:

      f.addVertex((0.0, 0.0, 0.0))

      where this should again call something like

      if (f_sptr.isValid())
      f_sptr->addVertex(...);
      else
      throw_pyException_ptrInvalid();

      Does Boost support this automatically ?
      Or do I have to wrap all these functions myself ?

      Greetings,

      - Strubi

      --
      Martin Strubel, Software Hooligan
      strubi@... www.blender.nl
      Not a Number - 3D Enabling Technology
      tel. +31 40 2501231 Eindhoven, The Netherlands
    Your message has been successfully submitted and would be delivered to recipients shortly.