Thread: [pygccxml-development] [FT]input_t class - new vision.
Brought to you by:
mbaas,
roman_yakovenko
From: Roman Y. <rom...@gm...> - 2006-09-14 11:42:33
|
Hi. I am sure you know that I have small problem with custom smart pointer. The problem introduced new use case to FT - input_t class. Consider next use case template<T> smart_ptr_t{...}; struct Y{ const smart_ptr_t<X>& do_smth( const smart_ptr_t<Z>& z ); }; For some reason, I am not able to expose do_smth function as is, but rather its trivial wrapper: smart_ptr_t<X> do_smth( smart_ptr_t<Z> z ); Consider another problem that Allen had few weeks/month ago: void do_smth( const class_with_private_destructor_t& x ) The solution was to remove const from the argument. So how it is related to "input_t" ? "input_t" transformer removes reference or pointer from the argument type. In my case I want to modify the argument type too, but I also want to specify the new type. Same logic is applied on return type. May be we can change\extend input_t class ( and rename it ) so it will provide this functionality? -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |
From: Matthias B. <ba...@ir...> - 2006-09-14 13:40:50
|
Roman Yakovenko wrote: > So how it is related to "input_t" ? "input_t" transformer removes > reference or pointer > from the argument type. In my case I want to modify the argument type > too, but I also > want to specify the new type. Same logic is applied on return type. > > May be we can change\extend input_t class ( and rename it ) so it will > provide this functionality? What name and new construction arguments do you suggest? This might also be an example where it could actually be useful to apply several transformers to one argument (I haven't had such a case yet). For example, if there would be a policy remove_const_t you could apply both, input_t and remove_const_t, to the same argument. I think this should even work already with the current version. - Matthias - |
From: Roman Y. <rom...@gm...> - 2006-09-14 18:12:14
|
On 9/14/06, Matthias Baas <ba...@ir...> wrote: > Roman Yakovenko wrote: > > So how it is related to "input_t" ? "input_t" transformer removes > > reference or pointer > > from the argument type. In my case I want to modify the argument type > > too, but I also > > want to specify the new type. Same logic is applied on return type. > > > > May be we can change\extend input_t class ( and rename it ) so it will > > provide this functionality? > > What name and new construction arguments do you suggest? > > This might also be an example where it could actually be useful to apply > several transformers to one argument (I haven't had such a case yet). > For example, if there would be a policy remove_const_t you could apply > both, input_t and remove_const_t, to the same argument. I think this > should even work already with the current version. from pygccxml import declarations type_transformation_t ? def __init__( self, arg_id, transformation=None ): self.arg_id = arg_id if None is self.transformation: #by default just remove reference #because I expect this will be applied to immutable passed by ref self.transformation = lambda type_: declarations.remove_reference( type_ ) elif is_callable( transformation ): #let user define the transformation self.transformation = transformation else: #user already knows what he wants, so we will just use it assert isinstance( transformation, declarations.type_t ) self.transformation = lambda type_: transformation transf = type_transformation_t( 1 , lambda type_: declarations.remove_reference( declarations.remove_const( type_ ) ) ) Something like this. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |
From: Matthias B. <ba...@ir...> - 2006-09-15 12:35:52
|
Roman Yakovenko wrote: > from pygccxml import declarations > type_transformation_t ? > > def __init__( self, arg_id, transformation=None ): > self.arg_id = arg_id > if None is self.transformation: > #by default just remove reference > #because I expect this will be applied to immutable passed by ref > self.transformation = lambda type_: > declarations.remove_reference( type_ ) > elif is_callable( transformation ): > #let user define the transformation > self.transformation = transformation > else: > #user already knows what he wants, so we will just use it > assert isinstance( transformation, declarations.type_t ) > self.transformation = lambda type_: transformation > > transf = type_transformation_t( 1 > , lambda type_: declarations.remove_reference( > > declarations.remove_const( type_ ) ) ) > > Something like this. Your example uses an entirely different interface than what is currently implemented, but I guess I can see what you want to have. I agree that functionality like this could be useful, I'd suggest to implement it as an additional transformer though and keep input_t still around. - Matthias - |
From: Roman Y. <rom...@gm...> - 2006-09-15 14:36:29
|
On 9/15/06, Matthias Baas <ba...@ir...> wrote: > Roman Yakovenko wrote: > > from pygccxml import declarations > > type_transformation_t ? > > > > def __init__( self, arg_id, transformation=None ): > > self.arg_id = arg_id > > if None is self.transformation: > > #by default just remove reference > > #because I expect this will be applied to immutable passed by ref > > self.transformation = lambda type_: > > declarations.remove_reference( type_ ) > > elif is_callable( transformation ): > > #let user define the transformation > > self.transformation = transformation > > else: > > #user already knows what he wants, so we will just use it > > assert isinstance( transformation, declarations.type_t ) > > self.transformation = lambda type_: transformation > > > > transf = type_transformation_t( 1 > > , lambda type_: declarations.remove_reference( > > > > declarations.remove_const( type_ ) ) ) > > > > Something like this. > > Your example uses an entirely different interface than what is currently > implemented, but I guess I can see what you want to have. > > I agree that functionality like this could be useful, I'd suggest to > implement it as an additional transformer though and keep input_t still > around. As I showed you can implement input_t in terms of type_transformation_t, but as you wish. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |