|
Boost : |
From: David Abrahams (dave_at_[hidden])
Date: 2002-11-08 09:19:56
Dan Nuffer <dnuffer_at_[hidden]> writes:
> David Abrahams wrote:
>> Dan Nuffer <dnuffer_at_[hidden]> writes:
>>>6. How can I get python indexing and slicing to work on OW_String? I
>>>couldn't see any information about this in the docs.
>> The same way you do it in Python: supply a "__getitem__" and a
>> "__getslice__" method.
>>
>
>
> Thanks, this works great!
>
>
>
>>
>>>7. Do I need to expose the copy constructor and assignment operator
>>>via Boost.Python?
>> You don't need assignment at all, and the copy constructor is exposed
>> automatically unless you have specified that your class is
>> noncopyable. You may want to build a copy() method, as Ralf suggests
>> we ought to do automatically in
>> http://aspn.activestate.com/ASPN/Mail/Message/c++-sig/1386367 (I'm now
>> beginning to think we should just generate copy() automatically).
>>
>
>
> I'm not quite sure what I'm doing here. I couldn't find an example
> that does this. This doesn't compile:
> .def("copy", init<const OW_String&>())
>
> This doesn't work:
>
> OW_String OW_String_copy(const OW_String& s)
> {
> return s;
> }
>
> ...
> .def("copy", &OW_String_copy)
>
> >>> t = copy.deepcopy(s)
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> File "/usr/local/lib/python2.2/copy.py", line 182, in deepcopy
> y = _reconstruct(x, reductor(), 1, memo)
> File "/usr/local/lib/python2.2/copy.py", line 305, in _reconstruct
> args = deepcopy(args, memo)
> File "/usr/local/lib/python2.2/copy.py", line 186, in deepcopy
> y = copierfunction(x, memo)
> File "/usr/local/lib/python2.2/copy.py", line 226, in _deepcopy_tuple
> y.append(deepcopy(a, memo))
> File "/usr/local/lib/python2.2/copy.py", line 182, in deepcopy
> y = _reconstruct(x, reductor(), 1, memo)
> File "/usr/local/lib/python2.2/copy_reg.py", line 57, in _reduce
> raise TypeError, "can't pickle %s objects" % base.__name__
> TypeError: can't pickle instance objects
>
> How am I supposed to do this?
Hmm, I'm not sure. Oh, probably you need to do something to make your
instances pickleable as well:
http://www.boost.org/libs/python/doc/v2/pickle.html
Ralf's the expert in this area...
-- David Abrahams dave_at_[hidden] * http://www.boost-consulting.com Boost support, enhancements, training, and commercial distribution
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk