Thread: [pygccxml-development] properties detection
Brought to you by:
mbaas,
roman_yakovenko
From: Damien F. <dam...@mo...> - 2008-08-07 17:47:33
|
Hi , we are trying to use the Python properties , idealy I would like to use the automatic detection : mb = module_builder_t( ... ) number = mb.class_( 'myClass' ) number.add_properties( exclude_accessors=False ) #accessors will be exposed our accessor are of type : float getRadius(); void setRadius(float rad); and I would like the properties to be 'radius' is this form normaly detected ? we try to do : self.moduleBuilder.classes().add_properties( exclude_accessors=False ) but nothing .. is there a way to see more what the add_properties algo is doing ? thanks Damien |
From: Roman Y. <rom...@gm...> - 2008-08-07 18:09:14
|
On Thu, Aug 7, 2008 at 8:47 PM, Damien Fagnou <dam...@mo...> wrote: > Hi , > > we are trying to use the Python properties , > idealy I would like to use the automatic detection : > > mb = module_builder_t( ... ) > number = mb.class_( 'myClass' ) > number.add_properties( exclude_accessors=False ) #accessors will be exposed > > our accessor are of type : > > float getRadius(); > void setRadius(float rad); > > and I would like the properties to be 'radius' > > is this form normaly detected ? No. "get" function should be const, otherwise Py++ thinks that the function has a side effect, and doesn't expose it as property. > we try to do : > self.moduleBuilder.classes().add_properties( exclude_accessors=False ) > > but nothing .. > is there a way to see more what the add_properties algo is doing ? Of course. It is open source project :-) Take a look on this file http://pygccxml.svn.sourceforge.net/viewvc/pygccxml/pyplusplus_dev/pyplusplus/decl_wrappers/properties.py?revision=842&view=markup In your case I suggest you to create new class, which derives from name_based_recognizer_t class and override "is_getter" function. Then pass instance of the new class to add_properties method: number.add_properties( recognizer=..., exclude_accessors=False ) #accessors will be exposed As for the name, you can also override "find_out_property_name" function, so it will convert "Radius" to "radius" HTH. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |
From: Ben S. <bsc...@lu...> - 2008-08-07 18:37:57
|
Isn't it better to use explicit annotations rather then relying on pattern-matching to figure out what is a property and what isn't? Like using the META_PROPERTY() macro to add __gccxml__ attributes into the code. Cheers Ben > -----Original Message----- > From: pyg...@li... > [mailto:pyg...@li...] > On Behalf Of Roman Yakovenko > Sent: Thursday, August 07, 2008 11:09 AM > To: Damien Fagnou > Cc: pyg...@li... > Subject: Re: [pygccxml-development] properties detection > > On Thu, Aug 7, 2008 at 8:47 PM, Damien Fagnou > <dam...@mo...> wrote: > > Hi , > > > > we are trying to use the Python properties , idealy I would like to > > use the automatic detection : > > > > mb = module_builder_t( ... ) > > number = mb.class_( 'myClass' ) > > number.add_properties( exclude_accessors=False ) #accessors will be > > exposed > > > > our accessor are of type : > > > > float getRadius(); > > void setRadius(float rad); > > > > and I would like the properties to be 'radius' > > > > is this form normaly detected ? > > No. "get" function should be const, otherwise Py++ thinks > that the function has a side effect, and doesn't expose it as > property. > > > we try to do : > > self.moduleBuilder.classes().add_properties( > exclude_accessors=False ) > > > > but nothing .. > > is there a way to see more what the add_properties algo is doing ? > > Of course. It is open source project :-) Take a look on this > file > http://pygccxml.svn.sourceforge.net/viewvc/pygccxml/pyplusplus > _dev/pyplusplus/decl_wrappers/properties.py?revision=842&view=markup > > In your case I suggest you to create new class, which derives > from name_based_recognizer_t class and override "is_getter" function. > > Then pass instance of the new class to add_properties method: > > number.add_properties( recognizer=..., > exclude_accessors=False ) #accessors will be exposed > > As for the name, you can also override "find_out_property_name" > function, so it will convert "Radius" to "radius" > > HTH. > > -- > Roman Yakovenko > C++ Python language binding > http://www.language-binding.net/ > > -------------------------------------------------------------- > ----------- > This SF.Net email is sponsored by the Moblin Your Move > Developer's challenge Build the coolest Linux based > applications with Moblin SDK & win great prizes Grand prize > is a trip for two to an Open Source event anywhere in the > world http://moblin-contest.org/redirect.php?banner_id=100&url=/ > _______________________________________________ > pygccxml-development mailing list > pyg...@li... > https://lists.sourceforge.net/lists/listinfo/pygccxml-development > > |
From: Roman Y. <rom...@gm...> - 2008-08-07 18:51:43
|
On Thu, Aug 7, 2008 at 9:37 PM, Ben Schleimer <bsc...@lu...> wrote: > Isn't it better to use explicit annotations rather then relying on > pattern-matching to figure out what is a property and what isn't? The only "right" answer is: it depends. If you have some coding convention - you can reuse it. Most projects do have the coding convention. > Like using the META_PROPERTY() macro to add __gccxml__ attributes into > the code. In many projects, changing the code is not an option and running some intelligent algorithm helps to cover 90-95% of all properties, so why not to use it? -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |