Salome HOME
Move medtool folder to MED base repository
[modules/med.git] / medtool / src / ParaMEDMEM_Swig / ParaMEDMEM.typemap
1 // Copyright (C) 2007-2015  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         free(aStrs);
39         PyErr_SetString(PyExc_ValueError, "List items must be strings");
40         return NULL;
41     }
42     aStrs[i] = PyString_AsString(s);
43   }
44   aStrs[i] = 0;
45   $2 = &aStrs;
46 }
47
48 %typemap(freearg) (int *argc, char ***argv) {
49    if ($2) free(*($2));
50 }
51
52 /*  MACRO: IN typemap for std::set<TYPE> C++ object */
53 %define TYPEMAP_INPUT_SET_BY_VALUE( TYPE )
54 {
55   /* typemap in for set<TYPE> */
56   /* Check if is a list */
57   if (PyList_Check($input))
58   {
59     int size = PyList_Size($input);
60     std::set< TYPE > tmpSet;
61
62     for (int i=0; i < size; i++)
63     {
64       PyObject * tmp = PyList_GetItem($input,i);
65       TYPE elem = PyInt_AsLong(tmp);
66       tmpSet.insert(elem);
67     }
68     $1 = tmpSet;
69   }
70   else
71   {
72     PyErr_SetString(PyExc_TypeError,"not a list");
73     return NULL;
74   }
75 }
76 %enddef
77
78 %typemap(in) std::set<int>
79
80   TYPEMAP_INPUT_SET_BY_VALUE( int ) 
81 }
82 %typecheck(SWIG_TYPECHECK_POINTER) std::set<int> {
83   $1 = PyList_Check($input) ? 1 : 0;
84 }