Boost logo

Boost :

From: rwgk_at_[hidden]
Date: 2000-12-07 23:24:34


I am trying to incrementally implement the feature *originally*
proposed in this thread. Superficially (!) I got the following
to work properly:

import dvect

d = dvect.dvect((1,2,3,4,5,6))
print d.as_tuple()

id = d.as_ivect()
print id.as_tuple()

did = id.as_dvect()
print did.as_tuple()

Output:
(1.0, 2.0, 3.0, 4.0, 5.0, 6.0)
(1, 2, 3, 4, 5, 6)
(1.0, 2.0, 3.0, 4.0, 5.0, 6.0)

The source code can be viewed at this location:
        http://cci.lbl.gov/~rwgk/cvs/cvsweb.cgi/bpl_tru64/

The files to look at are dvect.cpp, dvect.h, ivect.cpp, ivect.h, and
import_constructor.cpp. ivect.* and dvect.* are the same except for
the
type used (double vs. int), and the variable names (dvect <-> ivect).

The function to focus on is dvect_as_ivect_hack() in dvect.cpp. The
interesting bit is how a constructor is imported from another module.
At the moment, the rest is cheating.

The next incremental improvement would be to replace the
PyObject_CallObject() by a lower level way of constructing the ivect
object. I.e., I want to by-pass the Python layer and construct the
PyObject *ivect not from a Python tuple, but directly from a
vects::ivect object.

One idea is to add a PyCObject to each module's __dict__ and import it
in the other module the same way the constructor is currently
imported.
The PyCObject would contain a pointer to a C++ function that
constructs, e.g., the PyObject *ivect directly from a vects::ivect.

Does this idea make sense?

What part of BPL is related to this idea? I.e., where should I start
looking for such a function?

Finally, is there hope that the resulting mechanism could be hidden in
from_python/to_python templates that are instantiated by a call like:

python::import_class_builder<vects::ivect> ivect_handle
("ivect", "ivect");

Thanks!
        Ralf


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