Salome HOME
df14e88e25b5be869bd2b6c4a72cb6055049399c
[modules/med.git] / src / MEDCalculator / Swig / MEDCalculatorTypemaps.i
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // Author : Anthony Geay (CEA/DEN)
20
21 #include <limits>
22
23 static PyObject* convertMEDCalculatorDBField(ParaMEDMEM::MEDCalculatorDBField *f, int owner)
24 {
25   PyObject *ret=0;
26   if(dynamic_cast<ParaMEDMEM::MEDCalculatorDBFieldReal *>(f))
27     ret=SWIG_NewPointerObj((void*)f,SWIGTYPE_p_ParaMEDMEM__MEDCalculatorDBFieldReal,owner);
28   if(dynamic_cast<ParaMEDMEM::MEDCalculatorDBFieldCst *>(f))
29     ret=SWIG_NewPointerObj((void*)f,SWIGTYPE_p_ParaMEDMEM__MEDCalculatorDBFieldCst,owner);
30   return ret;
31 }
32
33 void convertPyObjToRS(PyObject *o, ParaMEDMEM::MEDCalculatorDBRangeSelection& rs)
34 {
35   if(PyInt_Check(o))
36     {
37       int val=(int)PyInt_AS_LONG(o);
38       rs=val;
39       return ;
40     }
41   if(PyString_Check(o))
42     {
43       char *s=PyString_AsString(o);
44       rs=s;
45       return ;
46     }
47   PyErr_SetString(PyExc_TypeError,"Range selection must be an integer or a string !");
48 }
49
50 void convertPyObjToRS2(PyObject *o, ParaMEDMEM::MEDCalculatorDBRangeSelection& rs, const char *msg)
51 {
52   if(PyInt_Check(o))
53     {
54       int val=(int)PyInt_AS_LONG(o);
55       rs=val;
56       return ;
57     }
58   if(!PySlice_Check(o))
59     {
60       std::ostringstream oss;
61       oss << "Expecting a slice or an integer for " << msg << " !";
62       throw INTERP_KERNEL::Exception(oss.str().c_str());
63     }
64   Py_ssize_t strt,stp,step;
65   PySliceObject *oC=reinterpret_cast<PySliceObject *>(o);
66   PySlice_GetIndices(oC,std::numeric_limits<int>::max(),&strt,&stp,&step);
67   rs.setPyStart(strt);
68   rs.setPyEnd(stp);
69 }