Better management of containers based on Octave one
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-scilab@13527 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
53b2b4405d
commit
28565a5b65
3 changed files with 245 additions and 533 deletions
|
|
@ -1,12 +1,10 @@
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
* scicontainer.swg
|
* scicontainer.swg
|
||||||
*
|
*
|
||||||
* Based on pycontainer.swg
|
* Scilab cell <-> C++ container wrapper (Basd on Octave version)
|
||||||
*
|
|
||||||
* Python sequence <-> 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 Python, thanks to the C++ templates.
|
* the mapping between C++ and Scilab, thanks to the C++ templates.
|
||||||
*
|
*
|
||||||
* Of course, it needs the C++ compiler to support templates, but
|
* Of course, it needs the C++ compiler to support templates, but
|
||||||
* since we will use this wrapper with the STL containers, that should
|
* since we will use this wrapper with the STL containers, that should
|
||||||
|
|
@ -15,12 +13,6 @@
|
||||||
|
|
||||||
%{
|
%{
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#if PY_VERSION_HEX >= 0x03020000
|
|
||||||
# define SWIGPY_SLICE_ARG(obj) ((PyObject*) (obj))
|
|
||||||
#else
|
|
||||||
# define SWIGPY_SLICE_ARG(obj) ((PySliceObject*) (obj))
|
|
||||||
#endif
|
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -32,7 +24,7 @@
|
||||||
|
|
||||||
%include <sciiterators.swg>
|
%include <sciiterators.swg>
|
||||||
|
|
||||||
/**** The PySequence C++ Wrap ***/
|
// The Octave C++ Wrap
|
||||||
|
|
||||||
%insert(header) %{
|
%insert(header) %{
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
@ -40,32 +32,30 @@
|
||||||
|
|
||||||
%include <std_except.i>
|
%include <std_except.i>
|
||||||
|
|
||||||
%fragment(SWIG_Traits_frag(swig::SwigPtr_PyObject),"header",fragment="StdTraits") {
|
%fragment(SWIG_Traits_frag(SciObject),"header",fragment="StdTraits") {
|
||||||
namespace swig {
|
namespace swig {
|
||||||
template <> struct traits<SwigPtr_PyObject > {
|
template <> struct traits<SciObject > {
|
||||||
typedef value_category category;
|
typedef value_category category;
|
||||||
static const char* type_name() { return "SwigPtr_PyObject"; }
|
static const char* type_name() { return "SciObject"; }
|
||||||
};
|
};
|
||||||
|
|
||||||
template <> struct traits_from<SwigPtr_PyObject> {
|
template <> struct traits_from<SciObject> {
|
||||||
typedef SwigPtr_PyObject value_type;
|
typedef SciObject value_type;
|
||||||
static PyObject *from(const value_type& val) {
|
static SciObject from(const value_type& val) {
|
||||||
PyObject *obj = static_cast<PyObject *>(val);
|
return val;
|
||||||
Py_XINCREF(obj);
|
|
||||||
return obj;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
struct traits_check<SwigPtr_PyObject, value_category> {
|
struct traits_check<SciObject, value_category> {
|
||||||
static bool check(SwigPtr_PyObject) {
|
static bool check(const SciObject&) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <> struct traits_asval<SwigPtr_PyObject > {
|
template <> struct traits_asval<SciObject > {
|
||||||
typedef SwigPtr_PyObject value_type;
|
typedef SciObject value_type;
|
||||||
static int asval(PyObject *obj, value_type *val) {
|
static int asval(const SciObject& obj, value_type *val) {
|
||||||
if (val) *val = obj;
|
if (val) *val = obj;
|
||||||
return SWIG_OK;
|
return SWIG_OK;
|
||||||
}
|
}
|
||||||
|
|
@ -73,120 +63,21 @@ namespace swig {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
%fragment(SWIG_Traits_frag(swig::SwigVar_PyObject),"header",fragment="StdTraits") {
|
%fragment("SciSequence_Base","header",fragment="<stddef.h>")
|
||||||
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>
|
%#include <functional>
|
||||||
|
|
||||||
namespace std {
|
namespace std {
|
||||||
template <>
|
template <>
|
||||||
struct less <PyObject *>: public binary_function<PyObject *, PyObject *, bool>
|
struct less <SciObject>: public binary_function<SciObject, SciObject, bool>
|
||||||
{
|
{
|
||||||
bool
|
bool
|
||||||
operator()(PyObject * v, PyObject *w) const
|
operator()(const SciObject& v, const SciObject& w) const
|
||||||
{
|
{
|
||||||
bool res;
|
SciObject res = do_binary_op(SciObject::op_le,v,w);
|
||||||
SWIG_PYTHON_THREAD_BEGIN_BLOCK;
|
return res.is_true();
|
||||||
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 {
|
namespace swig {
|
||||||
|
|
@ -253,7 +144,7 @@ namespace swig {
|
||||||
|
|
||||||
template <class Sequence, class Difference, class InputSeq>
|
template <class Sequence, class Difference, class InputSeq>
|
||||||
inline void
|
inline void
|
||||||
setslice(Sequence* self, Difference i, Difference j, const InputSeq& v = InputSeq()) {
|
setslice(Sequence* self, Difference i, Difference j, const InputSeq& v) {
|
||||||
typename Sequence::size_type size = self->size();
|
typename Sequence::size_type size = self->size();
|
||||||
typename Sequence::size_type ii = swig::check_index(i, size, true);
|
typename Sequence::size_type ii = swig::check_index(i, size, true);
|
||||||
typename Sequence::size_type jj = swig::slice_index(j, size);
|
typename Sequence::size_type jj = swig::slice_index(j, size);
|
||||||
|
|
@ -292,62 +183,64 @@ namespace swig {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
%fragment("SwigPySequence_Cont","header",
|
%fragment("SciSequence_Cont","header",
|
||||||
fragment="StdTraits",
|
fragment="StdTraits",
|
||||||
fragment="SwigPySequence_Base",
|
fragment="SciSequence_Base",
|
||||||
fragment="SwigPyIterator_T")
|
fragment="SciSwigIterator_T")
|
||||||
{
|
{
|
||||||
namespace swig
|
namespace swig
|
||||||
{
|
{
|
||||||
template <class T>
|
template <class T>
|
||||||
struct SwigPySequence_Ref
|
struct SciSequence_Ref // * octave can't support these, because of how assignment works
|
||||||
{
|
{
|
||||||
SwigPySequence_Ref(PyObject* seq, int index)
|
SciSequence_Ref(const SciObject& seq, int index)
|
||||||
: _seq(seq), _index(index)
|
: _seq(seq), _index(index)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
operator T () const
|
operator T () const
|
||||||
{
|
{
|
||||||
swig::SwigVar_PyObject item = PySequence_GetItem(_seq, _index);
|
// swig::SwigVar_PyObject item = SciSequence_GetItem(_seq, _index);
|
||||||
|
SciObject item; // * todo
|
||||||
try {
|
try {
|
||||||
return swig::as<T>(item, true);
|
return swig::as<T>(item, true);
|
||||||
} catch (std::exception& e) {
|
} catch (std::exception& e) {
|
||||||
char msg[1024];
|
char msg[1024];
|
||||||
sprintf(msg, "in sequence element %d ", _index);
|
sprintf(msg, "in sequence element %d ", _index);
|
||||||
if (!PyErr_Occurred()) {
|
if (!Scilab_Error_Occurred()) {
|
||||||
::%type_error(swig::type_name<T>());
|
%type_error(swig::type_name<T>());
|
||||||
}
|
}
|
||||||
SWIG_Python_AddErrorMsg(msg);
|
SWIG_Scilab_AddErrorMsg(msg);
|
||||||
SWIG_Python_AddErrorMsg(e.what());
|
SWIG_Scilab_AddErrorMsg(e.what());
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SwigPySequence_Ref& operator=(const T& v)
|
SciSequence_Ref& operator=(const T& v)
|
||||||
{
|
{
|
||||||
PySequence_SetItem(_seq, _index, swig::from<T>(v));
|
// SciSequence_SetItem(_seq, _index, swig::from<T>(v));
|
||||||
|
// * todo
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PyObject* _seq;
|
SciObject _seq;
|
||||||
int _index;
|
int _index;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
struct SwigPySequence_ArrowProxy
|
struct SciSequence_ArrowProxy
|
||||||
{
|
{
|
||||||
SwigPySequence_ArrowProxy(const T& x): m_value(x) {}
|
SciSequence_ArrowProxy(const T& x): m_value(x) {}
|
||||||
const T* operator->() const { return &m_value; }
|
const T* operator->() const { return &m_value; }
|
||||||
operator const T*() const { return &m_value; }
|
operator const T*() const { return &m_value; }
|
||||||
T m_value;
|
T m_value;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class T, class Reference >
|
template <class T, class Reference >
|
||||||
struct SwigPySequence_InputIterator
|
struct SciSequence_InputIterator
|
||||||
{
|
{
|
||||||
typedef SwigPySequence_InputIterator<T, Reference > self;
|
typedef SciSequence_InputIterator<T, Reference > self;
|
||||||
|
|
||||||
typedef std::random_access_iterator_tag iterator_category;
|
typedef std::random_access_iterator_tag iterator_category;
|
||||||
typedef Reference reference;
|
typedef Reference reference;
|
||||||
|
|
@ -355,11 +248,11 @@ namespace swig
|
||||||
typedef T* pointer;
|
typedef T* pointer;
|
||||||
typedef int difference_type;
|
typedef int difference_type;
|
||||||
|
|
||||||
SwigPySequence_InputIterator()
|
SciSequence_InputIterator()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
SwigPySequence_InputIterator(PyObject* seq, int index)
|
SciSequence_InputIterator(const SciObject& seq, int index)
|
||||||
: _seq(seq), _index(index)
|
: _seq(seq), _index(index)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
@ -369,14 +262,14 @@ namespace swig
|
||||||
return reference(_seq, _index);
|
return reference(_seq, _index);
|
||||||
}
|
}
|
||||||
|
|
||||||
SwigPySequence_ArrowProxy<T>
|
SciSequence_ArrowProxy<T>
|
||||||
operator->() const {
|
operator->() const {
|
||||||
return SwigPySequence_ArrowProxy<T>(operator*());
|
return SciSequence_ArrowProxy<T>(operator*());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator==(const self& ri) const
|
bool operator==(const self& ri) const
|
||||||
{
|
{
|
||||||
return (_index == ri._index) && (_seq == ri._seq);
|
return (_index == ri._index);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator!=(const self& ri) const
|
bool operator!=(const self& ri) const
|
||||||
|
|
@ -435,40 +328,43 @@ namespace swig
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PyObject* _seq;
|
SciObject _seq;
|
||||||
difference_type _index;
|
difference_type _index;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
struct SwigPySequence_Cont
|
struct SciSequence_Cont
|
||||||
{
|
{
|
||||||
typedef SwigPySequence_Ref<T> reference;
|
typedef SciSequence_Ref<T> reference;
|
||||||
typedef const SwigPySequence_Ref<T> const_reference;
|
typedef const SciSequence_Ref<T> const_reference;
|
||||||
typedef T value_type;
|
typedef T value_type;
|
||||||
typedef T* pointer;
|
typedef T* pointer;
|
||||||
typedef int difference_type;
|
typedef int difference_type;
|
||||||
typedef int size_type;
|
typedef int size_type;
|
||||||
typedef const pointer const_pointer;
|
typedef const pointer const_pointer;
|
||||||
typedef SwigPySequence_InputIterator<T, reference> iterator;
|
typedef SciSequence_InputIterator<T, reference> iterator;
|
||||||
typedef SwigPySequence_InputIterator<T, const_reference> const_iterator;
|
typedef SciSequence_InputIterator<T, const_reference> const_iterator;
|
||||||
|
|
||||||
SwigPySequence_Cont(PyObject* seq) : _seq(0)
|
SciSequence_Cont(const SciObject& seq) : _seq(seq)
|
||||||
{
|
{
|
||||||
if (!PySequence_Check(seq)) {
|
// * assert that we have map type etc.
|
||||||
|
/*
|
||||||
|
if (!SciSequence_Check(seq)) {
|
||||||
throw std::invalid_argument("a sequence is expected");
|
throw std::invalid_argument("a sequence is expected");
|
||||||
}
|
}
|
||||||
_seq = seq;
|
_seq = seq;
|
||||||
Py_INCREF(_seq);
|
Py_INCREF(_seq);
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
~SwigPySequence_Cont()
|
~SciSequence_Cont()
|
||||||
{
|
{
|
||||||
Py_XDECREF(_seq);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
size_type size() const
|
size_type size() const
|
||||||
{
|
{
|
||||||
return static_cast<size_type>(PySequence_Size(_seq));
|
// return static_cast<size_type>(SciSequence_Size(_seq));
|
||||||
|
return 0; // * todo
|
||||||
}
|
}
|
||||||
|
|
||||||
bool empty() const
|
bool empty() const
|
||||||
|
|
@ -510,7 +406,8 @@ namespace swig
|
||||||
{
|
{
|
||||||
int s = size();
|
int s = size();
|
||||||
for (int i = 0; i < s; ++i) {
|
for (int i = 0; i < s; ++i) {
|
||||||
swig::SwigVar_PyObject item = PySequence_GetItem(_seq, i);
|
// swig::SwigVar_PyObject item = SciSequence_GetItem(_seq, i);
|
||||||
|
SciObject item; // * todo
|
||||||
if (!swig::check<value_type>(item)) {
|
if (!swig::check<value_type>(item)) {
|
||||||
if (set_err) {
|
if (set_err) {
|
||||||
char msg[1024];
|
char msg[1024];
|
||||||
|
|
@ -524,7 +421,7 @@ namespace swig
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PyObject* _seq;
|
SciObject _seq;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -537,40 +434,42 @@ namespace swig
|
||||||
class const_iterator;
|
class const_iterator;
|
||||||
class const_reverse_iterator;
|
class const_reverse_iterator;
|
||||||
|
|
||||||
%typemap(out,noblock=1,fragment="SwigPySequence_Cont")
|
%typemap(out,noblock=1,fragment="SciSequence_Cont")
|
||||||
iterator, reverse_iterator, const_iterator, const_reverse_iterator {
|
iterator, reverse_iterator, const_iterator, const_reverse_iterator {
|
||||||
$result = SWIG_NewPointerObj(swig::make_output_iterator(%static_cast($1,const $type &)),
|
$result = SWIG_NewPointerObj(swig::make_output_iterator(%static_cast($1,const $type &)),
|
||||||
swig::SwigPyIterator::descriptor(),SWIG_POINTER_OWN);
|
swig::SciSwigIterator::descriptor(),SWIG_POINTER_OWN);
|
||||||
}
|
}
|
||||||
%typemap(out,noblock=1,fragment="SwigPySequence_Cont")
|
%typemap(out,fragment="SciSequence_Cont")
|
||||||
std::pair<iterator, iterator>, std::pair<const_iterator, const_iterator> {
|
std::pair<iterator, iterator>, std::pair<const_iterator, const_iterator> {
|
||||||
$result = PyTuple_New(2);
|
SciObject_list tmpc;
|
||||||
PyTuple_SetItem($result,0,SWIG_NewPointerObj(swig::make_output_iterator(%static_cast($1,const $type &).first),
|
tmpc.append(SWIG_NewPointerObj(swig::make_output_iterator(%static_cast($1,const $type &).first),
|
||||||
swig::SwigPyIterator::descriptor(),SWIG_POINTER_OWN));
|
swig::SciSwigIterator::descriptor(),SWIG_POINTER_OWN));
|
||||||
PyTuple_SetItem($result,1,SWIG_NewPointerObj(swig::make_output_iterator(%static_cast($1,const $type &).second),
|
tmpc.append(SWIG_NewPointerObj(swig::make_output_iterator(%static_cast($1,const $type &).second),
|
||||||
swig::SwigPyIterator::descriptor(),SWIG_POINTER_OWN));
|
swig::SciSwigIterator::descriptor(),SWIG_POINTER_OWN));
|
||||||
|
$result = Cell(tmpc);
|
||||||
}
|
}
|
||||||
|
|
||||||
%fragment("SwigPyPairBoolOutputIterator","header",fragment=SWIG_From_frag(bool),fragment="SwigPySequence_Cont") {}
|
%fragment("SwigPyPairBoolOutputIterator","header",fragment=SWIG_From_frag(bool),fragment="SciSequence_Cont") {}
|
||||||
|
|
||||||
%typemap(out,noblock=1,fragment="SwigPyPairBoolOutputIterator")
|
%typemap(out,fragment="SciPairBoolOutputIterator")
|
||||||
std::pair<iterator, bool>, std::pair<const_iterator, bool> {
|
std::pair<iterator, bool>, std::pair<const_iterator, bool> {
|
||||||
$result = PyTuple_New(2);
|
SciObject_list tmpc;
|
||||||
PyTuple_SetItem($result,0,SWIG_NewPointerObj(swig::make_output_iterator(%static_cast($1,const $type &).first),
|
tmpc.append(SWIG_NewPointerObj(swig::make_output_iterator(%static_cast($1,const $type &).first),
|
||||||
swig::SwigPyIterator::descriptor(),SWIG_POINTER_OWN));
|
swig::SciSwigIterator::descriptor(),SWIG_POINTER_OWN));
|
||||||
PyTuple_SetItem($result,1,SWIG_From(bool)(%static_cast($1,const $type &).second));
|
tmpc.append(SWIG_From(bool)(%static_cast($1,const $type &).second));
|
||||||
|
$result = Cell(tmpc);
|
||||||
}
|
}
|
||||||
|
|
||||||
%typemap(in,noblock=1,fragment="SwigPySequence_Cont")
|
%typemap(in,noblock=1,fragment="SciSequence_Cont")
|
||||||
iterator(swig::SwigPyIterator *iter = 0, int res),
|
iterator(swig::SciSwigIterator *iter = 0, int res),
|
||||||
reverse_iterator(swig::SwigPyIterator *iter = 0, int res),
|
reverse_iterator(swig::SciSwigIterator *iter = 0, int res),
|
||||||
const_iterator(swig::SwigPyIterator *iter = 0, int res),
|
const_iterator(swig::SciSwigIterator *iter = 0, int res),
|
||||||
const_reverse_iterator(swig::SwigPyIterator *iter = 0, int res) {
|
const_reverse_iterator(swig::SciSwigIterator *iter = 0, int res) {
|
||||||
res = SWIG_ConvertPtr($input, %as_voidptrptr(&iter), swig::SwigPyIterator::descriptor(), 0);
|
res = SWIG_ConvertPtr($input, %as_voidptrptr(&iter), swig::SciSwigIterator::descriptor(), 0);
|
||||||
if (!SWIG_IsOK(res) || !iter) {
|
if (!SWIG_IsOK(res) || !iter) {
|
||||||
%argument_fail(SWIG_TypeError, "$type", $symname, $argnum);
|
%argument_fail(SWIG_TypeError, "$type", $symname, $argnum);
|
||||||
} else {
|
} else {
|
||||||
swig::SwigPyIterator_T<$type > *iter_t = dynamic_cast<swig::SwigPyIterator_T<$type > *>(iter);
|
swig::SciSwigIterator_T<$type > *iter_t = dynamic_cast<swig::SciSwigIterator_T<$type > *>(iter);
|
||||||
if (iter_t) {
|
if (iter_t) {
|
||||||
$1 = iter_t->get_current();
|
$1 = iter_t->get_current();
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -579,76 +478,27 @@ namespace swig
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
%typecheck(%checkcode(ITERATOR),noblock=1,fragment="SwigPySequence_Cont")
|
%typecheck(%checkcode(ITERATOR),noblock=1,fragment="SciSequence_Cont")
|
||||||
iterator, reverse_iterator, const_iterator, const_reverse_iterator {
|
iterator, reverse_iterator, const_iterator, const_reverse_iterator {
|
||||||
swig::SwigPyIterator *iter = 0;
|
swig::SciSwigIterator *iter = 0;
|
||||||
int res = SWIG_ConvertPtr($input, %as_voidptrptr(&iter), swig::SwigPyIterator::descriptor(), 0);
|
int res = SWIG_ConvertPtr($input, %as_voidptrptr(&iter), swig::SciSwigIterator::descriptor(), 0);
|
||||||
$1 = (SWIG_IsOK(res) && iter && (dynamic_cast<swig::SwigPyIterator_T<$type > *>(iter) != 0));
|
$1 = (SWIG_IsOK(res) && iter && (dynamic_cast<swig::SciSwigIterator_T<$type > *>(iter) != 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
%fragment("SwigPySequence_Cont");
|
%fragment("SciSequence_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
|
|
||||||
// TODO
|
|
||||||
//%scilabcode {def __iter__(self): return self.iterator()}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
#endif //SWIG_EXPORT_ITERATOR_METHODS
|
#endif //SWIG_EXPORT_ITERATOR_METHODS
|
||||||
%enddef
|
%enddef
|
||||||
|
|
||||||
|
// The octave container methods
|
||||||
/**** The python container methods ****/
|
|
||||||
|
|
||||||
%define %swig_container_methods(Container...)
|
%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
|
%enddef
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
%define %swig_sequence_methods_common(Sequence...)
|
%define %swig_sequence_methods_common(Sequence...)
|
||||||
%swig_sequence_iterator(%arg(Sequence))
|
%swig_sequence_iterator(%arg(Sequence))
|
||||||
%swig_container_methods(%arg(Sequence))
|
%swig_container_methods(%arg(Sequence))
|
||||||
|
|
||||||
%fragment("SwigPySequence_Base");
|
%fragment("SciSequence_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 {
|
%extend {
|
||||||
value_type pop() throw (std::out_of_range) {
|
value_type pop() throw (std::out_of_range) {
|
||||||
|
|
@ -659,122 +509,28 @@ namespace swig
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* typemap for slice object support */
|
value_type __paren__(difference_type i) throw (std::out_of_range) {
|
||||||
%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));
|
return *(swig::cgetpos(self, i));
|
||||||
}
|
}
|
||||||
|
|
||||||
void __setitem__(difference_type i, const value_type& x) throw (std::out_of_range) {
|
void __paren_asgn__(difference_type i, 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;
|
*(swig::getpos(self,i)) = x;
|
||||||
}
|
}
|
||||||
|
|
||||||
void append(value_type x) {
|
void append(value_type x) {
|
||||||
self->push_back(x);
|
self->push_back(x);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
%enddef
|
%enddef
|
||||||
|
|
||||||
|
%define %swig_sequence_methods(Sequence...)
|
||||||
|
%swig_sequence_methods_common(%arg(Sequence))
|
||||||
|
%enddef
|
||||||
|
|
||||||
|
%define %swig_sequence_methods_val(Sequence...)
|
||||||
|
%swig_sequence_methods_common(%arg(Sequence))
|
||||||
|
%enddef
|
||||||
|
|
||||||
//
|
//
|
||||||
// Common fragments
|
// Common fragments
|
||||||
|
|
@ -782,18 +538,21 @@ namespace swig
|
||||||
|
|
||||||
%fragment("StdSequenceTraits","header",
|
%fragment("StdSequenceTraits","header",
|
||||||
fragment="StdTraits",
|
fragment="StdTraits",
|
||||||
fragment="SwigPySequence_Cont")
|
fragment="SciSequence_Cont")
|
||||||
{
|
{
|
||||||
namespace swig {
|
namespace swig {
|
||||||
template <class SwigPySeq, class Seq>
|
template <class SciSeq, class Seq>
|
||||||
inline void
|
inline void
|
||||||
assign(const SwigPySeq& swigpyseq, Seq* seq) {
|
assign(const SciSeq& octseq, Seq* seq) {
|
||||||
// seq->assign(swigpyseq.begin(), swigpyseq.end()); // not used as not always implemented
|
%#ifdef SWIG_STD_NOASSIGN_STL
|
||||||
typedef typename SwigPySeq::value_type value_type;
|
typedef typename SciSeq::value_type value_type;
|
||||||
typename SwigPySeq::const_iterator it = swigpyseq.begin();
|
typename SciSeq::const_iterator it = octseq.begin();
|
||||||
for (;it != swigpyseq.end(); ++it) {
|
for (;it != octseq.end(); ++it) {
|
||||||
seq->insert(seq->end(),(value_type)(*it));
|
seq->insert(seq->end(),(value_type)(*it));
|
||||||
}
|
}
|
||||||
|
%#else
|
||||||
|
seq->assign(octseq.begin(), octseq.end());
|
||||||
|
%#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Seq, class T = typename Seq::value_type >
|
template <class Seq, class T = typename Seq::value_type >
|
||||||
|
|
@ -801,31 +560,28 @@ namespace swig {
|
||||||
typedef Seq sequence;
|
typedef Seq sequence;
|
||||||
typedef T value_type;
|
typedef T value_type;
|
||||||
|
|
||||||
static int asptr(PyObject *obj, sequence **seq) {
|
static int asptr(const SciObject& obj, sequence **seq) {
|
||||||
if (obj == Py_None || SWIG_Python_GetSwigThis(obj)) {
|
if (!obj.is_defined() || Swig::swig_value_deref(obj)) {
|
||||||
sequence *p;
|
sequence *p;
|
||||||
if (::SWIG_ConvertPtr(obj,(void**)&p,
|
if (SWIG_ConvertPtr(obj,(void**)&p,
|
||||||
swig::type_info<sequence>(),0) == SWIG_OK) {
|
swig::type_info<sequence>(),0) == SWIG_OK) {
|
||||||
if (seq) *seq = p;
|
if (seq) *seq = p;
|
||||||
return SWIG_OLDOBJ;
|
return SWIG_OLDOBJ;
|
||||||
}
|
}
|
||||||
} else if (PySequence_Check(obj)) {
|
} else if (obj.is_cell()) {
|
||||||
try {
|
try {
|
||||||
SwigPySequence_Cont<value_type> swigpyseq(obj);
|
SciSequence_Cont<value_type> octseq(obj);
|
||||||
if (seq) {
|
if (seq) {
|
||||||
sequence *pseq = new sequence();
|
sequence *pseq = new sequence();
|
||||||
assign(swigpyseq, pseq);
|
assign(octseq, pseq);
|
||||||
*seq = pseq;
|
*seq = pseq;
|
||||||
return SWIG_NEWOBJ;
|
return SWIG_NEWOBJ;
|
||||||
} else {
|
} else {
|
||||||
return swigpyseq.check() ? SWIG_OK : SWIG_ERROR;
|
return octseq.check() ? SWIG_OK : SWIG_ERROR;
|
||||||
}
|
}
|
||||||
} catch (std::exception& e) {
|
} catch (std::exception& e) {
|
||||||
if (seq) {
|
if (seq&&!error_state)
|
||||||
if (!PyErr_Occurred()) {
|
Scierror(999, "swig type error: %s",e.what());
|
||||||
PyErr_SetString(PyExc_TypeError, e.what());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return SWIG_ERROR;
|
return SWIG_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -840,27 +596,29 @@ 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 PyObject *from(const sequence& seq) {
|
static SciObject from(const sequence& seq) {
|
||||||
%#ifdef SWIG_PYTHON_EXTRA_NATIVE_CONTAINERS
|
#ifdef SWIG_OCTAVE_EXTRA_NATIVE_CONTAINERS
|
||||||
swig_type_info *desc = swig::type_info<sequence>();
|
swig_type_info *desc = swig::type_info<sequence>();
|
||||||
if (desc && desc->clientdata) {
|
if (desc && desc->clientdata) {
|
||||||
return SWIG_NewPointerObj(new sequence(seq), desc, SWIG_POINTER_OWN);
|
return SWIG_NewPointerObj(new sequence(seq), desc, SWIG_POINTER_OWN);
|
||||||
}
|
}
|
||||||
%#endif
|
#endif
|
||||||
size_type size = seq.size();
|
size_type size = seq.size();
|
||||||
if (size <= (size_type)INT_MAX) {
|
if (size <= (size_type)INT_MAX) {
|
||||||
PyObject *obj = PyTuple_New((int)size);
|
Cell c(size,1);
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (const_iterator it = seq.begin();
|
for (const_iterator it = seq.begin();
|
||||||
it != seq.end(); ++it, ++i) {
|
it != seq.end(); ++it, ++i) {
|
||||||
PyTuple_SetItem(obj,i,swig::from<value_type>(*it));
|
c(i) = swig::from<value_type>(*it);
|
||||||
}
|
}
|
||||||
return obj;
|
return c;
|
||||||
} else {
|
} else {
|
||||||
PyErr_SetString(PyExc_OverflowError,"sequence size not valid in python");
|
Scierror(999, "swig overflow error: sequence size not valid in Scilab");
|
||||||
return NULL;
|
return SciObject();
|
||||||
}
|
}
|
||||||
|
return SciObject();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,121 +1,101 @@
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
* sciiterators.swg
|
* sciiterators.swg
|
||||||
*
|
*
|
||||||
* Based on pyiterators.swg
|
* Users can derive form the SciSwigIterator to implemet their
|
||||||
*
|
|
||||||
* Implement a python 'output' iterator for Python 2.2 or higher.
|
|
||||||
*
|
|
||||||
* Users can derive form the SwigPyIterator to implement their
|
|
||||||
* own iterators. As an example (real one since we use it for STL/STD
|
* own iterators. As an example (real one since we use it for STL/STD
|
||||||
* containers), the template SwigPyIterator_T does the
|
* containers), the template SciSwigIterator_T does the
|
||||||
* implementation for generic C++ iterators.
|
* implementation for generic C++ iterators.
|
||||||
* ----------------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------------- */
|
||||||
|
|
||||||
%include <std_common.i>
|
%include <std_common.i>
|
||||||
|
|
||||||
%fragment("SwigPyIterator","header") {
|
%fragment("SciSwigIterator","header",fragment="<stddef.h>") {
|
||||||
namespace swig {
|
namespace swig {
|
||||||
struct stop_iteration {
|
struct stop_iteration {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SwigPyIterator {
|
struct SciSwigIterator {
|
||||||
private:
|
private:
|
||||||
SwigPtr_PyObject _seq;
|
SciObject _seq;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
SwigPyIterator(PyObject *seq) : _seq(seq)
|
SciSwigIterator(SciObject seq) : _seq(seq)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual ~SwigPyIterator() {}
|
virtual ~SciSwigIterator() {}
|
||||||
|
|
||||||
// Access iterator method, required by Python
|
virtual SciObject value() const = 0;
|
||||||
virtual PyObject *value() const = 0;
|
|
||||||
|
|
||||||
// Forward iterator method, required by Python
|
virtual SciSwigIterator *incr(size_t n = 1) = 0;
|
||||||
virtual SwigPyIterator *incr(size_t n = 1) = 0;
|
|
||||||
|
virtual SciSwigIterator *decr(size_t n = 1)
|
||||||
// Backward iterator method, very common in C++, but not required in Python
|
|
||||||
virtual SwigPyIterator *decr(size_t /*n*/ = 1)
|
|
||||||
{
|
{
|
||||||
throw stop_iteration();
|
throw stop_iteration();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Random access iterator methods, but not required in Python
|
virtual ptrdiff_t distance(const SciSwigIterator &x) const
|
||||||
virtual ptrdiff_t distance(const SwigPyIterator &/*x*/) const
|
|
||||||
{
|
{
|
||||||
throw std::invalid_argument("operation not supported");
|
throw std::invalid_argument("operation not supported");
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool equal (const SwigPyIterator &/*x*/) const
|
virtual bool equal (const SciSwigIterator &x) const
|
||||||
{
|
{
|
||||||
throw std::invalid_argument("operation not supported");
|
throw std::invalid_argument("operation not supported");
|
||||||
}
|
}
|
||||||
|
|
||||||
// C++ common/needed methods
|
virtual SciSwigIterator *copy() const = 0;
|
||||||
virtual SwigPyIterator *copy() const = 0;
|
|
||||||
|
|
||||||
PyObject *next()
|
SciObject next()
|
||||||
{
|
{
|
||||||
SWIG_PYTHON_THREAD_BEGIN_BLOCK; // disable threads
|
SciObject obj = value();
|
||||||
PyObject *obj = value();
|
incr();
|
||||||
incr();
|
|
||||||
SWIG_PYTHON_THREAD_END_BLOCK; // re-enable threads
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Make an alias for Python 3.x */
|
|
||||||
PyObject *__next__()
|
|
||||||
{
|
|
||||||
return next();
|
|
||||||
}
|
|
||||||
|
|
||||||
PyObject *previous()
|
|
||||||
{
|
|
||||||
SWIG_PYTHON_THREAD_BEGIN_BLOCK; // disable threads
|
|
||||||
decr();
|
|
||||||
PyObject *obj = value();
|
|
||||||
SWIG_PYTHON_THREAD_END_BLOCK; // re-enable threads
|
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
SwigPyIterator *advance(ptrdiff_t n)
|
SciObject previous()
|
||||||
|
{
|
||||||
|
decr();
|
||||||
|
return value();
|
||||||
|
}
|
||||||
|
|
||||||
|
SciSwigIterator *advance(ptrdiff_t n)
|
||||||
{
|
{
|
||||||
return (n > 0) ? incr(n) : decr(-n);
|
return (n > 0) ? incr(n) : decr(-n);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator == (const SwigPyIterator& x) const
|
bool operator == (const SciSwigIterator& x) const
|
||||||
{
|
{
|
||||||
return equal(x);
|
return equal(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator != (const SwigPyIterator& x) const
|
bool operator != (const SciSwigIterator& x) const
|
||||||
{
|
{
|
||||||
return ! operator==(x);
|
return ! operator==(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
SwigPyIterator& operator += (ptrdiff_t n)
|
SciSwigIterator* operator ++ () {
|
||||||
{
|
incr();
|
||||||
return *advance(n);
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
SwigPyIterator& operator -= (ptrdiff_t n)
|
SciSwigIterator* operator -- () {
|
||||||
{
|
decr();
|
||||||
return *advance(-n);
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
SwigPyIterator* operator + (ptrdiff_t n) const
|
SciSwigIterator* operator + (ptrdiff_t n) const
|
||||||
{
|
{
|
||||||
return copy()->advance(n);
|
return copy()->advance(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
SwigPyIterator* operator - (ptrdiff_t n) const
|
SciSwigIterator* operator - (ptrdiff_t n) const
|
||||||
{
|
{
|
||||||
return copy()->advance(-n);
|
return copy()->advance(-n);
|
||||||
}
|
}
|
||||||
|
|
||||||
ptrdiff_t operator - (const SwigPyIterator& x) const
|
ptrdiff_t operator - (const SciSwigIterator& x) const
|
||||||
{
|
{
|
||||||
return x.distance(*this);
|
return x.distance(*this);
|
||||||
}
|
}
|
||||||
|
|
@ -124,35 +104,27 @@ namespace swig {
|
||||||
static int init = 0;
|
static int init = 0;
|
||||||
static swig_type_info* desc = 0;
|
static swig_type_info* desc = 0;
|
||||||
if (!init) {
|
if (!init) {
|
||||||
desc = SWIG_TypeQuery("swig::SwigPyIterator *");
|
desc = SWIG_TypeQuery("swig::SciSwigIterator *");
|
||||||
init = 1;
|
init = 1;
|
||||||
}
|
}
|
||||||
return desc;
|
return desc;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
%#if defined(SWIGPYTHON_BUILTIN)
|
|
||||||
inline PyObject* make_output_iterator_builtin (PyObject *pyself)
|
|
||||||
{
|
|
||||||
Py_INCREF(pyself);
|
|
||||||
return pyself;
|
|
||||||
}
|
|
||||||
%#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
%fragment("SwigPyIterator_T","header",fragment="SwigPyIterator",fragment="StdTraits",fragment="StdIteratorTraits") {
|
%fragment("SciSwigIterator_T","header",fragment="<stddef.h>",fragment="SciSwigIterator",fragment="StdTraits",fragment="StdIteratorTraits") {
|
||||||
namespace swig {
|
namespace swig {
|
||||||
template<typename OutIterator>
|
template<typename OutIterator>
|
||||||
class SwigPyIterator_T : public SwigPyIterator
|
class SciSwigIterator_T : public SciSwigIterator
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef OutIterator out_iterator;
|
typedef OutIterator out_iterator;
|
||||||
typedef typename std::iterator_traits<out_iterator>::value_type value_type;
|
typedef typename std::iterator_traits<out_iterator>::value_type value_type;
|
||||||
typedef SwigPyIterator_T<out_iterator> self_type;
|
typedef SciSwigIterator_T<out_iterator> self_type;
|
||||||
|
|
||||||
SwigPyIterator_T(out_iterator curr, PyObject *seq)
|
SciSwigIterator_T(out_iterator curr, SciObject seq)
|
||||||
: SwigPyIterator(seq), current(curr)
|
: SciSwigIterator(seq), current(curr)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -162,7 +134,7 @@ namespace swig {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool equal (const SwigPyIterator &iter) const
|
bool equal (const SciSwigIterator &iter) const
|
||||||
{
|
{
|
||||||
const self_type *iters = dynamic_cast<const self_type *>(&iter);
|
const self_type *iters = dynamic_cast<const self_type *>(&iter);
|
||||||
if (iters) {
|
if (iters) {
|
||||||
|
|
@ -172,7 +144,7 @@ namespace swig {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ptrdiff_t distance(const SwigPyIterator &iter) const
|
ptrdiff_t distance(const SciSwigIterator &iter) const
|
||||||
{
|
{
|
||||||
const self_type *iters = dynamic_cast<const self_type *>(&iter);
|
const self_type *iters = dynamic_cast<const self_type *>(&iter);
|
||||||
if (iters) {
|
if (iters) {
|
||||||
|
|
@ -190,7 +162,7 @@ namespace swig {
|
||||||
struct from_oper
|
struct from_oper
|
||||||
{
|
{
|
||||||
typedef const ValueType& argument_type;
|
typedef const ValueType& argument_type;
|
||||||
typedef PyObject *result_type;
|
typedef SciObject result_type;
|
||||||
result_type operator()(argument_type v) const
|
result_type operator()(argument_type v) const
|
||||||
{
|
{
|
||||||
return swig::from(v);
|
return swig::from(v);
|
||||||
|
|
@ -200,30 +172,30 @@ namespace swig {
|
||||||
template<typename OutIterator,
|
template<typename OutIterator,
|
||||||
typename ValueType = typename std::iterator_traits<OutIterator>::value_type,
|
typename ValueType = typename std::iterator_traits<OutIterator>::value_type,
|
||||||
typename FromOper = from_oper<ValueType> >
|
typename FromOper = from_oper<ValueType> >
|
||||||
class SwigPyIteratorOpen_T : public SwigPyIterator_T<OutIterator>
|
class SciSwigIteratorOpen_T : public SciSwigIterator_T<OutIterator>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
FromOper from;
|
FromOper from;
|
||||||
typedef OutIterator out_iterator;
|
typedef OutIterator out_iterator;
|
||||||
typedef ValueType value_type;
|
typedef ValueType value_type;
|
||||||
typedef SwigPyIterator_T<out_iterator> base;
|
typedef SciSwigIterator_T<out_iterator> base;
|
||||||
typedef SwigPyIteratorOpen_T<OutIterator, ValueType, FromOper> self_type;
|
typedef SciSwigIteratorOpen_T<OutIterator, ValueType, FromOper> self_type;
|
||||||
|
|
||||||
SwigPyIteratorOpen_T(out_iterator curr, PyObject *seq)
|
SciSwigIteratorOpen_T(out_iterator curr, SciObject seq)
|
||||||
: SwigPyIterator_T<OutIterator>(curr, seq)
|
: SciSwigIterator_T<OutIterator>(curr, seq)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
PyObject *value() const {
|
SciObject value() const {
|
||||||
return from(static_cast<const value_type&>(*(base::current)));
|
return from(static_cast<const value_type&>(*(base::current)));
|
||||||
}
|
}
|
||||||
|
|
||||||
SwigPyIterator *copy() const
|
SciSwigIterator *copy() const
|
||||||
{
|
{
|
||||||
return new self_type(*this);
|
return new self_type(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
SwigPyIterator *incr(size_t n = 1)
|
SciSwigIterator *incr(size_t n = 1)
|
||||||
{
|
{
|
||||||
while (n--) {
|
while (n--) {
|
||||||
++base::current;
|
++base::current;
|
||||||
|
|
@ -231,7 +203,7 @@ namespace swig {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
SwigPyIterator *decr(size_t n = 1)
|
SciSwigIterator *decr(size_t n = 1)
|
||||||
{
|
{
|
||||||
while (n--) {
|
while (n--) {
|
||||||
--base::current;
|
--base::current;
|
||||||
|
|
@ -243,21 +215,21 @@ namespace swig {
|
||||||
template<typename OutIterator,
|
template<typename OutIterator,
|
||||||
typename ValueType = typename std::iterator_traits<OutIterator>::value_type,
|
typename ValueType = typename std::iterator_traits<OutIterator>::value_type,
|
||||||
typename FromOper = from_oper<ValueType> >
|
typename FromOper = from_oper<ValueType> >
|
||||||
class SwigPyIteratorClosed_T : public SwigPyIterator_T<OutIterator>
|
class SciSwigIteratorClosed_T : public SciSwigIterator_T<OutIterator>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
FromOper from;
|
FromOper from;
|
||||||
typedef OutIterator out_iterator;
|
typedef OutIterator out_iterator;
|
||||||
typedef ValueType value_type;
|
typedef ValueType value_type;
|
||||||
typedef SwigPyIterator_T<out_iterator> base;
|
typedef SciSwigIterator_T<out_iterator> base;
|
||||||
typedef SwigPyIteratorClosed_T<OutIterator, ValueType, FromOper> self_type;
|
typedef SciSwigIteratorClosed_T<OutIterator, ValueType, FromOper> self_type;
|
||||||
|
|
||||||
SwigPyIteratorClosed_T(out_iterator curr, out_iterator first, out_iterator last, PyObject *seq)
|
SciSwigIteratorClosed_T(out_iterator curr, out_iterator first, out_iterator last, SciObject seq)
|
||||||
: SwigPyIterator_T<OutIterator>(curr, seq), begin(first), end(last)
|
: SciSwigIterator_T<OutIterator>(curr, seq), begin(first), end(last)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
PyObject *value() const {
|
SciObject value() const {
|
||||||
if (base::current == end) {
|
if (base::current == end) {
|
||||||
throw stop_iteration();
|
throw stop_iteration();
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -265,12 +237,12 @@ namespace swig {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SwigPyIterator *copy() const
|
SciSwigIterator *copy() const
|
||||||
{
|
{
|
||||||
return new self_type(*this);
|
return new self_type(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
SwigPyIterator *incr(size_t n = 1)
|
SciSwigIterator *incr(size_t n = 1)
|
||||||
{
|
{
|
||||||
while (n--) {
|
while (n--) {
|
||||||
if (base::current == end) {
|
if (base::current == end) {
|
||||||
|
|
@ -282,7 +254,7 @@ namespace swig {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
SwigPyIterator *decr(size_t n = 1)
|
SciSwigIterator *decr(size_t n = 1)
|
||||||
{
|
{
|
||||||
while (n--) {
|
while (n--) {
|
||||||
if (base::current == begin) {
|
if (base::current == begin) {
|
||||||
|
|
@ -300,107 +272,86 @@ namespace swig {
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename OutIter>
|
template<typename OutIter>
|
||||||
inline SwigPyIterator*
|
inline SciSwigIterator*
|
||||||
make_output_iterator(const OutIter& current, const OutIter& begin,const OutIter& end, PyObject *seq = 0)
|
make_output_iterator(const OutIter& current, const OutIter& begin,const OutIter& end, SciObject seq = SciObject())
|
||||||
{
|
{
|
||||||
return new SwigPyIteratorClosed_T<OutIter>(current, begin, end, seq);
|
return new SciSwigIteratorClosed_T<OutIter>(current, begin, end, seq);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename OutIter>
|
template<typename OutIter>
|
||||||
inline SwigPyIterator*
|
inline SciSwigIterator*
|
||||||
make_output_iterator(const OutIter& current, PyObject *seq = 0)
|
make_output_iterator(const OutIter& current, SciObject seq = SciObject())
|
||||||
{
|
{
|
||||||
return new SwigPyIteratorOpen_T<OutIter>(current, seq);
|
return new SciSwigIteratorOpen_T<OutIter>(current, seq);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
%fragment("SwigPyIterator");
|
%fragment("SciSwigIterator");
|
||||||
namespace swig
|
namespace swig
|
||||||
{
|
{
|
||||||
/*
|
// Throw a StopIteration exception
|
||||||
Throw a StopIteration exception
|
|
||||||
*/
|
|
||||||
%ignore stop_iteration;
|
%ignore stop_iteration;
|
||||||
struct stop_iteration {};
|
struct stop_iteration {};
|
||||||
|
|
||||||
%typemap(throws) stop_iteration {
|
%typemap(throws) stop_iteration {
|
||||||
(void)$1;
|
Scierror(999, "stop_iteration exception");
|
||||||
SWIG_SetErrorObj(PyExc_StopIteration, SWIG_Py_Void());
|
|
||||||
SWIG_fail;
|
SWIG_fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
// Mark methods that return new objects
|
||||||
Mark methods that return new objects
|
%newobject SciSwigIterator::copy;
|
||||||
*/
|
%newobject SciSwigIterator::operator + (ptrdiff_t n) const;
|
||||||
%newobject SwigPyIterator::copy;
|
%newobject SciSwigIterator::operator - (ptrdiff_t n) const;
|
||||||
%newobject SwigPyIterator::operator + (ptrdiff_t n) const;
|
|
||||||
%newobject SwigPyIterator::operator - (ptrdiff_t n) const;
|
|
||||||
|
|
||||||
%nodirector SwigPyIterator;
|
%nodirector SciSwigIterator;
|
||||||
|
|
||||||
#if defined(SWIGPYTHON_BUILTIN)
|
%catches(swig::stop_iteration) SciSwigIterator::value() const;
|
||||||
%feature("python:tp_iter") SwigPyIterator "&swig::make_output_iterator_builtin";
|
%catches(swig::stop_iteration) SciSwigIterator::incr(size_t n = 1);
|
||||||
%feature("python:slot", "tp_iternext", functype="iternextfunc") SwigPyIterator::__next__;
|
%catches(swig::stop_iteration) SciSwigIterator::decr(size_t n = 1);
|
||||||
#else
|
%catches(std::invalid_argument) SciSwigIterator::distance(const SciSwigIterator &x) const;
|
||||||
%extend SwigPyIterator {
|
%catches(std::invalid_argument) SciSwigIterator::equal (const SciSwigIterator &x) const;
|
||||||
//%scilabcode {def __iter__(self): return self}
|
%catches(swig::stop_iteration) SciSwigIterator::next();
|
||||||
}
|
%catches(swig::stop_iteration) SciSwigIterator::previous();
|
||||||
#endif
|
%catches(swig::stop_iteration) SciSwigIterator::advance(ptrdiff_t n);
|
||||||
|
%catches(swig::stop_iteration) SciSwigIterator::operator += (ptrdiff_t n);
|
||||||
|
%catches(swig::stop_iteration) SciSwigIterator::operator -= (ptrdiff_t n);
|
||||||
|
%catches(swig::stop_iteration) SciSwigIterator::operator + (ptrdiff_t n) const;
|
||||||
|
%catches(swig::stop_iteration) SciSwigIterator::operator - (ptrdiff_t n) const;
|
||||||
|
|
||||||
%catches(swig::stop_iteration) SwigPyIterator::value() const;
|
|
||||||
%catches(swig::stop_iteration) SwigPyIterator::incr(size_t n = 1);
|
|
||||||
%catches(swig::stop_iteration) SwigPyIterator::decr(size_t n = 1);
|
|
||||||
%catches(std::invalid_argument) SwigPyIterator::distance(const SwigPyIterator &x) const;
|
|
||||||
%catches(std::invalid_argument) SwigPyIterator::equal (const SwigPyIterator &x) const;
|
|
||||||
%catches(swig::stop_iteration) SwigPyIterator::__next__();
|
|
||||||
%catches(swig::stop_iteration) SwigPyIterator::next();
|
|
||||||
%catches(swig::stop_iteration) SwigPyIterator::previous();
|
|
||||||
%catches(swig::stop_iteration) SwigPyIterator::advance(ptrdiff_t n);
|
|
||||||
%catches(swig::stop_iteration) SwigPyIterator::operator += (ptrdiff_t n);
|
|
||||||
%catches(swig::stop_iteration) SwigPyIterator::operator -= (ptrdiff_t n);
|
|
||||||
%catches(swig::stop_iteration) SwigPyIterator::operator + (ptrdiff_t n) const;
|
|
||||||
%catches(swig::stop_iteration) SwigPyIterator::operator - (ptrdiff_t n) const;
|
|
||||||
|
|
||||||
struct SwigPyIterator
|
struct SciSwigIterator
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
SwigPyIterator(PyObject *seq);
|
SciSwigIterator(SciObject seq);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual ~SwigPyIterator();
|
virtual ~SciSwigIterator();
|
||||||
|
|
||||||
// Access iterator method, required by Python
|
virtual SciObject value() const = 0;
|
||||||
virtual PyObject *value() const = 0;
|
|
||||||
|
|
||||||
// Forward iterator method, required by Python
|
virtual SciSwigIterator *incr(size_t n = 1) = 0;
|
||||||
virtual SwigPyIterator *incr(size_t n = 1) = 0;
|
|
||||||
|
|
||||||
// Backward iterator method, very common in C++, but not required in Python
|
virtual SciSwigIterator *decr(size_t n = 1);
|
||||||
virtual SwigPyIterator *decr(size_t n = 1);
|
|
||||||
|
|
||||||
// Random access iterator methods, but not required in Python
|
virtual ptrdiff_t distance(const SciSwigIterator &x) const;
|
||||||
virtual ptrdiff_t distance(const SwigPyIterator &x) const;
|
|
||||||
|
|
||||||
virtual bool equal (const SwigPyIterator &x) const;
|
virtual bool equal (const SciSwigIterator &x) const;
|
||||||
|
|
||||||
// C++ common/needed methods
|
virtual SciSwigIterator *copy() const = 0;
|
||||||
virtual SwigPyIterator *copy() const = 0;
|
|
||||||
|
|
||||||
PyObject *next();
|
SciObject next();
|
||||||
PyObject *__next__();
|
SciObject previous();
|
||||||
PyObject *previous();
|
SciSwigIterator *advance(ptrdiff_t n);
|
||||||
SwigPyIterator *advance(ptrdiff_t n);
|
|
||||||
|
|
||||||
bool operator == (const SwigPyIterator& x) const;
|
bool operator == (const SciSwigIterator& x) const;
|
||||||
bool operator != (const SwigPyIterator& x) const;
|
bool operator != (const SciSwigIterator& x) const;
|
||||||
SwigPyIterator& operator += (ptrdiff_t n);
|
SciSwigIterator* operator ++ ();
|
||||||
SwigPyIterator& operator -= (ptrdiff_t n);
|
SciSwigIterator* operator -- ();
|
||||||
SwigPyIterator* operator + (ptrdiff_t n) const;
|
SciSwigIterator* operator + (ptrdiff_t n) const;
|
||||||
SwigPyIterator* operator - (ptrdiff_t n) const;
|
SciSwigIterator* operator - (ptrdiff_t n) const;
|
||||||
ptrdiff_t operator - (const SwigPyIterator& x) const;
|
ptrdiff_t operator - (const SciSwigIterator& x) const;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,3 +23,6 @@ static int SWIG_Scilab_GetOutputPositionAndReset(void) {
|
||||||
static void SWIG_Scilab_SetOutputPosition(int _outputPosition) {
|
static void SWIG_Scilab_SetOutputPosition(int _outputPosition) {
|
||||||
outputPosition = _outputPosition;
|
outputPosition = _outputPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define Scilab_Error_Occurred() 0
|
||||||
|
#define SWIG_Scilab_AddErrorMsg(msg) {;}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue