[C++-sig] call policies

Ricardo Kirkner ricardokirkner at gmail.com
Tue Nov 8 21:44:38 CET 2005


Hi:

I am doing great now... I am coding right in boost.python, without
recurring to pyste.

However I have found a situation that makes me doubt. Being mData defined as

real mData[3];

and having these methods as member functions of a class

		inline real * getData()
		{
			return mData;
		}

		inline const real * getData()const
		{
			return mData;
		}

How should I wrap them? I was thinking of defining a wrapper that
would return a list built from the elements of mData, but... how would
using a wrapper cope with this overloaded function? Should I only
define it once, and ignore the second override? (for example the one
with const?)

I have looked at the tutorial, but the part of overriding only handles
the case where the function itself doesn't return a pointer or a
reference...

More or less the same thing is happening with the [] operator... the
code (c++) would return a real & while I could return a real, and
using a wrapper, but this would prevent the returned item from being
modified (as opposed to the c++ version, where a reference can be used
to modify the object).

Any thoughts are appreciated...

Thanks again...

Ricardo

pd: I promise that as I continue to learn this wrapping_up_a_library
thing I will stop making basic questions and start making really
interesting ones :-P

On 11/7/05, Ralf W. Grosse-Kunstleve <rwgk at yahoo.com> wrote:
> --- Ricardo Kirkner <ricardokirkner at gmail.com> wrote:
>
> > Ok... thanks for the reply...
> >
> > How will boost.python figure out that the corresponding method for
> >
> > .def(self_ns::str(self))
> >
> > should be (for example)
> >
> > std::ostream& operator<< (in the c++ code)
>
> Only David knows *how* Boost.Python does it, but this test proves that it does
> exactly what you are looking for:
>
> boost/libs/python/test/operators.cpp
>
> Note that you can always provide your own custom string method via
>
> .def("__str__", &yours::method)
>
> or
>
> .def("__str__", another_thin_wrapper)
>
> BTW: I find the test source code extremely useful as a reference. It is worth
> spending 30 minutes looking through all the .cpp files to get an overview.
>
> Cheers,
>         Ralf
>
>
>
>
>
> __________________________________
> Yahoo! Mail - PC Magazine Editors' Choice 2005
> http://mail.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