Salome HOME
Bug fix in simplifyPolyhedronCells(). Thanks Antoine G. !
[tools/medcoupling.git] / src / ParaMEDMEM_Swig / ParaMEDMEM.typemap
1 // Copyright (C) 2007-2016  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, or (at your option) any later version.
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 std_set.i
21 %include std_string.i
22
23 %template() std::set<int>;
24
25 // Creates "int *argc, char ***argv" parameters from input list
26 %typemap(in) (int *argc, char ***argv) {
27   int i;
28   if (!PyList_Check($input)) {
29     PyErr_SetString(PyExc_ValueError, "Expecting a list");
30     return NULL;
31   }
32   int aSize = PyList_Size($input);
33   $1 = &aSize;
34   char** aStrs = (char **) malloc((aSize+1)*sizeof(char *));
35   for (i = 0; i < aSize; i++) {
36     PyObject *s = PyList_GetItem($input,i);
37     if (PyString_Check(s))
38       aStrs[i] = PyString_AsString(s);
39 %#if PY_VERSION_HEX >= 0x03000000
40     else if (PyUnicode_Check(s))
41       aStrs[i] = PyUnicode_AsUTF8(s);
42 %#endif
43     else {
44         free(aStrs);
45         PyErr_SetString(PyExc_ValueError, "List items must be strings");
46         return NULL;
47     }
48   }
49   aStrs[i] = 0;
50   $2 = &aStrs;
51 }
52
53 %typemap(freearg) (int *argc, char ***argv) {
54    if ($2) free(*($2));
55 }
56
57 /*  MACRO: IN typemap for std::set<TYPE> C++ object */
58 %define TYPEMAP_INPUT_SET_BY_VALUE( TYPE )
59 {
60   /* typemap in for set<TYPE> */
61   /* Check if is a list */
62   if (PyList_Check($input))
63   {
64     int size = PyList_Size($input);
65     std::set< TYPE > tmpSet;
66
67     for (int i=0; i < size; i++)
68     {
69       PyObject * tmp = PyList_GetItem($input,i);
70       TYPE elem = PyInt_AsLong(tmp);
71       tmpSet.insert(elem);
72     }
73     $1 = tmpSet;
74   }
75   else
76   {
77     PyErr_SetString(PyExc_TypeError,"not a list");
78     return NULL;
79   }
80 }
81 %enddef
82
83 %typemap(in) std::set<int>
84
85   TYPEMAP_INPUT_SET_BY_VALUE( int ) 
86 }
87 %typecheck(SWIG_TYPECHECK_POINTER) std::set<int> {
88   $1 = PyList_Check($input) ? 1 : 0;
89 }