From c66952a3f0e49b2d24ccfdad68d09425550f8256 Mon Sep 17 00:00:00 2001 From: Simon Marchetto Date: Wed, 17 Jul 2013 16:56:00 +0200 Subject: [PATCH] Scilab: add generic support for STL set --- Lib/scilab/std_set.i | 100 +++++++++++-------------------------------- Lib/scilab/stl.i | 7 +-- 2 files changed, 26 insertions(+), 81 deletions(-) diff --git a/Lib/scilab/std_set.i b/Lib/scilab/std_set.i index 0299e47b6..2a4b3b2cc 100644 --- a/Lib/scilab/std_set.i +++ b/Lib/scilab/std_set.i @@ -1,84 +1,32 @@ /* - * C++ type: std::set - * Scilab 5 type: integer matrix - */ + * + * C++ type : STL set + * Scilab type : matrix (for sets of primitive types) or list (for sets of all other types : pointers...) + * +*/ -%include +%fragment("StdSetTraits", "header", fragment="StdSequenceTraits") +%{ + namespace swig { + template + struct traits_asptr > { + static int asptr(const SciObject &obj, std::set **set) { + return traits_asptr_stdseq >::asptr(obj, set); + } + }; -%typemap(in, fragment="SWIG_SciInt32_AsIntArrayAndSize") std::set(std::set temp) -{ - int* imatrix; - int nbRows; - int nbCols; - if (SWIG_SciInt32_AsIntArrayAndSize(pvApiCtx, $input, &nbRows, &nbCols, &imatrix, fname) != SWIG_ERROR) - { - if ((nbRows > 1) && (nbCols > 1)) - { - Scierror(999, _("%s: Wrong size for input argument #%d: An integer vector expected.\n"), fname, $input); - return SWIG_ERROR; - } - - $1 = temp; - std::set& tmpset = (std::set&)$1; - std::copy(imatrix, imatrix + nbRows * nbCols, std::inserter(tmpset, tmpset.begin())); + template + struct traits_from > { + static SciObject from(const std::set& set) { + return traits_from_stdseq >::from(set); + } + }; } -} - -%typemap(in, fragment="SWIG_SciInt32_AsIntArrayAndSize") std::set& (std::set temp) -{ - int* imatrix; - int nbRows; - int nbCols; - if (SWIG_SciInt32_AsIntArrayAndSize(pvApiCtx, $input, &nbRows, &nbCols, &imatrix, fname) != SWIG_ERROR) - { - if ((nbRows > 1) && (nbCols > 1)) - { - Scierror(999, _("%s: Wrong size for input argument #%d: An integer vector expected.\n"), fname, $input); - return SWIG_ERROR; - } - - $1 = &temp; - std::set& tmpset = *$1; - std::copy(imatrix, imatrix + nbRows * nbCols, std::inserter(tmpset, tmpset.begin())); - } -} +%} -%typemap(out, fragment="SWIG_SciInt32_FromIntArrayAndSize") std::set -{ - int nbCols = $1.size(); - int* imatrix = new int[nbCols]; - std::copy($1.begin(), $1.end(), imatrix); +#define %swig_set_methods(Type...) %swig_sequence_methods(Type) +#define %swig_set_methods_val(Type...) %swig_sequence_methods_val(Type); - int ret = SWIG_SciInt32_FromIntArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), 1, nbCols, imatrix); - delete[] imatrix; - - if (ret != SWIG_ERROR) - { - AssignOutputVariable(pvApiCtx, outputPosition) = nbInputArgument(pvApiCtx) + SWIG_Scilab_GetOutputPosition(); - } - else - { - return SWIG_ERROR; - } -} - -%typemap(argout) std::set& -{ - int nbCols = $1->size(); - int* imatrix = new int[nbCols]; - std::copy($1->begin(), $1->end(), imatrix); - - int ret = SWIG_SciInt32_FromIntArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), 1, nbCols, imatrix); - delete[] imatrix; - - if (ret != SWIG_ERROR) - { - AssignOutputVariable(pvApiCtx, outputPosition) = nbInputArgument(pvApiCtx) + SWIG_Scilab_GetOutputPosition(); - } - else - { - return SWIG_ERROR; - } -} +%include diff --git a/Lib/scilab/stl.i b/Lib/scilab/stl.i index 9656ee6d4..27e7f262f 100644 --- a/Lib/scilab/stl.i +++ b/Lib/scilab/stl.i @@ -1,8 +1,5 @@ /* initial STL definition. extended as needed in each language */ %include std_common.i -%include std_vector.i %include std_string.i - - - - +%include std_vector.i +%include std_set.i