[pygccxml-development] multiple declarations wrapper
Brought to you by:
mbaas,
roman_yakovenko
From: Roman Y. <rom...@gm...> - 2006-03-06 05:09:44
|
Good morning. I created multiple declarations wrapper class - mdecl_wrapper= _t. I think you will like it. Sometimes, I don't like Python do be as fully dynamic language, but sometime I can not live without it: Here is the code: class call_redirector_t( object ): def __init__( self, name, decls ): object.__init__( self ) self.name =3D name self.decls =3D decls def __call__( self, *arguments, **keywords ): for d in self.decls: callable =3D getattr(d, self.name) callable( *arguments, **keywords ) class mdecl_wrapper_t( object ): def __init__( self, decls ): object.__init__( self ) self.__dict__['_decls'] =3D decls def __len__( self ): return len( self._decls ) def __getitem__( self, index ): return self._decls[index] def __ensure_attribute( self, name ): invalid_decls =3D filter( lambda d: not hasattr( d, name ), self._d= ecls ) if invalid_decls: raise RuntimeError( "Not all declarations have '%s' attribute." % name ) def __setattr__( self, name, value ): self.__ensure_attribute( name ) for d in self._decls: setattr( d, name, value ) def __getattr__( self, name ): return call_redirector_t( name, self._decls ) Usage: mdw =3D decl_wrappers.mdecl_wrapper_t( classes ) mdw.always_expose_using_scope =3D True mdw.include() for decl in mdw: print decl.name Comments and suggestions are welcome. I felt pretty good with this implementation, so I commited it. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |