Thread: [pygccxml-development] Removing template default arguments?
Brought to you by:
mbaas,
roman_yakovenko
From: Gustavo C. <gjc...@gm...> - 2008-08-26 12:09:38
|
2008/8/26 Roman Yakovenko <rom...@gm...> > On Tue, Aug 26, 2008 at 8:28 AM, Roman Yakovenko > <rom...@gm...> wrote: > > On Tue, Aug 26, 2008 at 1:58 AM, Gustavo Carneiro <gjc...@gm...> > wrote: > >> Sorry, I just discovered it's not a bug. It's not infinite recursion, > just > >> very slow :P > > > > This is also bug. I would like to see your use case, so I can improve it. > > > > The first obvious think we can do is to add cache for element_type > > method. This should dramatically improve the speed of your application > > - or discover another bottleneck. > > > >> It turns out that > >> pygccxml.declarations.container_traits.xxx_traits.element_type() is > rather > >> slow and I was calling it more often than I should. > >> > >> Now, I am left with the old problem of distinguishing between sequence > and > >> mapping containers... </hint> > > > > :-). I will work on this today. > > done. > > http://pygccxml.svn.sourceforge.net/viewvc/pygccxml?view=rev&revision=1408 > > I also added cache for element_type and key_type functionality. Let me > know whether this change improved performance or not. Thanks, Roman, it is indeed much faster now! :-) I have one more tricky question. I am getting this key_type: std::basic_string<char,std::char_traits<char>,std::allocator<char> > [struct] Now, I know this is just a std::string type, but PyBindGen does not know it. Is there any way to convert this into a simpler std::string -like definition. That is because I register and lookup types by type expression string, but if there are multiple definitions for the same type then things won't match. Well, I guess one solution for me would be to register the "std::basic_string<char, std::char_traits<char>, std::allocator<char> >" type string alongside std::string, but if there's anything better to do I'll take it. I guess this is a generic question. Given the simple test case I am working on: std::map<std::string, int> pygccxml reads this as: std::map<std::basic_string<char, std::char_traits<char>, std::allocator<char> >,int,std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >,std::allocator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int> > > Is there any easy way to just remove the template arguments that have the same value as the template default template argument value? I am guessing the answer is no, but it doesn't hurt to ask :P -- Gustavo J. A. M. Carneiro INESC Porto, Telecommunications and Multimedia Unit "The universe is always one step beyond logic." -- Frank Herbert |
From: Roman Y. <rom...@gm...> - 2008-08-26 12:41:01
|
On Tue, Aug 26, 2008 at 3:09 PM, Gustavo Carneiro <gjc...@gm...> wrote: > Thanks, Roman, it is indeed much faster now! :-) > > I have one more tricky question. I am getting this key_type: > > std::basic_string<char,std::char_traits<char>,std::allocator<char> > > [struct] > > Now, I know this is just a std::string type, but PyBindGen does not know > it. Is there any way to convert this into a simpler std::string -like > definition. That is because I register and lookup types by type expression > string, but if there are multiple definitions for the same type then things > won't match. > > Well, I guess one solution for me would be to register the > "std::basic_string<char, std::char_traits<char>, std::allocator<char> >" > type string alongside std::string, but if there's anything better to do I'll > take it. > > I guess this is a generic question. Given the simple test case I am working > on: > > std::map<std::string, int> > > pygccxml reads this as: > > std::map<std::basic_string<char, std::char_traits<char>, > std::allocator<char> >,int,std::less<std::basic_string<char, > std::char_traits<char>, std::allocator<char> > >>,std::allocator<std::pair<const std::basic_string<char, > std::char_traits<char>, std::allocator<char> >, int> > > > > Is there any easy way to just remove the template arguments that have the > same value as the template default template argument value? > > I am guessing the answer is no, but it doesn't hurt to ask :P Wrong guess: http://language-binding.net/pygccxml/apidocs/pygccxml.declarations.declaration.declaration_t-class.html#partial_name By the way, container_traits has "remove_defaults" functionality. Now, you know what it is for. This is a must functionality for a good code generator - the generated code should be as closed to "human written" as possible. HTH -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |
From: Gustavo C. <gjc...@gm...> - 2008-08-26 13:25:32
|
2008/8/26 Roman Yakovenko <rom...@gm...> > On Tue, Aug 26, 2008 at 3:09 PM, Gustavo Carneiro <gjc...@gm...> > wrote: > > Thanks, Roman, it is indeed much faster now! :-) > > > > I have one more tricky question. I am getting this key_type: > > > > std::basic_string<char,std::char_traits<char>,std::allocator<char> > > > [struct] > > > > Now, I know this is just a std::string type, but PyBindGen does not know > > it. Is there any way to convert this into a simpler std::string -like > > definition. That is because I register and lookup types by type > expression > > string, but if there are multiple definitions for the same type then > things > > won't match. > > > > Well, I guess one solution for me would be to register the > > "std::basic_string<char, std::char_traits<char>, std::allocator<char> >" > > type string alongside std::string, but if there's anything better to do > I'll > > take it. > > > > I guess this is a generic question. Given the simple test case I am > working > > on: > > > > std::map<std::string, int> > > > > pygccxml reads this as: > > > > std::map<std::basic_string<char, std::char_traits<char>, > > std::allocator<char> >,int,std::less<std::basic_string<char, > > std::char_traits<char>, std::allocator<char> > > >>,std::allocator<std::pair<const std::basic_string<char, > > std::char_traits<char>, std::allocator<char> >, int> > > > > > > Is there any easy way to just remove the template arguments that have the > > same value as the template default template argument value? > > > > I am guessing the answer is no, but it doesn't hurt to ask :P > > Wrong guess: > http://language-binding.net/pygccxml/apidocs/pygccxml.declarations.declaration.declaration_t-class.html#partial_name > Awesome! Unfortunately I found a small problem with it: ************* register_container std::map< std::basic_string< char, std::char_traits< char >, std::allocator< char > >, int, std::less< std::basic_string< char, std::char_traits< char >, std::allocator< char > > >, std::allocator< std::pair< const std::basic_string< char, std::char_traits< char >, std::allocator< char > >, int > > >; element_type=int, key_type=string key_type should be 'std::string', not 'string', right? > > By the way, container_traits has "remove_defaults" functionality. Now, > you know what it is for. remove_defaults rocks as well, but has the same problem of removing the std:: namespace prefix. > This is a must functionality for a good code generator - the generated > code should be as closed to "human written" as possible. Agreed. -- Gustavo J. A. M. Carneiro INESC Porto, Telecommunications and Multimedia Unit "The universe is always one step beyond logic." -- Frank Herbert |
From: Roman Y. <rom...@gm...> - 2008-08-26 13:53:14
|
On Tue, Aug 26, 2008 at 4:25 PM, Gustavo Carneiro <gjc...@gm...> wrote: > Unfortunately I found a small problem with it: > > ************* register_container std::map< std::basic_string< char, > std::char_traits< char >, std::allocator< char > >, int, std::less< > std::basic_string< char, std::char_traits< char >, std::allocator< char > > >>, std::allocator< std::pair< const std::basic_string< char, > std::char_traits< char >, std::allocator< char > >, int > > >; > element_type=int, key_type=string > > key_type should be 'std::string', not 'string', right? Can you submit small test case that reproduce the problem? Thanks -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |
From: Roman Y. <rom...@gm...> - 2008-08-26 19:07:18
|
On Tue, Aug 26, 2008 at 5:09 PM, Gustavo Carneiro <gjc...@gm...> wrote: > Attached. Okey. There is no bug in pygccxml, if I look on your test case. I still don't understand how you get std::map< string, int >? I would like to explain few things, that I hope, will make clear to you what and how to use. declaration_t class has 4 different properties, related to its name I will explain them, using the following example: namespace ns{ std::vector< int > do_smth(); } For do_smth return type: * name - the class name - vector< int, std::allocator< int > > * partial name - the class name without default template args - vector< int > * decl_string - full class name - std::vector< int, std::allocator< int > > * partial_decl_string - the full class name without default template args - std::vector< int > In most case, you want to use [partial_]decl_string, because it allows you to use the class in "other context". HTH -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |
From: Gustavo C. <gjc...@gm...> - 2008-08-26 20:45:59
|
2008/8/26 Roman Yakovenko <rom...@gm...> > On Tue, Aug 26, 2008 at 5:09 PM, Gustavo Carneiro <gjc...@gm...> > wrote: > > Attached. > > Okey. There is no bug in pygccxml, if I look on your test case. > I still don't understand how you get std::map< string, int >? > > I would like to explain few things, that I hope, will make clear to > you what and how to use. > > declaration_t class has 4 different properties, related to its name > > I will explain them, using the following example: > > namespace ns{ > std::vector< int > do_smth(); > } > > For do_smth return type: > > * name - the class name - vector< int, std::allocator< int > > > * partial name - the class name without default template args - vector< int > > > * decl_string - full class name - std::vector< int, std::allocator< int > > > * partial_decl_string - the full class name without default template > args - std::vector< int > > > In most case, you want to use [partial_]decl_string, because it allows > you to use the class in "other context". partial_decl_string works perfectly. Thank you! -- Gustavo J. A. M. Carneiro INESC Porto, Telecommunications and Multimedia Unit "The universe is always one step beyond logic." -- Frank Herbert |