[C++-sig] [Re: Added to a vector_indexing_suite container in python]

Jeff Holle jeff.holle at verizon.net
Sat Jun 19 11:18:37 CEST 2004


I suspect that my previous post concerning this problem does not provide 
adequite information.
So here is more.

Following is a grep of my files that highlite what I'm trying to wrap 
with pyste and how I'm doing it:

    typedef std::vector<CParameter> Parameters;
    MemberFunction.h:    Parameters& getParameters( void);
    MemberFunction.h:    const Parameters& getParameters( void) const;
    MemberFunction.h:UMLModel::Parameters&
    PygetParameters(UMLModel::CMemberFunction& self);
    MemberFunction.pyste:exclude(a.getParameters)
    MemberFunction.pyste:add_method(a,"PygetParameters")
    MemberFunction.pyste:set_policy(a.PygetParameters,return_value_policy(copy_non_const_reference))
    MemberFunction.pyste:rename(a.PygetParameters,"getParameters")

The PygetParameters function exists because pyste throws errors in 
encountering the overloaded pair that are in-place to facilitate const 
correct coding.

Note the method call policy that I'm applying, "copy_non_const_reference".

It appears that this policy causes a copy of the container in the 
process of calling "getParameters" in python.
I believe this because the following python script:
     aMethod.getParameters().append(aParm)
     print 'number of parameters is %d' % len(aMethod.getParameters())
prints:
    number of parameters is 0

I've added my own "push_back" method to this container in a way similiar 
to the iterator.cpp file.
The same results occur, which are explained if a container copy is going on.

It there a way to avoid this copy?
 






More information about the Cplusplus-sig mailing list