Boost logo

Boost :

From: David Abrahams (abrahams_at_[hidden])
Date: 2000-11-01 14:09:55


----- Original Message -----
From: "Prabhu Ramachandran" <prabhu_at_[hidden]>

> Well, I just tried the above with my test code and it seems to work fine.

Yes. This won't work in the long run; I need to implement a fix, but it will
handle your little exapmle.

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

The GNU command-line tool for demangling C++ symbol names.

> >> 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.
>
> David> What's a pipeline browser?
>
> Well, VTK is a high level graphics library that has a pipeline
> architecture. Basically, one has source, sink, filter and process
> objects. One "connects" these objects to form a visualization network
> or a visualization pipeline. I wrote some code with python +Tkinter
> that graphically represents the pipeline and allows one to configure
> the objects in that pipeline. Look here if you want more information
> http://freshmeat.net/projects/vtkpipeline

Neat!

> >> Is it also possible to get the number of arguments that a
> >> function expects?? Sorry to pester you with obscure things
> >> like this. :)
>
> David> Probably, though as I wrote earlier it might be a lot of
> David> work. Also, as I wrote earlier I would still like to know
> David> how one does this for a regular Python function. I'd rather
> David> mimic the native interface where possible. Can you show how
> David> it is done?
>
> Here are simple examples that illustrates how python does it.
>
> >>> def t (x):
> ... print "ok", x
> ...
> >>> dir (t)
> ['__doc__', '__name__', 'func_code', 'func_defaults', 'func_doc',
'func_globals', 'func_name']
> >>> t.func_code
> <code object t at 80813f8, file "<stdin>", line 1>
> >>> dir (t.func_code)
> ['co_argcount', 'co_code', 'co_consts', 'co_filename', 'co_firstlineno',
'co_flags', 'co_lnotab', 'co_name', 'co_names', 'co_nlocals',
'co_stacksize', 'co_varnames']
> >>> t.func_code.co_argcount
> 1

Okay, actually, this particular thing would probably be pretty easy. Of
course I can't get you the argument names. This will probably have to wait a
week until after the official Boost release, though. And I don't think I can
(or want to) provide everything you're finding in dir(t). I'm just curious:
why do you need this? It does seem a little obscure.

> >>> class T:
> ... def t (self, x):
> ... print "T", x
> ...
> >>> dir (T.t)
> ['__doc__', '__name__', 'im_class', 'im_func', 'im_self']
> >>> T.t.im_func
> <function t at 8081e70>
> >>> dir (T.t.im_func)
> ['__doc__', '__name__', 'func_code', 'func_defaults', 'func_doc',
'func_globals', 'func_name']
> >>>
>
> I hope that was of some use.

Hmm. The use of these "type wart" prefixes (e.g. "im_") are an impediment to
abstraction and genericity. For example, do I lie by using the "im_" prefix
even though my functions are not in fact InstanceMethods? Actually, member
functions of my extension classes are the same type as module-scope
functions, so I would have to supply an im_func attribute which refers back
to the function. Would that work for you?

> >> How does one set the __doc__ ??
>
> David> Right now, it's only supported for functions of derived
> David> classes in Python. Do you want to write docstrings in C++?
>
> Yeah, if possible. May be useful for some folks?

Sure, someday. But for you? Do you need this right now or is the request
"just for completeness?"

> I have yet another feature request. I just added a private member (an
> int called var) to a class A. Under python is there no way that I can
> access this data member? For instance
>
> >>> a = A()
> >>> print a.var
> Traceback (innermost last):
> File "<stdin>", line 1, in ?
> AttributeError: var
> >>>
>
> Or do data members have to exposed separately? Or is this
> impossible to do? I hope I am not getting on your nerves with
> feature requests. :)

See the sections titled "Getters and Setters" and "Direct Access to Data
Members" at http://people.ne.mediaone.net/abrahams/downloads/special.html

Also, are you sure you want to expose a /private/ data member? If so, you
may need to make the exposing code/function a friend of your class.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk