Add example for STL sets
This commit is contained in:
parent
96ba677aa2
commit
2e7a435440
5 changed files with 88 additions and 0 deletions
16
Examples/scilab/set/Makefile
Normal file
16
Examples/scilab/set/Makefile
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
TOP = ../..
|
||||||
|
SWIG = $(TOP)/../preinst-swig
|
||||||
|
SRCS = example.cpp
|
||||||
|
TARGET = example
|
||||||
|
INTERFACE = example.i
|
||||||
|
|
||||||
|
all:
|
||||||
|
$(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
|
||||||
|
$(MAKE) -f $(TOP)/Makefile scilab_run
|
||||||
29
Examples/scilab/set/example.cpp
Normal file
29
Examples/scilab/set/example.cpp
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
/* File : example.cpp */
|
||||||
|
|
||||||
|
#include "example.hxx"
|
||||||
|
|
||||||
|
std::set<int> create_iset(const int size, const int* values)
|
||||||
|
{
|
||||||
|
std::set<int> iset;
|
||||||
|
std::copy(values, values + size, std::inserter(iset, iset.begin()));
|
||||||
|
return iset;
|
||||||
|
}
|
||||||
|
|
||||||
|
int sum_iset(const std::set<int> iset)
|
||||||
|
{
|
||||||
|
int sum = 0;
|
||||||
|
std::set<int>::iterator it;
|
||||||
|
for (it = iset.begin(); it != iset.end(); it++)
|
||||||
|
{
|
||||||
|
sum += *it;
|
||||||
|
}
|
||||||
|
return sum;
|
||||||
|
}
|
||||||
|
|
||||||
|
void concat_iset(std::set<int>& iset, const std::set<int> other_iset)
|
||||||
|
{
|
||||||
|
std::copy(other_iset.begin(), other_iset.end(), std::inserter(iset, iset.begin()));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
13
Examples/scilab/set/example.hxx
Normal file
13
Examples/scilab/set/example.hxx
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
/* File : example.hxx */
|
||||||
|
|
||||||
|
#include <set>
|
||||||
|
|
||||||
|
std::set<int> create_iset(const int size, const int* values);
|
||||||
|
|
||||||
|
int sum_iset(const std::set<int> iset);
|
||||||
|
|
||||||
|
void concat_iset(std::set<int>& iset, const std::set<int> other_iset);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
14
Examples/scilab/set/example.i
Normal file
14
Examples/scilab/set/example.i
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
/* 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";
|
||||||
16
Examples/scilab/set/runme.sci
Normal file
16
Examples/scilab/set/runme.sci
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
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);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue