[C++-sig] [newbie] Pyste overloaded member function problems

Nicodemus nicodemus at globalite.com.br
Sun Apr 27 00:40:16 CEST 2003


Hi Sengan,

Sengan.Baring-Gould at nsc.com wrote:

>Hi,
>
>I am using pyste and boost 1.30.0 to wrap a C++ class which has the following
>overloaded member functions:
>  
>

I recommend that you use the latest CVS version, there has been *lots* 
of bug fixes and some features since boost 1.30.0 came out.

>class Parser {
>
>...
>
>typedef unsigned char CFormatFlags;
>const string& Get( string, string, const string&, const CFormatFlags in_flags = DEFAULT_FORMATTING ) const;
>long Get( string, string, const long ) const;
>int Get( string, string, const int ) const;
>const string& Get( string, const string&, const CFormatFlags in_flags = DEFAULT_FORMATTING ) const;
>long Get( string, const long ) const;
>int Get( string, const int ) const;
>
>...
>
>};
>
>In order to prevent Python from converting Get( string, string, const long )
>into const string& Get( string, const string&, CFormatFlags )  I have to hack
>the generated file to remove all but the first 2 def() statements corresponding
>to the first 2 Gets.
>1/ Is there a more elegant method to solve this problem?
>2/ Is there a way to tell pyste to exclude particular overloaded member
>   functions?
>3/ Is there a way to specify a policy in pyste dependent on the overloaded
>   member function: I have
>   set_policy(CSettingsParser.Get, return_value_policy(copy_const_reference))
>   but then I have to remove that for the long Get(string, string. long) case
>   from the generated file.
>  
>

Unfortunately, no. 8/
But I will implement in the next days support for meta-programming 
inside the pyste scripts, allowing you to do something like this:

C = Class(...)
for func in C.Get:
    if func._parameters[2].name == 'CFormatFlags':
        exclude(func)

>Secondly, this class has member functions:
>
>class Parser {
>...
>typedef list<string> CNameList;
>CNameList List( void ) const;
>CNameList List( const string section_name ) const;
>...  };
>
>
>In order to get a python list from this I wrote 2 wrapper functions.
>However, I can't figure out how to get pyste to use the set_wrapper() functions to use the wrappers. So again I hacked the generated file.
>4/ Is there some other way to do this without hacking the generated file?
>  
>

This problem is related to the last one too, ie, the inability to choose 
between functions with the same name.

>I would like to congratulate the authors of pyste and boost python. Having
>dipped my foot in the water by writing an extension module for
>std::list<int>/std::list<string>, I can see this package really reduces the
>amount of code one needs to write.
>  
>

Thanks a lot! 8)

>Thanks,
>
>Sengan
>  
>

Regards,
Nicodemus.





More information about the Cplusplus-sig mailing list