From cfe3458b969fae3cc21af205dbf456f85079b8a3 Mon Sep 17 00:00:00 2001 From: Gennady Pospelov <g.pospelov@fz-juelich.de> Date: Tue, 14 May 2019 17:17:49 +0200 Subject: [PATCH] Provide index operator for SimulationResult in PythonAPI --- Wrap/swig/extendCore.i | 9 ++++ auto/Wrap/libBornAgainCore.py | 10 ++++ auto/Wrap/libBornAgainCore_wrap.cpp | 78 +++++++++++++++++++++++++++++ 3 files changed, 97 insertions(+) diff --git a/Wrap/swig/extendCore.i b/Wrap/swig/extendCore.i index 37ab340b669..d29e4da7f32 100644 --- a/Wrap/swig/extendCore.i +++ b/Wrap/swig/extendCore.i @@ -18,6 +18,15 @@ } }; +%extend SimulationResult { + double __getitem__(unsigned int i) { return (*($self))[i]; } + double __setitem__(unsigned int i, double value) + { + (*($self))[i] = value; + return (*($self))[i]; + } +}; + %extend FixedBinAxis { double __getitem__(unsigned int i) { return (*($self))[i]; } }; diff --git a/auto/Wrap/libBornAgainCore.py b/auto/Wrap/libBornAgainCore.py index 494be848eca..198c18a4adf 100644 --- a/auto/Wrap/libBornAgainCore.py +++ b/auto/Wrap/libBornAgainCore.py @@ -18294,6 +18294,16 @@ class SimulationResult(_object): """ return _libBornAgainCore.SimulationResult_axis(self, *args) + + def __getitem__(self, i): + """__getitem__(SimulationResult self, unsigned int i) -> double""" + return _libBornAgainCore.SimulationResult___getitem__(self, i) + + + def __setitem__(self, i, value): + """__setitem__(SimulationResult self, unsigned int i, double value) -> double""" + return _libBornAgainCore.SimulationResult___setitem__(self, i, value) + __swig_destroy__ = _libBornAgainCore.delete_SimulationResult __del__ = lambda self: None SimulationResult_swigregister = _libBornAgainCore.SimulationResult_swigregister diff --git a/auto/Wrap/libBornAgainCore_wrap.cpp b/auto/Wrap/libBornAgainCore_wrap.cpp index 6eb125cb284..1344aa16476 100644 --- a/auto/Wrap/libBornAgainCore_wrap.cpp +++ b/auto/Wrap/libBornAgainCore_wrap.cpp @@ -8096,6 +8096,11 @@ SWIGINTERN std::vector< IFormFactor * >::iterator std_vector_Sl_IFormFactor_Sm__ SWIGINTERN std::vector< IFormFactor * >::iterator std_vector_Sl_IFormFactor_Sm__Sg__erase__SWIG_1(std::vector< IFormFactor * > *self,std::vector< IFormFactor * >::iterator first,std::vector< IFormFactor * >::iterator last){ return self->erase(first, last); } SWIGINTERN std::vector< IFormFactor * >::iterator std_vector_Sl_IFormFactor_Sm__Sg__insert__SWIG_0(std::vector< IFormFactor * > *self,std::vector< IFormFactor * >::iterator pos,std::vector< IFormFactor * >::value_type x){ return self->insert(pos, x); } SWIGINTERN void std_vector_Sl_IFormFactor_Sm__Sg__insert__SWIG_1(std::vector< IFormFactor * > *self,std::vector< IFormFactor * >::iterator pos,std::vector< IFormFactor * >::size_type n,std::vector< IFormFactor * >::value_type x){ self->insert(pos, n, x); } +SWIGINTERN double SimulationResult___getitem__(SimulationResult *self,unsigned int i){ return (*(self))[i]; } +SWIGINTERN double SimulationResult___setitem__(SimulationResult *self,unsigned int i,double value){ + (*(self))[i] = value; + return (*(self))[i]; + } SWIGINTERN double OutputData_Sl_double_Sg____getitem__(OutputData< double > *self,unsigned int i){ return (*(self))[i]; } SWIGINTERN double OutputData_Sl_double_Sg____setitem__(OutputData< double > *self,unsigned int i,double value){ (*(self))[i] = value; @@ -86279,6 +86284,77 @@ fail: } +SWIGINTERN PyObject *_wrap_SimulationResult___getitem__(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + SimulationResult *arg1 = (SimulationResult *) 0 ; + unsigned int arg2 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int val2 ; + int ecode2 = 0 ; + PyObject * obj0 = 0 ; + PyObject * obj1 = 0 ; + double result; + + if (!PyArg_ParseTuple(args,(char *)"OO:SimulationResult___getitem__",&obj0,&obj1)) SWIG_fail; + res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_SimulationResult, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "SimulationResult___getitem__" "', argument " "1"" of type '" "SimulationResult *""'"); + } + arg1 = reinterpret_cast< SimulationResult * >(argp1); + ecode2 = SWIG_AsVal_unsigned_SS_int(obj1, &val2); + if (!SWIG_IsOK(ecode2)) { + SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "SimulationResult___getitem__" "', argument " "2"" of type '" "unsigned int""'"); + } + arg2 = static_cast< unsigned int >(val2); + result = (double)SimulationResult___getitem__(arg1,arg2); + resultobj = SWIG_From_double(static_cast< double >(result)); + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *_wrap_SimulationResult___setitem__(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + SimulationResult *arg1 = (SimulationResult *) 0 ; + unsigned int arg2 ; + double arg3 ; + void *argp1 = 0 ; + int res1 = 0 ; + unsigned int val2 ; + int ecode2 = 0 ; + double val3 ; + int ecode3 = 0 ; + PyObject * obj0 = 0 ; + PyObject * obj1 = 0 ; + PyObject * obj2 = 0 ; + double result; + + if (!PyArg_ParseTuple(args,(char *)"OOO:SimulationResult___setitem__",&obj0,&obj1,&obj2)) SWIG_fail; + res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_SimulationResult, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "SimulationResult___setitem__" "', argument " "1"" of type '" "SimulationResult *""'"); + } + arg1 = reinterpret_cast< SimulationResult * >(argp1); + ecode2 = SWIG_AsVal_unsigned_SS_int(obj1, &val2); + if (!SWIG_IsOK(ecode2)) { + SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "SimulationResult___setitem__" "', argument " "2"" of type '" "unsigned int""'"); + } + arg2 = static_cast< unsigned int >(val2); + ecode3 = SWIG_AsVal_double(obj2, &val3); + if (!SWIG_IsOK(ecode3)) { + SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "SimulationResult___setitem__" "', argument " "3"" of type '" "double""'"); + } + arg3 = static_cast< double >(val3); + result = (double)SimulationResult___setitem__(arg1,arg2,arg3); + resultobj = SWIG_From_double(static_cast< double >(result)); + return resultobj; +fail: + return NULL; +} + + SWIGINTERN PyObject *_wrap_delete_SimulationResult(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *resultobj = 0; SimulationResult *arg1 = (SimulationResult *) 0 ; @@ -133340,6 +133416,8 @@ static PyMethodDef SwigMethods[] = { "Returns axis coordinates as a numpy array. With no parameters given returns coordinates of x-axis in default units. \n" "\n" ""}, + { (char *)"SimulationResult___getitem__", _wrap_SimulationResult___getitem__, METH_VARARGS, (char *)"SimulationResult___getitem__(SimulationResult self, unsigned int i) -> double"}, + { (char *)"SimulationResult___setitem__", _wrap_SimulationResult___setitem__, METH_VARARGS, (char *)"SimulationResult___setitem__(SimulationResult self, unsigned int i, double value) -> double"}, { (char *)"delete_SimulationResult", _wrap_delete_SimulationResult, METH_VARARGS, (char *)"delete_SimulationResult(SimulationResult self)"}, { (char *)"SimulationResult_swigregister", SimulationResult_swigregister, METH_VARARGS, NULL}, { (char *)"delete_IBackground", _wrap_delete_IBackground, METH_VARARGS, (char *)"\n" -- GitLab