[C++-sig] Re: manage_new_object using release() instead of delete
David Abrahams
dave at boost-consulting.com
Tue Apr 13 17:27:13 CEST 2004
"Eric" <wstwej03 at sneakemail.com> writes:
> Hi all,
>
>
>
> I am new to Boost.Python, but so far have been extremely
> impressed. I was wondering if there was a version of the
> manage_new_object return policy that called a release() function on
> an interface rather than calling delete?
>
>
>
> I am trying to wrap a chunk of code that works like this:
>
>
>
> class Interface {
>
> public:
>
> virtual void doSomething() = 0;
>
> virtual void release() = 0;
>
> protected:
>
> virtual ~Interface() {}
>
> };
>
>
>
> Interface *
>
> SomeFactory( ... );
>
>
>
> Now, if Interface was a normal data struct, I'd just use
> manage_new_object as the policy for SomeFactory, but that wouldn't
> work here because the destructor is protected. Is there some way to
> have the release function called at the end of the Interface
> pointer's life in python? And is it further possible to have the
> release() function not be callable from python (to protect against
> double-deletes)? Thanks!
Solution:
Put a thin wrapper around SomeFactory that builds a boost::shared_ptr
using a custom deleter that calls release(), and wrap that.
HTH,
--
Dave Abrahams
Boost Consulting
http://www.boost-consulting.com
More information about the Cplusplus-sig
mailing list