Start vector management

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-sploving@12945 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Vincent Couvert 2012-03-22 11:10:34 +00:00
commit eb64659740
27 changed files with 3908 additions and 267 deletions

View 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.cpp
check: all
$(MAKE) -f $(TOP)/Makefile scilab_run

View file

@ -0,0 +1,16 @@
mode(-1);
lines(0);
ilib_verbose(0);
ilib_name = "examplelib";
files = "example_wrap.cxx";
files($+1) = "example.cpp";
libs = [];
ldflags = "";
cflags = ["-g -I" + get_absolute_file_path("builder.sce")];
table = ["nlopt_doublevector_empty","_wrap_nlopt_doublevector_empty";"nlopt_doublevector_size","_wrap_nlopt_doublevector_size";"nlopt_doublevector_clear","_wrap_nlopt_doublevector_clear";"nlopt_doublevector_swap","_wrap_nlopt_doublevector_swap";"nlopt_doublevector_get_allocator","_wrap_nlopt_doublevector_get_allocator";"nlopt_doublevector_pop_back","_wrap_nlopt_doublevector_pop_back";"new_nlopt_doublevector","_wrap_new_nlopt_doublevector";"nlopt_doublevector_push_back","_wrap_nlopt_doublevector_push_back";"nlopt_doublevector_front","_wrap_nlopt_doublevector_front";];
table = [table;"nlopt_doublevector_back","_wrap_nlopt_doublevector_back";"nlopt_doublevector_assign","_wrap_nlopt_doublevector_assign";"nlopt_doublevector_resize","_wrap_nlopt_doublevector_resize";"nlopt_doublevector_reserve","_wrap_nlopt_doublevector_reserve";"nlopt_doublevector_capacity","_wrap_nlopt_doublevector_capacity";"delete_nlopt_doublevector","_wrap_delete_nlopt_doublevector";"opt_set_lower_bound","_wrap_opt_set_lower_bound";"new_opt","_wrap_new_opt";"delete_opt","_wrap_delete_opt";];
if ~isempty(table) then
ilib_build(ilib_name, table, files, libs, [], ldflags, cflags);
end
exit

View file

@ -0,0 +1,22 @@
// This file is released under the 3-clause BSD license. See COPYING-BSD.
// Generated by builder.sce : Please, do not edit this file
// cleaner.sce
// ------------------------------------------------------
curdir = pwd();
cleaner_path = get_file_path('cleaner.sce');
chdir(cleaner_path);
// ------------------------------------------------------
if fileinfo('loader.sce') <> [] then
mdelete('loader.sce');
end
// ------------------------------------------------------
if fileinfo('libexamplelib.so') <> [] then
mdelete('libexamplelib.so');
end
// ------------------------------------------------------
if fileinfo('libexamplelib.c') <> [] then
mdelete('libexamplelib.c');
end
// ------------------------------------------------------
chdir(curdir);
// ------------------------------------------------------

View file

@ -0,0 +1,19 @@
/* File : example.cpp */
#include <iostream>
#include <vector>
class opt {
public:
void set_lower_bound(const std::vector<double> &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;
}
};

View file

@ -0,0 +1,18 @@
/* File : example.cpp */
#include <vector>
namespace nlopt {
class opt {
public:
void set_lower_bound(const std::vector<double> &v) {
double sum = 0;
for (int i = 0; i < v.size(); i++) {
sum += v[i];
}
//return sum;
}
};
}

View file

@ -0,0 +1,13 @@
/* File : example.i */
%module example
%{
#include "example.hxx"
%}
%include "std_vector.i"
namespace std {
%template(nlopt_doublevector) vector<double>;
};
%include "example.hxx";

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,58 @@
#include <mex.h>
#include <sci_gateway.h>
#include <api_scilab.h>
#include <MALLOC.h>
static int direct_gateway(char *fname,void F(void)) { F();return 0;};
extern Gatefunc _wrap_nlopt_doublevector_empty;
extern Gatefunc _wrap_nlopt_doublevector_size;
extern Gatefunc _wrap_nlopt_doublevector_clear;
extern Gatefunc _wrap_nlopt_doublevector_swap;
extern Gatefunc _wrap_nlopt_doublevector_get_allocator;
extern Gatefunc _wrap_nlopt_doublevector_pop_back;
extern Gatefunc _wrap_new_nlopt_doublevector;
extern Gatefunc _wrap_nlopt_doublevector_push_back;
extern Gatefunc _wrap_nlopt_doublevector_front;
extern Gatefunc _wrap_nlopt_doublevector_back;
extern Gatefunc _wrap_nlopt_doublevector_assign;
extern Gatefunc _wrap_nlopt_doublevector_resize;
extern Gatefunc _wrap_nlopt_doublevector_reserve;
extern Gatefunc _wrap_nlopt_doublevector_capacity;
extern Gatefunc _wrap_delete_nlopt_doublevector;
extern Gatefunc _wrap_opt_set_lower_bound;
extern Gatefunc _wrap_new_opt;
extern Gatefunc _wrap_delete_opt;
static GenericTable Tab[]={
{(Myinterfun)sci_gateway,_wrap_nlopt_doublevector_empty,"nlopt_doublevector_empty"},
{(Myinterfun)sci_gateway,_wrap_nlopt_doublevector_size,"nlopt_doublevector_size"},
{(Myinterfun)sci_gateway,_wrap_nlopt_doublevector_clear,"nlopt_doublevector_clear"},
{(Myinterfun)sci_gateway,_wrap_nlopt_doublevector_swap,"nlopt_doublevector_swap"},
{(Myinterfun)sci_gateway,_wrap_nlopt_doublevector_get_allocator,"nlopt_doublevector_get_allocator"},
{(Myinterfun)sci_gateway,_wrap_nlopt_doublevector_pop_back,"nlopt_doublevector_pop_back"},
{(Myinterfun)sci_gateway,_wrap_new_nlopt_doublevector,"new_nlopt_doublevector"},
{(Myinterfun)sci_gateway,_wrap_nlopt_doublevector_push_back,"nlopt_doublevector_push_back"},
{(Myinterfun)sci_gateway,_wrap_nlopt_doublevector_front,"nlopt_doublevector_front"},
{(Myinterfun)sci_gateway,_wrap_nlopt_doublevector_back,"nlopt_doublevector_back"},
{(Myinterfun)sci_gateway,_wrap_nlopt_doublevector_assign,"nlopt_doublevector_assign"},
{(Myinterfun)sci_gateway,_wrap_nlopt_doublevector_resize,"nlopt_doublevector_resize"},
{(Myinterfun)sci_gateway,_wrap_nlopt_doublevector_reserve,"nlopt_doublevector_reserve"},
{(Myinterfun)sci_gateway,_wrap_nlopt_doublevector_capacity,"nlopt_doublevector_capacity"},
{(Myinterfun)sci_gateway,_wrap_delete_nlopt_doublevector,"delete_nlopt_doublevector"},
{(Myinterfun)sci_gateway,_wrap_opt_set_lower_bound,"opt_set_lower_bound"},
{(Myinterfun)sci_gateway,_wrap_new_opt,"new_opt"},
{(Myinterfun)sci_gateway,_wrap_delete_opt,"delete_opt"},
};
int C2F(libexamplelib)()
{
Rhs = Max(0, Rhs);
if (*(Tab[Fin-1].f) != NULL)
{
if(pvApiCtx == NULL)
{
pvApiCtx = (StrCtx*)MALLOC(sizeof(StrCtx));
}
pvApiCtx->pstName = (char*)Tab[Fin-1].name;
(*(Tab[Fin-1].f))(Tab[Fin-1].name,Tab[Fin-1].F);
}
return 0;
}

View file

@ -0,0 +1,38 @@
// 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 = [ 'nlopt_doublevector_empty';
'nlopt_doublevector_size';
'nlopt_doublevector_clear';
'nlopt_doublevector_swap';
'nlopt_doublevector_get_allocator';
'nlopt_doublevector_pop_back';
'new_nlopt_doublevector';
'nlopt_doublevector_push_back';
'nlopt_doublevector_front';
'nlopt_doublevector_back';
'nlopt_doublevector_assign';
'nlopt_doublevector_resize';
'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;
// ----------------------------------------------------------------------------

View file

@ -73,7 +73,7 @@ public:
%include "std_vector.i"
#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) || defined(SWIGR) || defined(SWIGOCTAVE) || defined(SWIGRUBY)
#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) || defined(SWIGR) || defined(SWIGOCTAVE) || defined(SWIGSCILAB) || defined(SWIGRUBY)
#define SWIG_GOOD_VECTOR
%ignore std::vector<Space::Flow>::vector(size_type);
%ignore std::vector<Space::Flow>::resize(size_type);

View file

