Re: [pygccxml-development] name_based_recognizer_t and pure functions
Brought to you by:
mbaas,
roman_yakovenko
|
From: Roman Y. <rom...@gm...> - 2010-01-13 19:20:04
|
On Wed, Jan 13, 2010 at 3:01 PM, Berserker <ber...@ho...> wrote:
> I'm using name_based_recognizer_t to bind properties to my exposed methods.
> I don't understand why pure virtual (public) functions are not supported.
> Given the code:
>
> class Foo {
> public:
> virtual std::string getName() const = 0;
> virtual std::string getDescription() const;
> }
>
> Py++ creates the "Description" property but not the "Name" one.
> I tweaked the code in "property_recognizer_i.is_accessor" in this way:
>
> def is_accessor( self, mem_fun ):
> if mem_fun.ignore:
> return False
> if mem_fun.access_type != 'public':
> return False
> if mem_fun.has_static:
> return False
> #if mem_fun.virtuality ==
> declarations.VIRTUALITY_TYPES.PURE_VIRTUAL:
> # return False
> return True
>
> and now it seems working, can I ask the meaning of that check?
There are few reasons:
* In my opinion, "get" property is a function which returns
"reference". It is impossible to "override" pure virtual function,
which returns reference, on Python side and call it from C++. So I
filter such functions.
* This behavior is "close" to "native" Python:
class Foo:
def __init__( self ):
pass
def x( self ):
return 1
x = property( x )
class DFoo(Foo):
def __init__( self ):
Foo.__init__(self)
def x( self ):
return 2
df = DFoo()
print df.x
The output is: <bound method DFoo.x of <__main__.DFoo instance at 0xb781758c>>
HTH
--
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/
|