Scilab: std_set example converted to test
This commit is contained in:
parent
f95e581dc5
commit
3abb810cc1
6 changed files with 52 additions and 83 deletions
|
|
@ -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
|
|
||||||
|
|
@ -1,14 +0,0 @@
|
||||||
/* File : example.hxx */
|
|
||||||
|
|
||||||
#include <set>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
|
|
||||||
// integer sets
|
|
||||||
std::set<int> create_integer_set(const int size, const int value);
|
|
||||||
int sum_integer_set(const std::set<int>& set);
|
|
||||||
std::set<int> concat_integer_set(const std::set<int> set, const std::set<int> other_set);
|
|
||||||
|
|
||||||
// string sets
|
|
||||||
std::set<std::string> create_string_set(const char* value);
|
|
||||||
std::set<std::string> concat_string_set(const std::set<std::string> set, const std::set<std::string> other_set);
|
|
||||||
|
|
@ -1,18 +0,0 @@
|
||||||
/* File : example.i */
|
|
||||||
|
|
||||||
%module example
|
|
||||||
|
|
||||||
%{
|
|
||||||
#include "example.hxx"
|
|
||||||
%}
|
|
||||||
|
|
||||||
%include stl.i
|
|
||||||
|
|
||||||
/* instantiate the required template specializations */
|
|
||||||
namespace std
|
|
||||||
{
|
|
||||||
%template(IntSet) set<int>;
|
|
||||||
%template(StringSet) set<std::string>;
|
|
||||||
}
|
|
||||||
|
|
||||||
%include "example.hxx"
|
|
||||||
|
|
@ -1,34 +0,0 @@
|
||||||
lines(0);
|
|
||||||
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
|
|
||||||
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
/* File : example.cpp */
|
%module li_std_set_as_argument
|
||||||
|
|
||||||
#include "example.hxx"
|
%{
|
||||||
|
#include <set>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
|
|
@ -8,7 +10,19 @@
|
||||||
#include <numeric>
|
#include <numeric>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
|
%}
|
||||||
|
|
||||||
|
%include stl.i
|
||||||
|
|
||||||
|
namespace std
|
||||||
|
{
|
||||||
|
%template(IntSet) set<int>;
|
||||||
|
%template(StringSet) set<std::string>;
|
||||||
|
}
|
||||||
|
|
||||||
|
%ignore concat_set;
|
||||||
|
|
||||||
|
%inline %{
|
||||||
template <typename T>
|
template <typename T>
|
||||||
std::set<T> concat_set(const std::set<T> set, const std::set<T> other_set)
|
std::set<T> concat_set(const std::set<T> set, const std::set<T> other_set)
|
||||||
{
|
{
|
||||||
|
|
@ -58,4 +72,5 @@ std::set<std::string> concat_string_set(const std::set<std::string> set, const s
|
||||||
{
|
{
|
||||||
return concat_set<std::string>(set, other_set);
|
return concat_set<std::string>(set, other_set);
|
||||||
}
|
}
|
||||||
|
%}
|
||||||
|
|
||||||
35
Examples/test-suite/scilab/li_std_set_as_argument_runme.sci
Normal file
35
Examples/test-suite/scilab/li_std_set_as_argument_runme.sci
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
// Tests C++ fonctions with STL sets as arguments
|
||||||
|
|
||||||
|
exec("swigtest.start", -1);
|
||||||
|
|
||||||
|
// integer sets
|
||||||
|
|
||||||
|
// Example of passing matrices of int as set arguments of C++ functions.");
|
||||||
|
// get a set of int {1...4} from create_integer_set():");
|
||||||
|
iset = create_integer_set(1, 4);
|
||||||
|
if ~exists("iset") | (iset <> [1 2 3 4]) then swigtesterror(); end
|
||||||
|
// get the sum of this set elements with sum_integer_set():")
|
||||||
|
isum = sum_integer_set(iset);
|
||||||
|
if ~exists("isum") | (isum <> 10) then swigtesterror(); end
|
||||||
|
// get a set of of int {3...6} from create_integer_set():");
|
||||||
|
iset2 = create_integer_set(3, 6);
|
||||||
|
if ~exists("iset2") | (iset2 <> [3 4 5 6]) then swigtesterror(); end
|
||||||
|
// concat the two sets with concat_integer_set():");
|
||||||
|
iset3 = concat_integer_set(iset, iset2);
|
||||||
|
if ~exists("iset3") | (iset3 <> [1 2 3 4 5 6]) then swigtesterror(); end
|
||||||
|
|
||||||
|
// string sets
|
||||||
|
|
||||||
|
// Example of passing matrices of string as set arguments of C++ functions.");
|
||||||
|
// get a set of string {''aa'', ''bb'', ''cc'', ''dd''} with create_string_set():");
|
||||||
|
sset = create_string_set("aa bb cc dd");
|
||||||
|
if ~exists("sset") | (sset <> ["aa"; "bb"; "cc"; "dd"]) then swigtesterror(); end
|
||||||
|
// get a set of string {''cc'', ''dd'', ''ee'', ''ff''} with create_string_set():");
|
||||||
|
sset2 = create_string_set("cc dd ee ff");
|
||||||
|
if ~exists("sset2") | (sset2 <> ["cc"; "dd"; "ee"; "ff"]) then swigtesterror(); end
|
||||||
|
// concat the two sets with concat_string_set():");
|
||||||
|
sset3 = concat_string_set(sset, sset2);
|
||||||
|
if ~exists("sset3") | (sset3 <> ["aa"; "bb"; "cc"; "dd"; "ee"; "ff"]) then swigtesterror(); end
|
||||||
|
|
||||||
|
exec("swigtest.quit", -1);
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue