[C++-sig] Re: Wrapping class methods with array parameters
RaoulGough at yahoo.co.uk
Sun Nov 9 20:13:13 CET 2003
"CLARKE,RON (HP-Vancouver,ex1)" <ron.clarke at hp.com> writes:
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
Please note that not everyone uses a HTML-capable viewer to read this
mailing list. I, for one, would prefer postings to the list in plain
> Here is one of the classes/methods:
> class scifidict
> /* a bunch of stuff */
> size_t getOwners(string* ps = NULL)
> throw (invalid_argument);
> /* more fun stuff */
> The other C++ class' method is similar, but it uses an array of
> integers as one of its arguments.
> In the above method, ps is a std::string array passed in by the
> caller, which getOwners() than proceeds to populate. It works fine
> in C++.
As long as the caller allocates enough space, I suppose.
> I've made numerous attempts to get code that works for
> Python, and either the code did not compile, or it did compile but
> then Python didn't like the method when I tried to execute it
> ("TypeError: bad argument type for built-in operation").
> What is the proper way to wrap array arguments so the data can be
>passed back and forth between C++ and Python?
I'm sure there are other solutions for this limited use of arrays, but
maybe you should look into the indexing support suite, which is
available in the CVS version of Boost (documentation is in
libs/python/doc/v2/containers.html if you've downloaded Boost from the
CVS). This currently allows you to wrap C++ vectors, so you could
switch over to doing it that way.
Alternatively, I've developed a new version of the indexing suite that
also supports arrays, although it will definitely want to know how big
the array is first, because it wouldn't be very Python-like to let
code write past the end of the array. The new suite (indexing_v2)
might make it into the next Boost release (1.31) but in the mean time,
you would have to get it from a side-branch of CVS. Some details are
on my website at http://home.clara.net/raoulgough/boost/ or by
searching for indexing_v2 in this mailing list.
(setq dabbrev-case-fold-search nil)
More information about the Cplusplus-sig