// Copyright (C) 2007-2015 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // %include std_set.i %include std_string.i %template() std::set; // Creates "int *argc, char ***argv" parameters from input list %typemap(in) (int *argc, char ***argv) { int i; if (!PyList_Check($input)) { PyErr_SetString(PyExc_ValueError, "Expecting a list"); return NULL; } int aSize = PyList_Size($input); $1 = &aSize; char** aStrs = (char **) malloc((aSize+1)*sizeof(char *)); for (i = 0; i < aSize; i++) { PyObject *s = PyList_GetItem($input,i); if (!PyString_Check(s)) { free(aStrs); PyErr_SetString(PyExc_ValueError, "List items must be strings"); return NULL; } aStrs[i] = PyString_AsString(s); } aStrs[i] = 0; $2 = &aStrs; } %typemap(freearg) (int *argc, char ***argv) { if ($2) free(*($2)); } /* MACRO: IN typemap for std::set C++ object */ %define TYPEMAP_INPUT_SET_BY_VALUE( TYPE ) { /* typemap in for set */ /* Check if is a list */ if (PyList_Check($input)) { int size = PyList_Size($input); std::set< TYPE > tmpSet; for (int i=0; i < size; i++) { PyObject * tmp = PyList_GetItem($input,i); TYPE elem = PyInt_AsLong(tmp); tmpSet.insert(elem); } $1 = tmpSet; } else { PyErr_SetString(PyExc_TypeError,"not a list"); return NULL; } } %enddef %typemap(in) std::set { TYPEMAP_INPUT_SET_BY_VALUE( int ) } %typecheck(SWIG_TYPECHECK_POINTER) std::set { $1 = PyList_Check($input) ? 1 : 0; }