Scilab: generic support for STL containers.
STL containers are mapped in Scilab as: - for int, double, string: matrices (of int, or double, etc....) - for other types (like pointers on objects): list of pointers
This commit is contained in:
parent
1b26ad8b21
commit
cdb6554fba
7 changed files with 771 additions and 246 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
* scicontainer.swg
|
* scicontainer.swg
|
||||||
*
|
*
|
||||||
* Scilab list <-> C++ container wrapper (Based on Octave wrapper)
|
* Scilab list <-> C++ container wrapper
|
||||||
*
|
*
|
||||||
* This wrapper, and its iterator, allows a general use (and reuse) of
|
* This wrapper, and its iterator, allows a general use (and reuse) of
|
||||||
* the mapping between C++ and Scilab, thanks to the C++ templates.
|
* the mapping between C++ and Scilab, thanks to the C++ templates.
|
||||||
|
|
@ -15,177 +15,32 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
|
||||||
#if !defined(SWIG_NO_EXPORT_ITERATOR_METHODS)
|
#if !defined(SWIG_NO_EXPORT_ITERATOR_METHODS)
|
||||||
# if !defined(SWIG_EXPORT_ITERATOR_METHODS)
|
# if !defined(SWIG_EXPORT_ITERATOR_METHODS)
|
||||||
# define SWIG_EXPORT_ITERATOR_METHODS SWIG_EXPORT_ITERATOR_METHODS
|
# define SWIG_EXPORT_ITERATOR_METHODS SWIG_EXPORT_ITERATOR_METHODS
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
// #define (SWIG_SCILAB_EXTRA_NATIVE_CONTAINERS)
|
||||||
|
// if defined: sequences in return are converted from/to Scilab lists or matrices
|
||||||
|
// if not defined: sequences are passed from/to Scilab as pointers
|
||||||
|
|
||||||
|
%{
|
||||||
|
#define SWIG_STD_NOASSIGN_STL
|
||||||
|
%}
|
||||||
|
|
||||||
%include <sciiterators.swg>
|
%include <sciiterators.swg>
|
||||||
|
%include <scisequence.swg>
|
||||||
|
|
||||||
// The Scilab C++ Wrap
|
%{
|
||||||
|
|
||||||
%insert(header) %{
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
%}
|
%}
|
||||||
|
|
||||||
%include <std_except.i>
|
%include <std_except.i>
|
||||||
|
|
||||||
%fragment(SWIG_Traits_frag(SciObject),"header",fragment="StdTraits") {
|
|
||||||
namespace swig {
|
|
||||||
template <> struct traits<SciObject > {
|
|
||||||
typedef value_category category;
|
|
||||||
static const char* type_name() { return "SciObject"; }
|
|
||||||
};
|
|
||||||
|
|
||||||
template <> struct traits_from<SciObject> {
|
|
||||||
typedef SciObject value_type;
|
|
||||||
static SciObject from(const value_type& val) {
|
|
||||||
return val;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <>
|
|
||||||
struct traits_check<SciObject, value_category> {
|
|
||||||
static bool check(const SciObject&) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <> struct traits_asval<SciObject > {
|
|
||||||
typedef SciObject value_type;
|
|
||||||
static int asval(const SciObject& obj, value_type *val) {
|
|
||||||
if (val) *val = obj;
|
|
||||||
return SWIG_OK;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
%fragment("SciSequence_Base","header",fragment="<stddef.h>")
|
|
||||||
{
|
|
||||||
%#include <functional>
|
|
||||||
|
|
||||||
namespace std {
|
|
||||||
template <>
|
|
||||||
struct less <SciObject>: public binary_function<SciObject, SciObject, bool>
|
|
||||||
{
|
|
||||||
bool
|
|
||||||
operator()(const SciObject& v, const SciObject& w) const
|
|
||||||
{
|
|
||||||
//SciObject res = do_binary_op(SciObject::op_le,v,w);
|
|
||||||
return true;//res.is_true();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
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) {
|
|
||||||
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("SciSequence_Cont", "header",
|
%fragment("SciSequence_Cont", "header",
|
||||||
fragment="StdTraits",
|
fragment="StdTraits",
|
||||||
fragment="SciSequence_Base",
|
|
||||||
fragment="SciSwigIterator_T")
|
fragment="SciSwigIterator_T")
|
||||||
{
|
{
|
||||||
%#include <stdio.h>
|
%#include <stdio.h>
|
||||||
|
|
@ -193,43 +48,46 @@ namespace swig {
|
||||||
namespace swig
|
namespace swig
|
||||||
{
|
{
|
||||||
template <class T>
|
template <class T>
|
||||||
struct SciSequence_Ref // * Scilab can't support these, because of how assignment works
|
struct SciSequence_Ref
|
||||||
{
|
{
|
||||||
SciSequence_Ref(const SciObject& seq, int index)
|
SciSequence_Ref(const SciObject& seq, int index)
|
||||||
: _seq(seq), _index(index)
|
: _seq(seq), _index(index)
|
||||||
{
|
{
|
||||||
|
if (traits_as_sequence<T>::get(_seq, &_piSeqAddr) != SWIG_OK)
|
||||||
|
{
|
||||||
|
throw std::invalid_argument("Cannot getl sequence data.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
operator T () const
|
operator T () const
|
||||||
{
|
{
|
||||||
// swig::SwigVar_PyObject item = SciSequence_GetItem(_seq, _index);
|
try
|
||||||
SciObject item; // * todo
|
{
|
||||||
try {
|
T value;
|
||||||
return swig::as<T>(item, true);
|
if (traits_asval_sequenceitem<T>::asval(_seq, _piSeqAddr, _index, &value) == SWIG_OK)
|
||||||
} catch (std::exception& e) {
|
{
|
||||||
char msg[1024];
|
return value;
|
||||||
sprintf(msg, "in sequence element %d ", _index);
|
|
||||||
if (!Scilab_Error_Occurred()) {
|
|
||||||
%type_error(swig::type_name<T>());
|
|
||||||
}
|
}
|
||||||
SWIG_Scilab_AddErrorMsg(msg);
|
}
|
||||||
|
catch (std::exception& e)
|
||||||
|
{
|
||||||
SWIG_Scilab_AddErrorMsg(e.what());
|
SWIG_Scilab_AddErrorMsg(e.what());
|
||||||
throw;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SciSequence_Ref& operator=(const T& v)
|
SciSequence_Ref& operator=(const T& v)
|
||||||
{
|
{
|
||||||
// SciSequence_SetItem(_seq, _index, swig::from<T>(v));
|
// TODO
|
||||||
// * todo
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SciObject _seq;
|
SciObject _seq;
|
||||||
int _index;
|
int _index;
|
||||||
|
void *_piSeqAddr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
struct SciSequence_ArrowProxy
|
struct SciSequence_ArrowProxy
|
||||||
{
|
{
|
||||||
|
|
@ -349,14 +207,6 @@ namespace swig
|
||||||
|
|
||||||
SciSequence_Cont(const SciObject& seq) : _seq(seq)
|
SciSequence_Cont(const SciObject& seq) : _seq(seq)
|
||||||
{
|
{
|
||||||
// * assert that we have map type etc.
|
|
||||||
/*
|
|
||||||
if (!SciSequence_Check(seq)) {
|
|
||||||
throw std::invalid_argument("a sequence is expected");
|
|
||||||
}
|
|
||||||
_seq = seq;
|
|
||||||
Py_INCREF(_seq);
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
~SciSequence_Cont()
|
~SciSequence_Cont()
|
||||||
|
|
@ -365,8 +215,15 @@ namespace swig
|
||||||
|
|
||||||
size_type size() const
|
size_type size() const
|
||||||
{
|
{
|
||||||
// return static_cast<size_type>(SciSequence_Size(_seq));
|
int iSeqSize;
|
||||||
return 0; // * todo
|
if (traits_as_sequence<value_type>::size(_seq, &iSeqSize) == SWIG_OK)
|
||||||
|
{
|
||||||
|
return iSeqSize;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool empty() const
|
bool empty() const
|
||||||
|
|
@ -404,28 +261,9 @@ namespace swig
|
||||||
return const_reference(_seq, n);
|
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 = SciSequence_GetItem(_seq, i);
|
|
||||||
SciObject item; // * todo
|
|
||||||
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:
|
private:
|
||||||
SciObject _seq;
|
SciObject _seq;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -491,30 +329,6 @@ namespace swig
|
||||||
%swig_sequence_iterator(%arg(Sequence))
|
%swig_sequence_iterator(%arg(Sequence))
|
||||||
%swig_container_methods(%arg(Sequence))
|
%swig_container_methods(%arg(Sequence))
|
||||||
|
|
||||||
%fragment("SciSequence_Base");
|
|
||||||
|
|
||||||
%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;
|
|
||||||
}
|
|
||||||
|
|
||||||
value_type __paren__(difference_type i) throw (std::out_of_range) {
|
|
||||||
return *(swig::cgetpos(self, i));
|
|
||||||
}
|
|
||||||
|
|
||||||
void __paren_asgn__(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
|
%enddef
|
||||||
|
|
||||||
%define %swig_sequence_methods(Sequence...)
|
%define %swig_sequence_methods(Sequence...)
|
||||||
|
|
@ -531,20 +345,21 @@ namespace swig
|
||||||
|
|
||||||
%fragment("StdSequenceTraits","header",
|
%fragment("StdSequenceTraits","header",
|
||||||
fragment="StdTraits",
|
fragment="StdTraits",
|
||||||
fragment="SciSequence_Cont")
|
fragment="SciSequence_Cont",
|
||||||
|
fragment=SWIG_Traits_SequenceItem_frag(ptr))
|
||||||
{
|
{
|
||||||
namespace swig {
|
namespace swig {
|
||||||
template <class SciSeq, class Seq>
|
template <class SciSeq, class Seq>
|
||||||
inline void
|
inline void
|
||||||
assign(const SciSeq& sciseq, Seq* seq) {
|
assign(const SciSeq& sciSeq, Seq* seq) {
|
||||||
%#ifdef SWIG_STD_NOASSIGN_STL
|
%#ifdef SWIG_STD_NOASSIGN_STL
|
||||||
typedef typename SciSeq::value_type value_type;
|
typedef typename SciSeq::value_type value_type;
|
||||||
typename SciSeq::const_iterator it = sciseq.begin();
|
typename SciSeq::const_iterator it = sciSeq.begin();
|
||||||
for (;it != sciseq.end(); ++it) {
|
for (;it != sciSeq.end(); ++it) {
|
||||||
seq->insert(seq->end(),(value_type)(*it));
|
seq->insert(seq->end(),(value_type)(*it));
|
||||||
}
|
}
|
||||||
%#else
|
%#else
|
||||||
seq->assign(sciseq.begin(), sciseq.end());
|
seq->assign(sciSeq.begin(), sciSeq.end());
|
||||||
%#endif
|
%#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -553,9 +368,41 @@ namespace swig {
|
||||||
typedef Seq sequence;
|
typedef Seq sequence;
|
||||||
typedef T value_type;
|
typedef T value_type;
|
||||||
|
|
||||||
static int asptr(const SciObject& obj, sequence **seq) {
|
static int asptr(const SciObject& obj, sequence **seq)
|
||||||
// TODO: convert input Scilab list (or pointer) to sequence.
|
{
|
||||||
return SWIG_ERROR;
|
swig_type_info *typeInfo = swig::type_info<sequence>();
|
||||||
|
if (typeInfo)
|
||||||
|
{
|
||||||
|
sequence *p;
|
||||||
|
if (SWIG_ConvertPtr(obj, (void**)&p, typeInfo, 0) == SWIG_OK)
|
||||||
|
{
|
||||||
|
if (seq)
|
||||||
|
*seq = p;
|
||||||
|
return SWIG_OLDOBJ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (traits_as_sequence<value_type>::check(obj) == SWIG_OK)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
SciSequence_Cont<value_type> sciSeq(obj);
|
||||||
|
if (seq)
|
||||||
|
{
|
||||||
|
*seq = new sequence();
|
||||||
|
assign(sciSeq, *seq);
|
||||||
|
return SWIG_NEWOBJ;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (std::exception& e)
|
||||||
|
{
|
||||||
|
SWIG_Scilab_AddErrorMsg(e.what());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -566,15 +413,39 @@ namespace swig {
|
||||||
typedef typename Seq::size_type size_type;
|
typedef typename Seq::size_type size_type;
|
||||||
typedef typename sequence::const_iterator const_iterator;
|
typedef typename sequence::const_iterator const_iterator;
|
||||||
|
|
||||||
static SciObject from(const sequence& seq) {
|
static SciObject from(const sequence& seq)
|
||||||
#ifdef SWIG_SCILAB_EXTRA_NATIVE_CONTAINERS
|
{
|
||||||
swig_type_info *desc = swig::type_info<sequence>();
|
%#ifdef SWIG_SCILAB_EXTRA_NATIVE_CONTAINERS
|
||||||
if (desc && desc->clientdata) {
|
swig_type_info *typeInfo = swig::type_info<sequence>();
|
||||||
return SWIG_NewPointerObj(new sequence(seq), desc, SWIG_POINTER_OWN);
|
if (typeInfo)
|
||||||
|
{
|
||||||
|
return SWIG_NewPointerObj(new sequence(seq), typeInfo, SWIG_POINTER_OWN);
|
||||||
|
}
|
||||||
|
%#endif
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
void *data;
|
||||||
|
size_type size = seq.size();
|
||||||
|
if (traits_from_sequence<value_type>::create(size, &data) == SWIG_OK) {
|
||||||
|
const_iterator it;
|
||||||
|
int index = 0;
|
||||||
|
for (it = seq.begin(); it != seq.end(); ++it)
|
||||||
|
{
|
||||||
|
traits_from_sequenceitem<value_type>::from(data, index, *it);
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
return traits_from_sequence<value_type>::set(size, data);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (std::exception& e)
|
||||||
|
{
|
||||||
|
SWIG_Scilab_AddErrorMsg(e.what());
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
// TODO: return a Scilab list from the sequence.
|
|
||||||
return (SciObject)0;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
78
Lib/scilab/scilist.swg
Normal file
78
Lib/scilab/scilist.swg
Normal file
|
|
@ -0,0 +1,78 @@
|
||||||
|
/*
|
||||||
|
* Scilab list related functions
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
%fragment("SWIG_ScilabList", "header")
|
||||||
|
{
|
||||||
|
SWIGINTERN int
|
||||||
|
SWIG_GetScilabList(SciObject _obj, int **_piListAddr)
|
||||||
|
{
|
||||||
|
SciErr sciErr;
|
||||||
|
|
||||||
|
sciErr = getVarAddressFromPosition(pvApiCtx, _obj, _piListAddr);
|
||||||
|
if (sciErr.iErr)
|
||||||
|
{
|
||||||
|
printError(&sciErr, 0);
|
||||||
|
return SWIG_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
return SWIG_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
SWIGINTERN int
|
||||||
|
SWIG_GetScilabListSize(SciObject _obj, int *_piListSize)
|
||||||
|
{
|
||||||
|
SciErr sciErr;
|
||||||
|
int *piListAddr;
|
||||||
|
|
||||||
|
sciErr = getVarAddressFromPosition(pvApiCtx, _obj, &piListAddr);
|
||||||
|
if (sciErr.iErr)
|
||||||
|
{
|
||||||
|
printError(&sciErr, 0);
|
||||||
|
return SWIG_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
sciErr = getListItemNumber(pvApiCtx, piListAddr, _piListSize);
|
||||||
|
if (sciErr.iErr)
|
||||||
|
{
|
||||||
|
printError(&sciErr, 0);
|
||||||
|
return SWIG_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
return SWIG_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SWIGINTERN int
|
||||||
|
SWIG_CheckScilabList(SciObject _obj)
|
||||||
|
{
|
||||||
|
SciErr sciErr;
|
||||||
|
int *piListAddr;
|
||||||
|
int iType;
|
||||||
|
|
||||||
|
sciErr = getVarAddressFromPosition(pvApiCtx, _obj, &piListAddr);
|
||||||
|
if (sciErr.iErr)
|
||||||
|
{
|
||||||
|
printError(&sciErr, 0);
|
||||||
|
return SWIG_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
sciErr = getVarType(pvApiCtx, piListAddr, &iType);
|
||||||
|
if (sciErr.iErr)
|
||||||
|
{
|
||||||
|
printError(&sciErr, 0);
|
||||||
|
return SWIG_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((iType != sci_list) && (iType != sci_tlist) && (iType != sci_mlist))
|
||||||
|
{
|
||||||
|
Scierror(999, _("%s: Wrong type for input argument #%d: A list is expected.\n"), fname, _obj);
|
||||||
|
return SWIG_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
return SWIG_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
153
Lib/scilab/scisequence.swg
Normal file
153
Lib/scilab/scisequence.swg
Normal file
|
|
@ -0,0 +1,153 @@
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* Scilab sequence conversions
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define SWIG_Traits_Sequence_frag(Type) %fragment_name(AsVal_Traits_Sequence, Type)
|
||||||
|
|
||||||
|
#define SWIG_AsCheck_Sequence_frag(Type...) %fragment_name(AsCheck_Sequence, Type)
|
||||||
|
#define SWIG_AsCheck_Sequence_dec(Type...) %symbol_name(AsCheck_Sequence, Type)
|
||||||
|
#define SWIG_AsGet_Sequence_frag(Type...) %fragment_name(AsGet_Sequence, Type)
|
||||||
|
#define SWIG_AsGet_Sequence_dec(Type...) %symbol_name(AsGet_Sequence, Type)
|
||||||
|
#define SWIG_AsSize_Sequence_frag(Type...) %fragment_name(AsSize_Sequence, Type)
|
||||||
|
#define SWIG_AsSize_Sequence_dec(Type...) %symbol_name(AsSize_Sequence, Type)
|
||||||
|
#define SWIG_FromCreate_Sequence_frag(Type...) %fragment_name(FromCreate_Sequence, Type)
|
||||||
|
#define SWIG_FromCreate_Sequence_dec(Type...) %symbol_name(FromCreate_Sequence, Type)
|
||||||
|
#define SWIG_FromSet_Sequence_frag(Type...) %fragment_name(FromSet_Sequence, Type)
|
||||||
|
#define SWIG_FromSet_Sequence_dec(Type...) %symbol_name(FromSet_Sequence, Type)
|
||||||
|
|
||||||
|
#define SWIG_Traits_SequenceItem_frag(Type) %fragment_name(AsVal_Traits_SequenceItem, Type)
|
||||||
|
#define SWIG_AsVal_SequenceItem_frag(Type...) %fragment_name(AsVal_SequenceItem, Type)
|
||||||
|
#define SWIG_AsVal_SequenceItem_dec(Type...) %symbol_name(AsVal_SequenceItem, Type)
|
||||||
|
#define SWIG_From_SequenceItem_frag(Type...) %fragment_name(From_SequenceItem, Type)
|
||||||
|
#define SWIG_From_SequenceItem_dec(Type...) %symbol_name(From_SequenceItem, Type)
|
||||||
|
|
||||||
|
|
||||||
|
%include <scisequencepointer.swg>
|
||||||
|
%include <scisequenceint.swg>
|
||||||
|
%include <scisequencedouble.swg>
|
||||||
|
%include <scisequencestring.swg>
|
||||||
|
|
||||||
|
//
|
||||||
|
// Sequence conversion
|
||||||
|
//
|
||||||
|
|
||||||
|
%fragment(SWIG_Traits_Sequence_frag(ptr), "header",
|
||||||
|
fragment=SWIG_AsCheck_Sequence_frag(ptr),
|
||||||
|
fragment=SWIG_AsGet_Sequence_frag(ptr),
|
||||||
|
fragment=SWIG_AsSize_Sequence_frag(ptr),
|
||||||
|
fragment=SWIG_FromCreate_Sequence_frag(ptr),
|
||||||
|
fragment=SWIG_FromSet_Sequence_frag(ptr)) {
|
||||||
|
|
||||||
|
namespace swig {
|
||||||
|
template <typename T> struct traits_as_sequence {
|
||||||
|
static int check(SciObject obj) {
|
||||||
|
return SWIG_AsCheck_Sequence_dec(ptr)(obj);
|
||||||
|
}
|
||||||
|
static int get(SciObject obj, void **sequence) {
|
||||||
|
return SWIG_AsGet_Sequence_dec(ptr)(obj, (int **)sequence);
|
||||||
|
}
|
||||||
|
static int size(SciObject obj, int *size) {
|
||||||
|
return SWIG_AsSize_Sequence_dec(ptr)(obj, size);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
template <typename T> struct traits_from_sequence {
|
||||||
|
static int create(int size, void **sequence) {
|
||||||
|
return SWIG_FromCreate_Sequence_dec(ptr)(size, (int ***)sequence);
|
||||||
|
}
|
||||||
|
static SciObject set(int size, void *sequence) {
|
||||||
|
return SWIG_FromSet_Sequence_dec(ptr)(size, (int **)sequence);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
%define %traits_sequence(CppType, ScilabType)
|
||||||
|
%fragment(SWIG_Traits_Sequence_frag(CppType), "header",
|
||||||
|
fragment=SWIG_Traits_Sequence_frag(ptr),
|
||||||
|
fragment=SWIG_AsCheck_Sequence_frag(CppType),
|
||||||
|
fragment=SWIG_AsGet_Sequence_frag(CppType),
|
||||||
|
fragment=SWIG_AsSize_Sequence_frag(CppType),
|
||||||
|
fragment=SWIG_FromCreate_Sequence_frag(CppType),
|
||||||
|
fragment=SWIG_FromSet_Sequence_frag(CppType)) {
|
||||||
|
|
||||||
|
namespace swig {
|
||||||
|
template <> struct traits_as_sequence<CppType > {
|
||||||
|
static int check(SciObject obj) {
|
||||||
|
return SWIG_AsCheck_Sequence_dec(CppType)(obj);
|
||||||
|
}
|
||||||
|
static int get(SciObject obj, void **sequence) {
|
||||||
|
return SWIG_AsGet_Sequence_dec(CppType)(obj, (ScilabType **)sequence);
|
||||||
|
}
|
||||||
|
static int size(SciObject obj, int *size) {
|
||||||
|
return SWIG_AsSize_Sequence_dec(CppType)(obj, size);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
template <> struct traits_from_sequence<CppType > {
|
||||||
|
static int create(int size, void **sequence) {
|
||||||
|
return SWIG_FromCreate_Sequence_dec(CppType)(size, (ScilabType **)sequence);
|
||||||
|
}
|
||||||
|
static SciObject set(int size, void *sequence) {
|
||||||
|
return SWIG_FromSet_Sequence_dec(CppType)(size, (ScilabType *)sequence);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
%enddef
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// Sequence item conversion
|
||||||
|
//
|
||||||
|
|
||||||
|
%fragment(SWIG_Traits_SequenceItem_frag(ptr), "header",
|
||||||
|
fragment=SWIG_AsVal_SequenceItem_frag(ptr),
|
||||||
|
fragment=SWIG_From_SequenceItem_frag(ptr)) {
|
||||||
|
|
||||||
|
namespace swig {
|
||||||
|
template <typename T> struct traits_asval_sequenceitem {
|
||||||
|
static int asval(SciObject obj, void *pSequence, int iItemIndex, T *pItemValue) {
|
||||||
|
return SWIG_AsVal_SequenceItem_dec(ptr)(obj, (int *)pSequence, iItemIndex, (int **)pItemValue);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
template <typename T> struct traits_from_sequenceitem {
|
||||||
|
static int from(void *pSequence, int iItemIndex, T itemValue) {
|
||||||
|
return SWIG_From_SequenceItem_dec(ptr)((int **)pSequence, iItemIndex, (int*)itemValue);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
%define %traits_sequenceitem(CppType, ScilabType)
|
||||||
|
%fragment(SWIG_Traits_SequenceItem_frag(CppType), "header",
|
||||||
|
fragment=SWIG_Traits_SequenceItem_frag(ptr),
|
||||||
|
fragment=SWIG_AsVal_SequenceItem_frag(CppType),
|
||||||
|
fragment=SWIG_From_SequenceItem_frag(CppType)) {
|
||||||
|
|
||||||
|
namespace swig {
|
||||||
|
template <> struct traits_asval_sequenceitem<CppType > {
|
||||||
|
static int asval(SciObject obj, void *pSequence, int iItemIndex, CppType *pItemValue) {
|
||||||
|
return SWIG_AsVal_SequenceItem_dec(CppType)(obj, (ScilabType *)pSequence, iItemIndex, pItemValue);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
template <> struct traits_from_sequenceitem<CppType > {
|
||||||
|
static int from(void *pSequence, int iItemIndex, CppType itemValue) {
|
||||||
|
return SWIG_From_SequenceItem_dec(CppType)((ScilabType *)pSequence, iItemIndex, itemValue);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
%enddef
|
||||||
|
|
||||||
|
%define %add_traits_sequence(CppType, ScilabType)
|
||||||
|
%traits_sequence(CppType, ScilabType);
|
||||||
|
%fragment(SWIG_Traits_Sequence_frag(CppType));
|
||||||
|
%traits_sequenceitem(CppType, ScilabType);
|
||||||
|
%fragment(SWIG_Traits_SequenceItem_frag(CppType));
|
||||||
|
%enddef
|
||||||
|
|
||||||
|
%add_traits_sequence(int, int);
|
||||||
|
%add_traits_sequence(double, double);
|
||||||
|
%add_traits_sequence(std::string, char*);
|
||||||
|
|
||||||
103
Lib/scilab/scisequencedouble.swg
Normal file
103
Lib/scilab/scisequencedouble.swg
Normal file
|
|
@ -0,0 +1,103 @@
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* Scilab matrix of double <-> C++ double container
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
%include <scidouble.swg>
|
||||||
|
|
||||||
|
%fragment(SWIG_AsCheck_Sequence_frag(double), "header",
|
||||||
|
fragment="SWIG_SciDouble_AsDoubleArrayAndSize") {
|
||||||
|
|
||||||
|
SWIGINTERN int
|
||||||
|
SWIG_AsCheck_Sequence_dec(double)(SciObject _obj) {
|
||||||
|
SciErr sciErr;
|
||||||
|
int *piAddrVar;
|
||||||
|
|
||||||
|
sciErr = getVarAddressFromPosition(pvApiCtx, _obj, &piAddrVar);
|
||||||
|
if (sciErr.iErr) {
|
||||||
|
printError(&sciErr, 0);
|
||||||
|
return SWIG_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isDoubleType(pvApiCtx, piAddrVar))
|
||||||
|
{
|
||||||
|
return SWIG_OK;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Scierror(999, _("%s: Wrong type for input argument #%d: A double is expected.\n"), SWIG_Scilab_GetFname(), _obj);
|
||||||
|
return SWIG_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
%fragment(SWIG_AsGet_Sequence_frag(double), "header",
|
||||||
|
fragment="SWIG_SciDouble_AsDoubleArrayAndSize") {
|
||||||
|
|
||||||
|
SWIGINTERN int
|
||||||
|
SWIG_AsGet_Sequence_dec(double)(SciObject _obj, double **_pSequence) {
|
||||||
|
int iMatrixRowCount;
|
||||||
|
int iMatrixColCount;
|
||||||
|
return (SWIG_SciDouble_AsDoubleArrayAndSize(pvApiCtx, _obj, &iMatrixRowCount, &iMatrixColCount, _pSequence, SWIG_Scilab_GetFname()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
%fragment(SWIG_AsSize_Sequence_frag(double), "header",
|
||||||
|
fragment="SWIG_SciDouble_AsDoubleArrayAndSize") {
|
||||||
|
|
||||||
|
SWIGINTERN int
|
||||||
|
SWIG_AsSize_Sequence_dec(double)(SciObject _obj, int *_piSize) {
|
||||||
|
double *pdblMatrix;
|
||||||
|
int iMatrixRowCount;
|
||||||
|
int iMatrixColCount;
|
||||||
|
if (SWIG_SciDouble_AsDoubleArrayAndSize(pvApiCtx, _obj, &iMatrixRowCount, &iMatrixColCount, &pdblMatrix, SWIG_Scilab_GetFname()) == SWIG_OK) {
|
||||||
|
if ((iMatrixRowCount > 1) && (iMatrixColCount > 1)) {
|
||||||
|
Scierror(999, _("%s: Wrong size for input argument #%d: A double vector is expected.\n"), SWIG_Scilab_GetFname(), _obj);
|
||||||
|
return SWIG_ERROR;
|
||||||
|
}
|
||||||
|
*_piSize = iMatrixRowCount * iMatrixColCount;
|
||||||
|
return SWIG_OK;
|
||||||
|
}
|
||||||
|
return SWIG_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
%fragment(SWIG_FromCreate_Sequence_frag(double), "header") {
|
||||||
|
|
||||||
|
SWIGINTERN int
|
||||||
|
SWIG_FromCreate_Sequence_dec(double)(int _size, double **_sequence) {
|
||||||
|
*_sequence = new double[_size];
|
||||||
|
return *_sequence != NULL ? SWIG_OK : SWIG_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
%fragment(SWIG_FromSet_Sequence_frag(double), "header",
|
||||||
|
fragment="SWIG_SciDouble_FromDoubleArrayAndSize") {
|
||||||
|
|
||||||
|
SWIGINTERN SciObject
|
||||||
|
SWIG_FromSet_Sequence_dec(double)(int _size, double *_sequence) {
|
||||||
|
SciObject obj = SWIG_SciDouble_FromDoubleArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), 1, _size, _sequence);
|
||||||
|
delete (double *)_sequence;
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
%fragment(SWIG_AsVal_SequenceItem_frag(double), "header") {
|
||||||
|
|
||||||
|
SWIGINTERN int
|
||||||
|
SWIG_AsVal_SequenceItem_dec(double)(SciObject _obj, double *_pSequence, int _iItemIndex, double *_pItemValue) {
|
||||||
|
*_pItemValue = _pSequence[_iItemIndex];
|
||||||
|
return SWIG_OK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
%fragment(SWIG_From_SequenceItem_frag(double), "header") {
|
||||||
|
|
||||||
|
SWIGINTERN int
|
||||||
|
SWIG_From_SequenceItem_dec(double)(double *_pSequence, int _iItemIndex, double _itemValue) {
|
||||||
|
_pSequence[_iItemIndex] = _itemValue;
|
||||||
|
return SWIG_OK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
102
Lib/scilab/scisequenceint.swg
Normal file
102
Lib/scilab/scisequenceint.swg
Normal file
|
|
@ -0,0 +1,102 @@
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* Scilab matrix of int <-> C++ int container
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
%include <sciint.swg>
|
||||||
|
|
||||||
|
%fragment(SWIG_AsCheck_Sequence_frag(int), "header",
|
||||||
|
fragment="SWIG_SciInt32_AsIntArrayAndSize") {
|
||||||
|
|
||||||
|
SWIGINTERN int
|
||||||
|
SWIG_AsCheck_Sequence_dec(int)(SciObject _obj) {
|
||||||
|
SciErr sciErr;
|
||||||
|
int *piAddrVar;
|
||||||
|
|
||||||
|
sciErr = getVarAddressFromPosition(pvApiCtx, _obj, &piAddrVar);
|
||||||
|
if (sciErr.iErr) {
|
||||||
|
printError(&sciErr, 0);
|
||||||
|
return SWIG_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isIntegerType(pvApiCtx, piAddrVar))
|
||||||
|
{
|
||||||
|
return SWIG_OK;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Scierror(999, _("%s: Wrong type for input argument #%d: An integer is expected.\n"), SWIG_Scilab_GetFname(), _obj);
|
||||||
|
return SWIG_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
%fragment(SWIG_AsGet_Sequence_frag(int), "header",
|
||||||
|
fragment="SWIG_SciInt32_AsIntArrayAndSize") {
|
||||||
|
|
||||||
|
SWIGINTERN int
|
||||||
|
SWIG_AsGet_Sequence_dec(int)(SciObject _obj, int **_pSequence) {
|
||||||
|
int iMatrixRowCount;
|
||||||
|
int iMatrixColCount;
|
||||||
|
return (SWIG_SciInt32_AsIntArrayAndSize(pvApiCtx, _obj, &iMatrixRowCount, &iMatrixColCount, _pSequence, SWIG_Scilab_GetFname()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
%fragment(SWIG_AsSize_Sequence_frag(int), "header",
|
||||||
|
fragment="SWIG_SciInt32_AsIntArrayAndSize") {
|
||||||
|
|
||||||
|
SWIGINTERN int
|
||||||
|
SWIG_AsSize_Sequence_dec(int)(SciObject _obj, int *_piSize) {
|
||||||
|
int *piMatrix;
|
||||||
|
int iMatrixRowCount;
|
||||||
|
int iMatrixColCount;
|
||||||
|
if (SWIG_SciInt32_AsIntArrayAndSize(pvApiCtx, _obj, &iMatrixRowCount, &iMatrixColCount, &piMatrix, SWIG_Scilab_GetFname()) == SWIG_OK) {
|
||||||
|
if ((iMatrixRowCount > 1) && (iMatrixColCount > 1)) {
|
||||||
|
Scierror(999, _("%s: Wrong size for input argument #%d: An integer vector is expected.\n"), SWIG_Scilab_GetFname(), _obj);
|
||||||
|
return SWIG_ERROR;
|
||||||
|
}
|
||||||
|
*_piSize = iMatrixRowCount * iMatrixColCount;
|
||||||
|
return SWIG_OK;
|
||||||
|
}
|
||||||
|
return SWIG_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
%fragment(SWIG_FromCreate_Sequence_frag(int), "header") {
|
||||||
|
|
||||||
|
SWIGINTERN int
|
||||||
|
SWIG_FromCreate_Sequence_dec(int)(int _size, int **_sequence) {
|
||||||
|
*_sequence = new int[_size];
|
||||||
|
return *_sequence != NULL ? SWIG_OK : SWIG_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
%fragment(SWIG_FromSet_Sequence_frag(int), "header",
|
||||||
|
fragment="SWIG_SciInt32_FromIntArrayAndSize") {
|
||||||
|
|
||||||
|
SWIGINTERN SciObject
|
||||||
|
SWIG_FromSet_Sequence_dec(int)(int _size, int *_sequence) {
|
||||||
|
SciObject obj = SWIG_SciInt32_FromIntArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), 1, _size, _sequence);
|
||||||
|
delete (int *)_sequence;
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
%fragment(SWIG_AsVal_SequenceItem_frag(int), "header") {
|
||||||
|
|
||||||
|
SWIGINTERN int
|
||||||
|
SWIG_AsVal_SequenceItem_dec(int)(SciObject _obj, int *_pSequence, int _iItemIndex, int *_pItemValue) {
|
||||||
|
*_pItemValue = _pSequence[_iItemIndex];
|
||||||
|
return SWIG_OK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
%fragment(SWIG_From_SequenceItem_frag(int), "header") {
|
||||||
|
|
||||||
|
SWIGINTERN int
|
||||||
|
SWIG_From_SequenceItem_dec(int)(int *_pSequence, int _iItemIndex, int _itemValue) {
|
||||||
|
_pSequence[_iItemIndex] = _itemValue;
|
||||||
|
return SWIG_OK;
|
||||||
|
}
|
||||||
|
}
|
||||||
121
Lib/scilab/scisequencepointer.swg
Normal file
121
Lib/scilab/scisequencepointer.swg
Normal file
|
|
@ -0,0 +1,121 @@
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* Scilab list of pointer <-> C++ pointer container
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
%include <scilist.swg>
|
||||||
|
|
||||||
|
%fragment(SWIG_AsCheck_Sequence_frag(ptr), "header",
|
||||||
|
fragment="SWIG_ScilabList") {
|
||||||
|
|
||||||
|
SWIGINTERN int
|
||||||
|
SWIG_AsCheck_Sequence_dec(ptr)(SciObject _obj) {
|
||||||
|
return SWIG_CheckScilabList(_obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
%fragment(SWIG_AsGet_Sequence_frag(ptr), "header",
|
||||||
|
fragment="SWIG_ScilabList") {
|
||||||
|
|
||||||
|
SWIGINTERN int
|
||||||
|
SWIG_AsGet_Sequence_dec(ptr)(SciObject _obj, int **_piSequence) {
|
||||||
|
return SWIG_GetScilabList(_obj, _piSequence);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
%fragment(SWIG_AsSize_Sequence_frag(ptr), "header",
|
||||||
|
fragment="SWIG_ScilabList") {
|
||||||
|
|
||||||
|
SWIGINTERN int
|
||||||
|
SWIG_AsSize_Sequence_dec(ptr)(SciObject _obj, int *_piSize) {
|
||||||
|
return SWIG_GetScilabListSize(_obj, _piSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
%fragment(SWIG_FromCreate_Sequence_frag(ptr), "header") {
|
||||||
|
|
||||||
|
SWIGINTERN int
|
||||||
|
SWIG_FromCreate_Sequence_dec(ptr)(int _size, int ***_sequence) {
|
||||||
|
*_sequence = new int*[_size];
|
||||||
|
return *_sequence != NULL ? SWIG_OK : SWIG_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
%fragment(SWIG_FromSet_Sequence_frag(ptr), "header") {
|
||||||
|
|
||||||
|
SWIGINTERN SciObject
|
||||||
|
SWIG_FromSet_Sequence_dec(ptr)(int _size, int **_sequence) {
|
||||||
|
SciErr sciErr;
|
||||||
|
int *piListAddr;
|
||||||
|
|
||||||
|
int iVarOut = nbInputArgument(pvApiCtx) + SWIG_Scilab_GetOutputPosition();
|
||||||
|
|
||||||
|
sciErr = createList(pvApiCtx, iVarOut, _size, &piListAddr);
|
||||||
|
if (sciErr.iErr)
|
||||||
|
{
|
||||||
|
printError(&sciErr, 0);
|
||||||
|
return SWIG_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i=0; i<_size; i++)
|
||||||
|
{
|
||||||
|
sciErr = createPointerInList(pvApiCtx, iVarOut, piListAddr, i + 1, (void *)_sequence[i]);
|
||||||
|
if (sciErr.iErr)
|
||||||
|
{
|
||||||
|
printError(&sciErr, 0);
|
||||||
|
return SWIG_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
delete (int*)_sequence;
|
||||||
|
return iVarOut;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
%fragment(SWIG_AsVal_SequenceItem_frag(ptr), "header") {
|
||||||
|
|
||||||
|
SWIGINTERN int
|
||||||
|
SWIG_AsVal_SequenceItem_dec(ptr)(SciObject _obj, int* _piSequence, int _itemIndex, int **_pItemValue)
|
||||||
|
{
|
||||||
|
SciErr sciErr;
|
||||||
|
int *piItemAddr;
|
||||||
|
int iType;
|
||||||
|
|
||||||
|
sciErr = getListItemAddress(pvApiCtx, _piSequence, _itemIndex + 1, &piItemAddr);
|
||||||
|
if (sciErr.iErr)
|
||||||
|
{
|
||||||
|
printError(&sciErr, 0);
|
||||||
|
return SWIG_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
sciErr = getVarType(pvApiCtx, piItemAddr, &iType);
|
||||||
|
if (sciErr.iErr)
|
||||||
|
{
|
||||||
|
printError(&sciErr, 0);
|
||||||
|
return SWIG_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (iType != sci_pointer)
|
||||||
|
{
|
||||||
|
Scierror(999, _("%s: Wrong type for input argument #%d: A pointer is expected at list item #%d.\n"), fname, _obj, _itemIndex + 1);
|
||||||
|
return SWIG_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
sciErr = getPointerInList(pvApiCtx, _piSequence, _itemIndex + 1, (void **)_pItemValue);
|
||||||
|
if (sciErr.iErr)
|
||||||
|
{
|
||||||
|
printError(&sciErr, 0);
|
||||||
|
return SWIG_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
return SWIG_OK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
%fragment(SWIG_From_SequenceItem_frag(ptr), "header") {
|
||||||
|
|
||||||
|
SWIGINTERN int
|
||||||
|
SWIG_From_SequenceItem_dec(ptr)(int **_pSequence, int _iItemIndex, int *_itemValue) {
|
||||||
|
_pSequence[_iItemIndex] = _itemValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
97
Lib/scilab/scisequencestring.swg
Normal file
97
Lib/scilab/scisequencestring.swg
Normal file
|
|
@ -0,0 +1,97 @@
|
||||||
|
/*
|
||||||
|
*char
|
||||||
|
* Scilab matrix of string <-> C++ std::string container
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
%include <scichar.swg>
|
||||||
|
|
||||||
|
%fragment(SWIG_AsCheck_Sequence_frag(std::string), "header",
|
||||||
|
fragment="SwigScilabStringToCharPtrArrayAndSize") {
|
||||||
|
|
||||||
|
SWIGINTERN int
|
||||||
|
SWIG_AsCheck_Sequence_dec(std::string)(SciObject _obj) {
|
||||||
|
SciErr sciErr;
|
||||||
|
int *piAddrVar;
|
||||||
|
|
||||||
|
sciErr = getVarAddressFromPosition(pvApiCtx, _obj, &piAddrVar);
|
||||||
|
if (sciErr.iErr) {
|
||||||
|
printError(&sciErr, 0);
|
||||||
|
return SWIG_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isStringType(pvApiCtx, piAddrVar))
|
||||||
|
{
|
||||||
|
return SWIG_OK;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Scierror(999, _("%s: Wrong type for input argument #%d: A string is expected.\n"), SWIG_Scilab_GetFname(), _obj);
|
||||||
|
return SWIG_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
%fragment(SWIG_AsGet_Sequence_frag(std::string), "header",
|
||||||
|
fragment="SwigScilabStringToCharPtrArrayAndSize") {
|
||||||
|
|
||||||
|
SWIGINTERN int
|
||||||
|
SWIG_AsGet_Sequence_dec(std::string)(SciObject _obj, char ***_pSequence) {
|
||||||
|
int iSize;
|
||||||
|
return (SwigScilabStringToCharPtrArrayAndSize(pvApiCtx, _obj, _pSequence, &iSize, SWIG_Scilab_GetFname()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
%fragment(SWIG_AsSize_Sequence_frag(std::string), "header",
|
||||||
|
fragment="SwigScilabStringToCharPtrArrayAndSize") {
|
||||||
|
|
||||||
|
SWIGINTERN int
|
||||||
|
SWIG_AsSize_Sequence_dec(std::string)(SciObject _obj, int *_piSize) {
|
||||||
|
char **pstMatrix;
|
||||||
|
if (SwigScilabStringToCharPtrArrayAndSize(pvApiCtx, _obj, &pstMatrix, _piSize, SWIG_Scilab_GetFname()) == SWIG_OK) {
|
||||||
|
return SWIG_OK;
|
||||||
|
}
|
||||||
|
return SWIG_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
%fragment(SWIG_FromCreate_Sequence_frag(std::string), "header") {
|
||||||
|
|
||||||
|
SWIGINTERN int
|
||||||
|
SWIG_FromCreate_Sequence_dec(std::string)(int _size, char ***_sequence) {
|
||||||
|
*_sequence = new char*[_size];
|
||||||
|
return *_sequence != NULL ? SWIG_OK : SWIG_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
%fragment(SWIG_FromSet_Sequence_frag(std::string), "header",
|
||||||
|
fragment="SwigScilabStringFromCharPtrArray") {
|
||||||
|
|
||||||
|
SWIGINTERN SciObject
|
||||||
|
SWIG_FromSet_Sequence_dec(std::string)(int _size, char **_sequence) {
|
||||||
|
SciObject obj = SwigScilabStringFromCharPtrArray(pvApiCtx, SWIG_Scilab_GetOutputPosition(), _sequence, _size);
|
||||||
|
delete (char **)_sequence;
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
%fragment(SWIG_AsVal_SequenceItem_frag(std::string), "header") {
|
||||||
|
|
||||||
|
SWIGINTERN int
|
||||||
|
SWIG_AsVal_SequenceItem_dec(std::string)(SciObject _obj, char **_pSequence, int _iItemIndex, std::string *_pItemValue) {
|
||||||
|
*_pItemValue = std::string(_pSequence[_iItemIndex]);
|
||||||
|
return SWIG_OK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
%fragment(SWIG_From_SequenceItem_frag(std::string), "header") {
|
||||||
|
|
||||||
|
SWIGINTERN int
|
||||||
|
SWIG_From_SequenceItem_dec(std::string)(char **_pSequence, int _iItemIndex, std::string _itemValue) {
|
||||||
|
char *pChar = new char(_itemValue.size() + 1);
|
||||||
|
strcpy(pChar, _itemValue.c_str());
|
||||||
|
_pSequence[_iItemIndex] = pChar;
|
||||||
|
return SWIG_OK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue