Salome HOME
Merge from BR_V5_DEV 16Feb09
[modules/med.git] / src / MEDMEM_SWIG / my_typemap.i
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 %{
23 #include <stdio.h>
24 %}
25
26 %typemap(python,in) string * , const string * , const string * const {
27   /* typemap in for string * , const string * , const string * const */
28   /* Check if is a list */
29   if (PyList_Check($input)) {
30     int size = PyList_Size($input);
31     int i = 0;
32     $1 = new string[size];
33     for (i = 0; i < size; i++) {
34       PyObject *o = PyList_GetItem($input,i);
35       if (PyString_Check(o))
36         $1[i] = string(PyString_AsString(PyList_GetItem($input,i)));
37       else {
38         PyErr_SetString(PyExc_TypeError,"list must contain strings");
39         free($1);
40         return NULL;
41       }
42     }
43   }
44   else
45     {
46       PyErr_SetString(PyExc_TypeError,"not a list");
47       return NULL;
48     }
49 }
50
51 %typemap(python,in) double * , const double * , const double * const
52 {
53   /* typemap in for double * , const double * , const double * const */
54   /* Check if is a list */
55   if (PyList_Check($input)) { 
56     int size = PyList_Size($input);
57     int i = 0; 
58     $1 = (double *) malloc(size*sizeof(double));
59     for (i = 0; i < size; i++) {
60       PyObject *o = PyList_GetItem($input,i);
61       if (PyFloat_Check(o))
62         $1[i] = PyFloat_AsDouble(PyList_GetItem($input,i));
63       else { 
64         PyErr_SetString(PyExc_TypeError,"list must contain floats");
65         free($1);
66         return NULL;
67       }
68     }
69   } 
70   else
71     { 
72       PyErr_SetString(PyExc_TypeError,"not a list");
73       return NULL;
74     }
75
76
77 %typemap(python,in) int * , const int * , const int * const
78 {
79   /* typemap in for int * , const int * , const int * const */
80   /* Check if is a list */
81   if (PyList_Check($input)) { 
82     int size = PyList_Size($input);
83     int i = 0; 
84     $1 = (int *) malloc(size*sizeof(int));
85     for (i = 0; i < size; i++) {
86       PyObject *o = PyList_GetItem($input,i);
87       if (PyInt_Check(o))
88         $1[i] = PyInt_AsLong(PyList_GetItem($input,i));
89       else { 
90         PyErr_SetString(PyExc_TypeError,"list must contain integers");
91         free($1);
92         return NULL;
93       }
94     }
95   } 
96   else
97     { 
98       PyErr_SetString(PyExc_TypeError,"not a list");
99       return NULL;
100     }
101
102
103
104 %typemap(python,in) medGeometryElement * , const  medGeometryElement * , const  medGeometryElement * const 
105 {
106   /* typemap in for medGeometryElement * , const  medGeometryElement * , const  medGeometryElement * const */
107   /* Check if is a list */
108   if (PyList_Check($input)) { 
109     int size = PyList_Size($input);
110     int i = 0; 
111     $1 = (medGeometryElement *) malloc(size*sizeof(int));
112     for (i = 0; i < size; i++) {
113       PyObject *o = PyList_GetItem($input,i);
114       if (PyInt_Check(o))
115         $1[i] = (medGeometryElement) PyInt_AsLong(PyList_GetItem($input,i));
116       else { 
117         PyErr_SetString(PyExc_TypeError,"list must contain integers");
118         free($1);
119         return NULL;
120       }
121     }
122   } 
123   else
124     { 
125       PyErr_SetString(PyExc_TypeError,"not a list");
126       return NULL;
127     }
128
129
130 %typemap(python,out) list<string> {
131   int i;
132   list<string>::iterator iL;
133
134   $result = PyList_New($1->size());
135   for (i=0, iL=$1->begin(); iL!=$1->end(); i++, iL++)
136     PyList_SetItem($result,i,PyString_FromString((*iL).c_str())); 
137 }
138
139 %typemap(freearg) int * , const int * , const int * const {
140   /* free the memory allocated in the typemap in for int * , const int * , const int * const */
141   free($1);
142 }
143
144 %typemap(freearg) double * , const double * , const double * const {
145   /* free the memory allocated in the typemap in for double * , const double * , const double * const */
146   free($1);
147 }
148
149 %typemap(freearg) medGeometryElement * , const medGeometryElement * , const medGeometryElement * const {
150   /* free the memory allocated in the typemap in for medGeometryElement * , const medGeometryElement * , const medGeometryElement * const */
151   free($1);
152 }