diff --git a/Examples/scilab/std_vector/std_vector_as_function_argument/Makefile b/Examples/scilab/std_vector/std_vector_as_function_argument/Makefile deleted file mode 100644 index b65b9e2f7..000000000 --- a/Examples/scilab/std_vector/std_vector_as_function_argument/Makefile +++ /dev/null @@ -1,15 +0,0 @@ -TOP = ../../.. -SWIG = $(TOP)/../preinst-swig -SRCS = example.cpp -TARGET = example_wrap.cxx -INTERFACE = example.i - -check: build - $(MAKE) -f $(TOP)/Makefile scilab_run - -build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ - TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' scilab_cpp - -clean: - $(MAKE) -f $(TOP)/Makefile scilab_clean 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 deleted file mode 100644 index e16ce8990..000000000 --- a/Examples/scilab/std_vector/std_vector_as_function_argument/example.hxx +++ /dev/null @@ -1,38 +0,0 @@ -/* 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 deleted file mode 100644 index a405742f4..000000000 --- a/Examples/scilab/std_vector/std_vector_as_function_argument/example.i +++ /dev/null @@ -1,21 +0,0 @@ -/* 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 deleted file mode 100644 index b0b399a68..000000000 --- a/Examples/scilab/std_vector/std_vector_as_function_argument/runme.sci +++ /dev/null @@ -1,70 +0,0 @@ -lines(0); -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/std_vector/std_vector_as_function_argument/example.cpp b/Examples/test-suite/li_std_vector_as_argument.i similarity index 59% rename from Examples/scilab/std_vector/std_vector_as_function_argument/example.cpp rename to Examples/test-suite/li_std_vector_as_argument.i index febe5f4e2..2b6f3d3b0 100644 --- a/Examples/scilab/std_vector/std_vector_as_function_argument/example.cpp +++ b/Examples/test-suite/li_std_vector_as_argument.i @@ -1,17 +1,50 @@ -/* File : example.cpp */ - -#include "example.hxx" +%module li_std_vector_as_argument +%{ +#include #include #include #include #include +%} - -template -std::vector concat_vector(const std::vector vector, const std::vector other_vector) +%{ +class classA { +public: + classA() : a(0) {} + classA(int _a) : a(_a) {} + classA(const classA& c) : a(c.a) {} + int a; +}; +%} + +%include stl.i + +namespace std +{ + %template(IntVector) vector; + %template(DoubleVector) vector; + %template(StringVector) vector; + %template(BoolVector) vector; + %template(ClassAPtrVector) vector; +} + +%ignore concat_vector; + +class classA +{ +public: + classA() : a(0) {} + classA(int _a) : a(_a) {} + classA(const classA& c) : a(c.a) {} + int a; +}; + +%inline %{ +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; @@ -19,87 +52,64 @@ std::vector concat_vector(const std::vector vector, const std::vector o // double vectors -std::vector create_double_vector(const int size, const double value) -{ +std::vector create_double_vector(const int size, const double value) { return std::vector(size, value); } -double sum_double_vector(const std::vector& vector) -{ +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) -{ +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) -{ +std::vector create_integer_vector(const int size, const int value) { return std::vector(size, value); } -int sum_integer_vector(const std::vector& vector) -{ +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) -{ +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) -{ +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) -{ +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) -{ +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) -{ +std::vector concat_bool_vector(const std::vector vector, const std::vector other_vector) { return concat_vector(vector, other_vector); } -// pointer (on objects) vectors +// pointer (on object) vectors -std::vector create_classAPtr_vector(const int size, const int value) -{ +std::vector create_classAPtr_vector(const int size, classA *aClassAPtr) { 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) -{ +std::vector concat_classAPtr_vector(const std::vector vector, const std::vector other_vector) { return concat_vector(vector, other_vector); } +%} diff --git a/Examples/test-suite/scilab/Makefile.in b/Examples/test-suite/scilab/Makefile.in index e67a7cc6c..b3a77e2a9 100644 --- a/Examples/test-suite/scilab/Makefile.in +++ b/Examples/test-suite/scilab/Makefile.in @@ -25,6 +25,9 @@ define get_runme_script RUNME_SCRIPT := $(srcdir)/$(SCRIPTPREFIX)$(1)$(SCRIPTSUFFIX) endef +CPP_STD_TEST_CASES += \ + li_std_vector_as_argument + include $(srcdir)/../common.mk # Override make commands to specify OUTDIR diff --git a/Examples/test-suite/scilab/li_std_vector_as_argument_runme.sci b/Examples/test-suite/scilab/li_std_vector_as_argument_runme.sci new file mode 100644 index 000000000..34e2fa55b --- /dev/null +++ b/Examples/test-suite/scilab/li_std_vector_as_argument_runme.sci @@ -0,0 +1,78 @@ +// Tests C++ fonctions with STL vectors as arguments + +exec("swigtest.start", -1); + +// double vectors + +// Test of using vector arguments of C++ functions +// Get a vector of double {2.0, 2.0, 2.0, 2.0} from create_double_vector() +dv = create_double_vector(4, 2.0); +if ~exists("dv") | (dv <> [2. 2. 2. 2.]) then swigtesterror(); end +// Get sum this vector elements with sum_double_vector() +ds = sum_double_vector(dv); +if ~exists("ds") | (ds <> 8.) then swigtesterror(); end +// Get a vector of double {5.0, 5.0} from create_double_vector() +dv2 = create_double_vector(2, 5.0); +if ~exists("dv2") | (dv2 <> [5. 5.]) then swigtesterror(); end +// Concat the two vectors with concat_double_vector() +dv3 = concat_double_vector(dv, dv2); +if ~exists("dv3") | (dv3 <> [dv dv2]) then swigtesterror(); end + +// integer vectors + +// Test of using vector arguments of C++ functions."); +// Get a vector of int {3, 3, 3, 3} from create_integer_vector() +iv = create_integer_vector(3, 3); +if ~exists("iv") | (iv <> int32([3 3 3])) then swigtesterror(); end +// Get the sum of this vector elements with sum_integer_vector() +is = sum_integer_vector(iv); +if ~exists("is") | (is <> int32(9)) then swigtesterror(); end +// Get a vector of int {1, 1} from create_integer_vector() +iv2 = create_integer_vector(2, 1); +// Concat the two vectors with concat_integer_vector() +iv3 = concat_integer_vector(iv, iv2); +if ~exists("iv3") | (iv3 <> int32([iv iv2])) then swigtesterror(); end + +// std::string vectors + +// Test of using vector arguments of C++ functions. +// Get a vector of string {''aa'', ''aa''} with create_string_vector() +sv = create_string_vector(2, "aa"); +if ~exists("sv") | (sv <> ["aa"; "aa"]) then swigtesterror(); end +// Get a vector of string {''bb'', ''bb''} with create_string_vector() +sv2 = create_string_vector(2, "bb"); +if ~exists("sv2") | (sv2 <> ["bb"; "bb"]) then swigtesterror(); end +// Concat the two vectors with concat_string_vector() +sv3 = concat_string_vector(sv, sv2); +if ~exists("sv3") | (sv3 <> [sv; sv2]) then swigtesterror(); end + +// bool vectors + +// Test of using vector arguments of C++ functions. +// Get a vector of bool {true, true} with create_bool_vector() +bv = create_bool_vector(2, %T); +if ~exists("bv") | (bv <> [%T %T]) then swigtesterror(); end +// Get a vector of bool {false, false, false} with create_bool_vector() +bv2 = create_bool_vector(3, %F); +if ~exists("bv2") | (bv2 <> [%F %F %F]) then swigtesterror(); end +// Concat the two vectors with concat_bool_vector() +bv3 = concat_bool_vector(bv, bv2); +if ~exists("bv3") | (bv3 <> [bv bv2]) then swigtesterror(); end + +// Pointer (on object) vectors + +// Test of using vector of pointers (on object) arguments of C++ functions. +// Get a vector of pointers on object {, , } with create_classAPtr_vector() +classA_1 = new_classA(10); +pv = create_classAPtr_vector(3, classA_1); +if ~exists("pv") | (size(pv) <> 3) | (classA_a_get(pv(1)) <> 10) then swigtesterror(); end +// Get a vector of pointers on object {, } with create_classAPtr_vector() +classA_2 = new_classA(5); +pv2 = create_classAPtr_vector(2, classA_2); +if ~exists("pv2") | (size(pv2) <> 2) | (classA_a_get(pv2(1)) <> 5) then swigtesterror(); end +// Concat the two vectors with concat_classAPtr_vector() +pv3 = concat_classAPtr_vector(pv, pv2); +if ~exists("pv3") | (size(pv3) <> 5) | (classA_a_get(pv3(1)) <> 10) | (classA_a_get(pv3(4)) <> 5) then swigtesterror(); end + +exec("swigtest.quit", -1); +