Boost logo

Boost :

From: daveh-lists_at_[hidden]
Date: 2001-10-01 11:16:09


I'll try and write something a little more comprehensive as this is a
sample of a simple case. There is a more generic solution to the
problem of pointers that can handle passing pointers to polymorphic
classes where the normal copy constructor for the base class would
not suffice.

Dave Hawkes

--- In boost_at_y..., "David Abrahams" <david.abrahams_at_r...> wrote:
> Great idea. Would you care to post it at the boost-users Wiki?
>
> http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl
>
> ===================================================
> David Abrahams, C++ library designer for hire
> resume: http://users.rcn.com/abrahams/resume.html
>
> C++ Booster (http://www.boost.org)
> email: david.abrahams_at_r...
> ===================================================
>
> ----- Original Message -----
> From: <daveh-lists_at_c...>
> To: <boost_at_y...>
> Sent: Monday, October 01, 2001 10:03 AM
> Subject: [boost] Re: Boost::Python
>
>
> >
> >
> > Another method that I have used is to create a class interface to
> > your buffer which includes a copy constructor, maybe something
along
> > these lines (This is not complete, just for an idea):
> >
> > class AccessBuffer
> > {
> > public:
> > AccessBuffer(const void *pData) : m_pData(pData)
> > {
> > }
> > AccessBuffer(const AccessBuffer &rBuffer)
> > {
> > m_pData = rBuffer.m_pData;
> > }
> > AccessBuffer &operator=(const AccessBuffer &rBuffer)
> > {
> > m_pData = rBuffer.m_pData;
> > return *this;
> > }
> > // Add your data manipulation functions here
> > unsigned char GetByte(int n)
> > {
> > return ((const unsigned char *)m_pData)[n];
> > }
> > private:
> > const void *m_pData;
> > };
> >
> > Then you just need to declare the class and the data manipulation
> > methods in boost and pass a reference (not pointer) to this class
in
> > your function call.
> >
> > I have successfully used boost::python to support embedding python
> > and have objects that simultaneously exist (can be called from) in
> > python and c++ and that have virtual methods that can be
overriden in
> > python.
> >
> >
> > Dave Hawkes
> >
> > --- In boost_at_y..., "David Abrahams" <david.abrahams_at_r...> wrote:
> > > Mike,
> > >
> > > First of all, you'll need to pick a different interface
> > for "function" (or
> > > wrap a different function and have it call your function),
because
> > > Boost.Python can only convert a single Python object into a
single
> > function
> > > parameter.
> > >
> > > Probably the easiest thing you can do is to write a function
taking
> > a
> > > boost::python::ref (which is kind of a smart pointer to a
> > PyObject), and
> > > just use the regular Python 'C' API to extract the buffer data.
> > >
> > > If you want to get fancier, you could create a type which
> > corresponds to a
> > > Python buffer (perhaps struct my_buffer { void* data; int
size; };)
> > and
> > > write a family of from_python(PyObject*, type<buffer>) functions
> > which check
> > > the argument type and convert Python buffers into your buffer
type.
> > You can
> > > look at boost/python/conversions.hpp for some examples. That
would
> > allow you
> > > to automatically wrap functions which accept my_buffer
arguments.
> > >
> > > HTH,
> > > Dave
> > >
> > > ===================================================
> > > David Abrahams, C++ library designer for hire
> > > resume: http://users.rcn.com/abrahams/resume.html
> > >
> > > C++ Booster (http://www.boost.org)
> > > email: david.abrahams_at_r...
> > > ===================================================
> > >
> > > ----- Original Message -----
> > > From: "Mike Ensor" <MikeEnsor_at_C...>
> > > To: <boost_at_y...>
> > > Sent: Saturday, September 29, 2001 7:47 PM
> > > Subject: [boost] Boost::Python
> > >
> > >
> > > > I am using Boost.Python to build c++ to python wrappers. I am
> > > > trying to make binary data available to python and visa
versa. I
> > have
> > > tried
> > > > many different approaches. The functions in C++ look similar
to
> > this:
> > > >
> > > > void function(const void* buffer, int size);
> > > >
> > > > and in python I can create a "buffer" of information. When I
> > check
> > > > the type of the "buffer" it is a "buffer".
> > > >
> > > > When I compile the c++ it won't let me because "none of the
425
> > > > overloads can convert prameter 2 from type 'struct
> > > boost::python::type<void
> > > > const*>'"
> > > >
> > > > How do I make the const void * be seen in Python and how do I
send
> > > > in binary data into this function from python?
> > > >
> > > > Thank you for your help,
> > > > Mike Ensor
> > > > mikeensor_at_c...
> > > >
> > > >
> > > > Info: http://www.boost.org Unsubscribe:
> > > <mailto:boost-unsubscribe_at_y...>
> > > >
> > > > Your use of Yahoo! Groups is subject to
> > http://docs.yahoo.com/info/terms/
> > > >
> > > >
> >
> >
> > Info: http://www.boost.org Unsubscribe:
> <mailto:boost-unsubscribe_at_y...>
> >
> > Your use of Yahoo! Groups is subject to
http://docs.yahoo.com/info/terms/
> >
> >
> >


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk