Thread: [pygccxml-development] Tag for Methods to bind ?
Brought to you by:
mbaas,
roman_yakovenko
From: Damien F. <dam...@mo...> - 2008-07-07 12:06:55
|
Hi , we are thinking of using py++ to create binding to one of our libraries . this is quite a large one 100+ class . py++ look like its doing what we need and initial test are very promising . one of our idea was to be able to explicitly 'tag' the methods/class to export . I though we might use a tag in the doxygen comments . but I can't really see if that is possible there is the extract_doc scheme , would there be a way to filter class and methods based on doxygen docs ? one other way we though was to run doxygen using xml out , sparse the result and extract a list of class and methods from there. but the 2 step workflow is not as nice and doxygen doesn't use the same parser ( I think .. ) example : /// base class for particle /// BINDABLE class A { /// creation methode /// BINDABLE APtr create() /// this class is not accessible from python float * getInternals(); private : A() {}; } in any case thanks a lot for py++ it look like its gonna save us a lot of time ! Damien |
From: Ben S. <bsc...@lu...> - 2008-07-07 18:14:47
|
I had this same idea. Instead of putting the annotations inside the comments, I made Qt style macros which I prepended to my function/enum/field declarations. Something like META_CLASS() class A { META_METHOD() APtr create(); // No annotations before this one so it isn't exposed float * getInternals(); .... } The macros turn into __attribute((gccxml("META_XXX"))); when a preprocessor flag is defined and turns into nothing otherwise. The cool thing is that you can have additional annotations work by using macro inlining... I can't find the code anymore but it did work... Cheers Ben > -----Original Message----- > From: pyg...@li... > [mailto:pyg...@li...] > On Behalf Of Damien Fagnou > Sent: Monday, July 07, 2008 5:07 AM > To: pyg...@li... > Subject: [pygccxml-development] Tag for Methods to bind ? > > Hi , > > we are thinking of using py++ to create binding to one of our > libraries . > this is quite a large one 100+ class . py++ look like its > doing what we need and initial test are very promising . > > one of our idea was to be able to explicitly 'tag' the > methods/class to export . > I though we might use a tag in the doxygen comments . but I > can't really see if that is possible there is the extract_doc > scheme , would there be a way to filter class and methods > based on doxygen docs ? > > one other way we though was to run doxygen using xml out , > sparse the result and extract a list of class and methods > from there. but the 2 step workflow is not as nice and > doxygen doesn't use the same parser ( I think .. ) > > example : > > /// base class for particle > /// BINDABLE > class A > { > /// creation methode > /// BINDABLE > APtr create() > > /// this class is not accessible from python > float * getInternals(); > > private : > A() {}; > } > > in any case thanks a lot for py++ it look like its gonna save > us a lot of time ! > > Damien > > > > > > -------------------------------------------------------------- > ----------- > Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW! > Studies have shown that voting for your favorite open source > project, along with a healthy diet, reduces your potential > for chronic lameness and boredom. Vote Now at > http://www.sourceforge.net/community/cca08 > _______________________________________________ > pygccxml-development mailing list > pyg...@li... > https://lists.sourceforge.net/lists/listinfo/pygccxml-development > > |
From: Roman Y. <rom...@gm...> - 2008-07-07 18:22:54
|
On Mon, Jul 7, 2008 at 9:14 PM, Ben Schleimer <bsc...@lu...> wrote: > I had this same idea. Instead of putting the annotations inside the > comments, > I made Qt style macros which I prepended to my function/enum/field > declarations. > > Something like > META_CLASS() class A { > META_METHOD() APtr create(); > > // No annotations before this one so it isn't exposed > float * getInternals(); > > .... > } > > The macros turn into __attribute((gccxml("META_XXX"))); > when a preprocessor flag is defined and turns into nothing otherwise. > The cool thing is that you can have additional annotations work by > using macro inlining... I can't find the code anymore but it did work... You are right, this is another valid option. Every declarations contains "attributes" property wchih gives you access to them ( http://language-binding.net/pyplusplus/documentation/apidocs/pygccxml.declarations.declaration.declaration_t-class.html#attributes ) This approach has speed advantage and it is less error prone. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |
From: Ben S. <bsc...@lu...> - 2008-07-07 18:46:53
|
I just found the code. -------------------------------------------- #ifndef PREPROCESS // This forces the class to have a virtual table so definition system works correctly #define META_CLASS(...) virtual void __META_CLASS_FUNCTION__(void) {}; #define META_FIELD(...) // #define META_METHOD(...) #define META_ENUM(...) #define META_INFO(key, value) #define META_PROPERTY(...) #else // Define the macros as nothing #define META_CLASS(x) __attribute__((gccxml("META_CLASS", #x))) \ virtual void __META_CLASS_FUNCTION__(void); // These multiple definitions of helper are intended to allow each META_INFO // line appear as a unique declaration to the compiler #define META_FIELD(x) META_FIELD_HELPER(__LINE__, x) #define META_FIELD_HELPER(line, x) META_FIELD_HELPER2(line, x) #define META_FIELD_HELPER2(line, x) \ __attribute__((gccxml("META_FIELD", #x))) \ void __META_FIELD_FUNCTION__ ## line () {}; #define META_METHOD(x) __attribute__((gccxml("META_METHOD", #x))) #define META_ENUM(x) META_ENUM_HELPER(__LINE__, x) #define META_ENUM_HELPER(line, x) META_ENUM_HELPER2(line, x) #define META_ENUM_HELPER2(line, x) \ __attribute__((gccxml("META_ENUM", #x))) \ void __META_ENUM_FUNCTION__ ## line () {}; #define META_INFO(key, value) META_INFO_HELPER(__LINE__, key, value) #define META_INFO_HELPER(line, key, value) META_INFO_HELPER2(line, key, value) #define META_INFO_HELPER2(line, key, value) \ __attribute__((gccxml("META_INFO", key, value))) \ void __META_INFO_FUNCTION__ ## line () {}; #define META_PROPERTY(x) META_PROPERTY_HELPER(__LINE__, x) #define META_PROPERTY_HELPER(line, x) META_PROPERTY_HELPER2(line, x) #define META_PROPERTY_HELPER2(line, x) \ __attribute__((gccxml("META_PROPERTY", #x))) \ void __META_PROPERTY_FUNCTION__ ## line () {}; #endif ---------------------------------------------- class Foo { META_CLASS(CLASS INFO HERE); META_INFO("Class Type", "This is info separated by spaces"); META_INFO("MY_COMPANY_SPECIFIC_INFO_NOTICE", "Some info here.."); META_INFO("DOC", "Class Documentation here.."); // These are Qt style property declarations. META_PROPERTY(int Foo); META_PROPERTY(string Name READONLY DOC "This is the name property of this"); // These fields is not exported void* nulptr; int baz; // These fields are exported META_FIELD(NODEF NOREFLECT VALUE="1,1,1") Vec3 foo; META_FIELD(NODEF DOC "This is the bar,:. field") int bar; // Exported META_METHOD(NODEF NOOID DOC "gfg") int doIt() const { return 4*3+12; } // Not exported int fooIt() { } // We can even export enums!! Yeah! META_ENUM(NOOID) enum colors { red, blue, green } ; } ----------------------------------------------------- I was really, really happy with this approach but it couldn't happen (yet!) for various reasons. :( Cheers Ben > -----Original Message----- > From: Roman Yakovenko [mailto:rom...@gm...] > Sent: Monday, July 07, 2008 11:23 AM > To: Ben Schleimer > Cc: Damien Fagnou; pyg...@li... > Subject: Re: [pygccxml-development] Tag for Methods to bind ? > > On Mon, Jul 7, 2008 at 9:14 PM, Ben Schleimer > <bsc...@lu...> wrote: > > I had this same idea. Instead of putting the annotations inside the > > comments, I made Qt style macros which I prepended to my > > function/enum/field declarations. > > > > Something like > > META_CLASS() class A { > > META_METHOD() APtr create(); > > > > // No annotations before this one so it isn't exposed > > float * getInternals(); > > > > .... > > } > > > > The macros turn into __attribute((gccxml("META_XXX"))); > > when a preprocessor flag is defined and turns into nothing > otherwise. > > The cool thing is that you can have additional annotations work by > > using macro inlining... I can't find the code anymore but > it did work... > > You are right, this is another valid option. > Every declarations contains "attributes" property wchih gives > you access to them ( > http://language-binding.net/pyplusplus/documentation/apidocs/p > ygccxml.declarations.declaration.declaration_t-class.html#attributes > ) > > This approach has speed advantage and it is less error prone. > > -- > Roman Yakovenko > C++ Python language binding > http://www.language-binding.net/ > > |
From: Roman Y. <rom...@gm...> - 2008-07-07 18:56:53
|
On Mon, Jul 7, 2008 at 9:46 PM, Ben Schleimer <bsc...@lu...> wrote: > I just found the code. >... > I was really, really happy with this approach but it couldn't happen > (yet!) for various reasons. :( If it is not a secret can you share them? Thank you. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |
From: Roman Y. <rom...@gm...> - 2008-07-07 18:18:21
|
On Mon, Jul 7, 2008 at 3:06 PM, Damien Fagnou <dam...@mo...> wrote: > Hi , > > we are thinking of using py++ to create binding to one of our libraries . > this is quite a large one 100+ class . py++ look like its doing what we > need and initial test are very promising . :-) > one of our idea was to be able to explicitly 'tag' the methods/class to > export . > I though we might use a tag in the doxygen comments . but I can't really > see if that is possible > there is the extract_doc scheme , would there be a way to filter class > and methods based on doxygen docs ? It is possible. Take a look on this file: http://python-ogre.svn.sourceforge.net/viewvc/python-ogre/trunk/python-ogre/code_generators/common_utils/extract_documentation.py?view=markup Python-Ogre project uses it to extract doxygen style documentation from the Ogre3d source code and embed it into Python objects. So they will have the documentation. After you updated the declarations with documentation you can use it ( untested ): mb = module_builder_t() mb.global_ns.decls().exclude() mb.global_ns.decls( lambda d: '/// BINDABLE' in d.documentation ).include() //class includes everything under it, so we need to run exclude mb.global_ns.decls( lambda d: '/// this class is not accessible from python' in d.documentation ).exclude() > one other way we though was to run doxygen using xml out , sparse the > result and extract a list of class and methods from there. but the 2 > step workflow is not as nice and doxygen doesn't use the same parser ( > I think .. ) > > example : > > /// base class for particle > /// BINDABLE > class A > { > /// creation methode > /// BINDABLE > APtr create() > > /// this class is not accessible from python > float * getInternals(); Take a look on return_range call policy, it provides solution for such API http://language-binding.net/pyplusplus/documentation/functions/call_policies.html#return-range > in any case thanks a lot for py++ it look like its gonna save us a lot > of time ! Thank you! P.S. In Russian we say "не говори гоп пока не перепрыгнешь", I guess the English variant is "Do not boast until you see the enemy dead". :-))) -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |
From: Damien F. <dam...@mo...> - 2008-07-07 19:04:11
|
Looks great !! thanks a lot for sharing that ! I will try it when I get to the office tomorow . damien -----Original Message----- From: Ben Schleimer [mailto:bsc...@lu...] Sent: Mon 7/7/2008 7:46 PM To: Roman Yakovenko Cc: Damien Fagnou; pyg...@li... Subject: RE: [pygccxml-development] Tag for Methods to bind ? I just found the code. -------------------------------------------- #ifndef PREPROCESS // This forces the class to have a virtual table so definition system works correctly #define META_CLASS(...) virtual void __META_CLASS_FUNCTION__(void) {}; #define META_FIELD(...) // #define META_METHOD(...) #define META_ENUM(...) #define META_INFO(key, value) #define META_PROPERTY(...) #else // Define the macros as nothing #define META_CLASS(x) __attribute__((gccxml("META_CLASS", #x))) \ virtual void __META_CLASS_FUNCTION__(void); // These multiple definitions of helper are intended to allow each META_INFO // line appear as a unique declaration to the compiler #define META_FIELD(x) META_FIELD_HELPER(__LINE__, x) #define META_FIELD_HELPER(line, x) META_FIELD_HELPER2(line, x) #define META_FIELD_HELPER2(line, x) \ __attribute__((gccxml("META_FIELD", #x))) \ void __META_FIELD_FUNCTION__ ## line () {}; #define META_METHOD(x) __attribute__((gccxml("META_METHOD", #x))) #define META_ENUM(x) META_ENUM_HELPER(__LINE__, x) #define META_ENUM_HELPER(line, x) META_ENUM_HELPER2(line, x) #define META_ENUM_HELPER2(line, x) \ __attribute__((gccxml("META_ENUM", #x))) \ void __META_ENUM_FUNCTION__ ## line () {}; #define META_INFO(key, value) META_INFO_HELPER(__LINE__, key, value) #define META_INFO_HELPER(line, key, value) META_INFO_HELPER2(line, key, value) #define META_INFO_HELPER2(line, key, value) \ __attribute__((gccxml("META_INFO", key, value))) \ void __META_INFO_FUNCTION__ ## line () {}; #define META_PROPERTY(x) META_PROPERTY_HELPER(__LINE__, x) #define META_PROPERTY_HELPER(line, x) META_PROPERTY_HELPER2(line, x) #define META_PROPERTY_HELPER2(line, x) \ __attribute__((gccxml("META_PROPERTY", #x))) \ void __META_PROPERTY_FUNCTION__ ## line () {}; #endif ---------------------------------------------- class Foo { META_CLASS(CLASS INFO HERE); META_INFO("Class Type", "This is info separated by spaces"); META_INFO("MY_COMPANY_SPECIFIC_INFO_NOTICE", "Some info here.."); META_INFO("DOC", "Class Documentation here.."); // These are Qt style property declarations. META_PROPERTY(int Foo); META_PROPERTY(string Name READONLY DOC "This is the name property of this"); // These fields is not exported void* nulptr; int baz; // These fields are exported META_FIELD(NODEF NOREFLECT VALUE="1,1,1") Vec3 foo; META_FIELD(NODEF DOC "This is the bar,:. field") int bar; // Exported META_METHOD(NODEF NOOID DOC "gfg") int doIt() const { return 4*3+12; } // Not exported int fooIt() { } // We can even export enums!! Yeah! META_ENUM(NOOID) enum colors { red, blue, green } ; } ----------------------------------------------------- I was really, really happy with this approach but it couldn't happen (yet!) for various reasons. :( Cheers Ben > -----Original Message----- > From: Roman Yakovenko [mailto:rom...@gm...] > Sent: Monday, July 07, 2008 11:23 AM > To: Ben Schleimer > Cc: Damien Fagnou; pyg...@li... > Subject: Re: [pygccxml-development] Tag for Methods to bind ? > > On Mon, Jul 7, 2008 at 9:14 PM, Ben Schleimer > <bsc...@lu...> wrote: > > I had this same idea. Instead of putting the annotations inside the > > comments, I made Qt style macros which I prepended to my > > function/enum/field declarations. > > > > Something like > > META_CLASS() class A { > > META_METHOD() APtr create(); > > > > // No annotations before this one so it isn't exposed > > float * getInternals(); > > > > .... > > } > > > > The macros turn into __attribute((gccxml("META_XXX"))); > > when a preprocessor flag is defined and turns into nothing > otherwise. > > The cool thing is that you can have additional annotations work by > > using macro inlining... I can't find the code anymore but > it did work... > > You are right, this is another valid option. > Every declarations contains "attributes" property wchih gives > you access to them ( > http://language-binding.net/pyplusplus/documentation/apidocs/p > ygccxml.declarations.declaration.declaration_t-class.html#attributes > ) > > This approach has speed advantage and it is less error prone. > > -- > Roman Yakovenko > C++ Python language binding > http://www.language-binding.net/ > > |
From: Ben S. <bsc...@lu...> - 2008-07-07 19:17:03
|
Please note that the way gcc works for FIELDs and ENUMs isn't too great. After a lot of experimentation, I discovered that __attribute() has to appear after the field and enum declaration. It can appear before for methods and classes. Thats why the META_FIELD and META_ENUM are written the way they are. The parser I wrote firsts finds the declaration __META_FIELD_FUNCTION and then looks for a field with the same or after line number. If it finds one, then that field is considered to have that annotation. If you are willing to give into gccxml's bug (feature?) and only put META_FIELD after the declaration, then META_FIELD's implementation doesn't have to be so complex and will be more robust. Cheers Ben ________________________________ From: Damien Fagnou [mailto:dam...@mo...] Sent: Monday, July 07, 2008 12:04 PM To: Ben Schleimer; Roman Yakovenko Cc: pyg...@li... Subject: RE: [pygccxml-development] Tag for Methods to bind ? Looks great !! thanks a lot for sharing that ! I will try it when I get to the office tomorow . damien -----Original Message----- From: Ben Schleimer [mailto:bsc...@lu...] Sent: Mon 7/7/2008 7:46 PM To: Roman Yakovenko Cc: Damien Fagnou; pyg...@li... Subject: RE: [pygccxml-development] Tag for Methods to bind ? I just found the code. -------------------------------------------- #ifndef PREPROCESS // This forces the class to have a virtual table so definition system works correctly #define META_CLASS(...) virtual void __META_CLASS_FUNCTION__(void) {}; #define META_FIELD(...) // #define META_METHOD(...) #define META_ENUM(...) #define META_INFO(key, value) #define META_PROPERTY(...) #else // Define the macros as nothing #define META_CLASS(x) __attribute__((gccxml("META_CLASS", #x))) \ virtual void __META_CLASS_FUNCTION__(void); // These multiple definitions of helper are intended to allow each META_INFO // line appear as a unique declaration to the compiler #define META_FIELD(x) META_FIELD_HELPER(__LINE__, x) #define META_FIELD_HELPER(line, x) META_FIELD_HELPER2(line, x) #define META_FIELD_HELPER2(line, x) \ __attribute__((gccxml("META_FIELD", #x))) \ void __META_FIELD_FUNCTION__ ## line () {}; #define META_METHOD(x) __attribute__((gccxml("META_METHOD", #x))) #define META_ENUM(x) META_ENUM_HELPER(__LINE__, x) #define META_ENUM_HELPER(line, x) META_ENUM_HELPER2(line, x) #define META_ENUM_HELPER2(line, x) \ __attribute__((gccxml("META_ENUM", #x))) \ void __META_ENUM_FUNCTION__ ## line () {}; #define META_INFO(key, value) META_INFO_HELPER(__LINE__, key, value) #define META_INFO_HELPER(line, key, value) META_INFO_HELPER2(line, key, value) #define META_INFO_HELPER2(line, key, value) \ __attribute__((gccxml("META_INFO", key, value))) \ void __META_INFO_FUNCTION__ ## line () {}; #define META_PROPERTY(x) META_PROPERTY_HELPER(__LINE__, x) #define META_PROPERTY_HELPER(line, x) META_PROPERTY_HELPER2(line, x) #define META_PROPERTY_HELPER2(line, x) \ __attribute__((gccxml("META_PROPERTY", #x))) \ void __META_PROPERTY_FUNCTION__ ## line () {}; #endif ---------------------------------------------- class Foo { META_CLASS(CLASS INFO HERE); META_INFO("Class Type", "This is info separated by spaces"); META_INFO("MY_COMPANY_SPECIFIC_INFO_NOTICE", "Some info here.."); META_INFO("DOC", "Class Documentation here.."); // These are Qt style property declarations. META_PROPERTY(int Foo); META_PROPERTY(string Name READONLY DOC "This is the name property of this"); // These fields is not exported void* nulptr; int baz; // These fields are exported META_FIELD(NODEF NOREFLECT VALUE="1,1,1") Vec3 foo; META_FIELD(NODEF DOC "This is the bar,:. field") int bar; // Exported META_METHOD(NODEF NOOID DOC "gfg") int doIt() const { return 4*3+12; } // Not exported int fooIt() { } // We can even export enums!! Yeah! META_ENUM(NOOID) enum colors { red, blue, green } ; } ----------------------------------------------------- I was really, really happy with this approach but it couldn't happen (yet!) for various reasons. :( Cheers Ben > -----Original Message----- > From: Roman Yakovenko [mailto:rom...@gm...] > Sent: Monday, July 07, 2008 11:23 AM > To: Ben Schleimer > Cc: Damien Fagnou; pyg...@li... > Subject: Re: [pygccxml-development] Tag for Methods to bind ? > > On Mon, Jul 7, 2008 at 9:14 PM, Ben Schleimer > <bsc...@lu...> wrote: > > I had this same idea. Instead of putting the annotations inside the > > comments, I made Qt style macros which I prepended to my > > function/enum/field declarations. > > > > Something like > > META_CLASS() class A { > > META_METHOD() APtr create(); > > > > // No annotations before this one so it isn't exposed > > float * getInternals(); > > > > .... > > } > > > > The macros turn into __attribute((gccxml("META_XXX"))); > > when a preprocessor flag is defined and turns into nothing > otherwise. > > The cool thing is that you can have additional annotations work by > > using macro inlining... I can't find the code anymore but > it did work... > > You are right, this is another valid option. > Every declarations contains "attributes" property wchih gives > you access to them ( > http://language-binding.net/pyplusplus/documentation/apidocs/p > ygccxml.declarations.declaration.declaration_t-class.html#attributes > ) > > This approach has speed advantage and it is less error prone. > > -- > Roman Yakovenko > C++ Python language binding > http://www.language-binding.net/ > > |
From: Damien F. <dam...@mo...> - 2008-07-07 19:16:16
|
there is an other issue that I have been wondering how to solve . our lib use IMath Internally to store and manipulate math objects ( vector , matrix , etc ) I could;t find boostBinding of Imath , I guess we are gonna try to create one using lovely py++ but in the mean time we already have wrapper for those class for our other binding to Lua ( Vector , Matrix etc ) those type easy construct with there repective Imath Type . my question is if I have a methode like void setTransform( Imath::m44f & mat ); could I define automatic converter like : bp::converter< Mattrix , Imath::m44f , myConvertionFunction > maybe this is more a boostPython question ? I am kindda new to that too ;) and then how would I register that to py++ , using the add_code_registration() ? thanks Damien -----Original Message----- From: Roman Yakovenko [mailto:rom...@gm...] Sent: Mon 7/7/2008 7:57 PM To: Ben Schleimer Cc: Damien Fagnou; pyg...@li... Subject: Re: [pygccxml-development] Tag for Methods to bind ? On Mon, Jul 7, 2008 at 9:46 PM, Ben Schleimer <bsc...@lu...> wrote: > I just found the code. >... > I was really, really happy with this approach but it couldn't happen > (yet!) for various reasons. :( If it is not a secret can you share them? Thank you. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |
From: Roman Y. <rom...@gm...> - 2008-07-07 19:37:01
|
On Mon, Jul 7, 2008 at 10:17 PM, Damien Fagnou <dam...@mo...> wrote: > there is an other issue that I have been wondering how to solve . Please start another thread. > our lib use IMath Internally to store and manipulate math objects ( vector , > matrix , etc ) > I could;t find boostBinding of Imath , I guess we are gonna try to create > one using lovely py++ but in the mean > time we already have wrapper for those class for our other binding to Lua ( > Vector , Matrix etc ) > > those type easy construct with there repective Imath Type . > > my question is if I have a methode like > > void setTransform( Imath::m44f & mat ); > > > could I define automatic converter like : > > bp::converter< Mattrix , Imath::m44f , myConvertionFunction > > > maybe this is more a boostPython question ? > I am kindda new to that too ;) I am not sure I understand you. It seems to me that you are looking for next document: http://www.boost.org/doc/libs/1_35_0/libs/python/doc/v2/implicit.html#implicitly_convertible-spec > and then how would I register that to py++ , using the > add_code_registration() ? If you will find solution it will not be a problem to integrate it with generated code: http://language-binding.net/pyplusplus/documentation/inserting_code.html -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |