[C++-sig] Need strategic advice designing Boost/Python program

Craig Finch oanjao at yahoo.com
Thu Apr 26 23:27:05 CEST 2007


As a fairly new boost.python user, I would like some expert advice on
which strategy to use in using Boost and Python, so that I don't go
down a dead end.  A clean interface is more important to me than
efficiency.

I am writing a numerical solver.  I want most of the code to be in
Python for ease of development.  However, I want to implement some
objects in C++ for speed, because they use iterative solution methods. 
I envision my Python code as creating a mesh on a domain, calling a C++
solver, and performing post-processing such as plotting.  The cleanest
way to do this seems to be to create a complex "mesh" object in Python,
and then pass all the mesh data to C++ at once.  However, I want to
implement the methods for creating and modifying the mesh in Python,
because flexibility is more important than speed.  After reading a lot,
there seem to be three main approaches to doing this.  I need help
choosing between:

1. Create the data portions of the mesh class in C++ and use Boost to
expose it to Python as a module.  Then use Python to add methods, as
shown in the Tutorial, and pass the whole object back to C++.  Finally,
use <extract> to get C++ values for computation.  One downside to this
approach is that apparently Python can't be used to implement a
constructor method for a wrapped C++ class.

2. Similar to #1, but instead create Python classes that inherit from
the C++ base classes, and then add Python methods.  Not sure how to get
the resulting objects back into C++.

3. Create the data and methods in Python, and then define custom lvalue
converters to get the data into C++.  This seems messy because I have
to use the classic Python/C API in the converter functions, which seems
to kind of defeat the purpose of using Boost.

Your input is greatly appreciated!  If I have misunderstood any thing,
please let me know.  The resulting code will be made available as an
example to others.

   Craig Finch

--------------
Please reply to cfinch at ieee.org

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 



More information about the Cplusplus-sig mailing list