Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2005-01-22 22:22:05


Preston,

The best place for Boost.Python questions is the C++-sig:
http://www.boost.org/more/mailing_lists.htm#cplussig

"Preston A. Elder" <prez_at_[hidden]> writes:

> I have some functions in C++ that take a void *, for example hexdump().
> The main use of this, obviously, is to pass a buffer and get the hex dump
> as a return value - without having to worry about the type passed, eg:
>
> std::string str("This is a test");
> hexdump(str.data(), str.length());
>
> std::wstring wstr(L"This is a test")
> hexdump(str.data(), str.length() * sizeof(wchar_t));
>
> I want to know the best way of exposing such a function to python without
> being too 'string specific' (theres no reason I couldn't do
> hexdump(&some_int, sizeof(int)) in C++, so I want something similar in
> python, if I can get it).

You have to decide what kind of interface you want in Python; nobody
can tell you what that should be. Write down some examples of Python
code showing what you'd like to be able to do with hexdump.

> Now hexdump is only an example, I have a few other functions that do
> the same (for example, recv() and send() in a socket class).
>
> Any ideas would be appreciated. Right now, the best thing I can
> think of is to create a wrapper function (for use in the python
> interface only) that accepts a std::string/std::wstring and calls
> hexdump, however this hamstrings me when I want to do things like
> integers, or complex structures.

Unless you can come up with some code that can take an arbitrary
complex structure and magically produce a contiguous array of bytes
for hexdump to work on, I think you're out of luck.

> Also, on another note, is there somewhere that has all of boost
> already pythonized?

No.

> I manually converted boost::date_time (at least all the gregorian
> and posix_time stuff) myself, however I would have expected most of
> boost to have been converted to python already ;)

It seems unlikely to me. Because so much of Boost is heavily
templated generic code, a great deal of it would make no sense as
Python wrappers. Can you imagine Pythonizing the Boost.Python
library? ;-)

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

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