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