@ -0,0 +1,307 @@
%include <shared_ptr.i>
// Language specific macro implementing all the customisations for handling the smart pointer
%define SWIG_SHARED_PTR_TYPEMAPS(CONST, TYPE...)
// %naturalvar is as documented for member variables
%naturalvar TYPE;
%naturalvar SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >;
// destructor wrapper customisation
%feature("unref") TYPE
//"if (debug_shared) { cout << \"deleting use_count: \" << (*smartarg1).use_count() << \" [\" << (boost::get_deleter<SWIG_null_deleter>(*smartarg1) ? std::string(\"CANNOT BE DETERMINED SAFELY\") : ( (*smartarg1).get() ? (*smartarg1)->getValue() : std::string(\"NULL PTR\") )) << \"]\" << endl << flush; }\n"
"(void)arg1; delete smartarg1;"
// Typemap customisations...
// plain value
%typemap(in) CONST TYPE (void *argp, int res = 0) {
int newmem = 0;
res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem);
if (!SWIG_IsOK(res)) {
%argument_fail(res, "$type", $symname, $argnum);
}
if (!argp) {
%argument_nullref("$type", $symname, $argnum);
} else {
$1 = *(%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)->get());
if (newmem & SWIG_CAST_NEW_MEMORY) delete %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *);
}
}
%typemap(out) CONST TYPE {
%set_output(SWIG_NewPointerObj(new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(new $1_ltype(($1_ltype &)$1)), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN));
}
%typemap(varin) CONST TYPE {
void *argp = 0;
int newmem = 0;
int res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem);
if (!SWIG_IsOK(res)) {
%variable_fail(res, "$type", "$name");
}
if (!argp) {
%argument_nullref("$type", $symname, $argnum);
} else {
$1 = *(%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)->get());
if (newmem & SWIG_CAST_NEW_MEMORY) delete %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *);
}
}
%typemap(varout) CONST TYPE {
%set_varoutput(SWIG_NewPointerObj(new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(new $1_ltype(($1_ltype &)$1)), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN));
}
// plain pointer
// Note: $disown not implemented as it will lead to a memory leak of the shared_ptr instance
%typemap(in) CONST TYPE * (void *argp = 0, int res = 0, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempshared, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0) {
int newmem = 0;
res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem);
if (!SWIG_IsOK(res)) {
%argument_fail(res, "$type", $symname, $argnum);
}
if (newmem & SWIG_CAST_NEW_MEMORY) {
tempshared = *%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *);
delete %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *);
$1 = %const_cast(tempshared.get(), $1_ltype);
} else {
smartarg = %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *);
$1 = %const_cast((smartarg ? smartarg->get() : 0), $1_ltype);
}
}
%typemap(out, fragment="SWIG_null_deleter") CONST TYPE * {
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_$owner) : 0;
%set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), $owner | SWIG_POINTER_OWN));
}
%typemap(varin) CONST TYPE * {
void *argp = 0;
int newmem = 0;
int res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem);
if (!SWIG_IsOK(res)) {
%variable_fail(res, "$type", "$name");
}
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempshared;
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0;
if (newmem & SWIG_CAST_NEW_MEMORY) {
tempshared = *%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *);
delete %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *);
$1 = %const_cast(tempshared.get(), $1_ltype);
} else {
smartarg = %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *);
$1 = %const_cast((smartarg ? smartarg->get() : 0), $1_ltype);
}
}
%typemap(varout, fragment="SWIG_null_deleter") CONST TYPE * {
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_0) : 0;
%set_varoutput(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN));
}
// plain reference
%typemap(in) CONST TYPE & (void *argp = 0, int res = 0, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempshared) {
int newmem = 0;
res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem);
if (!SWIG_IsOK(res)) {
%argument_fail(res, "$type", $symname, $argnum);
}
if (!argp) { %argument_nullref("$type", $symname, $argnum); }
if (newmem & SWIG_CAST_NEW_MEMORY) {
tempshared = *%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *);
delete %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *);
$1 = %const_cast(tempshared.get(), $1_ltype);
} else {
$1 = %const_cast(%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)->get(), $1_ltype);
}
}
%typemap(out, fragment="SWIG_null_deleter") CONST TYPE & {
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_$owner);
%set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN));
}
%typemap(varin) CONST TYPE & {
void *argp = 0;
int newmem = 0;
int res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem);
if (!SWIG_IsOK(res)) {
%variable_fail(res, "$type", "$name");
}
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempshared;
if (!argp) { %argument_nullref("$type", $symname, $argnum); }
if (newmem & SWIG_CAST_NEW_MEMORY) {
tempshared = *%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *);
delete %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *);
$1 = *%const_cast(tempshared.get(), $1_ltype);
} else {
$1 = *%const_cast(%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)->get(), $1_ltype);
}
}
%typemap(varout, fragment="SWIG_null_deleter") CONST TYPE & {
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(&$1 SWIG_NO_NULL_DELETER_0);
%set_varoutput(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN));
}
// plain pointer by reference
// Note: $disown not implemented as it will lead to a memory leak of the shared_ptr instance
%typemap(in) TYPE *CONST& (void *argp = 0, int res = 0, $*1_ltype temp = 0, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempshared) {
int newmem = 0;
res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem);
if (!SWIG_IsOK(res)) {
%argument_fail(res, "$type", $symname, $argnum);
}
if (newmem & SWIG_CAST_NEW_MEMORY) {
tempshared = *%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *);
delete %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *);
temp = %const_cast(tempshared.get(), $*1_ltype);
} else {
temp = %const_cast(%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)->get(), $*1_ltype);
}
$1 = &temp;
}
%typemap(out, fragment="SWIG_null_deleter") TYPE *CONST& {
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1 SWIG_NO_NULL_DELETER_$owner);
%set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN));
}
%typemap(varin) TYPE *CONST& %{
#error "varin typemap not implemented"
%}
%typemap(varout) TYPE *CONST& %{
#error "varout typemap not implemented"
%}
// shared_ptr by value
%typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > (void *argp, int res = 0) {
int newmem = 0;
res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem);
if (!SWIG_IsOK(res)) {
%argument_fail(res, "$type", $symname, $argnum);
}
if (argp) $1 = *(%reinterpret_cast(argp, $&ltype));
if (newmem & SWIG_CAST_NEW_MEMORY) delete %reinterpret_cast(argp, $&ltype);
}
%typemap(out) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > {
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1) : 0;
%set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN));
}
%typemap(varin) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > {
int newmem = 0;
void *argp = 0;
int res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem);
if (!SWIG_IsOK(res)) {
%variable_fail(res, "$type", "$name");
}
$1 = argp ? *(%reinterpret_cast(argp, $&ltype)) : SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE >();
if (newmem & SWIG_CAST_NEW_MEMORY) delete %reinterpret_cast(argp, $&ltype);
}
%typemap(varout) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > {
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1) : 0;
%set_varoutput(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN));
}
// shared_ptr by reference
%typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > & (void *argp, int res = 0, $*1_ltype tempshared) {
int newmem = 0;
res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem);
if (!SWIG_IsOK(res)) {
%argument_fail(res, "$type", $symname, $argnum);
}
if (newmem & SWIG_CAST_NEW_MEMORY) {
if (argp) tempshared = *%reinterpret_cast(argp, $ltype);
delete %reinterpret_cast(argp, $ltype);
$1 = &tempshared;
} else {
$1 = (argp) ? %reinterpret_cast(argp, $ltype) : &tempshared;
}
}
%typemap(out) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > & {
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = *$1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1) : 0;
%set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN));
}
%typemap(varin) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > & %{
#error "varin typemap not implemented"
%}
%typemap(varout) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > & %{
#error "varout typemap not implemented"
%}
// shared_ptr by pointer
%typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * (void *argp, int res = 0, $*1_ltype tempshared) {
int newmem = 0;
res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem);
if (!SWIG_IsOK(res)) {
%argument_fail(res, "$type", $symname, $argnum);
}
if (newmem & SWIG_CAST_NEW_MEMORY) {
if (argp) tempshared = *%reinterpret_cast(argp, $ltype);
delete %reinterpret_cast(argp, $ltype);
$1 = &tempshared;
} else {
$1 = (argp) ? %reinterpret_cast(argp, $ltype) : &tempshared;
}
}
%typemap(out) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * {
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = $1 && *$1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1) : 0;
%set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN));
if ($owner) delete $1;
}
%typemap(varin) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * %{
#error "varin typemap not implemented"
%}
%typemap(varout) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * %{
#error "varout typemap not implemented"
%}
// shared_ptr by pointer reference
%typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& (void *argp, int res = 0, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempshared, $*1_ltype temp = 0) {
int newmem = 0;
res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem);
if (!SWIG_IsOK(res)) {
%argument_fail(res, "$type", $symname, $argnum);
}
if (argp) tempshared = *%reinterpret_cast(argp, $*ltype);
if (newmem & SWIG_CAST_NEW_MEMORY) delete %reinterpret_cast(argp, $*ltype);
temp = &tempshared;
$1 = &temp;
}
%typemap(out) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& {
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = *$1 && **$1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(**$1) : 0;
%set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN));
}
%typemap(varin) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& %{
#error "varin typemap not implemented"
%}
%typemap(varout) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& %{
#error "varout typemap not implemented"
%}
// Typecheck typemaps
// Note: SWIG_ConvertPtr with void ** parameter set to 0 instead of using SWIG_ConvertPtrAndOwn, so that the casting
// function is not called thereby avoiding a possible smart pointer copy constructor call when casting up the inheritance chain.
%typemap(typecheck,precedence=SWIG_TYPECHECK_POINTER,noblock=1)
TYPE CONST,
TYPE CONST &,
TYPE CONST *,
TYPE *CONST&,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > &,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& {
int res = SWIG_ConvertPtr($input, 0, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), 0);
$1 = SWIG_CheckState(res);
}
// various missing typemaps - If ever used (unlikely) ensure compilation error rather than runtime bug
%typemap(in) CONST TYPE[], CONST TYPE[ANY], CONST TYPE (CLASS::*) %{
#error "typemaps for $1_type not available"
%}
%typemap(out) CONST TYPE[], CONST TYPE[ANY], CONST TYPE (CLASS::*) %{
#error "typemaps for $1_type not available"
%}
%template() SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >;
%enddef

View file

