Re: [pygccxml-development] mdecl and methods that return values
Brought to you by:
mbaas,
roman_yakovenko
|
From: Roman Y. <rom...@gm...> - 2006-05-30 20:00:52
|
On 5/30/06, Allen Bierbaum <al...@vr...> wrote:
> Roman Yakovenko wrote:
>
> > On 5/30/06, Allen Bierbaum <al...@vr...> wrote:
> >
> >> I think you are talking about this part of the test:
> >>
> >> mb.global_ns[ *'public_base_t'* ].exclude()
> >
> >
> > Right
> >
> >> Change it to something like this:
> >>
> >> mb.global_ns[ *'public_base_t'* ]['myFunction'].exclude()
> >>
> >> OR
> >>
> >> mb.global_ns[ *'public_base_t'*
> >> ].member_functions('myFunction').exclude()
> >
> >
> > Now, I don't need unit test. I see why this does not work. Thanks.
> >
> > Now I know that you want redefine call_redirector_t.__call__ method in
> > next way:
> >
> > #now
> > def __call__( self, *arguments, **keywords ):
> > for d in self.decls:
> > callable_ = getattr(d, self.name)
> > callable_( *arguments, **keywords )
> >
> > #you want:
> > def __call__( self, *arguments, **keywords ):
> > results = []
> > for d in self.decls:
> > callable_ = getattr(d, self.name)
> > answer = callable_( *arguments, **keywords )
> > results.append( answer )
> > #I assume that all functions will return same type:
> > if not results:
> > return
> > if isinstance( results[0], declaration_t ):
> > return mdecl_wrapper_t( results )
> > elif isinstance( results[0], mdecl_wrapper_t ):
> > temp_decls = []
> > for mdecl_wrapper in results:
> > temp_decls.extend( mdecl_wrapper.decls )
> > return mdecl_wrapper_t( temp_decls )
> > else:
> > return results
> >
> > Can you test whether this code will work for you or not?
>
> This is close, but not quite all the code is there. I have attached a
> diff where I fixed up the implementation and added code to the
> mdecl_wrapper.__getitem__ method to allow calls like I wanted to make.
>
> See attached...
>
>
> -Allen
>
> >
>
>
>
> Index: pygccxml_dev/pygccxml/declarations/mdecl_wrapper.py
> ===================================================================
> --- pygccxml_dev/pygccxml/declarations/mdecl_wrapper.py (revision 156)
> +++ pygccxml_dev/pygccxml/declarations/mdecl_wrapper.py (working copy)
> @@ -2,6 +2,7 @@
> # Distributed under the Boost Software License, Version 1.0. (See
> # accompanying file LICENSE_1_0.txt or copy at
> # http://www.boost.org/LICENSE_1_0.txt)
> +import declaration
>
> class call_redirector_t( object ):
> """Internal class used to call some function of objects"""
> @@ -11,9 +12,23 @@
> self.decls = decls
>
> def __call__( self, *arguments, **keywords ):
> - for d in self.decls:
> - callable_ = getattr(d, self.name)
> - callable_( *arguments, **keywords )
> + results = []
> + for d in self.decls:
> + callable_ = getattr(d, self.name)
> + answer = callable_( *arguments, **keywords )
> + results.append( answer )
> + #I assume that all functions will return same type:
> + if not results:
> + return
> + if isinstance( results[0], declaration.declaration_t ):
> + return mdecl_wrapper_t( results )
> + elif isinstance( results[0], mdecl_wrapper_t ):
> + temp_decls = []
> + for mdecl_wrapper in results:
> + temp_decls.extend( mdecl_wrapper.decls )
> + return mdecl_wrapper_t( temp_decls )
> + else:
> + return results
>
> class mdecl_wrapper_t( object ):
> """Multiple declarations wrapper.
> @@ -44,8 +59,14 @@
> return len( self.decls )
>
> def __getitem__( self, index ):
> - """provides access to declaration"""
> - return self.decls[index]
> + """provides access to declaration.
> + If passed a standard index, then return contained decl.
> + Else call the getitem method of contained decls.
> + """
> + if isinstance(index, int):
> + return self.decls[index]
> + else:
> + return call_redirector_t( '__getitem__', self.decls)(index)
>
> def __ensure_attribute( self, name ):
> invalid_decls = filter( lambda d: not hasattr( d, name ), self.decls )
> @@ -64,4 +85,4 @@
> def __getattr__( self, name ):
> """@param name: name of method
> """
> - return call_redirector_t( name, self.decls )
> \ No newline at end of file
> + return call_redirector_t( name, self.decls )
>
Allen, can you send me the whole file? Thanks
--
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/
|