Salome HOME
Merge from V6_main_20120808 08Aug12
[modules/med.git] / src / MEDCalculator / Swig / MEDCalculatorTypemaps.i
1 // Copyright (C) 2007-2012  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
20 #include <limits>
21
22 static PyObject* convertMEDCalculatorDBField(ParaMEDMEM::MEDCalculatorDBField *f, int owner)
23 {
24   PyObject *ret=0;
25   if(dynamic_cast<ParaMEDMEM::MEDCalculatorDBFieldReal *>(f))
26     ret=SWIG_NewPointerObj((void*)f,SWIGTYPE_p_ParaMEDMEM__MEDCalculatorDBFieldReal,owner);
27   if(dynamic_cast<ParaMEDMEM::MEDCalculatorDBFieldCst *>(f))
28     ret=SWIG_NewPointerObj((void*)f,SWIGTYPE_p_ParaMEDMEM__MEDCalculatorDBFieldCst,owner);
29   return ret;
30 }
31
32 void convertPyObjToRS(PyObject *o, ParaMEDMEM::MEDCalculatorDBRangeSelection& rs)
33 {
34   if(PyInt_Check(o))
35     {
36       int val=(int)PyInt_AS_LONG(o);
37       rs=val;
38       return ;
39     }
40   if(PyString_Check(o))
41     {
42       char *s=PyString_AsString(o);
43       rs=s;
44       return ;
45     }
46   PyErr_SetString(PyExc_TypeError,"Range selection must be an integer or a string !");
47 }
48
49 void convertPyObjToRS2(PyObject *o, ParaMEDMEM::MEDCalculatorDBRangeSelection& rs, const char *msg)
50 {
51   if(PyInt_Check(o))
52     {
53       int val=(int)PyInt_AS_LONG(o);
54       rs=val;
55       return ;
56     }
57   if(!PySlice_Check(o))
58     {
59       std::ostringstream oss;
60       oss << "Expecting a slice or an integer for " << msg << " !";
61       throw INTERP_KERNEL::Exception(oss.str().c_str());
62     }
63   Py_ssize_t strt,stp,step;
64   PySliceObject *oC=reinterpret_cast<PySliceObject *>(o);
65   PySlice_GetIndices(oC,std::numeric_limits<int>::max(),&strt,&stp,&step);
66   rs.setPyStart(strt);
67   rs.setPyEnd(stp);
68 }