@ -2,34 +2,31 @@
* C-type: bool
* Scilab type: boolean scalar
*/
%fragment(SWIG_AsVal_frag(bool), "header", fragment="SWIG_SciBoolean_AsBool") {
#define SWIG_AsVal_bool(scilabValue, valuePointer) SWIG_SciBoolean_AsBool(pvApiCtx, scilabValue, valuePointer, fname)
}
%fragment("SWIG_SciBoolean_AsBool", "header") {
%fragment(SWIG_AsVal_frag(bool), "header") {
SWIGINTERN int
SWIG_SciBoolean_AsBool(void *_pvApiCtx, int _iVar, bool *_pbValue, char *_fname) {
SWIG_AsVal_dec(bool)(SciObject _iVar, bool *_pbValue) {
SciErr sciErr;
int iRet = 0;
int *piAddrVar = NULL;
int iTempValue = 0;
sciErr = getVarAddressFromPosition(_pvApiCtx, _iVar, &piAddrVar);
sciErr = getVarAddressFromPosition(pvApiCtx, _iVar, &piAddrVar);
if (sciErr.iErr) {
printError(&sciErr, 0);
return SWIG_ERROR;
}
if (!isBooleanType(_pvApiCtx, piAddrVar)) {
Scierror(999, _("%s: Wrong type for input argument #%d: A boolean expected.\n"), _fname, _iVar);
if (!isBooleanType(pvApiCtx, piAddrVar)) {
Scierror(999, _("%s: Wrong type for input argument #%d: A boolean expected.\n"), SWIG_Scilab_GetFname(), _iVar);
return SWIG_ERROR;
}
if (!isScalar(_pvApiCtx, piAddrVar)) {
Scierror(999, _("%s: Wrong size for input argument #%d: A boolean expected.\n"), _fname, _iVar);
if (!isScalar(pvApiCtx, piAddrVar)) {
Scierror(999, _("%s: Wrong size for input argument #%d: A boolean expected.\n"), SWIG_Scilab_GetFname(), _iVar);
return SWIG_ERROR;
}
iRet = getScalarBoolean(_pvApiCtx, piAddrVar, &iTempValue);
iRet = getScalarBoolean(pvApiCtx, piAddrVar, &iTempValue);
if (iRet) {
return SWIG_ERROR;
}
@ -40,20 +37,18 @@ SWIG_SciBoolean_AsBool(void *_pvApiCtx, int _iVar, bool *_pbValue, char *_fname)
}
}
%fragment(SWIG_From_frag(bool), "header", fragment="SWIG_SciBoolean_FromBool") {
#define SWIG_From_bool(value) SWIG_SciBoolean_FromBool(pvApiCtx, $result, value)
}
%fragment("SWIG_SciBoolean_FromBool", "header") {
%fragment(SWIG_From_frag(bool), "header") {
SWIGINTERN int
SWIG_SciBoolean_FromBool(void *_pvApiCtx, int _iVarOut, bool _bValue) {
SWIG_From_dec(bool)(bool _bValue) {
int iRet = 0;
int iVarOut = Rhs + SWIG_Scilab_GetOutputPosition();
iRet = createScalarBoolean(_pvApiCtx, Rhs + _iVarOut, _bValue);
iRet = createScalarBoolean(pvApiCtx, iVarOut, _bValue);
if (iRet) {
return SWIG_ERROR;
}
return Rhs + _iVarOut;
return iVarOut;
}
}

866
Lib/scilab/scicontainer.swg Normal file
View file

@ -0,0 +1,866 @@
/* -----------------------------------------------------------------------------
* scicontainer.swg
*
* Based on pycontainer.swg
*
* Python sequence <-> C++ container wrapper
*
* This wrapper, and its iterator, allows a general use (and reuse) of
* the mapping between C++ and Python, thanks to the C++ templates.
*
* Of course, it needs the C++ compiler to support templates, but
* since we will use this wrapper with the STL containers, that should
* be the case.
* ----------------------------------------------------------------------------- */
%{
#include <iostream>
#if PY_VERSION_HEX >= 0x03020000
# define SWIGPY_SLICE_ARG(obj) ((PyObject*) (obj))
#else
# define SWIGPY_SLICE_ARG(obj) ((PySliceObject*) (obj))
#endif
%}
#if !defined(SWIG_NO_EXPORT_ITERATOR_METHODS)
# if !defined(SWIG_EXPORT_ITERATOR_METHODS)
# define SWIG_EXPORT_ITERATOR_METHODS SWIG_EXPORT_ITERATOR_METHODS
# endif
#endif
%include <pyiterators.swg>
/**** The PySequence C++ Wrap ***/
%insert(header) %{
#include <stdexcept>
%}
%include <std_except.i>
%fragment(SWIG_Traits_frag(swig::SwigPtr_PyObject),"header",fragment="StdTraits") {
namespace swig {
template <> struct traits<SwigPtr_PyObject > {
typedef value_category category;
static const char* type_name() { return "SwigPtr_PyObject"; }
};
template <> struct traits_from<SwigPtr_PyObject> {
typedef SwigPtr_PyObject value_type;
static PyObject *from(const value_type& val) {
PyObject *obj = static_cast<PyObject *>(val);
Py_XINCREF(obj);
return obj;
}
};
template <>
struct traits_check<SwigPtr_PyObject, value_category> {
static bool check(SwigPtr_PyObject) {
return true;
}
};
template <> struct traits_asval<SwigPtr_PyObject > {
typedef SwigPtr_PyObject value_type;
static int asval(PyObject *obj, value_type *val) {
if (val) *val = obj;
return SWIG_OK;
}
};
}
}
%fragment(SWIG_Traits_frag(swig::SwigVar_PyObject),"header",fragment="StdTraits") {
namespace swig {
template <> struct traits<SwigVar_PyObject > {
typedef value_category category;
static const char* type_name() { return "SwigVar_PyObject"; }
};
template <> struct traits_from<SwigVar_PyObject> {
typedef SwigVar_PyObject value_type;
static PyObject *from(const value_type& val) {
PyObject *obj = static_cast<PyObject *>(val);
Py_XINCREF(obj);
return obj;
}
};
template <>
struct traits_check<SwigVar_PyObject, value_category> {
static bool check(SwigVar_PyObject) {
return true;
}
};
template <> struct traits_asval<SwigVar_PyObject > {
typedef SwigVar_PyObject value_type;
static int asval(PyObject *obj, value_type *val) {
if (val) *val = obj;
return SWIG_OK;
}
};
}
}
%fragment("SwigPySequence_Base","header")
{
%#include <functional>
namespace std {
template <>
struct less <PyObject *>: public binary_function<PyObject *, PyObject *, bool>
{
bool
operator()(PyObject * v, PyObject *w) const
{
bool res;
SWIG_PYTHON_THREAD_BEGIN_BLOCK;
res = PyObject_RichCompareBool(v, w, Py_LT) ? true : false;
/* This may fall into a case of inconsistent
eg. ObjA > ObjX > ObjB
but ObjA < ObjB
*/
if( PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_TypeError) )
{
/* Objects can't be compared, this mostly occurred in Python 3.0 */
/* Compare their ptr directly for a workaround */
res = (v < w);
PyErr_Clear();
}
SWIG_PYTHON_THREAD_END_BLOCK;
return res;
}
};
template <>
struct less <swig::SwigPtr_PyObject>: public binary_function<swig::SwigPtr_PyObject, swig::SwigPtr_PyObject, bool>
{
bool
operator()(const swig::SwigPtr_PyObject& v, const swig::SwigPtr_PyObject& w) const
{
return std::less<PyObject *>()(v, w);
}
};
template <>
struct less <swig::SwigVar_PyObject>: public binary_function<swig::SwigVar_PyObject, swig::SwigVar_PyObject, bool>
{
bool
operator()(const swig::SwigVar_PyObject& v, const swig::SwigVar_PyObject& w) const
{
return std::less<PyObject *>()(v, w);
}
};
}
namespace swig {
template <> struct traits<PyObject *> {
typedef value_category category;
static const char* type_name() { return "PyObject *"; }
};
template <> struct traits_asval<PyObject * > {
typedef PyObject * value_type;
static int asval(PyObject *obj, value_type *val) {
if (val) *val = obj;
return SWIG_OK;
}
};
template <>
struct traits_check<PyObject *, value_category> {
static bool check(PyObject *) {
return true;
}
};
template <> struct traits_from<PyObject *> {
typedef PyObject * value_type;
static PyObject *from(const value_type& val) {
Py_XINCREF(val);
return val;
}
};
}
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 <class Sequence, class Difference>
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 <class Sequence, class Difference>
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 <class Sequence, class Difference>
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 <class Sequence, class Difference, class InputSeq>
inline void
setslice(Sequence* self, Difference i, Difference j, const InputSeq& v = InputSeq()) {
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 <class Sequence, class Difference>
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("SwigPySequence_Cont","header",
fragment="StdTraits",
fragment="SwigPySequence_Base",
fragment="SwigPyIterator_T")
{
namespace swig
{
template <class T>
struct SwigPySequence_Ref
{
SwigPySequence_Ref(PyObject* seq, int index)
: _seq(seq), _index(index)
{
}
operator T () const
{
swig::SwigVar_PyObject item = PySequence_GetItem(_seq, _index);
try {
return swig::as<T>(item, true);
} catch (std::exception& e) {
char msg[1024];
sprintf(msg, "in sequence element %d ", _index);
if (!PyErr_Occurred()) {
::%type_error(swig::type_name<T>());
}
SWIG_Python_AddErrorMsg(msg);
SWIG_Python_AddErrorMsg(e.what());
throw;
}
}
SwigPySequence_Ref& operator=(const T& v)
{
PySequence_SetItem(_seq, _index, swig::from<T>(v));
return *this;
}
private:
PyObject* _seq;
int _index;
};
template <class T>
struct SwigPySequence_ArrowProxy
{
SwigPySequence_ArrowProxy(const T& x): m_value(x) {}
const T* operator->() const { return &m_value; }
operator const T*() const { return &m_value; }
T m_value;
};
template <class T, class Reference >
struct SwigPySequence_InputIterator
{
typedef SwigPySequence_InputIterator<T, Reference > self;
typedef std::random_access_iterator_tag iterator_category;
typedef Reference reference;
typedef T value_type;
typedef T* pointer;
typedef int difference_type;
SwigPySequence_InputIterator()
{
}
SwigPySequence_InputIterator(PyObject* seq, int index)
: _seq(seq), _index(index)
{
}
reference operator*() const
{
return reference(_seq, _index);
}
SwigPySequence_ArrowProxy<T>
operator->() const {
return SwigPySequence_ArrowProxy<T>(operator*());
}
bool operator==(const self& ri) const
{
return (_index == ri._index) && (_seq == ri._seq);
}
bool operator!=(const self& ri) const
{
return !(operator==(ri));
}
self& operator ++ ()
{
++_index;
return *this;
}
self& operator -- ()
{
--_index;
return *this;
}
self& operator += (difference_type n)
{
_index += n;
return *this;
}
self operator +(difference_type n) const
{
return self(_seq, _index + n);
}
self& operator -= (difference_type n)
{
_index -= n;
return *this;
}
self operator -(difference_type n) const
{
return self(_seq, _index - n);
}
difference_type operator - (const self& ri) const
{
return _index - ri._index;
}
bool operator < (const self& ri) const
{
return _index < ri._index;
}
reference
operator[](difference_type n) const
{
return reference(_seq, _index + n);
}
private:
PyObject* _seq;
difference_type _index;
};
template <class T>
struct SwigPySequence_Cont
{
typedef SwigPySequence_Ref<T> reference;
typedef const SwigPySequence_Ref<T> const_reference;
typedef T value_type;
typedef T* pointer;
typedef int difference_type;
typedef int size_type;
typedef const pointer const_pointer;
typedef SwigPySequence_InputIterator<T, reference> iterator;
typedef SwigPySequence_InputIterator<T, const_reference> const_iterator;
SwigPySequence_Cont(PyObject* seq) : _seq(0)
{
if (!PySequence_Check(seq)) {
throw std::invalid_argument("a sequence is expected");
}
_seq = seq;
Py_INCREF(_seq);
}
~SwigPySequence_Cont()
{
Py_XDECREF(_seq);
}
size_type size() const
{
return static_cast<size_type>(PySequence_Size(_seq));
}
bool empty() const
{
return size() == 0;
}
iterator begin()
{
return iterator(_seq, 0);
}
const_iterator begin() const
{
return const_iterator(_seq, 0);
}
iterator end()
{
return iterator(_seq, size());
}
const_iterator end() const
{
return const_iterator(_seq, size());
}
reference operator[](difference_type n)
{
return reference(_seq, n);
}
const_reference operator[](difference_type n) const
{
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 = PySequence_GetItem(_seq, i);
if (!swig::check<value_type>(item)) {
if (set_err) {
char msg[1024];
sprintf(msg, "in sequence element %d", i);
SWIG_Error(SWIG_RuntimeError, msg);
}
return false;
}
}
return true;
}
private:
PyObject* _seq;
};
}
}
%define %swig_sequence_iterator(Sequence...)
#if defined(SWIG_EXPORT_ITERATOR_METHODS)
class iterator;
class reverse_iterator;
class const_iterator;
class const_reverse_iterator;
%typemap(out,noblock=1,fragment="SwigPySequence_Cont")
iterator, reverse_iterator, const_iterator, const_reverse_iterator {
$result = SWIG_NewPointerObj(swig::make_output_iterator(%static_cast($1,const $type &)),
swig::SwigPyIterator::descriptor(),SWIG_POINTER_OWN);
}
%typemap(out,noblock=1,fragment="SwigPySequence_Cont")
std::pair<iterator, iterator>, std::pair<const_iterator, const_iterator> {
$result = PyTuple_New(2);
PyTuple_SetItem($result,0,SWIG_NewPointerObj(swig::make_output_iterator(%static_cast($1,const $type &).first),
swig::SwigPyIterator::descriptor(),SWIG_POINTER_OWN));
PyTuple_SetItem($result,1,SWIG_NewPointerObj(swig::make_output_iterator(%static_cast($1,const $type &).second),
swig::SwigPyIterator::descriptor(),SWIG_POINTER_OWN));
}
%fragment("SwigPyPairBoolOutputIterator","header",fragment=SWIG_From_frag(bool),fragment="SwigPySequence_Cont") {}
%typemap(out,noblock=1,fragment="SwigPyPairBoolOutputIterator")
std::pair<iterator, bool>, std::pair<const_iterator, bool> {
$result = PyTuple_New(2);
PyTuple_SetItem($result,0,SWIG_NewPointerObj(swig::make_output_iterator(%static_cast($1,const $type &).first),
swig::SwigPyIterator::descriptor(),SWIG_POINTER_OWN));
PyTuple_SetItem($result,1,SWIG_From(bool)(%static_cast($1,const $type &).second));
}
%typemap(in,noblock=1,fragment="SwigPySequence_Cont")
iterator(swig::SwigPyIterator *iter = 0, int res),
reverse_iterator(swig::SwigPyIterator *iter = 0, int res),
const_iterator(swig::SwigPyIterator *iter = 0, int res),
const_reverse_iterator(swig::SwigPyIterator *iter = 0, int res) {
res = SWIG_ConvertPtr($input, %as_voidptrptr(&iter), swig::SwigPyIterator::descriptor(), 0);
if (!SWIG_IsOK(res) || !iter) {
%argument_fail(SWIG_TypeError, "$type", $symname, $argnum);
} else {
swig::SwigPyIterator_T<$type > *iter_t = dynamic_cast<swig::SwigPyIterator_T<$type > *>(iter);
if (iter_t) {
$1 = iter_t->get_current();
} else {
%argument_fail(SWIG_TypeError, "$type", $symname, $argnum);
}
}
}
%typecheck(%checkcode(ITERATOR),noblock=1,fragment="SwigPySequence_Cont")
iterator, reverse_iterator, const_iterator, const_reverse_iterator {
swig::SwigPyIterator *iter = 0;
int res = SWIG_ConvertPtr($input, %as_voidptrptr(&iter), swig::SwigPyIterator::descriptor(), 0);
$1 = (SWIG_IsOK(res) && iter && (dynamic_cast<swig::SwigPyIterator_T<$type > *>(iter) != 0));
}
%fragment("SwigPySequence_Cont");
%newobject iterator(PyObject **PYTHON_SELF);
%extend {
swig::SwigPyIterator* iterator(PyObject **PYTHON_SELF) {
return swig::make_output_iterator(self->begin(), self->begin(), self->end(), *PYTHON_SELF);
}
#if defined(SWIGPYTHON_BUILTIN)
%feature("python:slot", "tp_iter", functype="getiterfunc") iterator;
#else
%pythoncode {def __iter__(self): return self.iterator()}
#endif
}
#endif //SWIG_EXPORT_ITERATOR_METHODS
%enddef
/**** The python container methods ****/
%define %swig_container_methods(Container...)
%newobject __getslice__;
#if defined(SWIGPYTHON_BUILTIN)
%feature("python:slot", "nb_nonzero", functype="inquiry") __nonzero__;
%feature("python:slot", "sq_length", functype="lenfunc") __len__;
#endif // SWIGPYTHON_BUILTIN
%extend {
bool __nonzero__() const {
return !(self->empty());
}
/* Alias for Python 3 compatibility */
bool __bool__() const {
return !(self->empty());
}
size_type __len__() const {
return self->size();
}
}
%enddef
%define %swig_sequence_methods_common(Sequence...)
%swig_sequence_iterator(%arg(Sequence))
%swig_container_methods(%arg(Sequence))
%fragment("SwigPySequence_Base");
#if defined(SWIGPYTHON_BUILTIN)
//%feature("python:slot", "sq_item", functype="ssizeargfunc") __getitem__;
//%feature("python:slot", "sq_slice", functype="ssizessizeargfunc") __getslice__;
//%feature("python:slot", "sq_ass_item", functype="ssizeobjargproc") __setitem__;
//%feature("python:slot", "sq_ass_slice", functype="ssizessizeobjargproc") __setslice__;
%feature("python:slot", "mp_subscript", functype="binaryfunc") __getitem__;
%feature("python:slot", "mp_ass_subscript", functype="objobjargproc") __setitem__;
#endif // SWIGPYTHON_BUILTIN
%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;
}
/* typemap for slice object support */
%typemap(in) PySliceObject* {
if (!PySlice_Check($input)) {
%argument_fail(SWIG_TypeError, "$type", $symname, $argnum);
}
$1 = (PySliceObject *) $input;
}
%typemap(typecheck,precedence=SWIG_TYPECHECK_POINTER) PySliceObject* {
$1 = PySlice_Check($input);
}
Sequence* __getslice__(difference_type i, difference_type j) throw (std::out_of_range) {
return swig::getslice(self, i, j);
}
void __setslice__(difference_type i, difference_type j, const Sequence& v = Sequence())
throw (std::out_of_range, std::invalid_argument) {
swig::setslice(self, i, j, v);
}
void __delslice__(difference_type i, difference_type j) throw (std::out_of_range) {
swig::delslice(self, i, j);
}
void __delitem__(difference_type i) throw (std::out_of_range) {
self->erase(swig::getpos(self,i));
}
/* Overloaded methods for Python 3 compatibility
* (Also useful in Python 2.x)
*/
Sequence* __getitem__(PySliceObject *slice) throw (std::out_of_range) {
Py_ssize_t i, j, step;
if( !PySlice_Check(slice) ) {
SWIG_Error(SWIG_TypeError, "Slice object expected.");
return NULL;
}
PySlice_GetIndices(SWIGPY_SLICE_ARG(slice), self->size(), &i, &j, &step);
return swig::getslice(self, i, j);
}
void __setitem__(PySliceObject *slice, const Sequence& v)
throw (std::out_of_range, std::invalid_argument) {
Py_ssize_t i, j, step;
if( !PySlice_Check(slice) ) {
SWIG_Error(SWIG_TypeError, "Slice object expected.");
return;
}
PySlice_GetIndices(SWIGPY_SLICE_ARG(slice), self->size(), &i, &j, &step);
swig::setslice(self, i, j, v);
}
void __setitem__(PySliceObject *slice)
throw (std::out_of_range) {
Py_ssize_t i, j, step;
if( !PySlice_Check(slice) ) {
SWIG_Error(SWIG_TypeError, "Slice object expected.");
return;
}
PySlice_GetIndices(SWIGPY_SLICE_ARG(slice), self->size(), &i, &j, &step);
swig::delslice(self, i,j);
}
void __delitem__(PySliceObject *slice)
throw (std::out_of_range) {
Py_ssize_t i, j, step;
if( !PySlice_Check(slice) ) {
SWIG_Error(SWIG_TypeError, "Slice object expected.");
return;
}
PySlice_GetIndices(SWIGPY_SLICE_ARG(slice), self->size(), &i, &j, &step);
swig::delslice(self, i,j);
}
}
%enddef
%define %swig_sequence_methods(Sequence...)
%swig_sequence_methods_common(%arg(Sequence))
%extend {
const value_type& __getitem__(difference_type i) const throw (std::out_of_range) {
return *(swig::cgetpos(self, i));
}
void __setitem__(difference_type i, const value_type& x) throw (std::out_of_range) {
*(swig::getpos(self,i)) = x;
}
void append(const value_type& x) {
self->push_back(x);
}
}
%enddef
%define %swig_sequence_methods_val(Sequence...)
%swig_sequence_methods_common(%arg(Sequence))
%extend {
value_type __getitem__(difference_type i) throw (std::out_of_range) {
return *(swig::cgetpos(self, i));
}
void __setitem__(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
//
// Common fragments
//
%fragment("StdSequenceTraits","header",
fragment="StdTraits",
fragment="SwigPySequence_Cont")
{
namespace swig {
template <class SwigPySeq, class Seq>
inline void
assign(const SwigPySeq& swigpyseq, Seq* seq) {
// seq->assign(swigpyseq.begin(), swigpyseq.end()); // not used as not always implemented
typedef typename SwigPySeq::value_type value_type;
typename SwigPySeq::const_iterator it = swigpyseq.begin();
for (;it != swigpyseq.end(); ++it) {
seq->insert(seq->end(),(value_type)(*it));
}
}
template <class Seq, class T = typename Seq::value_type >
struct traits_asptr_stdseq {
typedef Seq sequence;
typedef T value_type;
static int asptr(PyObject *obj, sequence **seq) {
if (obj == Py_None || SWIG_Python_GetSwigThis(obj)) {
sequence *p;
if (::SWIG_ConvertPtr(obj,(void**)&p,
swig::type_info<sequence>(),0) == SWIG_OK) {
if (seq) *seq = p;
return SWIG_OLDOBJ;
}
} else if (PySequence_Check(obj)) {
try {
SwigPySequence_Cont<value_type> swigpyseq(obj);
if (seq) {
sequence *pseq = new sequence();
assign(swigpyseq, pseq);
*seq = pseq;
return SWIG_NEWOBJ;
} else {
return swigpyseq.check() ? SWIG_OK : SWIG_ERROR;
}
} catch (std::exception& e) {
if (seq) {
if (!PyErr_Occurred()) {
PyErr_SetString(PyExc_TypeError, e.what());
}
}
return SWIG_ERROR;
}
}
return SWIG_ERROR;
}
};
template <class Seq, class T = typename Seq::value_type >
struct traits_from_stdseq {
typedef Seq sequence;
typedef T value_type;
typedef typename Seq::size_type size_type;
typedef typename sequence::const_iterator const_iterator;
static PyObject *from(const sequence& seq) {
%#ifdef SWIG_PYTHON_EXTRA_NATIVE_CONTAINERS
swig_type_info *desc = swig::type_info<sequence>();
if (desc && desc->clientdata) {
return SWIG_NewPointerObj(new sequence(seq), desc, SWIG_POINTER_OWN);
}
%#endif
size_type size = seq.size();
if (size <= (size_type)INT_MAX) {
PyObject *obj = PyTuple_New((int)size);
int i = 0;
for (const_iterator it = seq.begin();
it != seq.end(); ++it, ++i) {
PyTuple_SetItem(obj,i,swig::from<value_type>(*it));
}
return obj;
} else {
PyErr_SetString(PyExc_OverflowError,"sequence size not valid in python");
return NULL;
}
}
};
}
}

View file

@ -1,37 +1,30 @@
/*
* DOUBLE SCALAR
*/
%fragment(SWIG_AsVal_frag(double), "header", fragment="SWIG_SciDouble_AsDouble") {
#define SWIG_AsVal_double(scilabValue, valuePointer) SWIG_SciDouble_AsDouble(pvApiCtx, scilabValue, valuePointer, fname)
}
%fragment(SWIG_From_frag(double), "header", fragment="SWIG_SciDouble_FromDouble") {
#define SWIG_From_double(value) SWIG_SciDouble_FromDouble(pvApiCtx, $result, value)
}
%fragment("SWIG_SciDouble_AsDouble", "header") {
%fragment(SWIG_AsVal_frag(double), "header") {
SWIGINTERN int
SWIG_SciDouble_AsDouble(void *_pvApiCtx, int _iVar, double *_pdblValue, char *_fname) {
SWIG_AsVal_dec(double)(SciObject _iVar, double *_pdblValue) {
SciErr sciErr;
int iRet = 0;
int *piAddrVar = NULL;
sciErr = getVarAddressFromPosition(_pvApiCtx, _iVar, &piAddrVar);
sciErr = getVarAddressFromPosition(pvApiCtx, _iVar, &piAddrVar);
if (sciErr.iErr) {
printError(&sciErr, 0);
return SWIG_ERROR;
}
if (!isDoubleType(_pvApiCtx, piAddrVar) || isVarComplex(_pvApiCtx, piAddrVar)) {
Scierror(999, _("%s: Wrong type for input argument #%d: A real expected.\n"), _fname, _iVar);
if (!isDoubleType(pvApiCtx, piAddrVar) || isVarComplex(pvApiCtx, piAddrVar)) {
Scierror(999, _("%s: Wrong type for input argument #%d: A real expected.\n"), SWIG_Scilab_GetFname(), _iVar);
return SWIG_ERROR;
}
if (!isScalar(_pvApiCtx, piAddrVar)) {
Scierror(999, _("%s: Wrong size for input argument #%d: A real expected.\n"), _fname, _iVar);
if (!isScalar(pvApiCtx, piAddrVar)) {
Scierror(999, _("%s: Wrong size for input argument #%d: A real expected.\n"), SWIG_Scilab_GetFname(), _iVar);
return SWIG_ERROR;
}
iRet = getScalarDouble(_pvApiCtx, piAddrVar, _pdblValue);
iRet = getScalarDouble(pvApiCtx, piAddrVar, _pdblValue);
if (iRet) {
return SWIG_ERROR;
}
@ -40,17 +33,17 @@ SWIG_SciDouble_AsDouble(void *_pvApiCtx, int _iVar, double *_pdblValue, char *_f
}
}
%fragment("SWIG_SciDouble_FromDouble", "header") {
%fragment(SWIG_From_frag(double), "header") {
SWIGINTERN int
SWIG_SciDouble_FromDouble(void *_pvApiCtx, int _iVarOut, double _dblValue) {
SWIG_From_dec(double)(double _dblValue) {
int iRet;
iRet = createScalarDouble(_pvApiCtx, Rhs + _iVarOut, _dblValue);
int iVarOut = Rhs + SWIG_Scilab_GetOutputPosition();
iRet = createScalarDouble(pvApiCtx, iVarOut, _dblValue);
if (iRet) {
return SWIG_ERROR;
}
return Rhs + _iVarOut;
return iVarOut;
}
}

View file

@ -1,19 +1,11 @@
/*
* FLOAT SCALAR
*/
%fragment(SWIG_AsVal_frag(float), "header", fragment="SwigScilabDoubleToFloat") {
#define SWIG_AsVal_float(scilabValue, valuePointer) SwigScilabDoubleToFloat(pvApiCtx, scilabValue, valuePointer, fname)
}
%fragment(SWIG_From_frag(float), "header", fragment="SwigScilabDoubleFromFloat") {
#define SWIG_From_float(value) SwigScilabDoubleFromFloat(pvApiCtx, $result, value)
}
%fragment("SwigScilabDoubleToFloat", "header", fragment="SWIG_SciDouble_AsDouble") {
%fragment(SWIG_AsVal_frag(float), "header", fragment=SWIG_AsVal_frag(double)) {
SWIGINTERN int
SwigScilabDoubleToFloat(void *_pvApiCtx, int _iVar, float *_pfValue, char *_fname) {
SWIG_AsVal_dec(float)(SciObject _iVar, float *_pfValue) {
double dblValue = 0.0;
if(SWIG_SciDouble_AsDouble(_pvApiCtx, _iVar, &dblValue, _fname) != SWIG_OK) {
if(SWIG_AsVal_dec(double)(_iVar, &dblValue) != SWIG_OK) {
return SWIG_ERROR;
}
*_pfValue = (float) dblValue;
@ -21,20 +13,21 @@ SwigScilabDoubleToFloat(void *_pvApiCtx, int _iVar, float *_pfValue, char *_fnam
}
}
%fragment("SwigScilabDoubleFromFloat", "header") {
%fragment(SWIG_From_frag(float), "header") {
SWIGINTERN int
SwigScilabDoubleFromFloat(void *_pvApiCtx, int _iVarOut, float _flValue) {
SWIG_From_dec(float)(float _flValue) {
SciErr sciErr;
double dblDoubleValue = (double) _flValue;
int iRowsOut = 1;
int iColsOut = 1;
int iVarOut = Rhs + SWIG_Scilab_GetOutputPosition();
sciErr = createMatrixOfDouble(_pvApiCtx, Rhs + _iVarOut, iRowsOut, iColsOut, &dblDoubleValue);
sciErr = createMatrixOfDouble(pvApiCtx, iVarOut, iRowsOut, iColsOut, &dblDoubleValue);
if (sciErr.iErr) {
printError(&sciErr, 0);
return SWIG_ERROR;
}
return Rhs + _iVarOut;
return iVarOut;
}
}

View file

@ -2,17 +2,22 @@
* C-type: int
* Scilab type: double scalar
*/
%fragment(SWIG_AsVal_frag(int), "header", fragment="SWIG_SciDouble_AsInt") {
#define SWIG_AsVal_int(scilabValue, valuePointer) SWIG_SciDouble_AsInt(pvApiCtx, scilabValue, valuePointer, fname)
}
%fragment(SWIG_AsVal_frag(size_t), "header", fragment="SWIG_SciDouble_AsInt") {
#define SWIG_AsVal_size_t(scilabValue, valuePointer) SWIG_SciDouble_AsInt(pvApiCtx, scilabValue, (int*)valuePointer, fname)
}
%fragment("SWIG_SciDouble_AsInt", "header", fragment="SWIG_SciDouble_AsDouble") {
%fragment(SWIG_AsVal_frag(int), "header", fragment=SWIG_AsVal_frag(double)) {
SWIGINTERN int
SWIG_SciDouble_AsInt(void *_pvApiCtx, int _iVar, int *_piValue, char *_fname) {
SWIG_AsVal_dec(int)(SciObject _iVar, int *_piValue) {
double dblValue = 0.0;
if(SWIG_SciDouble_AsDouble(_pvApiCtx, _iVar, &dblValue, _fname) != SWIG_OK) {
if(SWIG_AsVal_dec(double)(_iVar, &dblValue) != SWIG_OK) {
return SWIG_ERROR;
}
*_piValue = (int) dblValue;
return SWIG_OK;
}
}
%fragment(SWIG_AsVal_frag(size_t), "header", fragment=SWIG_AsVal_frag(double)) {
SWIGINTERN int
SWIG_AsVal_dec(size_t)(SciObject _iVar, size_t *_piValue) {
double dblValue = 0.0;
if(SWIG_AsVal_dec(double)(_iVar, &dblValue) != SWIG_OK) {
return SWIG_ERROR;
}
*_piValue = (int) dblValue;
@ -20,27 +25,40 @@ SWIG_SciDouble_AsInt(void *_pvApiCtx, int _iVar, int *_piValue, char *_fname) {
}
}
%fragment(SWIG_From_frag(int), "header", fragment="SWIG_SciDouble_FromInt") {
#define SWIG_From_int(value) SWIG_SciDouble_FromInt(pvApiCtx, $result, value)
}
%fragment(SWIG_From_frag(size_t), "header", fragment="SWIG_SciDouble_FromInt") {
#define SWIG_From_size_t(value) SWIG_SciDouble_FromInt(pvApiCtx, $result, (int)value)
}
%fragment("SWIG_SciDouble_FromInt", "header") {
%fragment(SWIG_From_frag(int), "header") {
SWIGINTERN int
SWIG_SciDouble_FromInt(void *_pvApiCtx, int _iVarOut, int _iValue) {
SWIG_From_dec(int)(int _iValue) {
SciErr sciErr;
double dblDoubleValue = (double) _iValue;
int iRowsOut = 1;
int iColsOut = 1;
int iVarOut = Rhs + SWIG_Scilab_GetOutputPosition();
sciErr = createMatrixOfDouble(_pvApiCtx, Rhs + _iVarOut, iRowsOut, iColsOut, &dblDoubleValue);
sciErr = createMatrixOfDouble(pvApiCtx, iVarOut, iRowsOut, iColsOut, &dblDoubleValue);
if (sciErr.iErr) {
printError(&sciErr, 0);
return SWIG_ERROR;
}
return Rhs + _iVarOut;
return iVarOut;
}
}
%fragment(SWIG_From_frag(size_t), "header") {
SWIGINTERN int
SWIG_From_dec(size_t)(size_t _iValue) {
SciErr sciErr;
double dblDoubleValue = (double) _iValue;
int iRowsOut = 1;
int iColsOut = 1;
int iVarOut = Rhs + SWIG_Scilab_GetOutputPosition();
sciErr = createMatrixOfDouble(pvApiCtx, iVarOut, iRowsOut, iColsOut, &dblDoubleValue);
if (sciErr.iErr) {
printError(&sciErr, 0);
return SWIG_ERROR;
}
return iVarOut;
}
}
/*

View file

@ -2,31 +2,11 @@
* C-type: long
* Scilab type: double scalar
*/
%fragment(SWIG_AsVal_frag(long), "header", fragment="SwigScilabDoubleToLong") {
#define SWIG_AsVal_long(scilabValue, valuePointer) SwigScilabDoubleToLong(pvApiCtx, scilabValue, valuePointer, fname)
}
%fragment(SWIG_From_frag(long), "header", fragment="SwigScilabDoubleFromLong") {
#define SWIG_From_long(value) SwigScilabDoubleFromLong(pvApiCtx, $result, value)
}
/*
* C-type: unsigned long
* Scilab type: double scalar
*/
%fragment(SWIG_AsVal_frag(unsigned long), "header", fragment="SwigScilabDoubleToUnsignedLong") {
#define SWIG_AsVal_unsigned_SS_long(scilabValue, valuePointer) SwigScilabDoubleToUnsignedLong(pvApiCtx, scilabValue, valuePointer, fname)
}
%fragment(SWIG_From_frag(unsigned long), "header", fragment="SwigScilabDoubleFromUnsignedLong") {
#define SWIG_From_unsigned_SS_long(value) SwigScilabDoubleFromUnsignedLong(pvApiCtx, $result, value)
}
%fragment("SwigScilabDoubleToLong", "header", fragment="SWIG_SciDouble_AsDouble") {
%fragment(SWIG_AsVal_frag(long), "header", fragment=SWIG_AsVal_frag(double)) {
SWIGINTERN int
SwigScilabDoubleToLong(void *_pvApiCtx, int _iVar, long *_plValue, char *_fname) {
SWIG_AsVal_dec(long)(SciObject _iVar, long *_plValue) {
double dblValue = 0.0;
if(SWIG_SciDouble_AsDouble(_pvApiCtx, _iVar, &dblValue, _fname) != SWIG_OK) {
if(SWIG_AsVal_dec(double)(_iVar, &dblValue) != SWIG_OK) {
return SWIG_ERROR;
}
*_plValue = (long) dblValue;
@ -34,11 +14,34 @@ SwigScilabDoubleToLong(void *_pvApiCtx, int _iVar, long *_plValue, char *_fname)
}
}
%fragment("SwigScilabDoubleToUnsignedLong", "header", fragment="SWIG_SciDouble_AsDouble") {
%fragment(SWIG_From_frag(long), "header") {
SWIGINTERN int
SwigScilabDoubleToUnsignedLong(void *_pvApiCtx, int _iVar, unsigned long *_pulValue, char *_fname) {
SWIG_From_dec(long)(long _lValue) {
SciErr sciErr;
double dblDoubleValue = (double) _lValue;
int iRowsOut = 1;
int iColsOut = 1;
int iVarOut = Rhs + SWIG_Scilab_GetOutputPosition();
sciErr = createMatrixOfDouble(pvApiCtx, iVarOut, iRowsOut, iColsOut, &dblDoubleValue);
if (sciErr.iErr) {
printError(&sciErr, 0);
return SWIG_ERROR;
}
return iVarOut;
}
}
/*
* C-type: unsigned long
* Scilab type: double scalar
*/
%fragment(SWIG_AsVal_frag(unsigned long), "header", fragment=SWIG_AsVal_frag(double)) {
SWIGINTERN int
SWIG_AsVal_dec(unsigned long)(SciObject _iVar, unsigned long *_pulValue) {
double dblValue = 0.0;
if(SWIG_SciDouble_AsDouble(_pvApiCtx, _iVar, &dblValue, _fname) != SWIG_OK) {
if(SWIG_AsVal_dec(double)(_iVar, &dblValue) != SWIG_OK) {
return SWIG_ERROR;
}
*_pulValue = (unsigned long) dblValue;
@ -46,38 +49,22 @@ SwigScilabDoubleToUnsignedLong(void *_pvApiCtx, int _iVar, unsigned long *_pulVa
}
}
%fragment("SwigScilabDoubleFromLong", "header") {
%fragment(SWIG_From_frag(unsigned long), "header") {
SWIGINTERN int
SwigScilabDoubleFromLong(void *_pvApiCtx, int _iVarOut, long _lValue) {
SciErr sciErr;
double dblDoubleValue = (double) _lValue;
int iRowsOut = 1;
int iColsOut = 1;
sciErr = createMatrixOfDouble(_pvApiCtx, Rhs + _iVarOut, iRowsOut, iColsOut, &dblDoubleValue);
if (sciErr.iErr) {
printError(&sciErr, 0);
return SWIG_ERROR;
}
return Rhs + _iVarOut;
}
}
%fragment("SwigScilabDoubleFromUnsignedLong", "header") {
SWIGINTERN int
SwigScilabDoubleFromUnsignedLong(void *_pvApiCtx, int _iVarOut, unsigned long _ulValue) {
SWIG_From_dec(unsigned long)(unsigned long _ulValue) {
SciErr sciErr;
double dblDoubleValue = (double) _ulValue;
int iRowsOut = 1;
int iColsOut = 1;
int iVarOut = Rhs + SWIG_Scilab_GetOutputPosition();
sciErr = createMatrixOfDouble(_pvApiCtx, Rhs + _iVarOut, iRowsOut, iColsOut, &dblDoubleValue);
sciErr = createMatrixOfDouble(pvApiCtx, iVarOut, iRowsOut, iColsOut, &dblDoubleValue);
if (sciErr.iErr) {
printError(&sciErr, 0);
return SWIG_ERROR;
}
return Rhs + _iVarOut;
return iVarOut;
}
}

25
Lib/scilab/scirun.swg Normal file
View file

@ -0,0 +1,25 @@
/* Scilab function name management */
#include <stdlib.h>
static char* fname = NULL;
static char* SWIG_Scilab_GetFname(void) {
return fname;
}
static void SWIG_Scilab_SetFname(char* _fname) {
if (fname != NULL) {
free(fname);
}
fname = strdup(_fname);
}
/* Scilab output argument management */
static int outputPosition = -1;
static int SWIG_Scilab_GetOutputPosition(void) {
return outputPosition;
}
static int SWIG_Scilab_GetOutputPositionAndReset(void) {
int returnValue = outputPosition;
outputPosition = -1; /* Set as read */
return returnValue;
}
static void SWIG_Scilab_SetOutputPosition(int _outputPosition) {
outputPosition = _outputPosition;
}

View file

@ -1,5 +1,6 @@
%insert(runtime) "swigrun.swg";
%insert(runtime) "swigerrors.swg";
%insert(runtime) "scirun.swg";
// Error message will be displayed inside Scilab fragment functions
// and the following line Will not work because code is not an int
@ -24,11 +25,13 @@ extern "C" {
#undef Max
#undef Min
typedef int SciObject;
#define SWIG_fail return SWIG_ERROR;
#define SWIG_Error return SWIG_ERROR;
/* Used for C++ enums */
#define SWIG_AsVal_int(scilabValue, valuePointer) SWIG_SciDouble_AsInt(pvApiCtx, scilabValue, valuePointer, fname)
//#define SWIG_AsVal_int(scilabValue, valuePointer) SWIG_SciDouble_AsInt(pvApiCtx, scilabValue, valuePointer, fname)
SWIGINTERN int
SwigScilabPtrToObject(void *_pvApiCtx, int _iVar, void **_pObjValue, swig_type_info *_descriptor, int _flags, char *_fname) {
@ -163,15 +166,14 @@ SWIG_Scilab_NewMemberObj(void *_pvApiCtx, int _iVarOut, void *_ptr, int _sz, swi
return Rhs + _iVarOut;
}
#define SwigScilabSetOutput(outputNumber, outputPosition)\
{\
/* Create a temporary variable to avoid calling function given as outputPosition two times */\
int stackPosition = outputPosition;\
if (stackPosition < 0) {\
return SWIG_ERROR;\
}\
LhsVar(outputNumber) = stackPosition;\
return SWIG_OK; \
SWIGRUNTIME int
SWIG_Scilab_SetOutput(SciObject _output) {
int outputPosition = SWIG_Scilab_GetOutputPositionAndReset();
if (outputPosition < 0 || _output < 0) {
return SWIG_ERROR;
}
LhsVar(outputPosition) = _output;
return SWIG_OK;
}
#define SwigScilabRaise(OBJ, TYPE, DESC) Scierror(999, "C++ side threw an exception of type %s.\n", TYPE)
@ -184,4 +186,4 @@ return SWIG_OK; \
* -----------------------------------------------------------------------------*/
SWIGEXPORT int SWIG_init(void) {
%}
%}

View file

@ -2,14 +2,11 @@
* C-type: short
* Scilab type: double scalar
*/
%fragment(SWIG_AsVal_frag(short), "header", fragment="SWIG_SciDouble_AsShort") {
#define SWIG_AsVal_short(scilabValue, valuePointer) SWIG_SciDouble_AsShort(pvApiCtx, scilabValue, valuePointer, fname)
}
%fragment("SWIG_SciDouble_AsShort", "header", fragment="SWIG_SciDouble_AsInt") {
%fragment(SWIG_AsVal_frag(short), "header", fragment=SWIG_AsVal_frag(int)) {
SWIGINTERN int
SWIG_SciDouble_AsShort(void *_pvApiCtx, int _iVar, short *_pshValue, char *_fname) {
SWIG_AsVal_dec(short)(SciObject _iVar, short *_pshValue) {
int iValue = 0.0;
if(SWIG_SciDouble_AsInt(_pvApiCtx, _iVar, &iValue, _fname) != SWIG_OK) {
if(SWIG_AsVal_dec(int)(_iVar, &iValue) != SWIG_OK) {
return SWIG_ERROR;
}
*_pshValue = (short) iValue;
@ -17,14 +14,11 @@ SWIG_SciDouble_AsShort(void *_pvApiCtx, int _iVar, short *_pshValue, char *_fnam
}
}
%fragment(SWIG_From_frag(short), "header", fragment="SWIG_SciDouble_FromShort") {
#define SWIG_From_short(value) SWIG_SciDouble_FromShort(pvApiCtx, $result, value)
}
%fragment("SWIG_SciDouble_FromShort", "header", fragment="SWIG_SciDouble_FromInt") {
%fragment(SWIG_From_frag(short), "header", fragment=SWIG_From_frag(int)) {
SWIGINTERN int
SWIG_SciDouble_FromShort(void *_pvApiCtx, int _iVarOut, short _shValue) {
SWIG_From_dec(short)(short _shValue) {
int iValue = (int) _shValue;
return SWIG_SciDouble_FromInt(pvApiCtx, _iVarOut, iValue);
return SWIG_From_dec(int)(iValue);
}
}

231
Lib/scilab/scistdcommon.swg Normal file
View file

@ -0,0 +1,231 @@
// Based on Python implementation
%fragment("StdTraits","header",fragment="StdTraitsCommon")
{
namespace swig {
/*
Traits that provides the from method
*/
template <class Type> struct traits_from_ptr {
static SciObject from(Type *val, int owner = 0) {
return SWIG_InternalNewPointerObj(val, type_info<Type>(), owner);
}
};
template <class Type> struct traits_from {
static SciObject from(const Type& val) {
return traits_from_ptr<Type>::from(new Type(val), 1);
}
};
template <class Type> struct traits_from<Type *> {
static SciObject from(Type* val) {
return traits_from_ptr<Type>::from(val, 0);
}
};
template <class Type> struct traits_from<const Type *> {
static SciObject from(const Type* val) {
return traits_from_ptr<Type>::from(const_cast<Type*>(val), 0);
}
};
template <class Type>
inline SciObject from(const Type& val) {
return traits_from<Type>::from(val);
}
template <class Type>
inline SciObject from_ptr(Type* val, int owner) {
return traits_from_ptr<Type>::from(val, owner);
}
/*
Traits that provides the asval/as/check method
*/
template <class Type>
struct traits_asptr {
static int asptr(SciObject obj, Type **val) {
Type *p;
int res = SWIG_ConvertPtr(obj, (void**)&p, type_info<Type>(), 0);
if (SWIG_IsOK(res)) {
if (val) *val = p;
}
return res;
}
};
template <class Type>
inline int asptr(SciObject obj, Type **vptr) {
return traits_asptr<Type>::asptr(obj, vptr);
}
template <class Type>
struct traits_asval {
static int asval(SciObject obj, Type *val) {
if (val) {
Type *p = 0;
int res = traits_asptr<Type>::asptr(obj, &p);
if (!SWIG_IsOK(res)) return res;
if (p) {
typedef typename noconst_traits<Type>::noconst_type noconst_type;
*(const_cast<noconst_type*>(val)) = *p;
if (SWIG_IsNewObj(res)){
%delete(p);
res = SWIG_DelNewMask(res);
}
return res;
} else {
return SWIG_ERROR;
}
} else {
return traits_asptr<Type>::asptr(obj, (Type **)(0));
}
}
};
template <class Type> struct traits_asval<Type*> {
static int asval(SciObject obj, Type **val) {
if (val) {
typedef typename noconst_traits<Type>::noconst_type noconst_type;
noconst_type *p = 0;
int res = traits_asptr<noconst_type>::asptr(obj, &p);
if (SWIG_IsOK(res)) {
*(const_cast<noconst_type**>(val)) = p;
}
return res;
} else {
return traits_asptr<Type>::asptr(obj, (Type **)(0));
}
}
};
template <class Type>
inline int asval(SciObject obj, Type *val) {
return traits_asval<Type>::asval(obj, val);
}
template <class Type>
struct traits_as<Type, value_category> {
static Type as(SciObject obj, bool throw_error) {
Type v;
int res = asval(obj, &v);
if (!obj || !SWIG_IsOK(res)) {
// if (!PyErr_Occurred()) {
// ::%type_error(swig::type_name<Type>());
// }
if (throw_error) throw std::invalid_argument("bad type");
}
return v;
}
};
template <class Type>
struct traits_as<Type, pointer_category> {
static Type as(SciObject obj, bool throw_error) {
Type *v = 0;
int res = (obj ? traits_asptr<Type>::asptr(obj, &v) : SWIG_ERROR);
if (SWIG_IsOK(res) && v) {
if (SWIG_IsNewObj(res)) {
Type r(*v);
%delete(v);
return r;
} else {
return *v;
}
} else {
// Uninitialized return value, no Type() constructor required.
static Type *v_def = (Type*) malloc(sizeof(Type));
// if (!PyErr_Occurred()) {
// %type_error(swig::type_name<Type>());
// }
if (throw_error) throw std::invalid_argument("bad type");
memset(v_def,0,sizeof(Type));
return *v_def;
}
}
};
template <class Type>
struct traits_as<Type*, pointer_category> {
static Type* as(SciObject obj, bool throw_error) {
Type *v = 0;
int res = (obj ? traits_asptr<Type>::asptr(obj, &v) : SWIG_ERROR);
if (SWIG_IsOK(res)) {
return v;
} else {
// if (!PyErr_Occurred()) {
// %type_error(swig::type_name<Type>());
// }
if (throw_error) throw std::invalid_argument("bad type");
return 0;
}
}
};
template <class Type>
inline Type as(SciObject obj, bool te = false) {
return traits_as<Type, typename traits<Type>::category>::as(obj, te);
}
template <class Type>
struct traits_check<Type, value_category> {
static bool check(SciObject obj) {
int res = obj ? asval(obj, (Type *)(0)) : SWIG_ERROR;
return SWIG_IsOK(res) ? true : false;
}
};
template <class Type>
struct traits_check<Type, pointer_category> {
static bool check(SciObject obj) {
int res = obj ? asptr(obj, (Type **)(0)) : SWIG_ERROR;
return SWIG_IsOK(res) ? true : false;
}
};
template <class Type>
inline bool check(SciObject obj) {
return traits_check<Type, typename traits<Type>::category>::check(obj);
}
}
}
%define %specialize_std_container(Type,Check,As,From)
%{
namespace swig {
template <> struct traits_asval<Type > {
typedef Type value_type;
static int asval(SciObject obj, value_type *val) {
if (Check(obj)) {
if (val) *val = As(obj);
return SWIG_OK;
}
return SWIG_ERROR;
}
};
template <> struct traits_from<Type > {
typedef Type value_type;
static SciObject from(const value_type& val) {
return From(val);
}
};
template <>
struct traits_check<Type, value_category> {
static int check(SciObject obj) {
int res = Check(obj);
return obj && res ? res : 0;
}
};
}
%}
%enddef
#define specialize_std_vector(Type,Check,As,From) %specialize_std_container(%arg(Type),Check,As,From)
#define specialize_std_list(Type,Check,As,From) %specialize_std_container(%arg(Type),Check,As,From)
#define specialize_std_deque(Type,Check,As,From) %specialize_std_container(%arg(Type),Check,As,From)
#define specialize_std_set(Type,Check,As,From) %specialize_std_container(%arg(Type),Check,As,From)
#define specialize_std_multiset(Type,Check,As,From) %specialize_std_container(%arg(Type),Check,As,From)

View file

@ -10,12 +10,12 @@
// In Scilab, returning void is ignored (no typemap associated)
//#define VOID_Object ScilabObject
#define %append_output(obj) SwigScilabSetOutput($result, obj)
#define %set_constant(name, obj) SwigScilabSetOutput($result, obj) // Name is managed by the the function name
#define %append_output(obj) if (!SWIG_IsOK(SWIG_Scilab_SetOutput(obj))) return SWIG_ERROR
#define %set_constant(name, obj) if (!SWIG_IsOK(SWIG_Scilab_SetOutput(obj))) return SWIG_ERROR // Name is managed by the the function name
#define %raise(obj, type, desc) SwigScilabRaise(obj, type, desc)
#define %set_output(obj) SwigScilabSetOutput($result, obj);
#define %set_varoutput(obj) SwigScilabSetOutput($result, obj);
#define %set_argoutput(obj) SwigScilabSetOutput($result, obj);
#define %set_output(obj) if (!SWIG_IsOK(SWIG_Scilab_SetOutput(obj))) return SWIG_ERROR
#define %set_varoutput(obj) if (!SWIG_IsOK(SWIG_Scilab_SetOutput(obj))) return SWIG_ERROR
#define %set_argoutput(obj) if (!SWIG_IsOK(SWIG_Scilab_SetOutput(obj))) return SWIG_ERROR
// Include the unified typemap library
%include <typemaps/swigtypemaps.swg>
@ -123,7 +123,7 @@
/**************/
%scilab_asarrayandsize_withcopy(varin, SWIG_SciDouble_AsDoubleArrayAndSize, double[ANY], double);
%typemap(varout, noblock=1, fragment="SWIG_SciDouble_FromDoubleArrayAndSize") double[ANY] {
%set_output(SWIG_SciDouble_FromDoubleArrayAndSize(pvApiCtx, $result, 1, $1_dim0, $1))
%set_output(SWIG_SciDouble_FromDoubleArrayAndSize(pvApiCtx, $result, 1, $1_dim0, $1));
}
%apply SWIGTYPE[] { double[] }; /* double[] variables managed as pointers */
%scilab_asarray_withcopy(in, SWIG_SciDouble_AsDoubleArrayAndSize, double[], double);
@ -147,10 +147,10 @@
}
%scilab_asarrayandsize_withcopy(varin, SWIG_SciInt8_AsSignedCharArrayAndSize, signed char[ANY], signed char);
%typemap(varout, noblock=1, fragment="SWIG_SciInt8_FromSignedCharArrayAndSize") signed char[ANY] {
%set_output(SWIG_SciInt8_FromSignedCharArrayAndSize(pvApiCtx, $result, 1, $1_dim0, $1))
%set_output(SWIG_SciInt8_FromSignedCharArrayAndSize(pvApiCtx, $result, 1, $1_dim0, $1));
}
%typemap(varout, noblock=1, fragment="SWIG_SciInt8_FromSignedCharArrayAndSize") signed char[] {
%set_output(SWIG_SciInt8_FromSignedCharArrayAndSize(pvApiCtx, $result, 1, strlen((const char*)$1), $1))
%set_output(SWIG_SciInt8_FromSignedCharArrayAndSize(pvApiCtx, $result, 1, strlen((const char*)$1), $1));
}
/*********************/
@ -173,10 +173,10 @@
%scilab_asarrayandsize_withcopy(varin, SWIG_SciUint8_AsUnsignedCharArrayAndSize, unsigned char[ANY], unsigned char);
%typemap(varout, noblock=1, fragment="SWIG_SciUint8_FromUnsignedCharArrayAndSize") unsigned char[ANY] {
%set_output(SWIG_SciUint8_FromUnsignedCharArrayAndSize(pvApiCtx, $result, 1, $1_dim0, $1))
%set_output(SWIG_SciUint8_FromUnsignedCharArrayAndSize(pvApiCtx, $result, 1, $1_dim0, $1));
}
%typemap(varout, noblock=1, fragment="SWIG_SciUint8_FromUnsignedCharArrayAndSize") unsigned char[] {
%set_output(SWIG_SciUint8_FromUnsignedCharArrayAndSize(pvApiCtx, $result, 1, strlen((const char*)$1), $1))
%set_output(SWIG_SciUint8_FromUnsignedCharArrayAndSize(pvApiCtx, $result, 1, strlen((const char*)$1), $1));
}
/*************/
@ -184,7 +184,7 @@
/*************/
%scilab_asarrayandsize_withcopy(varin, SWIG_SciInt16_AsShortArrayAndSize, short[ANY], short);
%typemap(varout, noblock=1, fragment="SWIG_SciInt16_FromShortArrayAndSize") short[ANY] {
%set_output(SWIG_SciInt16_FromShortArrayAndSize(pvApiCtx, $result, 1, $1_dim0, $1))
%set_output(SWIG_SciInt16_FromShortArrayAndSize(pvApiCtx, $result, 1, $1_dim0, $1));
}
%apply SWIGTYPE[] { short[] }; /* short[] variables managed as pointers */
%scilab_asarray_withcopy(in, SWIG_SciInt16_AsShortArrayAndSize, short[], short);
@ -196,7 +196,7 @@
/**********************/
%scilab_asarrayandsize_withcopy(varin, SWIG_SciUint16_AsUnsignedShortArrayAndSize, unsigned short[ANY], unsigned short);
%typemap(varout, noblock=1, fragment="SWIG_SciUint16_FromUnsignedShortArrayAndSize") unsigned short[ANY] {
%set_output(SWIG_SciUint16_FromUnsignedShortArrayAndSize(pvApiCtx, $result, 1, $1_dim0, $1))
%set_output(SWIG_SciUint16_FromUnsignedShortArrayAndSize(pvApiCtx, $result, 1, $1_dim0, $1));
}
%apply SWIGTYPE[] { unsigned short[] }; /* unsigned short[] variables managed as pointers */
%scilab_asarray_withcopy(in, SWIG_SciUint16_AsUnsignedShortArrayAndSize, unsigned short[], unsigned short);
@ -206,7 +206,7 @@
/***********/
%scilab_asarrayandsize_withcopy(varin, SWIG_SciInt32_AsIntArrayAndSize, int[ANY], int);
%typemap(varout, noblock=1, fragment="SWIG_SciInt32_FromIntArrayAndSize") int[ANY] {
%set_output(SWIG_SciInt32_FromIntArrayAndSize(pvApiCtx, $result, 1, $1_dim0, $1))
%set_output(SWIG_SciInt32_FromIntArrayAndSize(pvApiCtx, $result, 1, $1_dim0, $1));
}
%apply SWIGTYPE[] { int[] }; /* int[] variables managed as pointers */
%scilab_asarray_withcopy(in, SWIG_SciInt32_AsIntArrayAndSize, int[], int);
@ -216,7 +216,7 @@
/********************/
%scilab_asarrayandsize_withcopy(varin, SWIG_SciUint32_AsUnsignedIntArrayAndSize, unsigned int[ANY], unsigned int);
%typemap(varout, noblock=1, fragment="SWIG_SciUint32_FromUnsignedIntArrayAndSize") unsigned int[ANY] {
%set_output(SWIG_SciUint32_FromUnsignedIntArrayAndSize(pvApiCtx, $result, 1, $1_dim0, $1))
%set_output(SWIG_SciUint32_FromUnsignedIntArrayAndSize(pvApiCtx, $result, 1, $1_dim0, $1));
}
%apply SWIGTYPE[] { unsigned int[] }; /* unsigned int[] variables managed as pointers */
%scilab_asarray_withcopy(in, SWIG_SciUint32_AsUnsignedIntArrayAndSize, unsigned int[], unsigned int);
@ -226,7 +226,7 @@
/*************/
%scilab_asarrayandsize_withcopy(varin, SWIG_SciDouble_AsDoubleArrayAndSize, float[ANY], double);
%typemap(varout, noblock=1, fragment="SWIG_SciDouble_FromDoubleArrayAndSize") float[ANY] {
%set_output(SWIG_SciDouble_FromDoubleArrayAndSize(pvApiCtx, $result, 1, $1_dim0, (double*) $1))
%set_output(SWIG_SciDouble_FromDoubleArrayAndSize(pvApiCtx, $result, 1, $1_dim0, (double*) $1));
}
%apply SWIGTYPE[] { float[] }; /* float[] variables managed as pointers */
%scilab_asarray_withcopy(in, SWIG_SciDouble_AsDoubleArrayAndSize, float[], double);
@ -242,7 +242,7 @@
/************/
%scilab_asarrayandsize_withcopy(varin, SWIG_SciDouble_AsDoubleArrayAndSize, long[ANY], double);
%typemap(varout, noblock=1, fragment="SWIG_SciDouble_FromDoubleArrayAndSize") long[ANY] {
%set_output(SWIG_SciDouble_FromDoubleArrayAndSize(pvApiCtx, $result, 1, $1_dim0, (double*) $1))
%set_output(SWIG_SciDouble_FromDoubleArrayAndSize(pvApiCtx, $result, 1, $1_dim0, (double*) $1));
}
%apply SWIGTYPE[] { long[] }; /* long[] variables managed as pointers */
%scilab_asarray_withcopy(in, SWIG_SciDouble_AsDoubleArrayAndSize, long[], double);
@ -252,7 +252,7 @@
/*********************/
%scilab_asarrayandsize_withcopy(varin, SWIG_SciDouble_AsDoubleArrayAndSize, unsigned long[ANY], double);
%typemap(varout, noblock=1, fragment="SWIG_SciDouble_FromDoubleArrayAndSize") unsigned long[ANY] {
%set_output(SWIG_SciDouble_FromDoubleArrayAndSize(pvApiCtx, $result, 1, $1_dim0, (double*) $1))
%set_output(SWIG_SciDouble_FromDoubleArrayAndSize(pvApiCtx, $result, 1, $1_dim0, (double*) $1));
}
%apply SWIGTYPE[] { unsigned long[] }; /* long[] variables managed as pointers */
%scilab_asarray_withcopy(in, SWIG_SciDouble_AsDoubleArrayAndSize, unsigned long[], double);
@ -368,4 +368,4 @@
%typecheck(SWIG_TYPECHECK_BOOL_ARRAY) bool { SCILAB_TYPECHECK(isBooleanType) }
%typecheck(SWIG_TYPECHECK_STRING_ARRAY) char ** { SCILAB_TYPECHECK(isStringType) }
%apply int { size_t };
//%apply int { size_t };

View file

@ -1,2 +1,45 @@
%include <std/std_common.i>
// Based on Python implementation
%include <std/std_except.i>
%include <scistdcommon.swg>
/*
Generate the traits for a 'primitive' type, such as 'double',
for which the SWIG_AsVal and SWIG_From methods are already defined.
*/
%define %traits_ptypen(Type...)
%fragment(SWIG_Traits_frag(Type),"header",
fragment=SWIG_AsVal_frag(Type),
fragment=SWIG_From_frag(Type),
fragment="StdTraits") {
namespace swig {
template <> struct traits<Type > {
typedef value_category category;
static const char* type_name() { return #Type; }
};
template <> struct traits_asval<Type > {
typedef Type value_type;
static int asval(SciObject obj, value_type *val) {
return SWIG_AsVal(Type)(obj, val);
}
};
template <> struct traits_from<Type > {
typedef Type value_type;
static SciObject from(const value_type& val) {
return SWIG_From(Type)(val);
}
};
}
}
%enddef
%include <std/std_common.i>
//
// Generates the traits for all the known primitive
// C++ types (int, double, ...)
//
%apply_cpptypes(%traits_ptypen);

View file

@ -1,22 +1,14 @@
/*
* POINTER
*/
%fragment(SWIG_AsPtr_frag(std::string), "header", fragment="SwigScilabStringToString") {
#define SWIG_AsPtr_std_string(scilabValue, stringPointer) SwigScilabStringToString(pvApiCtx, scilabValue, stringPointer, fname)
}
%fragment(SWIG_From_frag(std::string), "header", fragment="SwigScilabStringFromString") {
#define SWIG_From_std_string(stringPointer) SwigScilabStringFromString(pvApiCtx, $result, stringPointer)
}
%fragment("SwigScilabStringToString", "header", fragment="SwigScilabStringToCharPtrAndSize") {
%fragment(SWIG_AsPtr_frag(std::string), "header", fragment="SwigScilabStringToCharPtrAndSize") {
SWIGINTERN int
SwigScilabStringToString(void *_pvApiCtx, int _iVar, std::string **_pstValue, char *_fname) {
SWIG_AsPtr_dec(std::string)(int _iVar, std::string **_pstValue) {
char* buf = 0;
size_t size = 0;
int alloc = SWIG_OLDOBJ;
if (SWIG_IsOK((SwigScilabStringToCharPtrAndSize(_pvApiCtx, _iVar, &buf, &size, &alloc, _fname)))) {
if (SWIG_IsOK((SwigScilabStringToCharPtrAndSize(pvApiCtx, _iVar, &buf, &size, &alloc, SWIG_Scilab_GetFname())))) {
if (buf) {
if (_pstValue) {
*_pstValue = new std::string(buf, size);
@ -37,10 +29,10 @@ SwigScilabStringToString(void *_pvApiCtx, int _iVar, std::string **_pstValue, ch
}
}
%fragment("SwigScilabStringFromString", "header", fragment="SwigScilabStringFromCharPtrAndSize") {
%fragment(SWIG_From_frag(std::string), "header", fragment="SwigScilabStringFromCharPtrAndSize") {
SWIGINTERN int
SwigScilabStringFromString(void *_pvApiCtx, int _iVarOut, std::string _pstValue) {
return SwigScilabStringFromCharPtrAndSize(_pvApiCtx, _iVarOut, _pstValue.c_str());
SWIG_From_dec(std::string)(std::string _pstValue) {
return SwigScilabStringFromCharPtrAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), _pstValue.c_str());
}
}

View file

@ -1,84 +1,10 @@
// Vectors
%fragment("StdVectorTraits","header")
%{
#include <vector>
%}
namespace std {
template<class T> class vector {
%define SCILAB_STD_VECTOR_IN(T, TYPECHECKINGFUNCTION, TEMPTYPE, READFUNCTIONNAME)
%typemap(in) vector<T> {
SciErr sciErr;
int *piAddrVar = NULL;
int *piChild = NULL;
int iType = 0;
int iNumberOfItem = 0;
TEMPTYPE *tempValue = NULL;
int iRows = 0;
int iCols = 0;
sciErr = getVarAddressFromPosition(pvApiCtx, $input, &piAddrVar);
if (sciErr.iErr) {
printError(&sciErr, 0);
return SWIG_ERROR;
}
/* Check input type */
sciErr = getVarType(pvApiCtx, piAddrVar, &iType);
if (sciErr.iErr) {
printError(&sciErr, 0);
return SWIG_ERROR;
}
if (iType != sci_list) {
Scierror(999, _("%s: Wrong type for input argument #%d: A list expected.\n"), fname, $argnum);
return 0;
}
/* Get list size */
sciErr = getListItemNumber(pvApiCtx, piAddrVar, &iNumberOfItem);
if(sciErr.iErr) {
printError(&sciErr, 0);
return SWIG_ERROR;
}
$1 = std::vector<T>(iNumberOfItem);
for (unsigned int i=0; i<iNumberOfItem; i++) {
sciErr = getListItemAddress(pvApiCtx, piAddrVar, i + 1, &piChild);
if(sciErr.iErr) {
printError(&sciErr, 0);
return SWIG_ERROR;
}
if (!TYPECHECKINGFUNCTION(pvApiCtx, piChild)) {
Scierror(999, _("%s: Wrong type for item #%d: A real scalar expected.\n"), fname, i + 1);
return 0;
}
sciErr = READFUNCTIONNAME(pvApiCtx, piAddrVar, i + 1, &iRows, &iCols, &tempValue);
if(sciErr.iErr) {
printError(&sciErr, 0);
return SWIG_ERROR;
}
if (iRows * iCols != 1) {
Scierror(999, _("%s: Wrong size for item #%d: A real scalar expected.\n"), fname, i + 1);
return 0;
}
(($1_type &)$1)[i] = (T)*tempValue;
}
}
%enddef
%typemap(out) vector<T>* {
/* %typemap(out) vector<T>* */
SciErr sciErr;
int *piAddrVar = NULL;
sciErr = createList(pvApiCtx, Rhs + $result, 0, &piAddrVar);
if(sciErr.iErr) {
printError(&sciErr, 0);
return SWIG_ERROR;
}
SwigScilabSetOutput(1, Rhs + $result);
}
SCILAB_STD_VECTOR_IN(double, isDoubleType, double, getMatrixOfDoubleInList);
SCILAB_STD_VECTOR_IN(int, isDoubleType, double, getMatrixOfDoubleInList);
};
}
#define %swig_vector_methods(Type...) %swig_sequence_methods(Type)
#define %swig_vector_methods_val(Type...) %swig_sequence_methods_val(Type);
%include <std/std_vector.i>

View file

@ -49,8 +49,8 @@ or you can use the %apply directive :
double fadd(double *a, double *b);
*/
%typemap(in, noblock=1, fragment="SWIG_SciDouble_AsInt") int *INPUT(int temp), int &INPUT(int temp) {
if (SWIG_SciDouble_AsInt(pvApiCtx, $input, &temp, fname) != SWIG_OK) {
%typemap(in, noblock=1, fragment=SWIG_AsVal_frag(int)) int *INPUT(int temp), int &INPUT(int temp) {
if (SWIG_AsVal_dec(int)($input, &temp) != SWIG_OK) {
SWIG_fail;
}
$1 = &temp;
@ -65,8 +65,8 @@ or you can use the %apply directive :
//unsigned char *INPUT
//bool *INPUT
//float *INPUT
%typemap(in, noblock=1, fragment="SWIG_SciDouble_AsDouble") double *INPUT(double temp), double &INPUT(double temp) {
if (SWIG_SciDouble_AsDouble(pvApiCtx, $input, &temp, fname) != SWIG_OK) {
%typemap(in, noblock=1, fragment=SWIG_AsVal_frag(double)) double *INPUT(double temp), double &INPUT(double temp) {
if (SWIG_AsVal_dec(double)($input, &temp) != SWIG_OK) {
SWIG_fail;
}
$1 = &temp;
@ -119,8 +119,8 @@ output values.
*/
%typemap(argout, noblock=1, fragment="SWIG_SciDouble_FromInt") int *OUTPUT, int &OUTPUT {
SwigScilabSetOutput($result, SWIG_SciDouble_FromInt(pvApiCtx, $result, *$1));
%typemap(argout, noblock=1, fragment=SWIG_From_frag(int)) int *OUTPUT, int &OUTPUT {
%set_output(SWIG_From_dec(int)(*$1));
}
//short *OUTPUT
//long *OUTPUT
@ -133,8 +133,8 @@ output values.
//bool *OUTPUT
//float *OUTPUT
//double *OUTPUT
%typemap(argout, noblock=1, fragment="SWIG_SciDouble_FromDouble") double *OUTPUT, double &OUTPUT {
SwigScilabSetOutput($result, SWIG_SciDouble_FromDouble(pvApiCtx, $result, *$1));
%typemap(argout, noblock=1, fragment=SWIG_From_frag(double)) double *OUTPUT, double &OUTPUT {
%set_output(SWIG_From_dec(double)(*$1));
}
// INOUT

View file

@ -258,6 +258,7 @@ public:
/* Insert calls to CheckRhs and CheckLhs */
Printf(wrapper->code, "CheckRhs($mininputarguments, $maxinputarguments);\n");
Printf(wrapper->code, "CheckLhs($minoutputarguments, $maxoutputarguments);\n");
Printf(wrapper->code, "SWIG_Scilab_SetFname(fname);\n");
for (paramIndex = 0, param = functionParamsList; paramIndex < maxInputArguments; ++paramIndex) {
@ -312,6 +313,9 @@ public:
String *functionReturnTypemap = Swig_typemap_lookup_out("out", node, "result", wrapper, functionActionCode);
if (functionReturnTypemap) {
// Result is actually the position of output value on stack
if (Len(functionReturnTypemap) > 0) {
Printf(wrapper->code, "SWIG_Scilab_SetOutputPosition(%d); /* functionReturnTypemap */ \n", 1);
}
Replaceall(functionReturnTypemap, "$result", "1");
if (GetFlag(node, "feature:new")) {
@ -340,6 +344,7 @@ public:
if (paramTypemap) {
minOutputArguments++;
maxOutputArguments++;
Printf(wrapper->code, "SWIG_Scilab_SetOutputPosition(%d); /* paramTypemap */ \n", minOutputArguments);
char result[64] = {};
sprintf(result, "%d", minOutputArguments);
Replaceall(paramTypemap, "$result", result);
@ -353,7 +358,7 @@ public:
/* Add cleanup code */
/* Close the function(ok) */
Printv(wrapper->code, "return 0;\n", NIL);
Printv(wrapper->code, "return SWIG_OK;\n", NIL);
Printv(wrapper->code, "}\n", NIL);
/* Add the failure cleanup code */
@ -426,7 +431,7 @@ public:
/* Dump the dispatch function */
Printv(wrapper->code, dispatch, "\n", NIL);
Printf(wrapper->code, "Scierror(999, _(\"No matching function for overload\"));\n");
Printf(wrapper->code, "return 0;\n");
Printf(wrapper->code, "return SWIG_OK;\n");
Printv(wrapper->code, "}\n", NIL);
Wrapper_print(wrapper, wrappersSection);
@ -458,11 +463,13 @@ public:
String *varoutTypemap = Swig_typemap_lookup("varout", node, origVariableName, 0);
if (varoutTypemap != NULL) {
Printf(getFunctionWrapper->code, "SWIG_Scilab_SetOutputPosition(%d); /* varoutTypemap */ \n", 1);
Replaceall(varoutTypemap, "$value", origVariableName);
Replaceall(varoutTypemap, "$result", "1");
emit_action_code(node, getFunctionWrapper->code, varoutTypemap);
Delete(varoutTypemap);
}
Append(getFunctionWrapper->code, "return SWIG_OK;\n");
Append(getFunctionWrapper->code, "}\n");
Wrapper_print(getFunctionWrapper, wrappersSection);
@ -487,6 +494,7 @@ public:
emit_action_code(node, setFunctionWrapper->code, varinTypemap);
Delete(varinTypemap);
}
Append(setFunctionWrapper->code, "return SWIG_OK;\n");
Append(setFunctionWrapper->code, "}\n");
Wrapper_print(setFunctionWrapper, wrappersSection);
@ -520,6 +528,7 @@ public:
constantTypemap = Swig_typemap_lookup("constcode", node, nodeName, 0);
if (constantTypemap != NULL) {
Printf(getFunctionWrapper->code, "SWIG_Scilab_SetOutputPosition(%d); /* constantTypemap */ \n", 1);
Replaceall(constantTypemap, "$value", constantValue);
Replaceall(constantTypemap, "$result", "1");
emit_action_code(node, getFunctionWrapper->code, constantTypemap);
@ -527,6 +536,7 @@ public:
}
/* Dump the wrapper function */
Append(getFunctionWrapper->code, "return SWIG_OK;\n");
Append(getFunctionWrapper->code, "}\n");
Wrapper_print(getFunctionWrapper, wrappersSection);