diff --git a/Examples/Makefile.in b/Examples/Makefile.in index a2d349268..9b14df4bf 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -1147,14 +1147,14 @@ R_CFLAGS=-fPIC r: $(SRCS) $(SWIG) -r $(SWIGOPT) $(INTERFACEPATH) ifneq ($(SRCS),) - $(CXX) -g -c $(CFLAGS) $(R_CFLAGS) $(SRCS) $(INCLUDES) + $(CXX) -g -c $(CFLAGS) $(R_CFLAGS) $(SRCS) $(INCLUDES) endif +( PKG_CPPFLAGS="$(INCLUDES)" $(COMPILETOOL) $(R) CMD SHLIB -o $(LIBPREFIX)$(TARGET)$(SO) $(ISRCS) $(OBJS) > /dev/null ) r_cpp: $(CXXSRCS) $(SWIG) -c++ -r $(SWIGOPT) -o $(RCXXSRCS) $(INTERFACEPATH) ifneq ($(CXXSRCS),) - $(CXX) -g -c $(CFLAGS) $(R_CFLAGS) $(CXXSRCS) $(INCLUDES) + $(CXX) -g -c $(CFLAGS) $(R_CFLAGS) $(CXXSRCS) $(INCLUDES) endif +( PKG_CPPFLAGS="$(INCLUDES)" $(COMPILETOOL) $(R) CMD SHLIB -o $(LIBPREFIX)$(TARGET)$(SO) $(RCXXSRCS) $(OBJS) > /dev/null ) @@ -1217,19 +1217,26 @@ scilab_cpp: $(SRCS) env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH SCILABPATH=$(srcdir):$$SCILABPATH echo 'exit(1)' |$(SCILAB) -nwni -noatomsautoload -nb -f builder.sce; \ fi -# ----------------------------------------------------------------- +# ----------------------------------------------------------------- # Running a Scilab example -# ----------------------------------------------------------------- +# ----------------------------------------------------------------- scilab_run: @env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH SCILABPATH=$(srcdir):$$SCILABPATH $(SCILAB) -nwni -noatomsautoload -nb -f runme.sci +# ----------------------------------------------------------------- +# Debugging a scilab example +# ----------------------------------------------------------------- + +scilab_debug: + @env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH SCILABPATH=$(srcdir):$$SCILABPATH $(SCILAB) -noatomsautoload -nb -debug -f runme.sci + # ----------------------------------------------------------------- # Cleaning the scilab examples # ----------------------------------------------------------------- scilab_clean: - rm -f *.sce *.so lib*lib.c + rm -f *.sce *.so lib*lib.c *_wrap.* ################################################################## ##### Go ###### diff --git a/Examples/scilab/check.list b/Examples/scilab/check.list index 57888c86c..038e99498 100644 --- a/Examples/scilab/check.list +++ b/Examples/scilab/check.list @@ -5,10 +5,14 @@ contract enum funcptr matrix -#matrix2 +matrix2 pointer simple +std_set +std_vector/std_vector +std_vector/std_vector_as_function_argument struct +template variables diff --git a/Examples/scilab/matrix2/matrixlib.c b/Examples/scilab/matrix2/matrixlib.c index 20b516444..43006bb8b 100644 --- a/Examples/scilab/matrix2/matrixlib.c +++ b/Examples/scilab/matrix2/matrixlib.c @@ -1,6 +1,8 @@ #include -double sumMatrixElements(double *inputMatrix, int nbRow, int nbCol) +// Double matrix functions + +double sumDoubleMatrix(double *inputMatrix, int nbRow, int nbCol) { int i; double total = 0.0; @@ -11,7 +13,7 @@ double sumMatrixElements(double *inputMatrix, int nbRow, int nbCol) return total; } -void squareMatrixElements(double *inputMatrix, int nbRow, int nbCol, double** resultMatrix, int* nbRowRes, int* nbColRes) +void squareDoubleMatrix(double *inputMatrix, int nbRow, int nbCol, double** resultMatrix, int* nbRowRes, int* nbColRes) { int i; int size = nbRow * nbCol; @@ -24,7 +26,7 @@ void squareMatrixElements(double *inputMatrix, int nbRow, int nbCol, double** re } } -void getMatrix(double **resultMatrix, int *nbRowRes, int *nbColRes) +void getDoubleMatrix(double **resultMatrix, int *nbRowRes, int *nbColRes) { int i; int size; @@ -37,3 +39,77 @@ void getMatrix(double **resultMatrix, int *nbRowRes, int *nbColRes) (*resultMatrix)[i] = i*2; } } + +// Integer matrix functions + +int sumIntegerMatrix(int *inputMatrix, int nbRow, int nbCol) +{ + int i; + int total = 0; + for (i=0; i create_iset(const int size, const int* values) -{ - std::set iset; - std::copy(values, values + size, std::inserter(iset, iset.begin())); - return iset; -} - -int sum_iset(const std::set iset) -{ - int sum = 0; - std::set::iterator it; - for (it = iset.begin(); it != iset.end(); it++) - { - sum += *it; - } - return sum; -} - -void concat_iset(std::set& iset, const std::set other_iset) -{ - std::copy(other_iset.begin(), other_iset.end(), std::inserter(iset, iset.begin())); -} - - - diff --git a/Examples/scilab/set/example.hxx b/Examples/scilab/set/example.hxx deleted file mode 100644 index e00b7b24b..000000000 --- a/Examples/scilab/set/example.hxx +++ /dev/null @@ -1,13 +0,0 @@ -/* File : example.hxx */ - -#include - -std::set create_iset(const int size, const int* values); - -int sum_iset(const std::set iset); - -void concat_iset(std::set& iset, const std::set other_iset); - - - - diff --git a/Examples/scilab/set/example.i b/Examples/scilab/set/example.i deleted file mode 100644 index a4ab23972..000000000 --- a/Examples/scilab/set/example.i +++ /dev/null @@ -1,14 +0,0 @@ -/* File : example.i */ - -%module example - -%{ -#include "example.hxx" -%} - -%include "std_set.i" - -%include "matrix.i" -%apply (int size, int* matrixAsInput) { (const int size, const int* values) }; - -%include "example.hxx"; diff --git a/Examples/scilab/set/runme.sci b/Examples/scilab/set/runme.sci deleted file mode 100644 index 475d95b34..000000000 --- a/Examples/scilab/set/runme.sci +++ /dev/null @@ -1,16 +0,0 @@ -exec loader.sce; - -disp("this is an example with sets of int."); -disp("create the set from matrix [1, 2, 4, 4]:"); -iset = create_iset(int32([1, 2, 4, 4])); -disp(iset); -s = sum_iset(iset); -disp("sum of this set elements is:"); -disp(s); -iset2 = create_iset(int32([1, 10])); -disp("concat this set with the set of int {1, 10}:"); -iset3 = concat_iset(iset, iset2); -disp(iset3); - - - diff --git a/Examples/scilab/set/Makefile b/Examples/scilab/std_list/Makefile similarity index 77% rename from Examples/scilab/set/Makefile rename to Examples/scilab/std_list/Makefile index e8ea02e15..8a3ebed0c 100644 --- a/Examples/scilab/set/Makefile +++ b/Examples/scilab/std_list/Makefile @@ -4,13 +4,17 @@ SRCS = example.cpp TARGET = example INTERFACE = example.i -all: +all: run + +loader.sce: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' scilab_cpp clean: $(MAKE) -f $(TOP)/Makefile scilab_clean - rm -f *.sce *.so lib*lib.c *_wrap.cxx -check: all +run: loader.sce $(MAKE) -f $(TOP)/Makefile scilab_run + +debug: loader.sce + $(MAKE) -f $(TOP)/Makefile scilab_debug diff --git a/Examples/scilab/std_list/example.cpp b/Examples/scilab/std_list/example.cpp new file mode 100644 index 000000000..416e1827a --- /dev/null +++ b/Examples/scilab/std_list/example.cpp @@ -0,0 +1,61 @@ +/* File : example.cpp */ + +#include "example.hxx" + +#include +#include +#include +#include +#include + + +template +std::list concat_list(const std::list list, const std::list other_list) +{ + std::list out_list(list); + out_list.insert(out_list.end(), other_list.begin(), other_list.end()); + return out_list; +} + +// int lists + +std::list create_integer_list(const int rangemin, const int rangemax) +{ + std::list out_list; + for (int i = rangemin; i <= rangemax; i++) + { + out_list.push_back(i); + } + return out_list; +} + +int sum_integer_list(const std::list& list) +{ + return std::accumulate(list.begin(), list.end(), 0); +} + +std::list concat_integer_list(const std::list list, const std::list other_list) +{ + return concat_list(list, other_list); +} + +// string lists + +std::list create_string_list(const char* svalue) +{ + std::list out_list; + std::string str(svalue); + + std::istringstream iss(str); + std::copy(std::istream_iterator(iss), + std::istream_iterator(), + std::inserter >(out_list, out_list.begin())); + + return out_list; +} + +std::list concat_string_list(const std::list list, const std::list other_list) +{ + return concat_list(list, other_list); +} + diff --git a/Examples/scilab/std_list/example.hxx b/Examples/scilab/std_list/example.hxx new file mode 100644 index 000000000..116fcc3d4 --- /dev/null +++ b/Examples/scilab/std_list/example.hxx @@ -0,0 +1,14 @@ +/* File : example.hxx */ + +#include +#include + + +// integer lists +std::list create_integer_list(const int size, const int value); +int sum_integer_list(const std::list& list); +std::list concat_integer_list(const std::list list, const std::list other_list); + +// string lists +std::list create_string_list(const char* value); +std::list concat_string_list(const std::list list, const std::list other_list); diff --git a/Examples/scilab/std_list/example.i b/Examples/scilab/std_list/example.i new file mode 100644 index 000000000..51210e726 --- /dev/null +++ b/Examples/scilab/std_list/example.i @@ -0,0 +1,18 @@ +/* File : example.i */ + +%module example + +%{ +#include "example.hxx" +%} + +%include stl.i + +/* instantiate the required template specializations */ +namespace std +{ + %template(IntList) list; + %template(StringList) list; +} + +%include "example.hxx" diff --git a/Examples/scilab/std_list/runme.sci b/Examples/scilab/std_list/runme.sci new file mode 100644 index 000000000..aba132f6b --- /dev/null +++ b/Examples/scilab/std_list/runme.sci @@ -0,0 +1,31 @@ +exec loader.sce; +SWIG_Init(); + +// This example shows how to use C++ fonctions with STL lists arguments +// Here, STL lists are converted from/to Scilab matrices (SWIG_SCILAB_EXTRA_NATIVE_CONTAINERS is not defined) + +// integer lists + +disp("Example of passing matrices of int as list arguments of C++ functions."); +disp("get a list of int {1...4} from create_integer_list():"); +is = create_integer_list(1, 4); +disp(is); +disp("get the sum of this list elements with sum_integer_list():") +sum = sum_integer_list(is); +disp(is); +is2 = create_integer_list(3, 6); +disp("concat this list with the list of int {3...6} with concat_integer_list():"); +is3 = concat_integer_list(is, is2); +disp(is3); + +// string lists + +disp("Example of passing matrices of string as list arguments of C++ functions."); +disp("get a list of string {''aa'', ''bb'', ''cc'', ''dd''} with create_string_list():"); +ss = create_string_list("aa bb cc dd"); +disp(ss); +ss2 = create_string_list("cc dd ee ff"); +disp("concat this list with the list of string {''cc'', ''dd'', ''ee'', ''ff''} with concat_string_list():"); +ss3 = concat_string_list(ss, ss2); +disp(ss3); + diff --git a/Examples/scilab/vector/Makefile b/Examples/scilab/std_set/Makefile similarity index 76% rename from Examples/scilab/vector/Makefile rename to Examples/scilab/std_set/Makefile index e8ea02e15..698e8a472 100644 --- a/Examples/scilab/vector/Makefile +++ b/Examples/scilab/std_set/Makefile @@ -4,13 +4,17 @@ SRCS = example.cpp TARGET = example INTERFACE = example.i -all: +all: check + +loader.sce: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' scilab_cpp clean: $(MAKE) -f $(TOP)/Makefile scilab_clean - rm -f *.sce *.so lib*lib.c *_wrap.cxx -check: all +check: loader.sce $(MAKE) -f $(TOP)/Makefile scilab_run + +debug: loader.sce + $(MAKE) -f $(TOP)/Makefile scilab_debug diff --git a/Examples/scilab/std_set/example.cpp b/Examples/scilab/std_set/example.cpp new file mode 100644 index 000000000..1cb136d77 --- /dev/null +++ b/Examples/scilab/std_set/example.cpp @@ -0,0 +1,61 @@ +/* File : example.cpp */ + +#include "example.hxx" + +#include +#include +#include +#include +#include + + +template +std::set concat_set(const std::set set, const std::set other_set) +{ + std::set out_set(set); + out_set.insert(other_set.begin(), other_set.end()); + return out_set; +} + +// int sets + +std::set create_integer_set(const int rangemin, const int rangemax) +{ + std::set out_set; + for (int i = rangemin; i <= rangemax; i++) + { + out_set.insert(i); + } + return out_set; +} + +int sum_integer_set(const std::set& set) +{ + return std::accumulate(set.begin(), set.end(), 0); +} + +std::set concat_integer_set(const std::set set, const std::set other_set) +{ + return concat_set(set, other_set); +} + +// string sets + +std::set create_string_set(const char* svalue) +{ + std::set out_set; + std::string str(svalue); + + std::istringstream iss(str); + std::copy(std::istream_iterator(iss), + std::istream_iterator(), + std::inserter >(out_set, out_set.begin())); + + return out_set; +} + +std::set concat_string_set(const std::set set, const std::set other_set) +{ + return concat_set(set, other_set); +} + diff --git a/Examples/scilab/std_set/example.hxx b/Examples/scilab/std_set/example.hxx new file mode 100644 index 000000000..615c8e9fa --- /dev/null +++ b/Examples/scilab/std_set/example.hxx @@ -0,0 +1,14 @@ +/* File : example.hxx */ + +#include +#include + + +// integer sets +std::set create_integer_set(const int size, const int value); +int sum_integer_set(const std::set& set); +std::set concat_integer_set(const std::set set, const std::set other_set); + +// string sets +std::set create_string_set(const char* value); +std::set concat_string_set(const std::set set, const std::set other_set); diff --git a/Examples/scilab/std_set/example.i b/Examples/scilab/std_set/example.i new file mode 100644 index 000000000..80032f677 --- /dev/null +++ b/Examples/scilab/std_set/example.i @@ -0,0 +1,18 @@ +/* File : example.i */ + +%module example + +%{ +#include "example.hxx" +%} + +%include stl.i + +/* instantiate the required template specializations */ +namespace std +{ + %template(IntSet) set; + %template(StringSet) set; +} + +%include "example.hxx" diff --git a/Examples/scilab/std_set/runme.sci b/Examples/scilab/std_set/runme.sci new file mode 100644 index 000000000..68078a0fb --- /dev/null +++ b/Examples/scilab/std_set/runme.sci @@ -0,0 +1,33 @@ +exec loader.sce; +SWIG_Init(); + +// This example shows how to use C++ fonctions with STL sets arguments +// Here, STL sets are converted from/to Scilab matrices (SWIG_SCILAB_EXTRA_NATIVE_CONTAINERS is not defined) + +// integer sets + +disp("Example of passing matrices of int as set arguments of C++ functions."); +disp("get a set of int {1...4} from create_integer_set():"); +is = create_integer_set(1, 4); +disp(is); +disp("get the sum of this set elements with sum_integer_set():") +sum = sum_integer_set(is); +disp(is); +is2 = create_integer_set(3, 6); +disp("concat this set with the set of int {3...6} with concat_integer_set():"); +is3 = concat_integer_set(is, is2); +disp(is3); + +// string sets + +disp("Example of passing matrices of string as set arguments of C++ functions."); +disp("get a set of string {''aa'', ''bb'', ''cc'', ''dd''} with create_string_set():"); +ss = create_string_set("aa bb cc dd"); +disp(ss); +ss2 = create_string_set("cc dd ee ff"); +disp("concat this set with the set of string {''cc'', ''dd'', ''ee'', ''ff''} with concat_string_set():"); +ss3 = concat_string_set(ss, ss2); +disp(ss3); + +exit + diff --git a/Examples/scilab/std_vector/std_vector/Makefile b/Examples/scilab/std_vector/std_vector/Makefile new file mode 100644 index 000000000..244ca1145 --- /dev/null +++ b/Examples/scilab/std_vector/std_vector/Makefile @@ -0,0 +1,20 @@ +TOP = ../../.. +SWIG = $(TOP)/../preinst-swig +SRCS = +TARGET = example +INTERFACE = example.i + +all: check + +loader.sce: + $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' scilab_cpp + +clean: + $(MAKE) -f $(TOP)/Makefile scilab_clean + +check: loader.sce + $(MAKE) -f $(TOP)/Makefile scilab_run + +debug: loader.sce + $(MAKE) -f $(TOP)/Makefile scilab_debug diff --git a/Examples/scilab/std_vector/std_vector/example.h b/Examples/scilab/std_vector/std_vector/example.h new file mode 100644 index 000000000..a5ea86d2a --- /dev/null +++ b/Examples/scilab/std_vector/std_vector/example.h @@ -0,0 +1,25 @@ +/* File : example.h */ + +#include +#include +#include +#include + +double average(std::vector v) { + return std::accumulate(v.begin(),v.end(),0.0)/v.size(); +} + +std::vector half(const std::vector v) { + std::vector w(v); + for (unsigned int i=0; i& v) { + // would you believe this is the same as the above? + std::transform(v.begin(),v.end(),v.begin(), + std::bind2nd(std::divides(),2.0)); +} + + diff --git a/Examples/scilab/std_vector/std_vector/example.i b/Examples/scilab/std_vector/std_vector/example.i new file mode 100644 index 000000000..18f0775aa --- /dev/null +++ b/Examples/scilab/std_vector/std_vector/example.i @@ -0,0 +1,18 @@ +/* File : example.i */ +%module example + +%{ +#include "example.h" +%} + +%include stl.i + +/* instantiate the required template specializations */ +namespace std { + %template(IntVector) vector; + %template(DoubleVector) vector; +} + +/* Let's just grab the original header file here */ +%include "example.h" + diff --git a/Examples/scilab/std_vector/std_vector/runme.sci b/Examples/scilab/std_vector/std_vector/runme.sci new file mode 100644 index 000000000..67f1a8eb6 --- /dev/null +++ b/Examples/scilab/std_vector/std_vector/runme.sci @@ -0,0 +1,37 @@ +// file: runme.sci +exec loader.sce; +SWIG_Init(); + + +disp(mean([1,2,3,4])); + +// ... or a wrapped std::vector + +v = new_IntVector(); +for i = 1:4 + IntVector_push_back(v, i); +end; +disp(average(v)); + + +// half will return a Scilab matrix. +// Call it with a Scilab matrix... + +disp(half([1.0, 1.5, 2.0, 2.5, 3.0])); + + +// ... or a wrapped std::vector + +v = new_DoubleVector(); +for i = 1:4 + DoubleVector_push_back(v, i); +end; +disp(half(v)); + +// now halve a wrapped std::vector in place + +halve_in_place(v); +disp(v); + +exit + diff --git a/Examples/scilab/std_vector/std_vector_as_function_argument/Makefile b/Examples/scilab/std_vector/std_vector_as_function_argument/Makefile new file mode 100644 index 000000000..ea885ccc9 --- /dev/null +++ b/Examples/scilab/std_vector/std_vector_as_function_argument/Makefile @@ -0,0 +1,20 @@ +TOP = ../../.. +SWIG = $(TOP)/../preinst-swig +SRCS = example.cpp +TARGET = example +INTERFACE = example.i + +all: check + +loader.sce: + $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' scilab_cpp + +clean: + $(MAKE) -f $(TOP)/Makefile scilab_clean + +check: loader.sce + $(MAKE) -f $(TOP)/Makefile scilab_run + +debug: loader.sce + $(MAKE) -f $(TOP)/Makefile scilab_debug diff --git a/Examples/scilab/std_vector/std_vector_as_function_argument/example.cpp b/Examples/scilab/std_vector/std_vector_as_function_argument/example.cpp new file mode 100644 index 000000000..febe5f4e2 --- /dev/null +++ b/Examples/scilab/std_vector/std_vector_as_function_argument/example.cpp @@ -0,0 +1,105 @@ +/* File : example.cpp */ + +#include "example.hxx" + +#include +#include +#include +#include + + + +template +std::vector concat_vector(const std::vector vector, const std::vector other_vector) +{ + std::vector out_vector(vector); + out_vector.insert(out_vector.end(), other_vector.begin(), other_vector.end()); + return out_vector; +} + +// double vectors + +std::vector create_double_vector(const int size, const double value) +{ + return std::vector(size, value); +} + +double sum_double_vector(const std::vector& vector) +{ + return std::accumulate(vector.begin(), vector.end(), 0); +} + +std::vector concat_double_vector(const std::vector vector, const std::vector other_vector) +{ + return concat_vector(vector, other_vector); +} + +// int vectors + +std::vector create_integer_vector(const int size, const int value) +{ + return std::vector(size, value); +} + +int sum_integer_vector(const std::vector& vector) +{ + return std::accumulate(vector.begin(), vector.end(), 0); +} + +std::vector concat_integer_vector(const std::vector vector, const std::vector other_vector) +{ + return concat_vector(vector, other_vector); +} + +// string vectors + +std::vector create_string_vector(const int size, const char* value) +{ + return std::vector(size, value); +} + +std::vector concat_string_vector(const std::vector vector, const std::vector other_vector) +{ + return concat_vector(vector, other_vector); +} + +// bool vectors + +std::vector create_bool_vector(const int size, const bool value) +{ + return std::vector(size, value); +} + +std::vector concat_bool_vector(const std::vector vector, const std::vector other_vector) +{ + return concat_vector(vector, other_vector); +} + +// pointer (on objects) vectors + +std::vector create_classAPtr_vector(const int size, const int value) +{ + std::vector out_vector; + for (int i=0; i& vector) +{ + std::vector::const_iterator it; + std::cout << std::endl; + for (it = vector.begin(); it != vector.end(); ++it) + { + std::cout << "a << ">" << std::endl; + } +} + +std::vector concat_classAPtr_vector(const std::vector vector, const std::vector other_vector) +{ + return concat_vector(vector, other_vector); +} + diff --git a/Examples/scilab/std_vector/std_vector_as_function_argument/example.hxx b/Examples/scilab/std_vector/std_vector_as_function_argument/example.hxx new file mode 100644 index 000000000..e16ce8990 --- /dev/null +++ b/Examples/scilab/std_vector/std_vector_as_function_argument/example.hxx @@ -0,0 +1,38 @@ +/* File : example.hxx */ + +#include +#include + + +// double vectors +std::vector create_double_vector(const int size, const double value); +double sum_double_vector(const std::vector& vector); +std::vector concat_double_vector(const std::vector vector, const std::vector other_vector); + +// integer vectors +std::vector create_integer_vector(const int size, const int value); +int sum_integer_vector(const std::vector& vector); +std::vector concat_integer_vector(const std::vector vector, const std::vector other_vector); + +// string vectors +std::vector create_string_vector(const int size, const char* value); +std::vector concat_string_vector(const std::vector vector, const std::vector other_vector); + +// bool vectors +std::vector create_bool_vector(const int size, const bool value); +std::vector concat_bool_vector(const std::vector vector, const std::vector other_vector); + +// pointer (on object) vectors +class classA +{ +public: + classA() : a(0) {} + classA(int _a) : a(_a) {} + classA(const classA& c) : a(c.a) {} + int a; +}; + +std::vector create_classAPtr_vector(const int size, const int value); +void print_classAPtr_vector(const std::vector& pvector); +std::vector concat_classAPtr_vector(const std::vector vector, const std::vector other_vector); + diff --git a/Examples/scilab/std_vector/std_vector_as_function_argument/example.i b/Examples/scilab/std_vector/std_vector_as_function_argument/example.i new file mode 100644 index 000000000..a405742f4 --- /dev/null +++ b/Examples/scilab/std_vector/std_vector_as_function_argument/example.i @@ -0,0 +1,21 @@ +/* File : example.i */ + +%module example + +%{ +#include "example.hxx" +%} + +%include stl.i + +/* instantiate the required template specializations */ +namespace std +{ + %template(IntVector) vector; + %template(DoubleVector) vector; + %template(StringVector) vector; + %template(BoolVector) vector; + %template(ClassAPtrVector) vector; +} + +%include "example.hxx" diff --git a/Examples/scilab/std_vector/std_vector_as_function_argument/runme.sci b/Examples/scilab/std_vector/std_vector_as_function_argument/runme.sci new file mode 100644 index 000000000..87535d617 --- /dev/null +++ b/Examples/scilab/std_vector/std_vector_as_function_argument/runme.sci @@ -0,0 +1,69 @@ +exec loader.sce; +SWIG_Init(); + +// This example shows how to use C++ fonctions with STL vectors arguments +// Here, STL vectors are converted from/to Scilab matrices (SWIG_SCILAB_EXTRA_NATIVE_CONTAINERS is not defined) + +// double vectors + +disp("Example of passing matrices of double as vector arguments of C++ functions."); +disp("get a vector of double {2.0, 2.0, 2.0, 2.0} from create_double_vector():"); +dv = create_double_vector(4, 2.0); +disp(dv); +disp("get the sum of this vector elements with sum_double_vector():") +ds = sum_double_vector(dv); +disp(ds); +dv2 = create_double_vector(2, 5.0); +disp("concat this vector with the vector of double {5.0, 5.0} with concat_double_vector():"); +dv3 = concat_double_vector(dv, dv2); +disp(dv3); + +// integer vectors + +disp("Example of passing matrices of int as vector arguments of C++ functions."); +disp("get a vector of int {3, 3, 3, 3} from create_integer_vector():"); +iv = create_integer_vector(3, 3); +disp(iv); +disp("get the sum of this vector elements with sum_integer_vector():") +is = sum_integer_vector(iv); +disp(is); +iv2 = create_integer_vector(2, 1); +disp("concat this vector with the vector of int {1, 1} with concat_integer_vector():"); +iv3 = concat_integer_vector(iv, iv2); +disp(iv3); + +// string vectors + +disp("Example of passing matrices of string as vector arguments of C++ functions."); +disp("get a vector of string {''aa'', ''aa''} with create_string_vector():"); +sv = create_string_vector(2, "aa"); +disp(sv); +sv2 = create_string_vector(2, "bb"); +disp("concat this vector with the vector of string {''bb'', ''bb''} with concat_string_vector():"); +sv3 = concat_string_vector(sv, sv2); +disp(sv3); + +// bool vectors + +disp("Example of passing matrices of bool as vector arguments of C++ functions."); +disp("get a vector of bool {true, true} with create_bool_vector():"); +bv = create_bool_vector(2, %T); +disp(bv); +bv2 = create_bool_vector(3, %F); +disp("concat this vector with the vector of bool {false, false, false} with concat_bool_vector():"); +bv3 = concat_bool_vector(bv, bv2); +disp(bv3); + +// pointer (on object) vectors + +disp("Example of passing lists of pointers on object as vector of pointers on objects arguments of C++ functions."); +disp("get a vector of pointers on object {, , } with create_classAPtr_vector():"); +pv = create_classAPtr_vector(3, 1); +print_classAPtr_vector(pv); +pv2 = create_classAPtr_vector(2, 5); +disp("concat this vector with the vector of pointers on object {, } with concat_classAPtr_vector():"); +pv3 = concat_classAPtr_vector(pv, pv2); +print_classAPtr_vector(pv3); + +exit + diff --git a/Examples/scilab/template/runme.sci b/Examples/scilab/template/runme.sci index 7c084f09e..d4d21ae09 100644 --- a/Examples/scilab/template/runme.sci +++ b/Examples/scilab/template/runme.sci @@ -30,3 +30,5 @@ delete_SquareDouble(s); printf("%i shapes remain\n", ShapeDouble_getNbShapes()); +exit + diff --git a/Examples/scilab/vector/example.cpp b/Examples/scilab/vector/example.cpp deleted file mode 100644 index eb1518f96..000000000 --- a/Examples/scilab/vector/example.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/* File : example.cpp */ - -#include "example.hxx" - - -std::vector create_dvector(const int size, const double value) -{ - return std::vector(size, value); -} - -std::vector create_ivector(const int size, const int value) -{ - return std::vector(size, value); -} - -double sum_dvector(const std::vector dvector) -{ - double sum = 0; - for (int i = 0; i < dvector.size(); i++) - { - sum += dvector[i]; - } - return sum; -} - -int sum_ivector(const std::vector ivector) -{ - int sum = 0; - for (int i = 0; i < ivector.size(); i++) - { - sum += ivector[i]; - } - return sum; -} - -void concat_dvector(std::vector& dvector, const std::vector other_dvector) -{ - dvector.insert(dvector.end(), other_dvector.begin(), other_dvector.end()); -} - -void concat_ivector(std::vector& ivector, const std::vector other_ivector) -{ - ivector.insert(ivector.end(), other_ivector.begin(), other_ivector.end()); -} - - - diff --git a/Examples/scilab/vector/example.hxx b/Examples/scilab/vector/example.hxx deleted file mode 100644 index 8d3fff734..000000000 --- a/Examples/scilab/vector/example.hxx +++ /dev/null @@ -1,16 +0,0 @@ -/* File : example.hxx */ - -#include - -std::vector create_dvector(const int size, const double value); -std::vector create_ivector(const int size, const int value); - -double sum_dvector(const std::vector dvector); -int sum_ivector(const std::vector ivector); - -void concat_dvector(std::vector& dvector, const std::vector other_dvector); -void concat_ivector(std::vector& ivector, const std::vector other_ivector); - - - - diff --git a/Examples/scilab/vector/example.i b/Examples/scilab/vector/example.i deleted file mode 100644 index 25981de3b..000000000 --- a/Examples/scilab/vector/example.i +++ /dev/null @@ -1,11 +0,0 @@ -/* File : example.i */ - -%module example - -%{ -#include "example.hxx" -%} - -%include "std_vector.i" - -%include "example.hxx"; diff --git a/Examples/scilab/vector/runme.sci b/Examples/scilab/vector/runme.sci deleted file mode 100644 index 2dce998bc..000000000 --- a/Examples/scilab/vector/runme.sci +++ /dev/null @@ -1,28 +0,0 @@ -exec loader.sce; - -disp("this is an example with vectors of double."); -disp("create the vector of double {2.0, 2.0, 2.0, 2.0}:"); -dv = create_dvector(4, 2.0); -disp(dv); -ds = sum_dvector(dv); -disp("sum of this vector elements is:") -disp(ds); -dv2 = create_dvector(2, 5.0); -disp("concat this vector with the vector of double {5.0, 5.0}:"); -dv3 = concat_dvector(dv, dv2); -disp(dv3); - -disp("now an example with vectors of int."); -disp("create the vector of int {3, 3, 3}:"); -iv = create_ivector(3, 3); -disp(iv); -is = sum_ivector(iv); -disp("sum of this vector elements is:"); -disp(is); -iv2 = create_ivector(2, 1); -disp("concat this vector with the vector of int {1, 1}:"); -iv3 = concat_ivector(iv, iv2); -disp(iv3); - - - diff --git a/Examples/test-suite/constructor_copy.i b/Examples/test-suite/constructor_copy.i index 02ae5f944..4b977034d 100644 --- a/Examples/test-suite/constructor_copy.i +++ b/Examples/test-suite/constructor_copy.i @@ -5,13 +5,13 @@ %nocopyctor Bar; %inline %{ - + struct Foo1 { int x; Foo1(int _x = 2) : x(_x) { - } + } }; struct Foo2 { @@ -25,7 +25,7 @@ struct Foo3 { struct Foo4 { Foo4() { } - + protected: Foo4(const Foo4& ) { } }; @@ -33,7 +33,7 @@ protected: struct Foo4a { Foo4a() { } - + private: Foo4a(const Foo4a& ) { } }; @@ -53,7 +53,7 @@ struct Foo8 { }; template -class Bar +class Bar { public: int x; @@ -95,12 +95,14 @@ public: namespace Space { class Flow { public: + Flow() {} Flow(int i) {} }; class FlowFlow { public: + FlowFlow() {} FlowFlow(int i) {} }; @@ -124,7 +126,7 @@ public: template struct ModelUtils_T {}; - } + } } %} @@ -142,13 +144,13 @@ namespace Space1 { class TotalReturnSwap { public: TotalReturnSwap() {} - }; + }; template class TotalReturnSwap_T { public: TotalReturnSwap_T() {} - }; + }; } } diff --git a/Lib/scilab/matrix.i b/Lib/scilab/matrix.i index d36240cd1..0be93fa50 100644 --- a/Lib/scilab/matrix.i +++ b/Lib/scilab/matrix.i @@ -5,6 +5,6 @@ %include %include - +%include diff --git a/Lib/scilab/scibool.swg b/Lib/scilab/scibool.swg index a73c3306f..8306f3f93 100644 --- a/Lib/scilab/scibool.swg +++ b/Lib/scilab/scibool.swg @@ -82,3 +82,18 @@ SWIG_SciBoolean_AsIntArrayAndSize(void *_pvApiCtx, int _iVar, int *_iRows, int * return SWIG_OK; } } + +%fragment("SWIG_SciBoolean_FromIntArrayAndSize", "header") { +SWIGINTERN int +SWIG_SciBoolean_FromIntArrayAndSize(void *_pvApiCtx, int _iVarOut, int _iRows, int _iCols, const int *_piData) { + SciErr sciErr; + + sciErr = createMatrixOfBoolean(_pvApiCtx, Rhs + _iVarOut, _iRows, _iCols, _piData); + if(sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + return Rhs + _iVarOut; +} +} diff --git a/Lib/scilab/scichar.swg b/Lib/scilab/scichar.swg index cfc3e353a..b0ca9d6f0 100644 --- a/Lib/scilab/scichar.swg +++ b/Lib/scilab/scichar.swg @@ -2,6 +2,10 @@ * C-type: char * Scilab type: string */ + +/* + * CHAR +*/ %fragment(SWIG_AsVal_frag(char), "header", fragment="SwigScilabStringToChar") { #define SWIG_AsVal_char(scilabValue, valuePointer) SwigScilabStringToChar(pvApiCtx, scilabValue, valuePointer, fname) } @@ -84,58 +88,37 @@ SwigScilabStringFromChar(void *_pvApiCtx, int _iVarOut, char _chValue) { #define SWIG_AsCharPtrAndSize(scilabValue, charPtrPointer, charPtrLength, allocMemory) SwigScilabStringToCharPtrAndSize(pvApiCtx, scilabValue, charPtrPointer, charPtrLength, allocMemory, fname) } %fragment("SWIG_FromCharPtr", "header", fragment = "SwigScilabStringFromCharPtr") { -#define SWIG_FromCharPtr(charPtr) SwigScilabStringFromCharPtr(pvApiCtx, $result, charPtr) +#define SWIG_FromCharPtr(charPtr) SwigScilabStringFromCharPtr(pvApiCtx, SWIG_Scilab_GetOutputPosition(), charPtr) } -%fragment("SWIG_FromCharPtrAndSize", "header", fragment = "SwigScilabStringFromCharPtrAndSize") { -#define SWIG_FromCharPtrAndSize(charPtr, charPtrLength) SwigScilabStringFromCharPtrAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), charPtr) +%fragment("SWIG_FromCharPtrAndSize", "header", fragment = "SwigScilabStringFromCharPtr") { +#define SWIG_FromCharPtrAndSize(charPtr, charPtrLength) SwigScilabStringFromCharPtr(pvApiCtx, SWIG_Scilab_GetOutputPosition(), charPtr) } + %fragment("SwigScilabStringToCharPtr", "header") { SWIGINTERN int SwigScilabStringToCharPtr(void *_pvApiCtx, int _iVar, char *_pcValue, int _iLength, char *_fname) { SciErr sciErr; - int iRows = 0; - int iCols = 0; - int iType = 0; int *piAddrVar = NULL; - char *pstStrings = NULL; - int piLength = 0; + char* pcTmpValue = NULL; + int iRet; - sciErr = getVarAddressFromPosition(pvApiCtx, _iVar, &piAddrVar); + if (_pcValue == NULL) { + return SWIG_ERROR; + } + + sciErr = getVarAddressFromPosition(_pvApiCtx, _iVar, &piAddrVar); if (sciErr.iErr) { printError(&sciErr, 0); return SWIG_ERROR; } - sciErr = getVarType(pvApiCtx, piAddrVar, &iType); - if (sciErr.iErr) { - printError(&sciErr, 0); - return SWIG_ERROR; - } - if (iType != sci_strings) { - Scierror(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), _fname, _iVar); + iRet = getAllocatedSingleString(_pvApiCtx, piAddrVar, &pcTmpValue); + if (iRet) { return SWIG_ERROR; } - sciErr = getMatrixOfString(pvApiCtx, piAddrVar, &iRows, &iCols, &piLength, NULL); - if (sciErr.iErr) { - printError(&sciErr, 0); - return SWIG_ERROR; - } - if (iRows * iCols != 1) { - Scierror(999, _("%s: Wrong size for input argument #%d: A string expected.\n"), _fname, _iVar); - return SWIG_ERROR; - } - - pstStrings = (char *)malloc(sizeof(char) * (piLength + 1)); - sciErr = getMatrixOfString(pvApiCtx, piAddrVar, &iRows, &iCols, &piLength, (char **)&pstStrings); - if (sciErr.iErr) { - printError(&sciErr, 0); - return SWIG_ERROR; - } - - strcpy(_pcValue, pstStrings); - - free(pstStrings); + strncpy(_pcValue, pcTmpValue, _iLength); + free(pcTmpValue); return SWIG_OK; } @@ -144,57 +127,33 @@ SwigScilabStringToCharPtr(void *_pvApiCtx, int _iVar, char *_pcValue, int _iLeng SWIGINTERN int SwigScilabStringToCharPtrAndSize(void *_pvApiCtx, int _iVar, char **_pcValue, size_t *_piLength, int *alloc, char *_fname) { SciErr sciErr; - int iRows = 0; - int iCols = 0; - int iType = 0; int *piAddrVar = NULL; - char *_pstStrings = NULL; - int piLength = 0; + int iRet; + char *pstStrings = NULL; - sciErr = getVarAddressFromPosition(pvApiCtx, _iVar, &piAddrVar); + sciErr = getVarAddressFromPosition(_pvApiCtx, _iVar, &piAddrVar); if (sciErr.iErr) { printError(&sciErr, 0); return SWIG_ERROR; } - sciErr = getVarType(pvApiCtx, piAddrVar, &iType); - if (sciErr.iErr) { - printError(&sciErr, 0); - return SWIG_ERROR; - } - if (iType != sci_strings) { - Scierror(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), _fname, _iVar); + iRet = getAllocatedSingleString(_pvApiCtx, piAddrVar, &pstStrings); + if (iRet) { return SWIG_ERROR; } - sciErr = getMatrixOfString(pvApiCtx, piAddrVar, &iRows, &iCols, &piLength, NULL); - if (sciErr.iErr) { - printError(&sciErr, 0); - return SWIG_ERROR; - } - if (iRows * iCols != 1) { - Scierror(999, _("%s: Wrong size for input argument #%d: A string expected.\n"), _fname, _iVar); - return SWIG_ERROR; + // TODO: return SWIG_ERROR if _pcValue NULL (now returning SWIG_ERROR fails some typechecks) + if (_pcValue) + { + *_pcValue = pstStrings; } - _pstStrings = (char *)malloc(sizeof(char) * (piLength + 1)); - sciErr = getMatrixOfString(pvApiCtx, piAddrVar, &iRows, &iCols, &piLength, (char **)&_pstStrings); - if (sciErr.iErr) { - printError(&sciErr, 0); - return SWIG_ERROR; - } - - if (alloc) { - *_pcValue = %new_copy_array(_pstStrings, piLength + 1, char); + if (alloc != NULL) { *alloc = SWIG_NEWOBJ; - } else if (_pcValue) { - *_pcValue = _pstStrings; } - free(_pstStrings); - if (_piLength != NULL) { - *_piLength = (size_t) piLength; + *_piLength = strlen(*_pcValue); } return SWIG_OK; @@ -220,23 +179,77 @@ SwigScilabStringFromCharPtr(void *_pvApiCtx, int _iVarOut, const char *_pchValue return Rhs + _iVarOut; } } -%fragment("SwigScilabStringFromCharPtrAndSize", "header") { + +/* + * CHAR * ARRAY +*/ +%fragment("SwigScilabStringToCharPtrArrayAndSize", "header") { SWIGINTERN int -SwigScilabStringFromCharPtrAndSize(void *_pvApiCtx, int _iVarOut, const char *_pchValue) { +SwigScilabStringToCharPtrArrayAndSize(void *_pvApiCtx, int _iVar, char ***_charPtrArray, int* _charPtrArraySize, char *_fname) { SciErr sciErr; - char **pstData = NULL; + int i = 0; + int *piAddrVar = NULL; + int iRows = 0; + int iCols = 0; + int* piLength = NULL; - pstData = (char **)malloc(sizeof(char *)); - pstData[0] = strdup(_pchValue); + if ((_charPtrArray == NULL) || (_charPtrArraySize == NULL)) { + return SWIG_ERROR; + } - sciErr = createMatrixOfString(_pvApiCtx, Rhs + _iVarOut, 1, 1, (char **)pstData); + sciErr = getVarAddressFromPosition(_pvApiCtx, _iVar, &piAddrVar); if (sciErr.iErr) { printError(&sciErr, 0); return SWIG_ERROR; } - free(pstData[0]); + sciErr = getMatrixOfString(_pvApiCtx, piAddrVar, &iRows, &iCols, NULL, NULL); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } - return Rhs + _iVarOut; + piLength = (int*) malloc(iRows * iCols * sizeof(int)); + + sciErr = getMatrixOfString(_pvApiCtx, piAddrVar, &iRows, &iCols, piLength, NULL); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + *_charPtrArray = (char**) malloc(iRows * iCols * sizeof(char*)); + for(i = 0 ; i < iRows * iCols ; i++) + { + (*_charPtrArray)[i] = (char*) malloc(sizeof(char) * (piLength[i] + 1)); + } + + sciErr = getMatrixOfString(_pvApiCtx, piAddrVar, &iRows, &iCols, piLength, *_charPtrArray); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + *_charPtrArraySize = iRows * iCols; + + free(piLength); + + return SWIG_OK; +} +} +%fragment("SwigScilabStringFromCharPtrArray", "header") { +SWIGINTERN int +SwigScilabStringFromCharPtrArray(void *_pvApiCtx, int _iVarOut, char **_charPtrArray, int _charPtrArraySize) { + SciErr sciErr; + + if (_charPtrArray == NULL) { + return SWIG_ERROR; + } + + sciErr = createMatrixOfString(_pvApiCtx, nbInputArgument(pvApiCtx) + _iVarOut, _charPtrArraySize, 1, _charPtrArray); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + return nbInputArgument(pvApiCtx) + _iVarOut; } } diff --git a/Lib/scilab/scicontainer.swg b/Lib/scilab/scicontainer.swg index a1e9b059f..41458d509 100644 --- a/Lib/scilab/scicontainer.swg +++ b/Lib/scilab/scicontainer.swg @@ -1,7 +1,7 @@ /* ----------------------------------------------------------------------------- * scicontainer.swg * - * Scilab list <-> C++ container wrapper (Based on Octave wrapper) + * Scilab list <-> C++ container wrapper * * This wrapper, and its iterator, allows a general use (and reuse) of * the mapping between C++ and Scilab, thanks to the C++ templates. @@ -15,177 +15,32 @@ #include %} - #if !defined(SWIG_NO_EXPORT_ITERATOR_METHODS) # if !defined(SWIG_EXPORT_ITERATOR_METHODS) # define SWIG_EXPORT_ITERATOR_METHODS SWIG_EXPORT_ITERATOR_METHODS # endif #endif + +// #define (SWIG_SCILAB_EXTRA_NATIVE_CONTAINERS) +// if defined: sequences in return are converted from/to Scilab lists or matrices +// if not defined: sequences are passed from/to Scilab as pointers + +%{ +#define SWIG_STD_NOASSIGN_STL +%} + %include +%include -// The Scilab C++ Wrap - -%insert(header) %{ +%{ #include %} %include -%fragment(SWIG_Traits_frag(SciObject),"header",fragment="StdTraits") { -namespace swig { - template <> struct traits { - typedef value_category category; - static const char* type_name() { return "SciObject"; } - }; - - template <> struct traits_from { - typedef SciObject value_type; - static SciObject from(const value_type& val) { - return val; - } - }; - - template <> - struct traits_check { - static bool check(const SciObject&) { - return true; - } - }; - - template <> struct traits_asval { - typedef SciObject value_type; - static int asval(const SciObject& obj, value_type *val) { - if (val) *val = obj; - return SWIG_OK; - } - }; -} -} - -%fragment("SciSequence_Base","header",fragment="") -{ -%#include - -namespace std { - template <> - struct less : public binary_function - { - bool - operator()(const SciObject& v, const SciObject& w) const - { - //SciObject res = do_binary_op(SciObject::op_le,v,w); - return true;//res.is_true(); - } - }; -} - -namespace swig { - inline size_t - check_index(ptrdiff_t i, size_t size, bool insert = false) { - if ( i < 0 ) { - if ((size_t) (-i) <= size) - return (size_t) (i + size); - } else if ( (size_t) i < size ) { - return (size_t) i; - } else if (insert && ((size_t) i == size)) { - return size; - } - - throw std::out_of_range("index out of range"); - } - - inline size_t - slice_index(ptrdiff_t i, size_t size) { - if ( i < 0 ) { - if ((size_t) (-i) <= size) { - return (size_t) (i + size); - } else { - throw std::out_of_range("index out of range"); - } - } else { - return ( (size_t) i < size ) ? ((size_t) i) : size; - } - } - - template - inline typename Sequence::iterator - getpos(Sequence* self, Difference i) { - typename Sequence::iterator pos = self->begin(); - std::advance(pos, check_index(i,self->size())); - return pos; - } - - template - inline typename Sequence::const_iterator - cgetpos(const Sequence* self, Difference i) { - typename Sequence::const_iterator pos = self->begin(); - std::advance(pos, check_index(i,self->size())); - return pos; - } - - template - inline Sequence* - getslice(const Sequence* self, Difference i, Difference j) { - typename Sequence::size_type size = self->size(); - typename Sequence::size_type ii = swig::check_index(i, size); - typename Sequence::size_type jj = swig::slice_index(j, size); - - if (jj > ii) { - typename Sequence::const_iterator vb = self->begin(); - typename Sequence::const_iterator ve = self->begin(); - std::advance(vb,ii); - std::advance(ve,jj); - return new Sequence(vb, ve); - } else { - return new Sequence(); - } - } - - template - inline void - setslice(Sequence* self, Difference i, Difference j, const InputSeq& v) { - typename Sequence::size_type size = self->size(); - typename Sequence::size_type ii = swig::check_index(i, size, true); - typename Sequence::size_type jj = swig::slice_index(j, size); - if (jj < ii) jj = ii; - size_t ssize = jj - ii; - if (ssize <= v.size()) { - typename Sequence::iterator sb = self->begin(); - typename InputSeq::const_iterator vmid = v.begin(); - std::advance(sb,ii); - std::advance(vmid, jj - ii); - self->insert(std::copy(v.begin(), vmid, sb), vmid, v.end()); - } else { - typename Sequence::iterator sb = self->begin(); - typename Sequence::iterator se = self->begin(); - std::advance(sb,ii); - std::advance(se,jj); - self->erase(sb,se); - self->insert(sb, v.begin(), v.end()); - } - } - - template - inline void - delslice(Sequence* self, Difference i, Difference j) { - typename Sequence::size_type size = self->size(); - typename Sequence::size_type ii = swig::check_index(i, size, true); - typename Sequence::size_type jj = swig::slice_index(j, size); - if (jj > ii) { - typename Sequence::iterator sb = self->begin(); - typename Sequence::iterator se = self->begin(); - std::advance(sb,ii); - std::advance(se,jj); - self->erase(sb,se); - } - } -} -} - -%fragment("SciSequence_Cont","header", +%fragment("SciSequence_Cont", "header", fragment="StdTraits", - fragment="SciSequence_Base", fragment="SciSwigIterator_T") { %#include @@ -193,43 +48,46 @@ namespace swig { namespace swig { template - struct SciSequence_Ref // * Scilab can't support these, because of how assignment works + struct SciSequence_Ref { SciSequence_Ref(const SciObject& seq, int index) : _seq(seq), _index(index) { + if (traits_as_sequence::get(_seq, &_piSeqAddr) != SWIG_OK) + { + throw std::invalid_argument("Cannot get sequence data."); + } } operator T () const { - // swig::SwigVar_PyObject item = SciSequence_GetItem(_seq, _index); - SciObject item; // * todo - try { - return swig::as(item, true); - } catch (std::exception& e) { - char msg[1024]; - sprintf(msg, "in sequence element %d ", _index); - if (!Scilab_Error_Occurred()) { - %type_error(swig::type_name()); - } - SWIG_Scilab_AddErrorMsg(msg); - SWIG_Scilab_AddErrorMsg(e.what()); - throw; + try + { + T value; + if (traits_asval_sequenceitem::asval(_seq, _piSeqAddr, _index, &value) == SWIG_OK) + { + return value; + } + } + catch (std::exception& e) + { + SWIG_Scilab_AddErrorMsg(e.what()); } } SciSequence_Ref& operator=(const T& v) { - // SciSequence_SetItem(_seq, _index, swig::from(v)); - // * todo + // TODO return *this; } - private: - SciObject _seq; - int _index; + private: + SciObject _seq; + int _index; + void *_piSeqAddr; }; + template struct SciSequence_ArrowProxy { @@ -349,14 +207,6 @@ namespace swig SciSequence_Cont(const SciObject& seq) : _seq(seq) { - // * assert that we have map type etc. - /* - if (!SciSequence_Check(seq)) { - throw std::invalid_argument("a sequence is expected"); - } - _seq = seq; - Py_INCREF(_seq); - */ } ~SciSequence_Cont() @@ -365,8 +215,15 @@ namespace swig size_type size() const { - // return static_cast(SciSequence_Size(_seq)); - return 0; // * todo + int iSeqSize; + if (traits_as_sequence::size(_seq, &iSeqSize) == SWIG_OK) + { + return iSeqSize; + } + else + { + return 0; + } } bool empty() const @@ -404,28 +261,9 @@ namespace swig return const_reference(_seq, n); } - bool check(bool set_err = true) const - { - int s = size(); - for (int i = 0; i < s; ++i) { - // swig::SwigVar_PyObject item = SciSequence_GetItem(_seq, i); - SciObject item; // * todo - if (!swig::check(item)) { - if (set_err) { - char msg[1024]; - sprintf(msg, "in sequence element %d", i); - SWIG_Error(SWIG_RuntimeError, msg); - } - return false; - } - } - return true; - } - private: SciObject _seq; }; - } } @@ -491,30 +329,6 @@ namespace swig %swig_sequence_iterator(%arg(Sequence)) %swig_container_methods(%arg(Sequence)) - %fragment("SciSequence_Base"); - - %extend { - value_type pop() throw (std::out_of_range) { - if (self->size() == 0) - throw std::out_of_range("pop from empty container"); - Sequence::value_type x = self->back(); - self->pop_back(); - return x; - } - - value_type __paren__(difference_type i) throw (std::out_of_range) { - return *(swig::cgetpos(self, i)); - } - - void __paren_asgn__(difference_type i, value_type x) throw (std::out_of_range) { - *(swig::getpos(self,i)) = x; - } - - void append(value_type x) { - self->push_back(x); - } - } - %enddef %define %swig_sequence_methods(Sequence...) @@ -531,20 +345,21 @@ namespace swig %fragment("StdSequenceTraits","header", fragment="StdTraits", - fragment="SciSequence_Cont") + fragment="SciSequence_Cont", + fragment=SWIG_Traits_SequenceItem_frag(ptr)) { namespace swig { template inline void - assign(const SciSeq& sciseq, Seq* seq) { + assign(const SciSeq& sciSeq, Seq* seq) { %#ifdef SWIG_STD_NOASSIGN_STL typedef typename SciSeq::value_type value_type; - typename SciSeq::const_iterator it = sciseq.begin(); - for (;it != sciseq.end(); ++it) { + typename SciSeq::const_iterator it = sciSeq.begin(); + for (;it != sciSeq.end(); ++it) { seq->insert(seq->end(),(value_type)(*it)); } %#else - seq->assign(sciseq.begin(), sciseq.end()); + seq->assign(sciSeq.begin(), sciSeq.end()); %#endif } @@ -553,9 +368,41 @@ namespace swig { typedef Seq sequence; typedef T value_type; - static int asptr(const SciObject& obj, sequence **seq) { - // TODO: convert input Scilab list (or pointer) to sequence. - return SWIG_ERROR; + static int asptr(const SciObject& obj, sequence **seq) + { + swig_type_info *typeInfo = swig::type_info(); + if (typeInfo) + { + sequence *p; + if (SWIG_ConvertPtr(obj, (void**)&p, typeInfo, 0) == SWIG_OK) + { + if (seq) + *seq = p; + return SWIG_OLDOBJ; + } + } + + if (traits_as_sequence::check(obj) == SWIG_OK) + { + try + { + SciSequence_Cont sciSeq(obj); + if (seq) + { + *seq = new sequence(); + assign(sciSeq, *seq); + return SWIG_NEWOBJ; + } + else + { + return true; + } + } + catch (std::exception& e) + { + SWIG_Scilab_AddErrorMsg(e.what()); + } + } } }; @@ -566,15 +413,39 @@ namespace swig { typedef typename Seq::size_type size_type; typedef typename sequence::const_iterator const_iterator; - static SciObject from(const sequence& seq) { -#ifdef SWIG_SCILAB_EXTRA_NATIVE_CONTAINERS - swig_type_info *desc = swig::type_info(); - if (desc && desc->clientdata) { - return SWIG_NewPointerObj(new sequence(seq), desc, SWIG_POINTER_OWN); + static SciObject from(const sequence& seq) + { + %#ifdef SWIG_SCILAB_EXTRA_NATIVE_CONTAINERS + swig_type_info *typeInfo = swig::type_info(); + if (typeInfo) + { + return SWIG_NewPointerObj(new sequence(seq), typeInfo, SWIG_POINTER_OWN); + } + %#endif + + try + { + void *data; + size_type size = seq.size(); + if (traits_from_sequence::create(size, &data) == SWIG_OK) { + const_iterator it; + int index = 0; + for (it = seq.begin(); it != seq.end(); ++it) + { + traits_from_sequenceitem::from(data, index, *it); + index++; + } + return traits_from_sequence::set(size, data); + } + else + { + return 0; + } + } + catch (std::exception& e) + { + SWIG_Scilab_AddErrorMsg(e.what()); } -#endif - // TODO: return a Scilab list from the sequence. - return (SciObject)0; } }; } diff --git a/Lib/scilab/scilist.swg b/Lib/scilab/scilist.swg new file mode 100644 index 000000000..fc73d463a --- /dev/null +++ b/Lib/scilab/scilist.swg @@ -0,0 +1,78 @@ +/* + * Scilab list related functions + * + */ + +%fragment("SWIG_ScilabList", "header") +{ +SWIGINTERN int +SWIG_GetScilabList(SciObject _obj, int **_piListAddr) +{ + SciErr sciErr; + + sciErr = getVarAddressFromPosition(pvApiCtx, _obj, _piListAddr); + if (sciErr.iErr) + { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + return SWIG_OK; +} + +SWIGINTERN int +SWIG_GetScilabListSize(SciObject _obj, int *_piListSize) +{ + SciErr sciErr; + int *piListAddr; + + sciErr = getVarAddressFromPosition(pvApiCtx, _obj, &piListAddr); + if (sciErr.iErr) + { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + sciErr = getListItemNumber(pvApiCtx, piListAddr, _piListSize); + if (sciErr.iErr) + { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + return SWIG_OK; +} + + +SWIGINTERN int +SWIG_CheckScilabList(SciObject _obj) +{ + SciErr sciErr; + int *piListAddr; + int iType; + + sciErr = getVarAddressFromPosition(pvApiCtx, _obj, &piListAddr); + if (sciErr.iErr) + { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + sciErr = getVarType(pvApiCtx, piListAddr, &iType); + if (sciErr.iErr) + { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + if ((iType != sci_list) && (iType != sci_tlist) && (iType != sci_mlist)) + { + Scierror(999, _("%s: Wrong type for input argument #%d: A list is expected.\n"), fname, _obj); + return SWIG_ERROR; + } + + return SWIG_OK; +} + +} + diff --git a/Lib/scilab/scimatrixchar.swg b/Lib/scilab/scimatrixchar.swg new file mode 100644 index 000000000..0619270fe --- /dev/null +++ b/Lib/scilab/scimatrixchar.swg @@ -0,0 +1,91 @@ +/* + * C-type: char* + * Scilab type: string matrix + */ + +%include + +// in (char** vectorIn, int vectorInSize) + +%typemap(in, fragment="SwigScilabStringToCharPtrArrayAndSize") (char** vectorIn, int vectorInSize) +{ + if (SwigScilabStringToCharPtrArrayAndSize(pvApiCtx, $input, &$1, &$2, fname) == SWIG_ERROR) + { + return SWIG_ERROR; + } +} + +// out (char*** vectorOut, int* vectorOutSize) + +%typemap(in, numinputs=0) (char*** vectorOut, int* vectorOutSize) +{ +} + +%typemap(arginit) (char*** vectorOut, int* vectorOutSize) +{ + $1 = (char***) malloc(sizeof(char**)); + $2 = (int*) malloc(sizeof(int)); +} + +%typemap(freearg) (char*** vectorOut, int* vectorOutSize) +{ + free(*(*$1)); + free(*$1); + free($1); + free($2); +} + +%typemap(argout, fragment="SwigScilabStringFromCharPtrArray") (char*** vectorOut, int* vectorOutSize) +{ + if (SwigScilabStringFromCharPtrArray(pvApiCtx, SWIG_Scilab_GetOutputPosition(), *$1, *$2) != SWIG_ERROR) + { + AssignOutputVariable(pvApiCtx, outputPosition) = nbInputArgument(pvApiCtx) + SWIG_Scilab_GetOutputPosition(); + } + else + { + return SWIG_ERROR; + } +} + +// in (int vectorInSize, char** vectorIn) + +%typemap(in, fragment="SwigScilabStringToCharPtrArrayAndSize") (int vectorInSize, char** vectorIn) +{ + if (SwigScilabStringToCharPtrArrayAndSize(pvApiCtx, $input, &$2, &$1, fname) == SWIG_ERROR) + { + return SWIG_ERROR; + } +} + +// out (int* vectorOutSize, char*** vectorOut) + +%typemap(in, numinputs=0) (int* vectorOutSize, char*** vectorOut) +{ +} + +%typemap(arginit) (int* vectorOutSize, char*** vectorOut) +{ + $1 = (int*) malloc(sizeof(int)); + $2 = (char***) malloc(sizeof(char**)); +} + +%typemap(argout, fragment="SwigScilabStringFromCharPtrArray") (int* vectorOutSize, char*** vectorOut) +{ + if (SwigScilabStringFromCharPtrArray(pvApiCtx, SWIG_Scilab_GetOutputPosition(), *$2, *$1) != SWIG_ERROR) + { + AssignOutputVariable(pvApiCtx, outputPosition) = nbInputArgument(pvApiCtx) + SWIG_Scilab_GetOutputPosition(); + } + else + { + return SWIG_ERROR; + } +} + +%typemap(freearg) (int* vectorOutSize, char*** vectorOut) +{ + free($1); + free(*(*$2)); + free(*$2); + free($2); +} + diff --git a/Lib/scilab/scimatrixdouble.swg b/Lib/scilab/scimatrixdouble.swg index 52823bf50..585d10e99 100644 --- a/Lib/scilab/scimatrixdouble.swg +++ b/Lib/scilab/scimatrixdouble.swg @@ -5,7 +5,9 @@ %include -%typemap(in, fragment="SWIG_SciDouble_AsDoubleArrayAndSize") (double* matrixAsInput, int rows, int cols) +// in (double* matrixIn, int matrixInRowCount, int matrixInColCount) + +%typemap(in, fragment="SWIG_SciDouble_AsDoubleArrayAndSize") (double* matrixIn, int matrixInRowCount, int matrixInColCount) { if (SWIG_SciDouble_AsDoubleArrayAndSize(pvApiCtx, $input, &$2, &$3, &$1, fname) == SWIG_ERROR) { @@ -13,7 +15,9 @@ } } -%typemap(in, fragment="SWIG_SciDouble_AsDoubleArrayAndSize") (int rows, int cols, double* matrixAsInput) +// in (int matrixInRowCount, int matrixInColCount, double* matrixIn) + +%typemap(in, fragment="SWIG_SciDouble_AsDoubleArrayAndSize") (int matrixInRowCount, int matrixInColCount, double* matrixIn) { if (SWIG_SciDouble_AsDoubleArrayAndSize(pvApiCtx, $input, &$1, &$2, &$3, fname) == SWIG_ERROR) { @@ -21,13 +25,15 @@ } } -%typemap(in) (double* matrixAsInput, int size) +// in (double* vectorIn, int vectorInSize) + +%typemap(in) (double* vectorIn, int vectorInSize) { - int nbRows; - int nbCols; - if (SWIG_SciDouble_AsDoubleArrayAndSize(pvApiCtx, $input, &nbRows, &nbCols, &$1, fname) != SWIG_ERROR) + int rowCount; + int colCount; + if (SWIG_SciDouble_AsDoubleArrayAndSize(pvApiCtx, $input, &rowCount, &colCount, &$1, fname) != SWIG_ERROR) { - $2 = nbRows * nbCols; + $2 = rowCount * colCount; } else { @@ -35,13 +41,15 @@ } } -%typemap(in) (int size, double* matrixAsInput) +// in (int vectorInSize, double* vectorIn) + +%typemap(in) (int vectorInSize, double* vectorIn) { - int nbRows; - int nbCols; - if (SWIG_SciDouble_AsDoubleArrayAndSize(pvApiCtx, $input, &nbRows, &nbCols, &$2, fname) != SWIG_ERROR) + int rowCount; + int colCount; + if (SWIG_SciDouble_AsDoubleArrayAndSize(pvApiCtx, $input, &rowCount, &colCount, &$2, fname) != SWIG_ERROR) { - $1 = nbRows * nbCols; + $1 = rowCount * colCount; } else { @@ -49,18 +57,20 @@ } } -%typemap(in, numinputs=0) (double** matrixAsOutput, int* rows, int* cols) +// out (double** matrixOut, int* matrixOutRowCount, int* matrixOutColCount) + +%typemap(in, numinputs=0) (double** matrixOut, int* matrixOutRowCount, int* matrixOutColCount) { } -%typemap(arginit) (double** matrixAsOutput, int* rows, int* cols) +%typemap(arginit) (double** matrixOut, int* matrixOutRowCount, int* matrixOutColCount) { $1 = (double**) malloc(sizeof(double*)); $2 = (int*) malloc(sizeof(int)); $3 = (int*) malloc(sizeof(int)); } -%typemap(freearg) (double** matrixAsOutput, int* rows, int* cols) +%typemap(freearg) (double** matrixOut, int* matrixOutRowCount, int* matrixOutColCount) { free(*$1); free($1); @@ -68,7 +78,7 @@ free($3); } -%typemap(argout, fragment="SWIG_SciDouble_FromDoubleArrayAndSize") (double** matrixAsOutput, int* rows, int* cols) +%typemap(argout, fragment="SWIG_SciDouble_FromDoubleArrayAndSize") (double** matrixOut, int* matrixOutRowCount, int* matrixOutColCount) { if (SWIG_SciDouble_FromDoubleArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), *$2, *$3, *$1) != SWIG_ERROR) { @@ -80,22 +90,22 @@ } } -// (int* rows, int* cols, double** matrixAsOutput) +// out (int* matrixOutRowCount, int* matrixOutColCount, double** matrixOut) -%typemap(in, numinputs=0) (int* rows, int* cols, double** matrixAsOutput) +%typemap(in, numinputs=0) (int* matrixOutRowCount, int* matrixOutColCount, double** matrixOut) { } -%typemap(arginit) (int* rows, int* cols, double** matrixAsOutput) +%typemap(arginit) (int* matrixOutRowCount, int* matrixOutColCount, double** matrixOut) { $1 = (int*) malloc(sizeof(int)); $2 = (int*) malloc(sizeof(int)); $3 = (double**) malloc(sizeof(double*)); } -%typemap(argout, fragment="SWIG_SciInt32_FromIntArrayAndSize") (int* rows, int* cols, double** matrixAsOutput) +%typemap(argout, fragment="SWIG_SciDouble_FromDoubleArrayAndSize") (int* matrixInRowCount, int* matrixInColCount, double** matrixOut) { - if (SWIG_SciInt32_FromIntArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), *$1, *$2, *$3) != SWIG_ERROR) + if (SWIG_SciDouble_FromDoubleArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), *$1, *$2, *$3) != SWIG_ERROR) { AssignOutputVariable(pvApiCtx, outputPosition) = nbInputArgument(pvApiCtx) + SWIG_Scilab_GetOutputPosition(); } @@ -105,7 +115,7 @@ } } -%typemap(freearg) (int* rows, int* cols, double** matrixAsOutput) +%typemap(freearg) (int* matrixOutRowCount, int* matrixOutColCount, double** matrixOut) { free($1); free($2); @@ -114,21 +124,20 @@ } -// (double** matrixAsOutput, int* size) +// out (double** vectorOut, int* vectorOutSize) -%typemap(in, numinputs=0) (double** matrixAsOutput, int* size) +%typemap(in, numinputs=0) (double** vectorOut, int* vectorOutSize) { } -%typemap(arginit) (double** matrixAsOutput, int* size) +%typemap(arginit) (double** vectorOut, int* vectorOutSize) { $1 = (double**) malloc(sizeof(double*)); $2 = (int*) malloc(sizeof(int)); } -%typemap(argout, fragment="SWIG_SciInt32_FromIntArrayAndSize") (double** matrixAsOutput, int* size) +%typemap(argout, fragment="SWIG_SciDouble_FromDoubleArrayAndSize") (double** vectorOut, int* vectorOutSize) { - if (SWIG_SciDouble_FromDoubleArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), 1, *$2, *$1) != SWIG_ERROR) { AssignOutputVariable(pvApiCtx, outputPosition) = nbInputArgument(pvApiCtx) + SWIG_Scilab_GetOutputPosition(); @@ -139,7 +148,7 @@ } } -%typemap(freearg) (double** matrixAsOutput, int* size) +%typemap(freearg) (double** vectorOut, int* vectorOutSize) { free(*$1); free($1); @@ -147,21 +156,20 @@ } -// (int* size, double** matrixAsOutput) +// out (int* vectorOutSize, double** vectorOut) -%typemap(in, numinputs=0) (int* size, double** matrixAsOutput) +%typemap(in, numinputs=0) (int* vectorOutSize, double** vectorOut) { } -%typemap(arginit) (int* size, double** matrixAsOutput) +%typemap(arginit) (int* vectorOutSize, double** vectorOut) { $1 = (int*) malloc(sizeof(int)); $2 = (double**) malloc(sizeof(double*)); } -%typemap(argout, fragment="SWIG_SciInt32_FromIntArrayAndSize") (int* size, double** matrixAsOutput) +%typemap(argout, fragment="SWIG_SciDouble_FromDoubleArrayAndSize") (int* vectorOutSize, double** vectorOut) { - if (SWIG_SciDouble_FromDoubleArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), 1, *$1, *$2) != SWIG_ERROR) { AssignOutputVariable(pvApiCtx, outputPosition) = nbInputArgument(pvApiCtx) + SWIG_Scilab_GetOutputPosition(); @@ -172,7 +180,7 @@ } } -%typemap(freearg) (int* size, double** matrixAsOutput) +%typemap(freearg) (int* vectorOutSize, double** vectorOut) { free($1); free(*$2); diff --git a/Lib/scilab/scimatrixint.swg b/Lib/scilab/scimatrixint.swg index 435f40875..11ffa9364 100644 --- a/Lib/scilab/scimatrixint.swg +++ b/Lib/scilab/scimatrixint.swg @@ -5,9 +5,9 @@ %include -// (int* matrixAsInput, int rows, int cols) +// in (int* matrixIn, int matrixInRowCount, int matrixInColCount) -%typemap(in, fragment="SWIG_SciInt32_AsIntArrayAndSize") (int* matrixAsInput, int rows, int cols) +%typemap(in, fragment="SWIG_SciInt32_AsIntArrayAndSize") (int* matrixIn, int matrixInRowCount, int matrixInColCount) { if (SWIG_SciInt32_AsIntArrayAndSize(pvApiCtx, $input, &$2, &$3, &$1, fname) == SWIG_ERROR) { @@ -16,9 +16,9 @@ } -// (int rows, int cols, int* matrixAsInput) +// in (int matrixInRowCount, int matrixInColCount, int* matrixIn) -%typemap(in, fragment="SWIG_SciInt32_AsIntArrayAndSize") (int rows, int cols, int* matrixAsInput) +%typemap(in, fragment="SWIG_SciInt32_AsIntArrayAndSize") (int matrixInRowCount, int matrixInColCount, int* matrixIn) { if (SWIG_SciInt32_AsIntArrayAndSize(pvApiCtx, $input, &$1, &$2, &$3, fname) == SWIG_ERROR) { @@ -27,15 +27,15 @@ } -// (int* matrixAsInput, int size) +// in (int* vectorIn, int vectorInSize) -%typemap(in) (int* matrixAsInput, int size) +%typemap(in) (int* vectorIn, int vectorInSize) { - int nbRows; - int nbCols; - if (SWIG_SciInt32_AsIntArrayAndSize(pvApiCtx, $input, &nbRows, &nbCols, &$1, fname) != SWIG_ERROR) + int rowCount; + int colCount; + if (SWIG_SciInt32_AsIntArrayAndSize(pvApiCtx, $input, &rowCount, &colCount, &$1, fname) != SWIG_ERROR) { - $2 = nbRows * nbCols; + $2 = rowCount * colCount; } else { @@ -44,15 +44,15 @@ } -// (int size, int* matrixAsInput) +// in (int vectorInSize, int* vectorIn) -%typemap(in) (int size, int* matrixAsInput) +%typemap(in) (int vectorInSize, int* vectorIn) { - int nbRows; - int nbCols; - if (SWIG_SciInt32_AsIntArrayAndSize(pvApiCtx, $input, &nbRows, &nbCols, &$2, fname) != SWIG_ERROR) + int rowCount; + int colCount; + if (SWIG_SciInt32_AsIntArrayAndSize(pvApiCtx, $input, &rowCount, &colCount, &$2, fname) != SWIG_ERROR) { - $1 = nbRows * nbCols; + $1 = rowCount * colCount; } else { @@ -60,20 +60,20 @@ } } -// (int** matrixAsOutput, int* rows, int* cols) +// out (int** matrixOut, int* matrixOutRowCount, int* matrixOutColCount) -%typemap(in, numinputs=0) (int** matrixAsOutput, int* rows, int* cols) +%typemap(in, numinputs=0) (int** matrixOut, int* matrixOutRowCount, int* matrixOutColCount) { } -%typemap(arginit) (int** matrixAsOutput, int* rows, int* cols) +%typemap(arginit) (int** matrixOut, int* matrixOutRowCount, int* matrixOutColCount) { $1 = (int**) malloc(sizeof(int*)); $2 = (int*) malloc(sizeof(int)); $3 = (int*) malloc(sizeof(int)); } -%typemap(argout, fragment="SWIG_SciInt32_FromIntArrayAndSize") (int** matrixAsOutput, int* rows, int* cols) +%typemap(argout, fragment="SWIG_SciInt32_FromIntArrayAndSize") (int** matrixOut, int* matrixOutRowCount, int* matrixOutColCount) { if (SWIG_SciInt32_FromIntArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), *$2, *$3, *$1) != SWIG_ERROR) { @@ -85,7 +85,7 @@ } } -%typemap(freearg) (int** matrixAsOutput, int* rows, int* cols) +%typemap(freearg) (int** matrixOut, int* matrixOutRowCount, int* matrixOutColCount) { free(*$1); free($1); @@ -94,20 +94,20 @@ } -// (int* rows, int* cols, int** matrixAsOutput) +// out (int* matrixOutRowCount, int* matrixOutColCount, int** matrixOut) -%typemap(in, numinputs=0) (int* rows, int* cols, int** matrixAsOutput) +%typemap(in, numinputs=0) (int* matrixOutRowCount, int* matrixOutColCount, int** matrixOut) { } -%typemap(arginit) (int* rows, int* cols, int** matrixAsOutput) +%typemap(arginit) (int* matrixOutRowCount, int* matrixOutColCount, int** matrixOut) { $1 = (int*) malloc(sizeof(int)); $2 = (int*) malloc(sizeof(int)); $3 = (int**) malloc(sizeof(int*)); } -%typemap(argout, fragment="SWIG_SciInt32_FromIntArrayAndSize") (int* rows, int* cols, int** matrixAsOutput) +%typemap(argout, fragment="SWIG_SciInt32_FromIntArrayAndSize") (int* matrixOutRowCount, int* matrixOutColCount, int** matrixOut) { if (SWIG_SciInt32_FromIntArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), *$1, *$2, *$3) != SWIG_ERROR) { @@ -119,7 +119,7 @@ } } -%typemap(freearg) (int* rows, int* cols, int** matrixAsOutput) +%typemap(freearg) (int* matrixOutRowCount, int* matrixOutColCount, int** matrixOut) { free($1); free($2); @@ -128,21 +128,20 @@ } -// (int** matrixAsOutput, int* size) +// out (int** vectorOut, int* vectorOutSize) -%typemap(in, numinputs=0) (int** matrixAsOutput, int* size) +%typemap(in, numinputs=0) (int** vectorOut, int* vectorOutSize) { } -%typemap(arginit) (int** matrixAsOutput, int* size) +%typemap(arginit) (int** vectorOut, int* vectorOutSize) { $1 = (int**) malloc(sizeof(int*)); $2 = (int*) malloc(sizeof(int)); } -%typemap(argout, fragment="SWIG_SciInt32_FromIntArrayAndSize") (int** matrixAsOutput, int* size) +%typemap(argout, fragment="SWIG_SciInt32_FromIntArrayAndSize") (int** vectorOut, int* vectorOutSize) { - if (SWIG_SciInt32_FromIntArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), 1, *$2, *$1) != SWIG_ERROR) { AssignOutputVariable(pvApiCtx, outputPosition) = nbInputArgument(pvApiCtx) + SWIG_Scilab_GetOutputPosition(); @@ -153,7 +152,7 @@ } } -%typemap(freearg) (int** matrixAsOutput, int* size) +%typemap(freearg) (int** vectorOut, int* vectorOutSize) { free(*$1); free($1); @@ -161,21 +160,20 @@ } -// (int* size, int** matrixAsOutput) +// out (int* vectorOutSize, int** vectorOut) -%typemap(in, numinputs=0) (int* size, int** matrixAsOutput) +%typemap(in, numinputs=0) (int* vectorOutSize, int** vectorOut) { } -%typemap(arginit) (int* size, int** matrixAsOutput) +%typemap(arginit) (int* vectorOutSize, int** vectorOut) { $1 = (int*) malloc(sizeof(int)); $2 = (int**) malloc(sizeof(int*)); } -%typemap(argout, fragment="SWIG_SciInt32_FromIntArrayAndSize") (int* size, int** matrixAsOutput) +%typemap(argout, fragment="SWIG_SciInt32_FromIntArrayAndSize") (int* vectorOutSize, int** vectorOut) { - if (SWIG_SciInt32_FromIntArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), 1, *$1, *$2) != SWIG_ERROR) { AssignOutputVariable(pvApiCtx, outputPosition) = nbInputArgument(pvApiCtx) + SWIG_Scilab_GetOutputPosition(); @@ -186,7 +184,7 @@ } } -%typemap(freearg) (int* size, int** matrixAsOutput) +%typemap(freearg) (int* vectorInSize, int** vectorOut) { free($1); free(*$2); diff --git a/Lib/scilab/scipointer.swg b/Lib/scilab/scipointer.swg index 3a50e6f31..a80dbcd1c 100644 --- a/Lib/scilab/scipointer.swg +++ b/Lib/scilab/scipointer.swg @@ -6,7 +6,7 @@ } %fragment("SWIG_NewPointerObj", "header") { -#define SWIG_NewPointerObj(pointer, pointerDescriptor, flags) SwigScilabPtrFromObject(pvApiCtx, $result, pointer, pointerDescriptor, flags) +#define SWIG_NewPointerObj(pointer, pointerDescriptor, flags) SwigScilabPtrFromObject(pvApiCtx, SWIG_Scilab_GetOutputPosition(), pointer, pointerDescriptor, flags) } /* @@ -17,7 +17,7 @@ } %fragment("SWIG_NewFunctionPtrObj", "header") { -#define SWIG_NewFunctionPtrObj(pointer, pointerDescriptor) SwigScilabPtrFromObject(pvApiCtx, $result, pointer, pointerDescriptor, 0) +#define SWIG_NewFunctionPtrObj(pointer, pointerDescriptor) SwigScilabPtrFromObject(pvApiCtx, SWIG_Scilab_GetOutputPosition(), pointer, pointerDescriptor, 0) } // No fragment used here, the functions "SwigScilabPtrToObject" and "SwigScilabPtrFromObject" are defined in sciruntime.swg diff --git a/Lib/scilab/sciruntime.swg b/Lib/scilab/sciruntime.swg index 956a8094a..ee6c9e792 100644 --- a/Lib/scilab/sciruntime.swg +++ b/Lib/scilab/sciruntime.swg @@ -69,7 +69,7 @@ SWIG_Scilab_ErrorMsg(int code, const char *mesg) #define SWIG_fail return SWIG_ERROR; -#define SWIG_ErrorType(code) SWIG_Scilab_ErrorType(code) +#define SWIG_ErrorType(code) SWIG_Scilab_ErrorType(code) #define SWIG_Error(code, msg) SWIG_Scilab_ErrorMsg(code,msg) /* Used for C++ enums */ @@ -218,14 +218,39 @@ SWIG_Scilab_SetOutput(void *_pvApiCtx, SciObject _output) { return SWIG_OK; } -#define SwigScilabRaise(OBJ, TYPE, DESC) Scierror(999, "C++ side threw an exception of type %s.\n", TYPE) +#define SWIG_Scilab_Raise(obj, type, desc) SwigScilabRaise(type) + +SWIGRUNTIME int +SwigScilabRaise(const char *type) { + Scierror(999, "An exception of type %s has been thrown.\n", type); +#ifdef __cplusplus + throw; +#endif +} + %} -//%insert(init) "swiginit.swg" %init %{ -/* -----------------------------------------------------------------------------* - * Partial Init method - * -----------------------------------------------------------------------------*/ +#define SWIG_GetModule(clientdata) SWIG_Scilab_GetModule() +#define SWIG_SetModule(clientdata, pointer) SWIG_Scilab_SetModule(pointer) -SWIGEXPORT int SWIG_init(void) { +SWIGRUNTIME swig_module_info* +SWIG_Scilab_GetModule(void) +{ + return NULL; +} + +SWIGRUNTIME void +SWIG_Scilab_SetModule(swig_module_info *swig_module) +{ +} +%} + +%insert(init) "swiginit.swg" + +%init %{ +#ifdef __cplusplus +extern "C" +int SWIG_Init(char *fname, unsigned long fname_len) { + SWIG_InitializeModule(NULL); %} diff --git a/Lib/scilab/scisequence.swg b/Lib/scilab/scisequence.swg new file mode 100644 index 000000000..2319f811c --- /dev/null +++ b/Lib/scilab/scisequence.swg @@ -0,0 +1,155 @@ +/* + * + * Scilab sequence conversions + * + */ + +#define SWIG_Traits_Sequence_frag(Type) %fragment_name(AsVal_Traits_Sequence, Type) + +#define SWIG_AsCheck_Sequence_frag(Type...) %fragment_name(AsCheck_Sequence, Type) +#define SWIG_AsCheck_Sequence_dec(Type...) %symbol_name(AsCheck_Sequence, Type) +#define SWIG_AsGet_Sequence_frag(Type...) %fragment_name(AsGet_Sequence, Type) +#define SWIG_AsGet_Sequence_dec(Type...) %symbol_name(AsGet_Sequence, Type) +#define SWIG_AsSize_Sequence_frag(Type...) %fragment_name(AsSize_Sequence, Type) +#define SWIG_AsSize_Sequence_dec(Type...) %symbol_name(AsSize_Sequence, Type) +#define SWIG_FromCreate_Sequence_frag(Type...) %fragment_name(FromCreate_Sequence, Type) +#define SWIG_FromCreate_Sequence_dec(Type...) %symbol_name(FromCreate_Sequence, Type) +#define SWIG_FromSet_Sequence_frag(Type...) %fragment_name(FromSet_Sequence, Type) +#define SWIG_FromSet_Sequence_dec(Type...) %symbol_name(FromSet_Sequence, Type) + +#define SWIG_Traits_SequenceItem_frag(Type) %fragment_name(AsVal_Traits_SequenceItem, Type) +#define SWIG_AsVal_SequenceItem_frag(Type...) %fragment_name(AsVal_SequenceItem, Type) +#define SWIG_AsVal_SequenceItem_dec(Type...) %symbol_name(AsVal_SequenceItem, Type) +#define SWIG_From_SequenceItem_frag(Type...) %fragment_name(From_SequenceItem, Type) +#define SWIG_From_SequenceItem_dec(Type...) %symbol_name(From_SequenceItem, Type) + + +%include +%include +%include +%include +%include + +// +// Sequence conversion +// + +%fragment(SWIG_Traits_Sequence_frag(ptr), "header", + fragment=SWIG_AsCheck_Sequence_frag(ptr), + fragment=SWIG_AsGet_Sequence_frag(ptr), + fragment=SWIG_AsSize_Sequence_frag(ptr), + fragment=SWIG_FromCreate_Sequence_frag(ptr), + fragment=SWIG_FromSet_Sequence_frag(ptr)) { + +namespace swig { + template struct traits_as_sequence { + static int check(SciObject obj) { + return SWIG_AsCheck_Sequence_dec(ptr)(obj); + } + static int get(SciObject obj, void **sequence) { + return SWIG_AsGet_Sequence_dec(ptr)(obj, (int **)sequence); + } + static int size(SciObject obj, int *size) { + return SWIG_AsSize_Sequence_dec(ptr)(obj, size); + } + }; + template struct traits_from_sequence { + static int create(int size, void **sequence) { + return SWIG_FromCreate_Sequence_dec(ptr)(size, (int ***)sequence); + } + static SciObject set(int size, void *sequence) { + return SWIG_FromSet_Sequence_dec(ptr)(size, (int **)sequence); + } + }; +} +} + +%define %traits_sequence(CppType, ScilabType) + %fragment(SWIG_Traits_Sequence_frag(CppType), "header", + fragment=SWIG_Traits_Sequence_frag(ptr), + fragment=SWIG_AsCheck_Sequence_frag(CppType), + fragment=SWIG_AsGet_Sequence_frag(CppType), + fragment=SWIG_AsSize_Sequence_frag(CppType), + fragment=SWIG_FromCreate_Sequence_frag(CppType), + fragment=SWIG_FromSet_Sequence_frag(CppType)) { + +namespace swig { + template <> struct traits_as_sequence { + static int check(SciObject obj) { + return SWIG_AsCheck_Sequence_dec(CppType)(obj); + } + static int get(SciObject obj, void **sequence) { + return SWIG_AsGet_Sequence_dec(CppType)(obj, (ScilabType **)sequence); + } + static int size(SciObject obj, int *size) { + return SWIG_AsSize_Sequence_dec(CppType)(obj, size); + } + }; + template <> struct traits_from_sequence { + static int create(int size, void **sequence) { + return SWIG_FromCreate_Sequence_dec(CppType)(size, (ScilabType **)sequence); + } + static SciObject set(int size, void *sequence) { + return SWIG_FromSet_Sequence_dec(CppType)(size, (ScilabType *)sequence); + } + }; +} +} +%enddef + + +// +// Sequence item conversion +// + +%fragment(SWIG_Traits_SequenceItem_frag(ptr), "header", + fragment=SWIG_AsVal_SequenceItem_frag(ptr), + fragment=SWIG_From_SequenceItem_frag(ptr)) { + +namespace swig { + template struct traits_asval_sequenceitem { + static int asval(SciObject obj, void *pSequence, int iItemIndex, T *pItemValue) { + return SWIG_AsVal_SequenceItem_dec(ptr)(obj, (int *)pSequence, iItemIndex, (int **)pItemValue); + } + }; + template struct traits_from_sequenceitem { + static int from(void *pSequence, int iItemIndex, T itemValue) { + return SWIG_From_SequenceItem_dec(ptr)((int **)pSequence, iItemIndex, (int*)itemValue); + } + }; +} +} + +%define %traits_sequenceitem(CppType, ScilabType) + %fragment(SWIG_Traits_SequenceItem_frag(CppType), "header", + fragment=SWIG_Traits_SequenceItem_frag(ptr), + fragment=SWIG_AsVal_SequenceItem_frag(CppType), + fragment=SWIG_From_SequenceItem_frag(CppType)) { + +namespace swig { + template <> struct traits_asval_sequenceitem { + static int asval(SciObject obj, void *pSequence, int iItemIndex, CppType *pItemValue) { + return SWIG_AsVal_SequenceItem_dec(CppType)(obj, (ScilabType *)pSequence, iItemIndex, pItemValue); + } + }; + template <> struct traits_from_sequenceitem { + static int from(void *pSequence, int iItemIndex, CppType itemValue) { + return SWIG_From_SequenceItem_dec(CppType)((ScilabType *)pSequence, iItemIndex, itemValue); + } + }; +} +} +%enddef + +%define %add_traits_sequence(CppType, ScilabType) + %traits_sequence(CppType, ScilabType); + %fragment(SWIG_Traits_Sequence_frag(CppType)); + %traits_sequenceitem(CppType, ScilabType); + %fragment(SWIG_Traits_SequenceItem_frag(CppType)); +%enddef + +%add_traits_sequence(int, int); +%add_traits_sequence(double, double); +%add_traits_sequence(std::string, char*); +%add_traits_sequence(bool, int); + diff --git a/Lib/scilab/scisequencebool.swg b/Lib/scilab/scisequencebool.swg new file mode 100644 index 000000000..510dbb68e --- /dev/null +++ b/Lib/scilab/scisequencebool.swg @@ -0,0 +1,102 @@ +/* + * + * Scilab matrix of bool <-> C++ bool container + * + */ + +%include + +%fragment(SWIG_AsCheck_Sequence_frag(bool), "header", + fragment="SWIG_SciInt32_AsIntArrayAndSize") { + +SWIGINTERN int +SWIG_AsCheck_Sequence_dec(bool)(SciObject _obj) { + SciErr sciErr; + int *piAddrVar; + + sciErr = getVarAddressFromPosition(pvApiCtx, _obj, &piAddrVar); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + if (isBooleanType(pvApiCtx, piAddrVar)) + { + return SWIG_OK; + } + else + { + Scierror(999, _("%s: Wrong type for input argument #%d: A boolean is expected.\n"), SWIG_Scilab_GetFname(), _obj); + return SWIG_ERROR; + } +} +} + +%fragment(SWIG_AsGet_Sequence_frag(bool), "header", + fragment="SWIG_SciBoolean_AsIntArrayAndSize") { + +SWIGINTERN int +SWIG_AsGet_Sequence_dec(bool)(SciObject _obj, int **_pSequence) { + int iMatrixRowCount; + int iMatrixColCount; + return (SWIG_SciBoolean_AsIntArrayAndSize(pvApiCtx, _obj, &iMatrixRowCount, &iMatrixColCount, _pSequence, SWIG_Scilab_GetFname())); +} +} + +%fragment(SWIG_AsSize_Sequence_frag(bool), "header", + fragment="SWIG_SciBoolean_AsIntArrayAndSize") { + +SWIGINTERN int +SWIG_AsSize_Sequence_dec(bool)(SciObject _obj, int *_piSize) { + int *piMatrix; + int iMatrixRowCount; + int iMatrixColCount; + if (SWIG_SciBoolean_AsIntArrayAndSize(pvApiCtx, _obj, &iMatrixRowCount, &iMatrixColCount, &piMatrix, SWIG_Scilab_GetFname()) == SWIG_OK) { + if ((iMatrixRowCount > 1) && (iMatrixColCount > 1)) { + Scierror(999, _("%s: Wrong size for input argument #%d: An integer vector is expected.\n"), SWIG_Scilab_GetFname(), _obj); + return SWIG_ERROR; + } + *_piSize = iMatrixRowCount * iMatrixColCount; + return SWIG_OK; + } + return SWIG_ERROR; +} +} + +%fragment(SWIG_FromCreate_Sequence_frag(bool), "header") { + +SWIGINTERN int +SWIG_FromCreate_Sequence_dec(bool)(int _size, int **_sequence) { + *_sequence = new int[_size]; + return *_sequence != NULL ? SWIG_OK : SWIG_ERROR; +} +} + +%fragment(SWIG_FromSet_Sequence_frag(bool), "header", + fragment="SWIG_SciBoolean_FromIntArrayAndSize") { + +SWIGINTERN SciObject +SWIG_FromSet_Sequence_dec(bool)(int _size, int *_sequence) { + SciObject obj = SWIG_SciBoolean_FromIntArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), 1, _size, _sequence); + delete (int *)_sequence; + return obj; +} +} + +%fragment(SWIG_AsVal_SequenceItem_frag(bool), "header") { + +SWIGINTERN int +SWIG_AsVal_SequenceItem_dec(bool)(SciObject _obj, int *_pSequence, int _iItemIndex, bool *_pItemValue) { + *_pItemValue = _pSequence[_iItemIndex]; + return SWIG_OK; +} +} + +%fragment(SWIG_From_SequenceItem_frag(bool), "header") { + +SWIGINTERN int +SWIG_From_SequenceItem_dec(bool)(int *_pSequence, int _iItemIndex, bool _itemValue) { + _pSequence[_iItemIndex] = _itemValue; + return SWIG_OK; +} +} diff --git a/Lib/scilab/scisequencedouble.swg b/Lib/scilab/scisequencedouble.swg new file mode 100644 index 000000000..cc07f6a39 --- /dev/null +++ b/Lib/scilab/scisequencedouble.swg @@ -0,0 +1,103 @@ +/* + * + * Scilab matrix of double <-> C++ double container + * + */ + +%include + +%fragment(SWIG_AsCheck_Sequence_frag(double), "header", + fragment="SWIG_SciDouble_AsDoubleArrayAndSize") { + +SWIGINTERN int +SWIG_AsCheck_Sequence_dec(double)(SciObject _obj) { + SciErr sciErr; + int *piAddrVar; + + sciErr = getVarAddressFromPosition(pvApiCtx, _obj, &piAddrVar); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + if (isDoubleType(pvApiCtx, piAddrVar)) + { + return SWIG_OK; + } + else + { + Scierror(999, _("%s: Wrong type for input argument #%d: A double is expected.\n"), SWIG_Scilab_GetFname(), _obj); + return SWIG_ERROR; + } +} +} + +%fragment(SWIG_AsGet_Sequence_frag(double), "header", + fragment="SWIG_SciDouble_AsDoubleArrayAndSize") { + +SWIGINTERN int +SWIG_AsGet_Sequence_dec(double)(SciObject _obj, double **_pSequence) { + int iMatrixRowCount; + int iMatrixColCount; + return (SWIG_SciDouble_AsDoubleArrayAndSize(pvApiCtx, _obj, &iMatrixRowCount, &iMatrixColCount, _pSequence, SWIG_Scilab_GetFname())); +} +} + +%fragment(SWIG_AsSize_Sequence_frag(double), "header", + fragment="SWIG_SciDouble_AsDoubleArrayAndSize") { + +SWIGINTERN int +SWIG_AsSize_Sequence_dec(double)(SciObject _obj, int *_piSize) { + double *pdblMatrix; + int iMatrixRowCount; + int iMatrixColCount; + if (SWIG_SciDouble_AsDoubleArrayAndSize(pvApiCtx, _obj, &iMatrixRowCount, &iMatrixColCount, &pdblMatrix, SWIG_Scilab_GetFname()) == SWIG_OK) { + if ((iMatrixRowCount > 1) && (iMatrixColCount > 1)) { + Scierror(999, _("%s: Wrong size for input argument #%d: A double vector is expected.\n"), SWIG_Scilab_GetFname(), _obj); + return SWIG_ERROR; + } + *_piSize = iMatrixRowCount * iMatrixColCount; + return SWIG_OK; + } + return SWIG_ERROR; +} +} + +%fragment(SWIG_FromCreate_Sequence_frag(double), "header") { + +SWIGINTERN int +SWIG_FromCreate_Sequence_dec(double)(int _size, double **_sequence) { + *_sequence = new double[_size]; + return *_sequence != NULL ? SWIG_OK : SWIG_ERROR; +} +} + +%fragment(SWIG_FromSet_Sequence_frag(double), "header", + fragment="SWIG_SciDouble_FromDoubleArrayAndSize") { + +SWIGINTERN SciObject +SWIG_FromSet_Sequence_dec(double)(int _size, double *_sequence) { + SciObject obj = SWIG_SciDouble_FromDoubleArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), 1, _size, _sequence); + delete (double *)_sequence; + return obj; +} +} + +%fragment(SWIG_AsVal_SequenceItem_frag(double), "header") { + +SWIGINTERN int +SWIG_AsVal_SequenceItem_dec(double)(SciObject _obj, double *_pSequence, int _iItemIndex, double *_pItemValue) { + *_pItemValue = _pSequence[_iItemIndex]; + return SWIG_OK; +} +} + +%fragment(SWIG_From_SequenceItem_frag(double), "header") { + +SWIGINTERN int +SWIG_From_SequenceItem_dec(double)(double *_pSequence, int _iItemIndex, double _itemValue) { + _pSequence[_iItemIndex] = _itemValue; + return SWIG_OK; +} +} + diff --git a/Lib/scilab/scisequenceint.swg b/Lib/scilab/scisequenceint.swg new file mode 100644 index 000000000..f4e4427d8 --- /dev/null +++ b/Lib/scilab/scisequenceint.swg @@ -0,0 +1,102 @@ +/* + * + * Scilab matrix of int <-> C++ int container + * + */ + +%include + +%fragment(SWIG_AsCheck_Sequence_frag(int), "header", + fragment="SWIG_SciInt32_AsIntArrayAndSize") { + +SWIGINTERN int +SWIG_AsCheck_Sequence_dec(int)(SciObject _obj) { + SciErr sciErr; + int *piAddrVar; + + sciErr = getVarAddressFromPosition(pvApiCtx, _obj, &piAddrVar); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + if (isIntegerType(pvApiCtx, piAddrVar)) + { + return SWIG_OK; + } + else + { + Scierror(999, _("%s: Wrong type for input argument #%d: An integer is expected.\n"), SWIG_Scilab_GetFname(), _obj); + return SWIG_ERROR; + } +} +} + +%fragment(SWIG_AsGet_Sequence_frag(int), "header", + fragment="SWIG_SciInt32_AsIntArrayAndSize") { + +SWIGINTERN int +SWIG_AsGet_Sequence_dec(int)(SciObject _obj, int **_pSequence) { + int iMatrixRowCount; + int iMatrixColCount; + return (SWIG_SciInt32_AsIntArrayAndSize(pvApiCtx, _obj, &iMatrixRowCount, &iMatrixColCount, _pSequence, SWIG_Scilab_GetFname())); +} +} + +%fragment(SWIG_AsSize_Sequence_frag(int), "header", + fragment="SWIG_SciInt32_AsIntArrayAndSize") { + +SWIGINTERN int +SWIG_AsSize_Sequence_dec(int)(SciObject _obj, int *_piSize) { + int *piMatrix; + int iMatrixRowCount; + int iMatrixColCount; + if (SWIG_SciInt32_AsIntArrayAndSize(pvApiCtx, _obj, &iMatrixRowCount, &iMatrixColCount, &piMatrix, SWIG_Scilab_GetFname()) == SWIG_OK) { + if ((iMatrixRowCount > 1) && (iMatrixColCount > 1)) { + Scierror(999, _("%s: Wrong size for input argument #%d: An integer vector is expected.\n"), SWIG_Scilab_GetFname(), _obj); + return SWIG_ERROR; + } + *_piSize = iMatrixRowCount * iMatrixColCount; + return SWIG_OK; + } + return SWIG_ERROR; +} +} + +%fragment(SWIG_FromCreate_Sequence_frag(int), "header") { + +SWIGINTERN int +SWIG_FromCreate_Sequence_dec(int)(int _size, int **_sequence) { + *_sequence = new int[_size]; + return *_sequence != NULL ? SWIG_OK : SWIG_ERROR; +} +} + +%fragment(SWIG_FromSet_Sequence_frag(int), "header", + fragment="SWIG_SciInt32_FromIntArrayAndSize") { + +SWIGINTERN SciObject +SWIG_FromSet_Sequence_dec(int)(int _size, int *_sequence) { + SciObject obj = SWIG_SciInt32_FromIntArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), 1, _size, _sequence); + delete (int *)_sequence; + return obj; +} +} + +%fragment(SWIG_AsVal_SequenceItem_frag(int), "header") { + +SWIGINTERN int +SWIG_AsVal_SequenceItem_dec(int)(SciObject _obj, int *_pSequence, int _iItemIndex, int *_pItemValue) { + *_pItemValue = _pSequence[_iItemIndex]; + return SWIG_OK; +} +} + +%fragment(SWIG_From_SequenceItem_frag(int), "header") { + +SWIGINTERN int +SWIG_From_SequenceItem_dec(int)(int *_pSequence, int _iItemIndex, int _itemValue) { + _pSequence[_iItemIndex] = _itemValue; + return SWIG_OK; +} +} diff --git a/Lib/scilab/scisequencepointer.swg b/Lib/scilab/scisequencepointer.swg new file mode 100644 index 000000000..36f6ca2d5 --- /dev/null +++ b/Lib/scilab/scisequencepointer.swg @@ -0,0 +1,121 @@ +/* + * + * Scilab list of pointer <-> C++ pointer container + * + */ + +%include + +%fragment(SWIG_AsCheck_Sequence_frag(ptr), "header", + fragment="SWIG_ScilabList") { + +SWIGINTERN int +SWIG_AsCheck_Sequence_dec(ptr)(SciObject _obj) { + return SWIG_CheckScilabList(_obj); +} +} + +%fragment(SWIG_AsGet_Sequence_frag(ptr), "header", + fragment="SWIG_ScilabList") { + +SWIGINTERN int +SWIG_AsGet_Sequence_dec(ptr)(SciObject _obj, int **_piSequence) { + return SWIG_GetScilabList(_obj, _piSequence); +} +} + +%fragment(SWIG_AsSize_Sequence_frag(ptr), "header", + fragment="SWIG_ScilabList") { + +SWIGINTERN int +SWIG_AsSize_Sequence_dec(ptr)(SciObject _obj, int *_piSize) { + return SWIG_GetScilabListSize(_obj, _piSize); +} +} + +%fragment(SWIG_FromCreate_Sequence_frag(ptr), "header") { + +SWIGINTERN int +SWIG_FromCreate_Sequence_dec(ptr)(int _size, int ***_sequence) { + *_sequence = new int*[_size]; + return *_sequence != NULL ? SWIG_OK : SWIG_ERROR; +} +} + +%fragment(SWIG_FromSet_Sequence_frag(ptr), "header") { + +SWIGINTERN SciObject +SWIG_FromSet_Sequence_dec(ptr)(int _size, int **_sequence) { + SciErr sciErr; + int *piListAddr; + + int iVarOut = nbInputArgument(pvApiCtx) + SWIG_Scilab_GetOutputPosition(); + + sciErr = createList(pvApiCtx, iVarOut, _size, &piListAddr); + if (sciErr.iErr) + { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + for (int i=0; i<_size; i++) + { + sciErr = createPointerInList(pvApiCtx, iVarOut, piListAddr, i + 1, (void *)_sequence[i]); + if (sciErr.iErr) + { + printError(&sciErr, 0); + return SWIG_ERROR; + } + } + delete (int*)_sequence; + return iVarOut; +} +} + +%fragment(SWIG_AsVal_SequenceItem_frag(ptr), "header") { + +SWIGINTERN int +SWIG_AsVal_SequenceItem_dec(ptr)(SciObject _obj, int* _piSequence, int _itemIndex, int **_pItemValue) +{ + SciErr sciErr; + int *piItemAddr; + int iType; + + sciErr = getListItemAddress(pvApiCtx, _piSequence, _itemIndex + 1, &piItemAddr); + if (sciErr.iErr) + { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + sciErr = getVarType(pvApiCtx, piItemAddr, &iType); + if (sciErr.iErr) + { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + if (iType != sci_pointer) + { + Scierror(999, _("%s: Wrong type for input argument #%d: A pointer is expected at list item #%d.\n"), fname, _obj, _itemIndex + 1); + return SWIG_ERROR; + } + + sciErr = getPointerInList(pvApiCtx, _piSequence, _itemIndex + 1, (void **)_pItemValue); + if (sciErr.iErr) + { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + return SWIG_OK; +} +} + +%fragment(SWIG_From_SequenceItem_frag(ptr), "header") { + +SWIGINTERN int +SWIG_From_SequenceItem_dec(ptr)(int **_pSequence, int _iItemIndex, int *_itemValue) { + _pSequence[_iItemIndex] = _itemValue; +} +} diff --git a/Lib/scilab/scisequencestring.swg b/Lib/scilab/scisequencestring.swg new file mode 100644 index 000000000..bde797728 --- /dev/null +++ b/Lib/scilab/scisequencestring.swg @@ -0,0 +1,97 @@ +/* + *char + * Scilab matrix of string <-> C++ std::string container + * + */ + +%include + +%fragment(SWIG_AsCheck_Sequence_frag(std::string), "header", + fragment="SwigScilabStringToCharPtrArrayAndSize") { + +SWIGINTERN int +SWIG_AsCheck_Sequence_dec(std::string)(SciObject _obj) { + SciErr sciErr; + int *piAddrVar; + + sciErr = getVarAddressFromPosition(pvApiCtx, _obj, &piAddrVar); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + if (isStringType(pvApiCtx, piAddrVar)) + { + return SWIG_OK; + } + else + { + Scierror(999, _("%s: Wrong type for input argument #%d: A string is expected.\n"), SWIG_Scilab_GetFname(), _obj); + return SWIG_ERROR; + } +} +} + +%fragment(SWIG_AsGet_Sequence_frag(std::string), "header", + fragment="SwigScilabStringToCharPtrArrayAndSize") { + +SWIGINTERN int +SWIG_AsGet_Sequence_dec(std::string)(SciObject _obj, char ***_pSequence) { + int iSize; + return (SwigScilabStringToCharPtrArrayAndSize(pvApiCtx, _obj, _pSequence, &iSize, SWIG_Scilab_GetFname())); +} +} + +%fragment(SWIG_AsSize_Sequence_frag(std::string), "header", + fragment="SwigScilabStringToCharPtrArrayAndSize") { + +SWIGINTERN int +SWIG_AsSize_Sequence_dec(std::string)(SciObject _obj, int *_piSize) { + char **pstMatrix; + if (SwigScilabStringToCharPtrArrayAndSize(pvApiCtx, _obj, &pstMatrix, _piSize, SWIG_Scilab_GetFname()) == SWIG_OK) { + return SWIG_OK; + } + return SWIG_ERROR; +} +} + +%fragment(SWIG_FromCreate_Sequence_frag(std::string), "header") { + +SWIGINTERN int +SWIG_FromCreate_Sequence_dec(std::string)(int _size, char ***_sequence) { + *_sequence = new char*[_size]; + return *_sequence != NULL ? SWIG_OK : SWIG_ERROR; +} +} + +%fragment(SWIG_FromSet_Sequence_frag(std::string), "header", + fragment="SwigScilabStringFromCharPtrArray") { + +SWIGINTERN SciObject +SWIG_FromSet_Sequence_dec(std::string)(int _size, char **_sequence) { + SciObject obj = SwigScilabStringFromCharPtrArray(pvApiCtx, SWIG_Scilab_GetOutputPosition(), _sequence, _size); + delete (char **)_sequence; + return obj; +} +} + +%fragment(SWIG_AsVal_SequenceItem_frag(std::string), "header") { + +SWIGINTERN int +SWIG_AsVal_SequenceItem_dec(std::string)(SciObject _obj, char **_pSequence, int _iItemIndex, std::string *_pItemValue) { + *_pItemValue = std::string(_pSequence[_iItemIndex]); + return SWIG_OK; +} +} + +%fragment(SWIG_From_SequenceItem_frag(std::string), "header") { + +SWIGINTERN int +SWIG_From_SequenceItem_dec(std::string)(char **_pSequence, int _iItemIndex, std::string _itemValue) { + char *pChar = new char(_itemValue.size() + 1); + strcpy(pChar, _itemValue.c_str()); + _pSequence[_iItemIndex] = pChar; + return SWIG_OK; +} +} + diff --git a/Lib/scilab/scitypemaps.swg b/Lib/scilab/scitypemaps.swg index 537bb43d5..657717cda 100644 --- a/Lib/scilab/scitypemaps.swg +++ b/Lib/scilab/scitypemaps.swg @@ -12,7 +12,7 @@ #define %append_output(obj) if (!SWIG_IsOK(SWIG_Scilab_SetOutput(pvApiCtx, obj))) return SWIG_ERROR #define %set_constant(name, obj) if (!SWIG_IsOK(SWIG_Scilab_SetOutput(pvApiCtx, obj))) return SWIG_ERROR // Name is managed by the the function name -#define %raise(obj, type, desc) SwigScilabRaise(obj, type, desc) +#define %raise(obj, type, desc) SWIG_Scilab_Raise(obj, type, desc) #define %set_output(obj) if (!SWIG_IsOK(SWIG_Scilab_SetOutput(pvApiCtx, obj))) return SWIG_ERROR #define %set_varoutput(obj) if (!SWIG_IsOK(SWIG_Scilab_SetOutput(pvApiCtx, obj))) return SWIG_ERROR #define %set_argoutput(obj) if (!SWIG_IsOK(SWIG_Scilab_SetOutput(pvApiCtx, obj))) return SWIG_ERROR diff --git a/Lib/scilab/scivectordouble.swg b/Lib/scilab/scivectordouble.swg deleted file mode 100644 index ee7e7b4ff..000000000 --- a/Lib/scilab/scivectordouble.swg +++ /dev/null @@ -1,94 +0,0 @@ -/* - * C++ type: std::vector - * Scilab 5 type: double matrix - */ - -%include - -%typemap(in, fragment="SWIG_SciDouble_AsDoubleArrayAndSize") std::vector(std::vector temp) -{ - double* dmatrix; - int nbRows; - int nbCols; - if (SWIG_SciDouble_AsDoubleArrayAndSize(pvApiCtx, $input, &nbRows, &nbCols, &dmatrix, fname) != SWIG_ERROR) - { - if ((nbRows > 1) && (nbCols > 1)) - { - Scierror(999, _("%s: Wrong size for input argument #%d: A real vector expected.\n"), fname, $input); - return SWIG_ERROR; - } - - $1 = temp; - $1.reserve(nbRows * nbCols); - std::copy(dmatrix, dmatrix + nbRows * nbCols, std::back_inserter((std::vector&)$1)); - } - else - { - return SWIG_ERROR; - } -} - -%typemap(in, fragment="SWIG_SciDouble_AsDoubleArrayAndSize") std::vector&(std::vector temp) -{ - double* dmatrix; - int nbRows; - int nbCols; - if (SWIG_SciDouble_AsDoubleArrayAndSize(pvApiCtx, $input, &nbRows, &nbCols, &dmatrix, fname) != SWIG_ERROR) - { - if ((nbRows > 1) && (nbCols > 1)) - { - Scierror(999, _("%s: Wrong size for input argument #%d: A real vector expected.\n"), fname, $input); - return SWIG_ERROR; - } - - $1 = &temp; - $1->reserve(nbRows * nbCols); - std::copy(dmatrix, dmatrix + nbRows * nbCols, std::back_inserter(*$1)); - } - else - { - return SWIG_ERROR; - } -} - -%typemap(out, fragment="SWIG_SciDouble_FromDoubleArrayAndSize") std::vector -{ - int nbCols = $1.size(); - double* dmatrix = new double[nbCols]; - std::copy($1.begin(), $1.end(), dmatrix); - - int ret = SWIG_SciDouble_FromDoubleArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), 1, nbCols, dmatrix); - delete[] dmatrix; - - if (ret != SWIG_ERROR) - { - AssignOutputVariable(pvApiCtx, outputPosition) = nbInputArgument(pvApiCtx) + SWIG_Scilab_GetOutputPosition(); - } - else - { - return SWIG_ERROR; - } -} - -%typemap(argout, fragment="SWIG_SciDouble_FromDoubleArrayAndSize") std::vector& -{ - int nbCols = $1->size(); - double* dmatrix = new double[nbCols]; - std::copy($1->begin(), $1->end(), dmatrix); - - int ret = SWIG_SciDouble_FromDoubleArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), 1, nbCols, dmatrix); - delete[] dmatrix; - - if (ret != SWIG_ERROR) - { - AssignOutputVariable(pvApiCtx, outputPosition) = nbInputArgument(pvApiCtx) + SWIG_Scilab_GetOutputPosition(); - } - else - { - return SWIG_ERROR; - } -} - - - - diff --git a/Lib/scilab/scivectorint.swg b/Lib/scilab/scivectorint.swg deleted file mode 100644 index 3cc9dd0d5..000000000 --- a/Lib/scilab/scivectorint.swg +++ /dev/null @@ -1,91 +0,0 @@ -/* - * C++ type: std::vector - * Scilab 5 type: integer matrix - */ - -%include - -%typemap(in, fragment="SWIG_SciInt32_AsIntArrayAndSize") std::vector(std::vector 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; - $1.reserve(nbRows * nbCols); - std::copy(imatrix, imatrix + nbRows * nbCols, std::back_inserter((std::vector&)$1)); - } - else - { - return SWIG_ERROR; - } -} - -%typemap(in, fragment="SWIG_SciInt32_AsIntArrayAndSize") std::vector&(std::vector 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; - $1->reserve(nbRows * nbCols); - std::copy(imatrix, imatrix + nbRows * nbCols, std::back_inserter(*$1)); - } - else - { - return SWIG_ERROR; - } -} - -%typemap(out, fragment="SWIG_SciInt32_FromIntArrayAndSize") std::vector -{ - 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; - } -} - -%typemap(argout, fragment="SWIG_SciInt32_FromIntArrayAndSize") std::vector& -{ - 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; - } -} - diff --git a/Lib/scilab/scivectorstring.swg b/Lib/scilab/scivectorstring.swg deleted file mode 100644 index 305f11424..000000000 --- a/Lib/scilab/scivectorstring.swg +++ /dev/null @@ -1,94 +0,0 @@ -/* - * C++ type: std::vector - * Scilab 5 type: double matrix - */ - -%include - -%typemap(in, fragment="SWIG_SciDouble_AsDoubleArrayAndSize") std::vector(std::vector temp) -{ - double* dmatrix; - int nbRows; - int nbCols; - if (SWIG_SciDouble_AsDoubleArrayAndSize(pvApiCtx, $input, &nbRows, &nbCols, &dmatrix, fname) != SWIG_ERROR) - { - if ((nbRows > 1) && (nbCols > 1)) - { - Scierror(999, _("%s: Wrong size for input argument #%d: A real vector expected.\n"), fname, $input); - return SWIG_ERROR; - } - - $1 = temp; - $1.reserve(nbRows * nbCols); - std::copy(dmatrix, dmatrix + nbRows * nbCols, std::back_inserter((std::vector&)$1)); - } - else - { - return SWIG_ERROR; - } -} - -%typemap(in, fragment="SWIG_SciDouble_AsDoubleArrayAndSize") std::vector&(std::vector temp) -{ - double* dmatrix; - int nbRows; - int nbCols; - if (SWIG_SciDouble_AsDoubleArrayAndSize(pvApiCtx, $input, &nbRows, &nbCols, &dmatrix, fname) != SWIG_ERROR) - { - if ((nbRows > 1) && (nbCols > 1)) - { - Scierror(999, _("%s: Wrong size for input argument #%d: A real vector expected.\n"), fname, $input); - return SWIG_ERROR; - } - - $1 = &temp; - $1->reserve(nbRows * nbCols); - std::copy(dmatrix, dmatrix + nbRows * nbCols, std::back_inserter(*$1)); - } - else - { - return SWIG_ERROR; - } -} - -%typemap(out, fragment="SWIG_SciDouble_FromDoubleArrayAndSize") std::vector -{ - int nbCols = $1.size(); - double* dmatrix = new double[nbCols]; - std::copy($1.begin(), $1.end(), dmatrix); - - int ret = SWIG_SciDouble_FromDoubleArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), 1, nbCols, dmatrix); - delete[] dmatrix; - - if (ret != SWIG_ERROR) - { - AssignOutputVariable(pvApiCtx, outputPosition) = nbInputArgument(pvApiCtx) + SWIG_Scilab_GetOutputPosition(); - } - else - { - return SWIG_ERROR; - } -} - -%typemap(argout, fragment="SWIG_SciDouble_FromDoubleArrayAndSize") std::vector& -{ - int nbCols = $1->size(); - double* dmatrix = new double[nbCols]; - std::copy($1->begin(), $1->end(), dmatrix); - - int ret = SWIG_SciDouble_FromDoubleArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), 1, nbCols, dmatrix); - delete[] dmatrix; - - if (ret != SWIG_ERROR) - { - AssignOutputVariable(pvApiCtx, outputPosition) = nbInputArgument(pvApiCtx) + SWIG_Scilab_GetOutputPosition(); - } - else - { - return SWIG_ERROR; - } -} - - - - diff --git a/Lib/scilab/std_list.i b/Lib/scilab/std_list.i new file mode 100644 index 000000000..a82349bcb --- /dev/null +++ b/Lib/scilab/std_list.i @@ -0,0 +1,27 @@ +/* + Lists +*/ + +%fragment("StdListTraits", "header", fragment="StdSequenceTraits") +%{ + namespace swig { + template + struct traits_asptr > { + static int asptr(SciObject obj, std::list **lis) { + return traits_asptr_stdseq >::asptr(obj, lis); + } + }; + + template + struct traits_from > { + static SciObject from(const std::list &lis) { + return traits_from_stdseq >::from(lis); + } + }; + } +%} + +#define %swig_list_methods(Type...) %swig_sequence_methods(Type) +#define %swig_list_methods_val(Type...) %swig_sequence_methods_val(Type); + +%include \ No newline at end of file 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/std_string.i b/Lib/scilab/std_string.i index 3a0106a70..7a20d5afa 100644 --- a/Lib/scilab/std_string.i +++ b/Lib/scilab/std_string.i @@ -29,10 +29,10 @@ SWIG_AsPtr_dec(std::string)(int _iVar, std::string **_pstValue) { } } -%fragment(SWIG_From_frag(std::string), "header", fragment="SwigScilabStringFromCharPtrAndSize") { +%fragment(SWIG_From_frag(std::string), "header", fragment="SwigScilabStringFromCharPtr") { SWIGINTERN int SWIG_From_dec(std::string)(std::string _pstValue) { - return SwigScilabStringFromCharPtrAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), _pstValue.c_str()); + return SwigScilabStringFromCharPtr(pvApiCtx, SWIG_Scilab_GetOutputPosition(), _pstValue.c_str()); } } diff --git a/Lib/scilab/std_vector.i b/Lib/scilab/std_vector.i index b6e8f16c6..be7a1bde2 100644 --- a/Lib/scilab/std_vector.i +++ b/Lib/scilab/std_vector.i @@ -1,6 +1,10 @@ /* - Vectors + * + * C++ type : STL vector + * Scilab type : matrix (for vectors of primitive types) or list (for sets of all other types : pointers...) + * */ + %fragment("StdVectorTraits","header",fragment="StdSequenceTraits") %{ namespace swig { @@ -14,7 +18,7 @@ template struct traits_from > { static SciObject from(const std::vector& vec) { - return traits_from_stdseq >::from(vec); + return traits_from_stdseq >::from(vec); } }; } @@ -24,9 +28,5 @@ #define %swig_vector_methods(Type...) %swig_sequence_methods(Type) #define %swig_vector_methods_val(Type...) %swig_sequence_methods_val(Type); - -%include -%include - %include diff --git a/Lib/scilab/stl.i b/Lib/scilab/stl.i index 9656ee6d4..76553c221 100644 --- a/Lib/scilab/stl.i +++ b/Lib/scilab/stl.i @@ -1,8 +1,6 @@ /* 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 +%include std_list.i diff --git a/Source/Modules/scilab.cxx b/Source/Modules/scilab.cxx index 6ece54dd5..37c1cb041 100644 --- a/Source/Modules/scilab.cxx +++ b/Source/Modules/scilab.cxx @@ -17,10 +17,12 @@ /*#define SWIG_DEBUG*/ static const char *usage = (char*) "\ -Scilab Options (available with -scilab)\n\ - -addsrc - Additionnal source file for builder.sce file (Ex: myfile.cxx)\n\ - -addcflag - Additionnal path to includes for builder.sce file (Ex: -I/usr/includes/)\n\ - -addldlag - Additionnal library flag for builder.sce file (Ex: -lm)\n\n"; +Scilab options\n\ + -addsrc additionnal source files (separated by comma) to include in build script (ex: myfile.cxx myfile2.cxx)\n\ + -addcflag -I additionnal include path to include in build script (ex: -I/usr/includes/)\n\ + -addldlag additionnal link flag to include in build script (ex: -lm)\n\n"; + +const char* SWIG_INIT_FUNCTION_NAME = "SWIG_Init"; class SCILAB : public Language { protected: @@ -174,6 +176,11 @@ public: Printf(builderCode, "table = ["); + /* In C++ mode, add initialization function to builder table */ + if (CPlusPlus) { + Printf(builderCode, "\"%s\",\"%s\";", SWIG_INIT_FUNCTION_NAME, SWIG_INIT_FUNCTION_NAME); + } + /* Emit code for children */ if (CPlusPlus) { Printf(wrappersSection, "extern \"C\" {\n"); @@ -201,8 +208,8 @@ public: Close(builderFile); Delete(builderFile); - /* Close the init function and quit (opened in sciruntime.swg) */ - Printf(initSection, "return 0;\n}\n"); + /* Close the init function (opened in sciinit.swg) */ + Printf(initSection, "return 0;\n}\n#endif\n"); /* Write all to the wrapper file */ SwigType_emit_type_table(runtimeSection, wrappersSection); // Declare pointer types, ... (Ex: SWIGTYPE_p_p_double) @@ -219,6 +226,8 @@ public: Close(beginSection); Delete(beginSection); + Delete(sourceFileList); + return SWIG_OK; } @@ -350,7 +359,7 @@ public: maxOutputArguments++; } - Delete(functionReturnTypemap); + //Delete(functionReturnTypemap); // Makes SWIG crash on vararg test case. } else { Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number, "Unable to use return type %s in function %s.\n", SwigType_str(functionReturnType, 0), functionName);