From: Allen B. <al...@vr...> - 2006-09-19 15:10:04
Attachments:
Classes.h
|
I am having trouble wrapping a class right now. The problem is that the class uses template base classes to mixin functionality. This makes it appear to pygccxml that the class has a half-dozen base classes. But I don't want to expose these base classes, all I want to expose is the class that is composed from the mixin functionality. To make matters worse there is something in the handling of these mixins that is making pyplusplus code creators expose them all as having the same name ("Inherited"). I think this is because each mixin class uses a typedef called Inherited to keep track of the class that it is inheriting from. (I have attached a file that shows the basic idea, but it is a vast simplification of the case I am really trying to handle) Anyway, to make a long story short, what I would like to do is just tell pyplusplus to ignore the base classes (ie. don't expose them) but to instead pull all of the methods defined in those base classes into the derived class I am trying to expose. Then the generated code would only create a wrapper for the derived class and would just create "def"'s that reference the methods from the mixins. Is this possible? -Allen |
From: Roman Y. <rom...@gm...> - 2006-09-19 18:51:57
|
On 9/19/06, Allen Bierbaum <al...@vr...> wrote: > I am having trouble wrapping a class right now. The problem is that the > class uses template base classes to mixin functionality. This makes it > appear to pygccxml that the class has a half-dozen base classes. But I > don't want to expose these base classes, all I want to expose is the > class that is composed from the mixin functionality. I understand. > To make matters > worse there is something in the handling of these mixins that is making > pyplusplus code creators expose them all as having the same name > ("Inherited"). I think this is because each mixin class uses a typedef > called Inherited to keep track of the class that it is inheriting from. This is the right guess. > (I have attached a file that shows the basic idea, but it is a vast > simplification of the case I am really trying to handle) > > Anyway, to make a long story short, what I would like to do is just tell > pyplusplus to ignore the base classes (ie. don't expose them) but to > instead pull all of the methods defined in those base classes into the > derived class I am trying to expose. Then the generated code would only > create a wrapper for the derived class and would just create "def"'s > that reference the methods from the mixins. > > Is this possible? What do you think? Before I answer the question, I would like to make it clear: this is not "the main success scenario", so you will have to touch here and there few low level details. 1. create module_builder_t object and pass "optimize_queries=False" as a parameter. 2. Using adopt_declaration and remove_declaration methods of declarations.class_t put the method into right place. Be careful! Declaration can have only 1 parent. So if you have few derived classes you will have to "copy" declaration and to add the copy to every derived class. 3. after you finished to modify the declarations tree, run query optimizer mb.run_query_optimizer() 4. don't forget to exclude the base classes. I think this should work and it does not require too much work. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |
From: Allen B. <al...@vr...> - 2006-09-19 19:13:35
|
Roman Yakovenko wrote: > On 9/19/06, Allen Bierbaum <al...@vr...> wrote: > >> I am having trouble wrapping a class right now. The problem is that the >> class uses template base classes to mixin functionality. This makes it >> appear to pygccxml that the class has a half-dozen base classes. But I >> don't want to expose these base classes, all I want to expose is the >> class that is composed from the mixin functionality. > > > I understand. > >> To make matters >> worse there is something in the handling of these mixins that is making >> pyplusplus code creators expose them all as having the same name >> ("Inherited"). I think this is because each mixin class uses a typedef >> called Inherited to keep track of the class that it is inheriting from. > > > This is the right guess. > >> (I have attached a file that shows the basic idea, but it is a vast >> simplification of the case I am really trying to handle) >> >> Anyway, to make a long story short, what I would like to do is just tell >> pyplusplus to ignore the base classes (ie. don't expose them) but to >> instead pull all of the methods defined in those base classes into the >> derived class I am trying to expose. Then the generated code would only >> create a wrapper for the derived class and would just create "def"'s >> that reference the methods from the mixins. >> >> Is this possible? > > > What do you think? Before I answer the question, I would like to make > it clear: > this is not "the main success scenario", so you will have to touch > here and there > few low level details. > > 1. create module_builder_t object and pass "optimize_queries=False" > as a parameter. > 2. Using adopt_declaration and remove_declaration methods of > declarations.class_t > put the method into right place. Be careful! Declaration can have > only 1 parent. > So if you have few derived classes you will have to "copy" > declaration and to > add the copy to every derived class. > 3. after you finished to modify the declarations tree, run query > optimizer > mb.run_query_optimizer() > 4. don't forget to exclude the base classes. > > I think this should work and it does not require too much work. > Step 2 may be the problem. To do step 2 I would have to still find and reference all the mixin base classes in the system and use them. Are you thinking I should/could build this using the recursive_bases property? -Allen |
From: Roman Y. <rom...@gm...> - 2006-09-19 19:20:03
|
On 9/19/06, Allen Bierbaum <al...@vr...> wrote: > Roman Yakovenko wrote: > > > On 9/19/06, Allen Bierbaum <al...@vr...> wrote: > > > >> I am having trouble wrapping a class right now. The problem is that the > >> class uses template base classes to mixin functionality. This makes it > >> appear to pygccxml that the class has a half-dozen base classes. But I > >> don't want to expose these base classes, all I want to expose is the > >> class that is composed from the mixin functionality. > > > > > > I understand. > > > >> To make matters > >> worse there is something in the handling of these mixins that is making > >> pyplusplus code creators expose them all as having the same name > >> ("Inherited"). I think this is because each mixin class uses a typedef > >> called Inherited to keep track of the class that it is inheriting from. > > > > > > This is the right guess. > > > >> (I have attached a file that shows the basic idea, but it is a vast > >> simplification of the case I am really trying to handle) > >> > >> Anyway, to make a long story short, what I would like to do is just tell > >> pyplusplus to ignore the base classes (ie. don't expose them) but to > >> instead pull all of the methods defined in those base classes into the > >> derived class I am trying to expose. Then the generated code would only > >> create a wrapper for the derived class and would just create "def"'s > >> that reference the methods from the mixins. > >> > >> Is this possible? > > > > > > What do you think? Before I answer the question, I would like to make > > it clear: > > this is not "the main success scenario", so you will have to touch > > here and there > > few low level details. > > > > 1. create module_builder_t object and pass "optimize_queries=False" > > as a parameter. > > 2. Using adopt_declaration and remove_declaration methods of > > declarations.class_t > > put the method into right place. Be careful! Declaration can have > > only 1 parent. > > So if you have few derived classes you will have to "copy" > > declaration and to > > add the copy to every derived class. > > 3. after you finished to modify the declarations tree, run query > > optimizer > > mb.run_query_optimizer() > > 4. don't forget to exclude the base classes. > > > > I think this should work and it does not require too much work. > > > Step 2 may be the problem. To do step 2 I would have to still find and > reference all the mixin base classes in the system and use them. Are > you thinking I should/could build this using the recursive_bases property? Yes, you also have recursive_derived property. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |
From: Allen B. <al...@vr...> - 2006-10-15 21:11:12
|
Roman Yakovenko wrote: > On 9/19/06, Allen Bierbaum <al...@vr...> wrote: > >> Roman Yakovenko wrote: >> >> > On 9/19/06, Allen Bierbaum <al...@vr...> wrote: >> > >> >> I am having trouble wrapping a class right now. The problem is >> that the >> >> class uses template base classes to mixin functionality. This >> makes it >> >> appear to pygccxml that the class has a half-dozen base classes. >> But I >> >> don't want to expose these base classes, all I want to expose is the >> >> class that is composed from the mixin functionality. >> > >> > >> > I understand. >> > >> >> To make matters >> >> worse there is something in the handling of these mixins that is >> making >> >> pyplusplus code creators expose them all as having the same name >> >> ("Inherited"). I think this is because each mixin class uses a >> typedef >> >> called Inherited to keep track of the class that it is inheriting >> from. >> > >> > >> > This is the right guess. >> > >> >> (I have attached a file that shows the basic idea, but it is a vast >> >> simplification of the case I am really trying to handle) >> >> >> >> Anyway, to make a long story short, what I would like to do is >> just tell >> >> pyplusplus to ignore the base classes (ie. don't expose them) but to >> >> instead pull all of the methods defined in those base classes into >> the >> >> derived class I am trying to expose. Then the generated code >> would only >> >> create a wrapper for the derived class and would just create "def"'s >> >> that reference the methods from the mixins. >> >> >> >> Is this possible? >> > >> > >> > What do you think? Before I answer the question, I would like to make >> > it clear: >> > this is not "the main success scenario", so you will have to touch >> > here and there >> > few low level details. > Sorry to reply to an old thread, but I was just dealing with this problem in another case and I started thinking about it again. I agree that this it outside the normal usage scenario for py++, but I just thought of a reasonable way for the user to think about this in a way that may be useful to many more people. Namely, I was thinking that if the user exposes a class Derived but the class Base is not exposed, I think it would be reasonable for Py++ to automatically expose all the methods of Base in Derived. This seems like a fairly reasonable usecase because there may just be some times that users only want to expose a couple of classes and don't want to expose all of their base classes. What do other people think, is this a common enough usage to make a feature request out of it? -Allen |
From: Roman Y. <rom...@gm...> - 2006-10-16 06:27:52
|
On 10/15/06, Allen Bierbaum <al...@vr...> wrote: > I agree that this it outside the normal usage scenario for py++, but I > just thought of a reasonable way for the user to think about this in a > way that may be useful to many more people. > > Namely, I was thinking that if the user exposes a class Derived but the > class Base is not exposed, I think it would be reasonable for Py++ to > automatically expose all the methods of Base in Derived. This seems > like a fairly reasonable usecase because there may just be some times > that users only want to expose a couple of classes and don't want to > expose all of their base classes. I am not sure whether it is reasonable or not. It is very easy to implement it in Py++. To tell you the True the functionality like this already presents in Py++: http://language-binding.net/pyplusplus/documentation/apidocs/pyplusplus.decl_wrappers.class_wrapper.class_t-class.html#redefine_operators It could be extended to member functions too. You are welcome to prepare patches and unit test and I will commit them after this release. > What do other people think, is this a common enough usage to make a > feature request out of it? There is more interesting use case, that I would like to support: Lets say that you already have hand written code for base class and now you want to export derived one, using Py++. It could be nice if Py++ would support such mixes. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |
From: Allen B. <al...@vr...> - 2006-10-16 15:44:52
|
I have this sort of working now, but I have run into an additional problem. Because of the way the mixins work (I assume the templated base class), py++ is not figuring out that this class has a base class. Because of this I am not getting the standard support for using the methods of the base class that I have exposed. Is there anyway to manually tell py++ about a class's base classes? For example given a class decl could I manually tell it that it is derived from class "Base" somehow so this would influence the code creators and thus the generated code? -Allen Allen Bierbaum wrote: > I am having trouble wrapping a class right now. The problem is that > the class uses template base classes to mixin functionality. This > makes it appear to pygccxml that the class has a half-dozen base > classes. But I don't want to expose these base classes, all I want to > expose is the class that is composed from the mixin functionality. To > make matters worse there is something in the handling of these mixins > that is making pyplusplus code creators expose them all as having the > same name ("Inherited"). I think this is because each mixin class > uses a typedef called Inherited to keep track of the class that it is > inheriting from. (I have attached a file that shows the basic idea, > but it is a vast simplification of the case I am really trying to handle) > > Anyway, to make a long story short, what I would like to do is just > tell pyplusplus to ignore the base classes (ie. don't expose them) but > to instead pull all of the methods defined in those base classes into > the derived class I am trying to expose. Then the generated code > would only create a wrapper for the derived class and would just > create "def"'s that reference the methods from the mixins. > Is this possible? > > -Allen > >------------------------------------------------------------------------ > > >namespace test_ns >{ >template <class ParentT> >class MethodAMixin : public ParentT >{ >public: > void methodA(); >}; > >template <class ParentT> >class MethodBMixin : public ParentT >{ >public: > void methodB(); >}; > >template <class ParentT> >class MethodCMixin : public ParentT >{ >public: > void methodC(); >}; > >class Base >{ >public: > void methodBase(); >}; > >typedef MethodAMixin< MethodBMixin< MethodCMixin< Base > > > ParentType; > > >class MyClass : public ParentType >{ >public: > MyClass(); > bool getSomething(); >}; > > >} // namespace test_ns > > >------------------------------------------------------------------------ > >------------------------------------------------------------------------- >Take Surveys. Earn Cash. Influence the Future of IT >Join SourceForge.net's Techsay panel and you'll get the chance to share your >opinions on IT & business topics through brief surveys -- and earn cash >http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > >------------------------------------------------------------------------ > >_______________________________________________ >pygccxml-development mailing list >pyg...@li... >https://lists.sourceforge.net/lists/listinfo/pygccxml-development > > |
From: Roman Y. <rom...@gm...> - 2006-10-16 18:51:21
|
On 10/16/06, Allen Bierbaum <al...@vr...> wrote: > I have this sort of working now, but I have run into an additional > problem. Because of the way the mixins work (I assume the templated > base class), py++ is not figuring out that this class has a base class. > Because of this I am not getting the standard support for using the > methods of the base class that I have exposed. > > Is there anyway to manually tell py++ about a class's base classes? For > example given a class decl could I manually tell it that it is derived > from class "Base" somehow so this would influence the code creators and > thus the generated code? Allen I am pretty busy, can you create small test case that reproduce the problem? ( C++ and Py++ files ). Boost.Date_Time uses same pattern and it works okay. May be you should take a look on it. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |