[C++-sig] Boost "From Python" Conversion and Template Classes
Sean Ross-Ross
srossross at gmail.com
Sat May 19 21:38:12 CEST 2007
I have a project where there is an internal reference count pointer
to the objects passed through. And all of class methods are templated
similar to:
template<class ScalarType, class MV, class OP>
class BasicEigenproblem : public virtual Eigenproblem<ScalarType,
MV, OP> {
....
setOperator( const Teuchos::RefCountPtr<OP>& Op );
....
}
In the C++ code to call this method you must do:
RefCountPtr< Matrix > A = rcp( new Matrix( ... ) );
eigenproblem. setOperator(A);
I would like to have the methods in python be just:
A = Matrix()
eigenproblem. setOperator(A)
where I have templated BasicEigenproblem<double,object,object>.
And without dealing with the RefCountPtr, and have some method that
calls in the background:
RefCountPtr< object > RCPA = rcp( A );
I have tried experimenting with the extraction methods with no luck:
8: using namespace boost::python;
10: typedef Teuchos::RefCountPtr<object> RCP;
12: void* extract_rcp(PyObject* obj)
13: {
14: RCP *r = new RCP( new object(handle<>(obj)), false );
15: return r;
16: }
18: converter::registry::insert ( &extract_rcp, type_id<RCP>() );
I get a few errors with this at compile time:
extraction.cpp:18: error: expected constructor, destructor, or type
conversion before '(' token
I can not see to find a concrete example of how to do this. Am I one
the right track, any Sugestions?
Thanks, and sorry for the long winded message.
~Sean
More information about the Cplusplus-sig
mailing list