Boost logo

Boost :

From: David Abrahams (abrahams_at_[hidden])
Date: 2000-10-31 15:01:12

----- Original Message -----
From: "Prabhu Ramachandran" <prabhu_at_[hidden]>
> hi,
> >>>>> "David" == David Abrahams <abrahams_at_[hidden]> writes:
> David> See
> David>
> David> New features: 1. support for non-const reference parameters
> David> to constructors 2. support for special member attributes
> David> __doc__, __class__, __bases__, etc. 3. support for
> Ummm. A few problems I found with the latest code base. I have a
> small test program with classes named A and B (it is really a test :)

Could you send me this program? It always helps to have a way to reproduce
problems ;-)

> class A has a single virtual method - func(const int x) const
> class B : public A and has a method - func1(const int x) const
> I wrapped this and compiled it into a module called test. And in
> python I get the following.
> >>> from test import *
> >>> dir (A)
> ['__init__', 'func', 'func1']
> # This should not show func1.

Hard to say what might be happening here. Oh, I see it now. Sorry, something
should be done about this. In the meantime, make sure your declare_base()
calls come /after/ all methods have been added to all the classes concerned.

[This is an interaction between the new inheritance feature and the
mechanism required to support smart pointers and default virtual function
implementations. For the masochistic, a long explanation of part of this can
be found in the comment for ExtensionClassBase::add_default_method() in

> >>> dir (B)
> ['__doc__', '__module__']
> # This is not good. :(

No, not good. But at least it's consistent with what I think is going wrong

> >>> B.__bases__
> (<Q22pyt5Class1ZQ22py17ExtensionInstance object at 807d644>,)
> # Is this Ok? I dont know. Maybe.

Yes, it's OK, but probably I ought to fix the repr() for classes so it
prints something more like
<extension_class test.B at 807d644>

> >>> dir (B.__bases__[0])
> ['__init__', 'func', 'func1']
> # Ok. Atleast this is consistent.
> >>> b = B ()
> >>> b.func (1)
> A::func : t = 1
> # Ok! this is correct. I was able to call A's func.
> >>> b.__class__
> <Q22pyt5Class1ZQ22py17ExtensionInstance object at 807d90c>
> # Correct?

Yes, but not pretty. See my earlier comment. (run it through c++filt for a
nicer-though-not-ideal representation)

> >>> a = A ()
> >>> dir (a.__class__)
> ['__init__', 'func', 'func1']
> # Ok. consistent.


> The reason I am particular about these attributes is because there is
> some pretty useful stuff that one can do using these. I use this
> routinely to generate a pipeline browser for VTK.

What's a pipeline browser?

> Is it also possible
> to get the number of arguments that a function expects?? Sorry to
> pester you with obscure things like this. :)

Probably, though as I wrote earlier it might be a lot of work. Also, as I
wrote earlier I would still like to know how one does this for a regular
Python function. I'd rather mimic the native interface where possible. Can
you show how it is done?

> How does one set the __doc__ ??

Right now, it's only supported for functions of derived classes in Python.
Do you want to write docstrings in C++?

> Could the other special attributes
> __dict__ etc. be added or are they irrelevant (I dont use them, I do
> use dir, __bases__ and __class__).

__dict__ is already supported.

> For reference on the special
> attributes look here

Of course I used that page as a reference when implementing py_cpp ;->


Boost list run by bdawes at, gregod at, cpdaniel at, john at