[C++-sig] Need strategic advice designing Boost/Python program
Craig Finch
oanjao at yahoo.com
Mon Apr 30 21:20:49 CEST 2007
Stefan,
Thank you for your input. To answer your questions:
> I'm not sure what you mean by 'implement a constructor'. Can you
> elaborate ?
> As a minor point, if you go this route, there is no need to use
> extract<>
> to access values, as within C++, you'll always deal with the (native)
> C++
> interface directly. extract<> is useful to pull out embedded C++
> objects
> from python (wrapper) objects, or to require an explicit conversion /
> cast.
Let's say that I have created classes in C++ that represent the data
needed for my program. However, I want to build the methods in Python
because they need to be modified easily. I have gotten this approach
to work for methods except for __init__. If I try to add a Python
constructor to the class, it can't access the data members of the C++
class. I don't want to write the constructor in C++ because it's
potentially very complicated, defeating the purpose of writing methods
in Python. What do you suggest?
Also, thank you for your explanation of <extract>. It seems like I
will still need to use extract, because I want the Python interface to
use arrays in a Python-like manner. On Ralf's suggestion, I will look
at scitbx to see how he handles it.
> > 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++.
>
> If you add new methods, or, more generally, attributes, you'll have
> to
> access them through the boost.python 'attr()' method that is part of
> the
> object protocol. However, if these attributes are only added for
> convenience
> (i.e. used within python, but not necessary for the C++ solvers),
> there
> isn't any need to access them from within C++, right ?
Correct--the methods I am building in Python should not need to be
accessible to the C++ solvers. So, if I have a C++ base class
containing all the "core" data, I can then derive Python classes which
add methods and "extra" data. In this case, how do I access the "core"
data from C++, since it is now a derived class?
Also--Ralf, thanks for the information about scitbx, and I may have
more questions once I've studied it. I'll take a look at it and try to
learn from its design, but currently the server
http://cci.lbl.gov/ seems to be unreachable.
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