diff --git a/Examples/scilab/vector/Makefile b/Examples/scilab/vector/Makefile index 168d5a5dc..e8ea02e15 100644 --- a/Examples/scilab/vector/Makefile +++ b/Examples/scilab/vector/Makefile @@ -4,13 +4,13 @@ SRCS = example.cpp TARGET = example INTERFACE = example.i -all:: +all: $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' scilab_cpp -clean:: +clean: $(MAKE) -f $(TOP)/Makefile scilab_clean - rm -f *.sce *.so lib*lib.c *_wrap.cpp + rm -f *.sce *.so lib*lib.c *_wrap.cxx check: all $(MAKE) -f $(TOP)/Makefile scilab_run diff --git a/Examples/scilab/vector/example.cpp b/Examples/scilab/vector/example.cpp index 3afe6b12a..eb1518f96 100644 --- a/Examples/scilab/vector/example.cpp +++ b/Examples/scilab/vector/example.cpp @@ -1,19 +1,47 @@ /* File : example.cpp */ -#include -#include +#include "example.hxx" -class opt { -public: - void set_lower_bound(const std::vector &v) { - double sum = 0; - std::cout << "coucou" << std::endl; - for (int i = 0; i < v.size(); i++) { - sum += v[i]; - std::cout << v[i] << std::endl; - } - //return sum; + +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 index b272099e9..8d3fff734 100644 --- a/Examples/scilab/vector/example.hxx +++ b/Examples/scilab/vector/example.hxx @@ -1,18 +1,16 @@ -/* File : example.cpp */ +/* File : example.hxx */ #include -namespace nlopt { - class opt { - public: - void set_lower_bound(const std::vector &v) { - double sum = 0; - for (int i = 0; i < v.size(); i++) { - sum += v[i]; - } - //return sum; - } - }; -} +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 index 75d700cbd..25981de3b 100644 --- a/Examples/scilab/vector/example.i +++ b/Examples/scilab/vector/example.i @@ -1,4 +1,5 @@ /* File : example.i */ + %module example %{ @@ -6,8 +7,5 @@ %} %include "std_vector.i" -namespace std { - %template(nlopt_doublevector) vector; - }; %include "example.hxx"; diff --git a/Examples/scilab/vector/loader.sce b/Examples/scilab/vector/loader.sce deleted file mode 100644 index 4cb5545b0..000000000 --- a/Examples/scilab/vector/loader.sce +++ /dev/null @@ -1,58 +0,0 @@ -// This file is released under the 3-clause BSD license. See COPYING-BSD. -// Generated by builder.sce : Please, do not edit this file -// ---------------------------------------------------------------------------- -// -libexamplelib_path = get_absolute_file_path('loader.sce'); -// -// ulink previous function with same name -[bOK, ilib] = c_link('libexamplelib'); -if bOK then - ulink(ilib); -end -// -list_functions = [ 'delete_SciSwigIterator'; - 'SciSwigIterator_value'; - 'SciSwigIterator_incr'; - 'SciSwigIterator_decr'; - 'SciSwigIterator_distance'; - 'SciSwigIterator_equal'; - 'SciSwigIterator_copy'; - 'SciSwigIterator_next'; - 'SciSwigIterator_previous'; - 'SciSwigIterator_advance'; - 'nlopt_doublevector_pop'; - 'nlopt_doublevector___paren__'; - 'nlopt_doublevector___paren_asgn__'; - 'nlopt_doublevector_append'; - 'nlopt_doublevector_empty'; - 'nlopt_doublevector_size'; - 'nlopt_doublevector_clear'; - 'nlopt_doublevector_swap'; - 'nlopt_doublevector_get_allocator'; - 'nlopt_doublevector_begin'; - 'nlopt_doublevector_end'; - 'nlopt_doublevector_rbegin'; - 'nlopt_doublevector_rend'; - 'nlopt_doublevector_pop_back'; - 'nlopt_doublevector_erase'; - 'new_nlopt_doublevector'; - 'nlopt_doublevector_push_back'; - 'nlopt_doublevector_front'; - 'nlopt_doublevector_back'; - 'nlopt_doublevector_assign'; - 'nlopt_doublevector_resize'; - 'nlopt_doublevector_insert'; - 'nlopt_doublevector_reserve'; - 'nlopt_doublevector_capacity'; - 'delete_nlopt_doublevector'; - 'opt_set_lower_bound'; - 'new_opt'; - 'delete_opt'; -]; -addinter(libexamplelib_path + filesep() + 'libexamplelib' + getdynlibext(), 'libexamplelib', list_functions); -// remove temp. variables on stack -clear libexamplelib_path; -clear bOK; -clear ilib; -clear list_functions; -// ---------------------------------------------------------------------------- diff --git a/Examples/scilab/vector/runme.sci b/Examples/scilab/vector/runme.sci new file mode 100644 index 000000000..2dce998bc --- /dev/null +++ b/Examples/scilab/vector/runme.sci @@ -0,0 +1,28 @@ +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); + + +