[C++-sig] bpl_utils explained

David Abrahams dave at boost-consulting.com
Sun Jul 28 03:43:40 CEST 2002


Hi Ralf,

I'm appreciative of all the work you've been doing, so please don't take
this the wrong way: I don't understand why the simple change of using a
pointer or non-const reference as the first argument to one of your
functions instead of a const reference is distasteful enough to warrant
removing conversion from general sequences. That seems like a pretty
radical change to make for the sake of the style of what is essentially an
implementation detail.

-Dave

-----------------------------------------------------------
           David Abrahams * Boost Consulting
dave at boost-consulting.com * http://www.boost-consulting.com


----- Original Message -----
From: "Ralf W. Grosse-Kunstleve" <rwgk at yahoo.com>
To: <c++-sig at python.org>
Sent: Saturday, July 27, 2002 4:40 PM
Subject: [C++-sig] bpl_utils explained


> I beat some more on the convertible() function of the
> register_container_from_python_sequence class in bpl_utils.h
> (everything else pretty much unchanged). The goal was to make
> this "more robust" rather than "more magical." This is how
> it works now:
>
> - Only Python lists, tuples, iterators and xrange objects are
>   convertible. The limitation to these types is essential for
>   avoiding surprises without much loss of generality: the Python
>   list() or iter() command can be used to easily convert
>   custom sequence types before passing them to a wrapped
>   C++ function.
>
> - Conversion policies are defined by a "registration_adaptor"
>   struct (see bpl_utils.h).
>
> - There are two fundamentally different conversion policies.
>   Which one is used is determined by a static member function
>   in the registration adaptors, e.g.:
>
>   static bool check_convertibility_per_element() { return true; }
>
>   true: The native Python object must be a list, tuple or xrange
>         object. Any other object is not convertible.
>         PyObject_Length() is used to determine the size of the
>         sequence and passed to the check_size() function of
>         the registration adaptor. If this returns true,
>         lists and tuples are traversed. extract<> is called
>         for each element. The input object is deemed convertible only
>         if the size check returns true and if all elements are
>         convertible.
>         As an optimization, if the input sequence is a xrange
>         object, only the first element is tested for convertibility.
>
>         If overload resolution finally calls the construct()
>         function, the input object is traversed a second time.
>
>   false: convertible() returns true if the input object is a
>          list, tuple, iterator or xrange object. No other
>          checks are performed. The input sequence or iterator
>          is not traversed.
>          If overload resolution finally calls the construct()
>          function the input object is traversed. An exception is
>          thrown if any of the elements is not convertible.
>
> David, I feel that this is now at a point where it could be moved to
> the library. When doing this, we should rename virtually everything.
> E.g.
>
> registration_adaptor -> registration_policy,
> register_container_from_python_sequence -> register_container_from_native
> or maybe extract_container_from_native. Feel free to make
> unilateral decisions on the naming.
>
> Ralf
>
> To get the files:
>
> cvs -z3 -d:pserver:anonymous at cvs.cctbx.sourceforge.net:/cvsroot/cctbx
co -r
> boost_python_v2_transition cctbx
>
> cctbx/include/cctbx/bpl_utils.h
> cctbx/misc
>
>
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Health - Feel better, live better
> http://health.yahoo.com
>
> _______________________________________________
> C++-sig mailing list
> C++-sig at python.org
> http://mail.python.org/mailman/listinfo/c++-sig





More information about the Cplusplus-sig mailing list