13 #include <boost/python.hpp>
29 using namespace boost::python;
36 class_ < FunctionWrap, std::auto_ptr < FunctionWrap> >
38 "The base class for raw functions. FunctionBase objects need to\n"
39 "wrapped with Function objects to be displayed. FunctionBase\n"
40 "can be derived from and cloned so they can be added to the\n"
42 init < const FunctionBase & >
43 (
"FunctionBase () -> FunctionBase\n"
44 "FunctionBase ( FunctionBase ) -> FunctionBase\n"
46 "Constructors of the FunctionBase object.\n" ) )
50 .def ( init < const FunctionWrap & > () )
52 .def (
"initialize", &FunctionWrap::initialize,
53 "initialize () -> None\n"
55 "Initializes the function parameter values and the names.\n"
56 "The number of parameters is taken from the number of names." )
58 .def (
"name", &FunctionBase::name,
59 return_value_policy < copy_const_reference > (),
62 "Returns the name of the function." )
64 .def (
"setName", &FunctionWrap::setName,
65 "setName ( string ) -> None\n"
67 "Sets the name of the function." )
70 &FunctionBase::parmNames,
71 return_value_policy < copy_const_reference > (),
72 "parmNames () -> sequence\n"
74 "Returns the names of the parameters" )
76 .def (
"setParmNames",
77 &FunctionWrap::setParmNames,
78 "setParmNames ( sequence ) -> None\n"
80 "Sets the parameter names and re-sizes the parameters" )
82 .def (
"setParameters",
84 (
const std::vector < double > & ) )
85 &FunctionBase::setParameters,
86 "setParameters ( sequence ) -> None\n"
88 "Sets the values of the parameters." )
90 .def (
"getParameters", &FunctionBase::getParameters,
91 return_value_policy < copy_const_reference > (),
92 "getParameters () -> sequence\n"
94 "Returns the current function parameter values." )
101 using namespace hippodraw;
124 #ifndef HAVE_OLD_PYTHON
125 PyGILState_STATE state = PyGILState_Ensure ();
127 extract<std::auto_ptr<FunctionWrap>&> x(
get_owner(
this));
128 if ( x.check() ) x().release();
130 PyGILState_Release ( state );
143 object ( handle<> ( borrowed ( detail::wrapper_base_::get_owner(*
this))));
150 unsigned int dims = 0;
151 #ifndef HAVE_OLD_PYTHON
152 PyGILState_STATE state = PyGILState_Ensure ();
154 if (
override member =
this -> get_override (
"dimensions" ) ) {
157 dims = call_method < unsigned int > (
self.ptr(),
"dimensions" );
162 PyGILState_Release ( state );
174 if (
override member =
this -> get_override (
"derivByParm" ) ) {
185 #ifndef HAVE_OLD_PYTHON
186 PyGILState_STATE state = PyGILState_Ensure ();
190 if (
override clone = this->get_override(
"clone")) {
194 py_result (
clone() );
195 }
catch ( error_already_set & ) {
198 PyGILState_Release ( state );
206 object my_class =
self.attr(
"__class__");
208 py_result = my_class ( );
209 }
catch ( error_already_set & ) {
212 PyGILState_Release ( state );
217 FunctionWrap* result = extract<FunctionWrap*>(py_result);
221 PyGILState_Release ( state );
257 #ifndef HAVE_OLD_PYTHON
259 PyGILState_STATE state = PyGILState_Ensure ();
265 value = call_method < double, int, double >
266 (
self.ptr(),
"derivByParm", i, x );
271 PyGILState_Release ( state );
285 #ifndef HAVE_OLD_PYTHON
286 PyGILState_STATE state = PyGILState_Ensure ();
290 call_method < void > (
self.ptr(),
"initialize" );
293 PyGILState_Release ( state );
307 #ifndef HAVE_OLD_PYTHON
308 PyGILState_STATE state = PyGILState_Ensure ();
313 value = call_method < double, double > (
self.ptr(),
"valueAt", x );
314 PyGILState_Release ( state );
316 catch (
const error_already_set & ) {
317 PyGILState_Release ( state );
333 #ifndef HAVE_OLD_PYTHON
334 PyGILState_STATE state = PyGILState_Ensure ();
337 unsigned int size = x.size();
341 value = call_method < double, double, double >
342 (
self.ptr(),
"valueAt", x[0], x[1] );
345 value = call_method < double, double, double, double >
346 (
self.ptr(),
"valueAt", x[0], x[1], x[2] );
351 PyGILState_Release ( state );
363 #endif // BOOST_DEFECT