Initial commit of Octave module.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@10290 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
50b1578e19
commit
393391965c
275 changed files with 14004 additions and 5 deletions
1
Lib/octave/attribute.i
Normal file
1
Lib/octave/attribute.i
Normal file
|
|
@ -0,0 +1 @@
|
|||
%include <typemaps/attribute.swg>
|
||||
5
Lib/octave/carrays.i
Normal file
5
Lib/octave/carrays.i
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
%define %array_class(TYPE,NAME)
|
||||
%array_class_wrap(TYPE,NAME,__paren,__paren_asgn)
|
||||
%enddef
|
||||
|
||||
%include <typemaps/carrays.swg>
|
||||
1
Lib/octave/cdata.i
Normal file
1
Lib/octave/cdata.i
Normal file
|
|
@ -0,0 +1 @@
|
|||
%include <typemaps/cdata.swg>
|
||||
1
Lib/octave/cmalloc.i
Normal file
1
Lib/octave/cmalloc.i
Normal file
|
|
@ -0,0 +1 @@
|
|||
%include <typemaps/cmalloc.swg>
|
||||
3
Lib/octave/director.swg
Normal file
3
Lib/octave/director.swg
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
|
||||
// ***** move the director stuff from octrun.swg here...
|
||||
|
||||
6
Lib/octave/exception.i
Normal file
6
Lib/octave/exception.i
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
%include <typemaps/exception.swg>
|
||||
|
||||
|
||||
%insert("runtime") {
|
||||
%define_as(SWIG_exception(code, msg), %block(%error(code, msg); SWIG_fail; ))
|
||||
}
|
||||
1
Lib/octave/factory.i
Normal file
1
Lib/octave/factory.i
Normal file
|
|
@ -0,0 +1 @@
|
|||
%include <typemaps/factory.swg>
|
||||
7
Lib/octave/implicit.i
Normal file
7
Lib/octave/implicit.i
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
%include <std_common.i>
|
||||
%include <typemaps/implicit.swg>
|
||||
|
||||
#warning "This file provides the %implicit directive, which is an old and fragile"
|
||||
#warning "way to implement the C++ implicit conversion mechanism."
|
||||
#warning "Try using the more robust '%implicitconv Type;' directive instead."
|
||||
|
||||
12
Lib/octave/octave.swg
Normal file
12
Lib/octave/octave.swg
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
|
||||
|
||||
%include <typemaps/swigmacros.swg>
|
||||
%include <typemaps/fragments.swg>
|
||||
%include <octruntime.swg>
|
||||
%include <octtypemaps.swg>
|
||||
%include <octopers.swg>
|
||||
|
||||
|
||||
%typemap(constcode) int double {
|
||||
SWIG_Octave_SetConstant(module_ns,"$symname",octave_value($value));
|
||||
}
|
||||
95
Lib/octave/octcomplex.swg
Normal file
95
Lib/octave/octcomplex.swg
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
/*
|
||||
Defines the As/From conversors for double/float complex, you need to
|
||||
provide complex Type, the Name you want to use in the conversors,
|
||||
the complex Constructor method, and the Real and Imag complex
|
||||
accesor methods.
|
||||
|
||||
See the std_complex.i and ccomplex.i for concret examples.
|
||||
*/
|
||||
|
||||
/* the common from conversor */
|
||||
%define %swig_fromcplx_conv(Type, Real, Imag)
|
||||
%fragment(SWIG_From_frag(Type),"header")
|
||||
{
|
||||
SWIGINTERNINLINE octave_value
|
||||
SWIG_From(Type)(%ifcplusplus(const Type&, Type) c)
|
||||
{
|
||||
return octave_value(Complex(Real(c), Imag(c)));
|
||||
}
|
||||
}
|
||||
%enddef
|
||||
|
||||
// the double case
|
||||
%define %swig_cplxdbl_conv(Type, Constructor, Real, Imag)
|
||||
%fragment(SWIG_AsVal_frag(Type),"header",
|
||||
fragment=SWIG_AsVal_frag(double))
|
||||
{
|
||||
SWIGINTERN int
|
||||
SWIG_AsVal(Type) (const octave_value& ov, Type* val)
|
||||
{
|
||||
if (ov.is_complex_scalar()) {
|
||||
if (val) {
|
||||
Complex c(ov.complex_value());
|
||||
*val=Constructor(c.real(),c.imag());
|
||||
}
|
||||
return SWIG_OK;
|
||||
} else {
|
||||
double d;
|
||||
int res = SWIG_AddCast(SWIG_AsVal(double)(ov, &d));
|
||||
if (SWIG_IsOK(res)) {
|
||||
if (val)
|
||||
*val = Constructor(d, 0.0);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
}
|
||||
%swig_fromcplx_conv(Type, Real, Imag);
|
||||
%enddef
|
||||
|
||||
// the float case
|
||||
%define %swig_cplxflt_conv(Type, Constructor, Real, Imag)
|
||||
%fragment(SWIG_AsVal_frag(Type),"header",
|
||||
fragment=SWIG_AsVal_frag(float)) {
|
||||
SWIGINTERN int
|
||||
SWIG_AsVal(Type)(PyObject *o, Type *val)
|
||||
{
|
||||
if (ov.is_complex_scalar()) {
|
||||
if (val) {
|
||||
Complex c(ov.complex_value());
|
||||
double re = c.real();
|
||||
double im = c.imag();
|
||||
if ((-FLT_MAX <= re && re <= FLT_MAX) && (-FLT_MAX <= im && im <= FLT_MAX)) {
|
||||
if (val)
|
||||
*val = Constructor(%numeric_cast(re, float),
|
||||
%numeric_cast(im, float));
|
||||
return SWIG_OK;
|
||||
} else
|
||||
return SWIG_OverflowError;
|
||||
}
|
||||
} else {
|
||||
float d;
|
||||
int res = SWIG_AddCast(SWIG_AsVal(float)(ov, &d));
|
||||
if (SWIG_IsOK(res)) {
|
||||
if (val)
|
||||
*val = Constructor(d, 0.0);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
}
|
||||
|
||||
%swig_fromcplx_conv(Type, Real, Imag);
|
||||
%enddef
|
||||
|
||||
#define %swig_cplxflt_convn(Type, Constructor, Real, Imag) \
|
||||
%swig_cplxflt_conv(Type, Constructor, Real, Imag)
|
||||
|
||||
|
||||
#define %swig_cplxdbl_convn(Type, Constructor, Real, Imag) \
|
||||
%swig_cplxdbl_conv(Type, Constructor, Real, Imag)
|
||||
|
||||
|
||||
|
||||
640
Lib/octave/octcontainer.swg
Normal file
640
Lib/octave/octcontainer.swg
Normal file
|
|
@ -0,0 +1,640 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* See the LICENSE file for information on copyright, usage and redistribution
|
||||
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
|
||||
*
|
||||
* pycontainer.swg
|
||||
*
|
||||
* Octave sequence <-> C++ container wrapper
|
||||
*
|
||||
* This wrapper, and its iterator, allows a general use (and reuse) of
|
||||
* the the mapping between C++ and Octave, thanks to the C++
|
||||
* templates.
|
||||
*
|
||||
* Of course, it needs the C++ compiler to support templates, but
|
||||
* since we will use this wrapper with the STL containers, that should
|
||||
* be the case.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
%{
|
||||
#include <iostream>
|
||||
%}
|
||||
|
||||
|
||||
#if !defined(SWIG_NO_EXPORT_ITERATOR_METHODS)
|
||||
# if !defined(SWIG_EXPORT_ITERATOR_METHODS)
|
||||
# define SWIG_EXPORT_ITERATOR_METHODS SWIG_EXPORT_ITERATOR_METHODS
|
||||
# endif
|
||||
#endif
|
||||
|
||||
%include <octiterators.swg>
|
||||
|
||||
// The Octave C++ Wrap
|
||||
|
||||
%insert(header) %{
|
||||
#include <stdexcept>
|
||||
%}
|
||||
|
||||
%include <std_except.i>
|
||||
|
||||
%fragment(SWIG_Traits_frag(octave_value),"header",fragment="StdTraits") {
|
||||
namespace swig {
|
||||
template <> struct traits<octave_value > {
|
||||
typedef value_category category;
|
||||
static const char* type_name() { return "octave_value"; }
|
||||
};
|
||||
|
||||
template <> struct traits_from<octave_value> {
|
||||
typedef octave_value value_type;
|
||||
static octave_value from(const value_type& val) {
|
||||
return val;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct traits_check<octave_value, value_category> {
|
||||
static bool check(octave_value) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
template <> struct traits_asval<octave_value > {
|
||||
typedef octave_value value_type;
|
||||
static int asval(octave_value obj, value_type *val) {
|
||||
if (val) *val = obj;
|
||||
return SWIG_OK;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
%fragment("OctSequence_Base","header")
|
||||
{
|
||||
%#include <functional>
|
||||
|
||||
namespace std {
|
||||
template <>
|
||||
struct less <octave_value>: public binary_function<octave_value, octave_value, bool>
|
||||
{
|
||||
bool
|
||||
operator()(octave_value v, octave_value w) const
|
||||
{
|
||||
/*
|
||||
bool res;
|
||||
SWIG_PYTHON_THREAD_BEGIN_BLOCK;
|
||||
res = PyObject_Compare(v, w) < 0;
|
||||
SWIG_PYTHON_THREAD_END_BLOCK;
|
||||
return res;
|
||||
*/
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
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("OctSequence_Cont","header",
|
||||
fragment="StdTraits",
|
||||
fragment="OctSequence_Base",
|
||||
fragment="OctSwigIterator_T")
|
||||
{
|
||||
namespace swig
|
||||
{
|
||||
template <class T>
|
||||
struct OctSequence_Ref
|
||||
{
|
||||
OctSequence_Ref(octave_value seq, int index)
|
||||
: _seq(seq), _index(index)
|
||||
{
|
||||
}
|
||||
|
||||
operator T () const
|
||||
{
|
||||
// swig::PyObject_var item = OctSequence_GetItem(_seq, _index);
|
||||
octave_value item; // * todo
|
||||
try {
|
||||
return swig::as<T>(item, true);
|
||||
} catch (std::exception& e) {
|
||||
char msg[1024];
|
||||
sprintf(msg, "in sequence element %d ", _index);
|
||||
if (!Octave_Error_Occurred()) {
|
||||
%type_error(swig::type_name<T>());
|
||||
}
|
||||
SWIG_Octave_AddErrorMsg(msg);
|
||||
SWIG_Octave_AddErrorMsg(e.what());
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
OctSequence_Ref& operator=(const T& v)
|
||||
{
|
||||
// OctSequence_SetItem(_seq, _index, swig::from<T>(v));
|
||||
// * todo
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
octave_value _seq;
|
||||
int _index;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct OctSequence_ArrowProxy
|
||||
{
|
||||
OctSequence_ArrowProxy(const T& x): m_value(x) {}
|
||||
const T* operator->() const { return &m_value; }
|
||||
operator const T*() const { return &m_value; }
|
||||
T m_value;
|
||||
};
|
||||
|
||||
template <class T, class Reference >
|
||||
struct OctSequence_InputIterator
|
||||
{
|
||||
typedef OctSequence_InputIterator<T, Reference > self;
|
||||
|
||||
typedef std::random_access_iterator_tag iterator_category;
|
||||
typedef Reference reference;
|
||||
typedef T value_type;
|
||||
typedef T* pointer;
|
||||
typedef int difference_type;
|
||||
|
||||
OctSequence_InputIterator()
|
||||
{
|
||||
}
|
||||
|
||||
OctSequence_InputIterator(octave_value seq, int index)
|
||||
: _seq(seq), _index(index)
|
||||
{
|
||||
}
|
||||
|
||||
reference operator*() const
|
||||
{
|
||||
return reference(_seq, _index);
|
||||
}
|
||||
|
||||
OctSequence_ArrowProxy<T>
|
||||
operator->() const {
|
||||
return OctSequence_ArrowProxy<T>(operator*());
|
||||
}
|
||||
|
||||
bool operator==(const self& ri) const
|
||||
{
|
||||
return (_index == ri._index) && (_seq == ri._seq);
|
||||
}
|
||||
|
||||
bool operator!=(const self& ri) const
|
||||
{
|
||||
return !(operator==(ri));
|
||||
}
|
||||
|
||||
self& operator ++ ()
|
||||
{
|
||||
++_index;
|
||||
return *this;
|
||||
}
|
||||
|
||||
self& operator -- ()
|
||||
{
|
||||
--_index;
|
||||
return *this;
|
||||
}
|
||||
|
||||
self& operator += (difference_type n)
|
||||
{
|
||||
_index += n;
|
||||
return *this;
|
||||
}
|
||||
|
||||
self operator +(difference_type n) const
|
||||
{
|
||||
return self(_seq, _index + n);
|
||||
}
|
||||
|
||||
self& operator -= (difference_type n)
|
||||
{
|
||||
_index -= n;
|
||||
return *this;
|
||||
}
|
||||
|
||||
self operator -(difference_type n) const
|
||||
{
|
||||
return self(_seq, _index - n);
|
||||
}
|
||||
|
||||
difference_type operator - (const self& ri) const
|
||||
{
|
||||
return _index - ri._index;
|
||||
}
|
||||
|
||||
bool operator < (const self& ri) const
|
||||
{
|
||||
return _index < ri._index;
|
||||
}
|
||||
|
||||
reference
|
||||
operator[](difference_type n) const
|
||||
{
|
||||
return reference(_seq, _index + n);
|
||||
}
|
||||
|
||||
private:
|
||||
octave_value _seq;
|
||||
difference_type _index;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct OctSequence_Cont
|
||||
{
|
||||
typedef OctSequence_Ref<T> reference;
|
||||
typedef const OctSequence_Ref<T> const_reference;
|
||||
typedef T value_type;
|
||||
typedef T* pointer;
|
||||
typedef int difference_type;
|
||||
typedef int size_type;
|
||||
typedef const pointer const_pointer;
|
||||
typedef OctSequence_InputIterator<T, reference> iterator;
|
||||
typedef OctSequence_InputIterator<T, const_reference> const_iterator;
|
||||
|
||||
OctSequence_Cont(octave_value seq) : _seq(seq)
|
||||
{
|
||||
// * assert that we have map type etc.
|
||||
/*
|
||||
if (!OctSequence_Check(seq)) {
|
||||
throw std::invalid_argument("a sequence is expected");
|
||||
}
|
||||
_seq = seq;
|
||||
Py_INCREF(_seq);
|
||||
*/
|
||||
}
|
||||
|
||||
~OctSequence_Cont()
|
||||
{
|
||||
}
|
||||
|
||||
size_type size() const
|
||||
{
|
||||
// return static_cast<size_type>(OctSequence_Size(_seq));
|
||||
return 0; // * todo
|
||||
}
|
||||
|
||||
bool empty() const
|
||||
{
|
||||
return size() == 0;
|
||||
}
|
||||
|
||||
iterator begin()
|
||||
{
|
||||
return iterator(_seq, 0);
|
||||
}
|
||||
|
||||
const_iterator begin() const
|
||||
{
|
||||
return const_iterator(_seq, 0);
|
||||
}
|
||||
|
||||
iterator end()
|
||||
{
|
||||
return iterator(_seq, size());
|
||||
}
|
||||
|
||||
const_iterator end() const
|
||||
{
|
||||
return const_iterator(_seq, size());
|
||||
}
|
||||
|
||||
reference operator[](difference_type n)
|
||||
{
|
||||
return reference(_seq, n);
|
||||
}
|
||||
|
||||
const_reference operator[](difference_type n) const
|
||||
{
|
||||
return const_reference(_seq, n);
|
||||
}
|
||||
|
||||
bool check(bool set_err = true) const
|
||||
{
|
||||
int s = size();
|
||||
for (int i = 0; i < s; ++i) {
|
||||
// swig::PyObject_var item = OctSequence_GetItem(_seq, i);
|
||||
octave_value 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:
|
||||
octave_value _seq;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
%define %swig_sequence_iterator(Sequence...)
|
||||
#if defined(SWIG_EXPORT_ITERATOR_METHODS)
|
||||
class iterator;
|
||||
class reverse_iterator;
|
||||
class const_iterator;
|
||||
class const_reverse_iterator;
|
||||
|
||||
%typemap(out,noblock=1,fragment="OctSequence_Cont")
|
||||
iterator, reverse_iterator, const_iterator, const_reverse_iterator {
|
||||
/*
|
||||
$result = SWIG_NewPointerObj(swig::make_output_iterator(%static_cast($1,const $type &)),
|
||||
swig::OctSwigIterator::descriptor(),SWIG_POINTER_OWN);
|
||||
*/
|
||||
}
|
||||
%typemap(out,noblock=1,fragment="OctSequence_Cont")
|
||||
std::pair<iterator, iterator>, std::pair<const_iterator, const_iterator> {
|
||||
/*
|
||||
$result = PyTuple_New(2);
|
||||
PyTuple_SetItem($result,0,SWIG_NewPointerObj(swig::make_output_iterator(%static_cast($1,const $type &).first),
|
||||
swig::OctSwigIterator::descriptor(),SWIG_POINTER_OWN));
|
||||
PyTuple_SetItem($result,1,SWIG_NewPointerObj(swig::make_output_iterator(%static_cast($1,const $type &).second),
|
||||
swig::OctSwigIterator::descriptor(),SWIG_POINTER_OWN));
|
||||
*/
|
||||
}
|
||||
|
||||
%fragment("PyPairBoolOutputIterator","header",fragment=SWIG_From_frag(bool),fragment="OctSequence_Cont") {}
|
||||
|
||||
%typemap(out,noblock=1,fragment="OctPairBoolOutputIterator")
|
||||
std::pair<iterator, bool>, std::pair<const_iterator, bool> {
|
||||
/*
|
||||
$result = PyTuple_New(2);
|
||||
PyTuple_SetItem($result,0,SWIG_NewPointerObj(swig::make_output_iterator(%static_cast($1,const $type &).first),
|
||||
swig::OctSwigIterator::descriptor(),SWIG_POINTER_OWN));
|
||||
PyTuple_SetItem($result,1,SWIG_From(bool)(%static_cast($1,const $type &).second));
|
||||
*/
|
||||
}
|
||||
|
||||
%typemap(in,noblock=1,fragment="OctSequence_Cont")
|
||||
iterator(swig::OctSwigIterator *iter = 0, int res),
|
||||
reverse_iterator(swig::OctSwigIterator *iter = 0, int res),
|
||||
const_iterator(swig::OctSwigIterator *iter = 0, int res),
|
||||
const_reverse_iterator(swig::OctSwigIterator *iter = 0, int res) {
|
||||
/*
|
||||
res = SWIG_ConvertPtr($input, %as_voidptrptr(&iter), swig::OctSwigIterator::descriptor(), 0);
|
||||
if (!SWIG_IsOK(res) || !iter) {
|
||||
%argument_fail(SWIG_TypeError, "$type", $symname, $argnum);
|
||||
} else {
|
||||
swig::OctSwigIterator_T<$type > *iter_t = dynamic_cast<swig::OctSwigIterator_T<$type > *>(iter);
|
||||
if (iter_t) {
|
||||
$1 = iter_t->get_current();
|
||||
} else {
|
||||
%argument_fail(SWIG_TypeError, "$type", $symname, $argnum);
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
%typecheck(%checkcode(ITERATOR),noblock=1,fragment="OctSequence_Cont")
|
||||
iterator, reverse_iterator, const_iterator, const_reverse_iterator {
|
||||
/*
|
||||
swig::OctSwigIterator *iter = 0;
|
||||
int res = SWIG_ConvertPtr($input, %as_voidptrptr(&iter), swig::OctSwigIterator::descriptor(), 0);
|
||||
$1 = (SWIG_IsOK(res) && iter && (dynamic_cast<swig::OctSwigIterator_T<$type > *>(iter) != 0));
|
||||
*/
|
||||
}
|
||||
|
||||
%fragment("OctSequence_Cont");
|
||||
#endif //SWIG_EXPORT_ITERATOR_METHODS
|
||||
%enddef
|
||||
|
||||
// The octave container methods
|
||||
|
||||
%define %swig_container_methods(Container...)
|
||||
%enddef
|
||||
|
||||
%define %swig_sequence_methods_common(Sequence...)
|
||||
%swig_sequence_iterator(%arg(Sequence))
|
||||
%swig_container_methods(%arg(Sequence))
|
||||
|
||||
%fragment("OctSequence_Base");
|
||||
%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))
|
||||
%extend {
|
||||
value_type __getitem__(difference_type i) throw (std::out_of_range) {
|
||||
return *(swig::cgetpos(self, i));
|
||||
}
|
||||
|
||||
void __setitem__(difference_type i, value_type x) throw (std::out_of_range) {
|
||||
*(swig::getpos(self,i)) = x;
|
||||
}
|
||||
|
||||
void append(value_type x) {
|
||||
self->push_back(x);
|
||||
}
|
||||
}
|
||||
%enddef
|
||||
|
||||
//
|
||||
// Common fragments
|
||||
//
|
||||
|
||||
%fragment("StdSequenceTraits","header",
|
||||
fragment="StdTraits",
|
||||
fragment="OctSequence_Cont")
|
||||
{
|
||||
namespace swig {
|
||||
template <class PySeq, class Seq>
|
||||
inline void
|
||||
assign(const PySeq& pyseq, Seq* seq) {
|
||||
%#ifdef SWIG_STD_NOASSIGN_STL
|
||||
typedef typename PySeq::value_type value_type;
|
||||
typename PySeq::const_iterator it = pyseq.begin();
|
||||
for (;it != pyseq.end(); ++it) {
|
||||
seq->insert(seq->end(),(value_type)(*it));
|
||||
}
|
||||
%#else
|
||||
seq->assign(pyseq.begin(), pyseq.end());
|
||||
%#endif
|
||||
}
|
||||
|
||||
template <class Seq, class T = typename Seq::value_type >
|
||||
struct traits_asptr_stdseq {
|
||||
typedef Seq sequence;
|
||||
typedef T value_type;
|
||||
|
||||
static int asptr(octave_value obj, sequence **seq) {
|
||||
/*
|
||||
if (obj == Py_None || SWIG_Python_GetSwigThis(obj)) {
|
||||
sequence *p;
|
||||
if (SWIG_ConvertPtr(obj,(void**)&p,
|
||||
swig::type_info<sequence>(),0) == SWIG_OK) {
|
||||
if (seq) *seq = p;
|
||||
return SWIG_OLDOBJ;
|
||||
}
|
||||
} else if (OctSequence_Check(obj)) {
|
||||
try {
|
||||
OctSequence_Cont<value_type> pyseq(obj);
|
||||
if (seq) {
|
||||
sequence *pseq = new sequence();
|
||||
assign(pyseq, pseq);
|
||||
*seq = pseq;
|
||||
return SWIG_NEWOBJ;
|
||||
} else {
|
||||
return pyseq.check() ? SWIG_OK : SWIG_ERROR;
|
||||
}
|
||||
} catch (std::exception& e) {
|
||||
if (seq) {
|
||||
if (!PyErr_Occurred()) {
|
||||
PyErr_SetString(PyExc_TypeError, e.what());
|
||||
}
|
||||
}
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
}
|
||||
return SWIG_ERROR;
|
||||
*/
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
};
|
||||
|
||||
template <class Seq, class T = typename Seq::value_type >
|
||||
struct traits_from_stdseq {
|
||||
typedef Seq sequence;
|
||||
typedef T value_type;
|
||||
typedef typename Seq::size_type size_type;
|
||||
typedef typename sequence::const_iterator const_iterator;
|
||||
|
||||
static octave_value from(const sequence& seq) {
|
||||
/*
|
||||
#ifdef SWIG_PYTHON_EXTRA_NATIVE_CONTAINERS
|
||||
swig_type_info *desc = swig::type_info<sequence>();
|
||||
if (desc && desc->clientdata) {
|
||||
return SWIG_NewPointerObj(new sequence(seq), desc, SWIG_POINTER_OWN);
|
||||
}
|
||||
#endif
|
||||
size_type size = seq.size();
|
||||
if (size <= (size_type)INT_MAX) {
|
||||
PyObject *obj = PyTuple_New((int)size);
|
||||
int i = 0;
|
||||
for (const_iterator it = seq.begin();
|
||||
it != seq.end(); ++it, ++i) {
|
||||
PyTuple_SetItem(obj,i,swig::from<value_type>(*it));
|
||||
}
|
||||
return obj;
|
||||
} else {
|
||||
PyErr_SetString(PyExc_OverflowError,"sequence size not valid in python");
|
||||
return NULL;
|
||||
}
|
||||
*/
|
||||
return octave_value();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
1
Lib/octave/octfragments.swg
Normal file
1
Lib/octave/octfragments.swg
Normal file
|
|
@ -0,0 +1 @@
|
|||
|
||||
379
Lib/octave/octiterators.swg
Normal file
379
Lib/octave/octiterators.swg
Normal file
|
|
@ -0,0 +1,379 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* See the LICENSE file for information on copyright, usage and redistribution
|
||||
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
|
||||
*
|
||||
* pyiterators.swg
|
||||
*
|
||||
* Implement a python 'output' iterator for Python 2.2 or higher.
|
||||
*
|
||||
* Users can derive form the OctSwigIterator to implemet their
|
||||
* own iterators. As an example (real one since we use it for STL/STD
|
||||
* containers), the template OctSwigIterator_T does the
|
||||
* implementation for generic C++ iterators.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
%include <std_common.i>
|
||||
|
||||
%fragment("OctSwigIterator","header") {
|
||||
namespace swig {
|
||||
struct stop_iteration {
|
||||
};
|
||||
|
||||
struct OctSwigIterator {
|
||||
private:
|
||||
octave_value _seq;
|
||||
|
||||
protected:
|
||||
OctSwigIterator(octave_value seq) : _seq(seq)
|
||||
{
|
||||
}
|
||||
|
||||
public:
|
||||
virtual ~OctSwigIterator() {}
|
||||
|
||||
// Access iterator method, required by Python
|
||||
virtual octave_value value() const = 0;
|
||||
|
||||
// Forward iterator method, required by Python
|
||||
virtual OctSwigIterator *incr(size_t n = 1) = 0;
|
||||
|
||||
// Backward iterator method, very common in C++, but not required in Python
|
||||
virtual OctSwigIterator *decr(size_t n = 1)
|
||||
{
|
||||
throw stop_iteration();
|
||||
}
|
||||
|
||||
// Random access iterator methods, but not required in Python
|
||||
virtual ptrdiff_t distance(const OctSwigIterator &x) const
|
||||
{
|
||||
throw std::invalid_argument("operation not supported");
|
||||
}
|
||||
|
||||
virtual bool equal (const OctSwigIterator &x) const
|
||||
{
|
||||
throw std::invalid_argument("operation not supported");
|
||||
}
|
||||
|
||||
// C++ common/needed methods
|
||||
virtual OctSwigIterator *copy() const = 0;
|
||||
|
||||
octave_value next()
|
||||
{
|
||||
octave_value obj = value();
|
||||
incr();
|
||||
return obj;
|
||||
}
|
||||
|
||||
octave_value previous()
|
||||
{
|
||||
decr();
|
||||
return value();
|
||||
}
|
||||
|
||||
OctSwigIterator *advance(ptrdiff_t n)
|
||||
{
|
||||
return (n > 0) ? incr(n) : decr(-n);
|
||||
}
|
||||
|
||||
bool operator == (const OctSwigIterator& x) const
|
||||
{
|
||||
return equal(x);
|
||||
}
|
||||
|
||||
bool operator != (const OctSwigIterator& x) const
|
||||
{
|
||||
return ! operator==(x);
|
||||
}
|
||||
|
||||
OctSwigIterator& operator += (ptrdiff_t n)
|
||||
{
|
||||
return *advance(n);
|
||||
}
|
||||
|
||||
OctSwigIterator& operator -= (ptrdiff_t n)
|
||||
{
|
||||
return *advance(-n);
|
||||
}
|
||||
|
||||
OctSwigIterator* operator + (ptrdiff_t n) const
|
||||
{
|
||||
return copy()->advance(n);
|
||||
}
|
||||
|
||||
OctSwigIterator* operator - (ptrdiff_t n) const
|
||||
{
|
||||
return copy()->advance(-n);
|
||||
}
|
||||
|
||||
ptrdiff_t operator - (const OctSwigIterator& x) const
|
||||
{
|
||||
return x.distance(*this);
|
||||
}
|
||||
|
||||
static swig_type_info* descriptor() {
|
||||
static int init = 0;
|
||||
static swig_type_info* desc = 0;
|
||||
if (!init) {
|
||||
desc = SWIG_TypeQuery("swig::OctSwigIterator *");
|
||||
init = 1;
|
||||
}
|
||||
return desc;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
%fragment("OctSwigIterator_T","header",fragment="OctSwigIterator",fragment="StdTraits",fragment="StdIteratorTraits") {
|
||||
namespace swig {
|
||||
template<typename OutIterator>
|
||||
class OctSwigIterator_T : public OctSwigIterator
|
||||
{
|
||||
public:
|
||||
typedef OutIterator out_iterator;
|
||||
typedef typename std::iterator_traits<out_iterator>::value_type value_type;
|
||||
typedef OctSwigIterator_T<out_iterator> self_type;
|
||||
|
||||
OctSwigIterator_T(out_iterator curr, octave_value seq)
|
||||
: OctSwigIterator(seq), current(curr)
|
||||
{
|
||||
}
|
||||
|
||||
const out_iterator& get_current() const
|
||||
{
|
||||
return current;
|
||||
}
|
||||
|
||||
|
||||
bool equal (const OctSwigIterator &iter) const
|
||||
{
|
||||
const self_type *iters = dynamic_cast<const self_type *>(&iter);
|
||||
if (iters) {
|
||||
return (current == iters->get_current());
|
||||
} else {
|
||||
throw std::invalid_argument("bad iterator type");
|
||||
}
|
||||
}
|
||||
|
||||
ptrdiff_t distance(const OctSwigIterator &iter) const
|
||||
{
|
||||
const self_type *iters = dynamic_cast<const self_type *>(&iter);
|
||||
if (iters) {
|
||||
return std::distance(current, iters->get_current());
|
||||
} else {
|
||||
throw std::invalid_argument("bad iterator type");
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
out_iterator current;
|
||||
};
|
||||
|
||||
template <class ValueType>
|
||||
struct from_oper
|
||||
{
|
||||
typedef const ValueType& argument_type;
|
||||
typedef octave_value result_type;
|
||||
result_type operator()(argument_type v) const
|
||||
{
|
||||
return swig::from(v);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename OutIterator,
|
||||
typename ValueType = typename std::iterator_traits<OutIterator>::value_type,
|
||||
typename FromOper = from_oper<ValueType> >
|
||||
class OctSwigIteratorOpen_T : public OctSwigIterator_T<OutIterator>
|
||||
{
|
||||
public:
|
||||
FromOper from;
|
||||
typedef OutIterator out_iterator;
|
||||
typedef ValueType value_type;
|
||||
typedef OctSwigIterator_T<out_iterator> base;
|
||||
typedef OctSwigIteratorOpen_T<OutIterator, ValueType, FromOper> self_type;
|
||||
|
||||
OctSwigIteratorOpen_T(out_iterator curr, octave_value seq)
|
||||
: OctSwigIterator_T<OutIterator>(curr, seq)
|
||||
{
|
||||
}
|
||||
|
||||
octave_value value() const {
|
||||
return from(static_cast<const value_type&>(*(base::current)));
|
||||
}
|
||||
|
||||
OctSwigIterator *copy() const
|
||||
{
|
||||
return new self_type(*this);
|
||||
}
|
||||
|
||||
OctSwigIterator *incr(size_t n = 1)
|
||||
{
|
||||
while (n--) {
|
||||
++base::current;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
OctSwigIterator *decr(size_t n = 1)
|
||||
{
|
||||
while (n--) {
|
||||
--base::current;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename OutIterator,
|
||||
typename ValueType = typename std::iterator_traits<OutIterator>::value_type,
|
||||
typename FromOper = from_oper<ValueType> >
|
||||
class OctSwigIteratorClosed_T : public OctSwigIterator_T<OutIterator>
|
||||
{
|
||||
public:
|
||||
FromOper from;
|
||||
typedef OutIterator out_iterator;
|
||||
typedef ValueType value_type;
|
||||
typedef OctSwigIterator_T<out_iterator> base;
|
||||
typedef OctSwigIteratorClosed_T<OutIterator, ValueType, FromOper> self_type;
|
||||
|
||||
OctSwigIteratorClosed_T(out_iterator curr, out_iterator first, out_iterator last, octave_value seq)
|
||||
: OctSwigIterator_T<OutIterator>(curr, seq), begin(first), end(last)
|
||||
{
|
||||
}
|
||||
|
||||
octave_value value() const {
|
||||
if (base::current == end) {
|
||||
throw stop_iteration();
|
||||
} else {
|
||||
return from(static_cast<const value_type&>(*(base::current)));
|
||||
}
|
||||
}
|
||||
|
||||
OctSwigIterator *copy() const
|
||||
{
|
||||
return new self_type(*this);
|
||||
}
|
||||
|
||||
OctSwigIterator *incr(size_t n = 1)
|
||||
{
|
||||
while (n--) {
|
||||
if (base::current == end) {
|
||||
throw stop_iteration();
|
||||
} else {
|
||||
++base::current;
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
OctSwigIterator *decr(size_t n = 1)
|
||||
{
|
||||
while (n--) {
|
||||
if (base::current == begin) {
|
||||
throw stop_iteration();
|
||||
} else {
|
||||
--base::current;
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
private:
|
||||
out_iterator begin;
|
||||
out_iterator end;
|
||||
};
|
||||
|
||||
template<typename OutIter>
|
||||
inline OctSwigIterator*
|
||||
make_output_iterator(const OutIter& current, const OutIter& begin,const OutIter& end, octave_value seq = octave_value())
|
||||
{
|
||||
return new OctSwigIteratorClosed_T<OutIter>(current, begin, end, seq);
|
||||
}
|
||||
|
||||
template<typename OutIter>
|
||||
inline OctSwigIterator*
|
||||
make_output_iterator(const OutIter& current, octave_value seq = octave_value())
|
||||
{
|
||||
return new OctSwigIteratorOpen_T<OutIter>(current, seq);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
%fragment("OctSwigIterator");
|
||||
namespace swig
|
||||
{
|
||||
// Throw a StopIteration exception
|
||||
%ignore stop_iteration;
|
||||
struct stop_iteration {};
|
||||
|
||||
%typemap(throws) stop_iteration {
|
||||
assert(0); *(int*)0=0;
|
||||
/*
|
||||
(void)$1;
|
||||
SWIG_SetErrorObj(PyExc_StopIteration, SWIG_Py_Void());
|
||||
SWIG_fail;
|
||||
*/
|
||||
}
|
||||
|
||||
// Mark methods that return new objects
|
||||
%newobject OctSwigIterator::copy;
|
||||
%newobject OctSwigIterator::operator + (ptrdiff_t n) const;
|
||||
%newobject OctSwigIterator::operator - (ptrdiff_t n) const;
|
||||
|
||||
%nodirector OctSwigIterator;
|
||||
|
||||
%catches(swig::stop_iteration) OctSwigIterator::value() const;
|
||||
%catches(swig::stop_iteration) OctSwigIterator::incr(size_t n = 1);
|
||||
%catches(swig::stop_iteration) OctSwigIterator::decr(size_t n = 1);
|
||||
%catches(std::invalid_argument) OctSwigIterator::distance(const OctSwigIterator &x) const;
|
||||
%catches(std::invalid_argument) OctSwigIterator::equal (const OctSwigIterator &x) const;
|
||||
%catches(swig::stop_iteration) OctSwigIterator::next();
|
||||
%catches(swig::stop_iteration) OctSwigIterator::previous();
|
||||
%catches(swig::stop_iteration) OctSwigIterator::advance(ptrdiff_t n);
|
||||
%catches(swig::stop_iteration) OctSwigIterator::operator += (ptrdiff_t n);
|
||||
%catches(swig::stop_iteration) OctSwigIterator::operator -= (ptrdiff_t n);
|
||||
%catches(swig::stop_iteration) OctSwigIterator::operator + (ptrdiff_t n) const;
|
||||
%catches(swig::stop_iteration) OctSwigIterator::operator - (ptrdiff_t n) const;
|
||||
|
||||
|
||||
struct OctSwigIterator
|
||||
{
|
||||
protected:
|
||||
OctSwigIterator(octave_value seq);
|
||||
|
||||
public:
|
||||
virtual ~OctSwigIterator();
|
||||
|
||||
// Access iterator method, required by Python
|
||||
virtual octave_value value() const = 0;
|
||||
|
||||
// Forward iterator method, required by Python
|
||||
virtual OctSwigIterator *incr(size_t n = 1) = 0;
|
||||
|
||||
// Backward iterator method, very common in C++, but not required in Python
|
||||
virtual OctSwigIterator *decr(size_t n = 1);
|
||||
|
||||
// Random access iterator methods, but not required in Python
|
||||
virtual ptrdiff_t distance(const OctSwigIterator &x) const;
|
||||
|
||||
virtual bool equal (const OctSwigIterator &x) const;
|
||||
|
||||
// C++ common/needed methods
|
||||
virtual OctSwigIterator *copy() const = 0;
|
||||
|
||||
octave_value next();
|
||||
octave_value previous();
|
||||
OctSwigIterator *advance(ptrdiff_t n);
|
||||
|
||||
// * todo: need operator support
|
||||
/*
|
||||
bool operator == (const OctSwigIterator& x) const;
|
||||
bool operator != (const OctSwigIterator& x) const;
|
||||
OctSwigIterator& operator += (ptrdiff_t n);
|
||||
OctSwigIterator& operator -= (ptrdiff_t n);
|
||||
OctSwigIterator* operator + (ptrdiff_t n) const;
|
||||
OctSwigIterator* operator - (ptrdiff_t n) const;
|
||||
ptrdiff_t operator - (const OctSwigIterator& x) const;
|
||||
*/
|
||||
};
|
||||
}
|
||||
|
||||
88
Lib/octave/octopers.swg
Normal file
88
Lib/octave/octopers.swg
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
/* ------------------------------------------------------------
|
||||
* Overloaded operator support
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
// operators supported in Octave, and the methods they are routed to
|
||||
|
||||
// __brace a{args}
|
||||
// __brace_asgn a{args} = rhs
|
||||
// __paren a(args)
|
||||
// __paren_asgn a(args) = rhs
|
||||
// __str generates string rep
|
||||
|
||||
// __not !a
|
||||
// __uplus +a
|
||||
// __uminus -a
|
||||
// __transpose a.'
|
||||
// __hermitian a'
|
||||
// __incr a++
|
||||
// __decr a--
|
||||
// __add a + b
|
||||
// __sub a - b
|
||||
// __mul a * b
|
||||
// __div a / b
|
||||
// __pow a ^ b
|
||||
// __ldiv a \ b
|
||||
// __lshift a << b
|
||||
// __rshift a >> b
|
||||
// __lt a < b
|
||||
// __le a <= b
|
||||
// __eq a == b
|
||||
// __ge a >= b
|
||||
// __gt a > b
|
||||
// __ne a != b
|
||||
// __el_mul a .* b
|
||||
// __el_div a ./ b
|
||||
// __el_pow a .^ b
|
||||
// __el_ldiv a .\ b
|
||||
// __el_and a & b
|
||||
// __el_or a | b
|
||||
|
||||
// operators supported in C++, and the methods that route to them
|
||||
|
||||
%rename(__add) *::operator+;
|
||||
%rename(__add) *::operator+();
|
||||
%rename(__add) *::operator+() const;
|
||||
%rename(__sub) *::operator-;
|
||||
%rename(__uminus) *::operator-();
|
||||
%rename(__uminus) *::operator-() const;
|
||||
%rename(__mul) *::operator*;
|
||||
%rename(__div) *::operator/;
|
||||
%rename(__mod) *::operator%;
|
||||
%rename(__lshift) *::operator<<;
|
||||
%rename(__rshift) *::operator>>;
|
||||
%rename(__el_and) *::operator&&;
|
||||
%rename(__el_or) *::operator||;
|
||||
%rename(__xor) *::operator^;
|
||||
%rename(__invert) *::operator~;
|
||||
%rename(__lt) *::operator<;
|
||||
%rename(__le) *::operator<=;
|
||||
%rename(__gt) *::operator>;
|
||||
%rename(__ge) *::operator>=;
|
||||
%rename(__eq) *::operator==;
|
||||
%rename(__ne) *::operator!=;
|
||||
%rename(__not) *::operator!;
|
||||
%rename(__incr) *::operator++;
|
||||
%rename(__decr) *::operator--;
|
||||
%rename(__paren) *::operator();
|
||||
%rename(__brace) *::operator[];
|
||||
|
||||
// Ignored inplace operators
|
||||
%ignoreoperator(PLUSEQ) operator+=;
|
||||
%ignoreoperator(MINUSEQ) operator-=;
|
||||
%ignoreoperator(MULEQ) operator*=;
|
||||
%ignoreoperator(DIVEQ) operator/=;
|
||||
%ignoreoperator(MODEQ) operator%=;
|
||||
%ignoreoperator(LSHIFTEQ) operator<<=;
|
||||
%ignoreoperator(RSHIFTEQ) operator>>=;
|
||||
%ignoreoperator(ANDEQ) operator&=;
|
||||
%ignoreoperator(OREQ) operator|=;
|
||||
%ignoreoperator(XOREQ) operator^=;
|
||||
|
||||
// Ignored operators
|
||||
%ignoreoperator(EQ) operator=;
|
||||
%ignoreoperator(ARROWSTAR) operator->*;
|
||||
|
||||
#endif /* __cplusplus */
|
||||
218
Lib/octave/octprimtypes.swg
Normal file
218
Lib/octave/octprimtypes.swg
Normal file
|
|
@ -0,0 +1,218 @@
|
|||
/* ------------------------------------------------------------
|
||||
* Primitive Types
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
|
||||
// boolean
|
||||
|
||||
%fragment(SWIG_From_frag(bool),"header") {
|
||||
SWIGINTERNINLINE octave_value
|
||||
SWIG_From_dec(bool)(bool value)
|
||||
{
|
||||
return octave_value(value);
|
||||
}
|
||||
}
|
||||
|
||||
%fragment(SWIG_AsVal_frag(bool),"header",
|
||||
fragment=SWIG_AsVal_frag(long)) {
|
||||
SWIGINTERN int
|
||||
SWIG_AsVal_dec(bool)(const octave_value& ov, bool *val)
|
||||
{
|
||||
if (!ov.is_bool_type())
|
||||
return SWIG_ERROR;
|
||||
if (val)
|
||||
*val = ov.bool_value();
|
||||
return SWIG_OK;
|
||||
}
|
||||
}
|
||||
|
||||
// long
|
||||
|
||||
%fragment(SWIG_From_frag(long),"header") {
|
||||
SWIGINTERNINLINE octave_value SWIG_From_dec(long) (long value)
|
||||
{
|
||||
return octave_value(value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
%fragment(SWIG_AsVal_frag(long),"header") {
|
||||
SWIGINTERN int SWIG_AsVal_dec(long)(const octave_value& ov, long* val)
|
||||
{
|
||||
if (!ov.is_scalar_type())
|
||||
return SWIG_TypeError;
|
||||
if (ov.is_double_type()||ov.is_single_type()) {
|
||||
double v=ov.double_value();
|
||||
if (v!=floor(v))
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
if (val)
|
||||
*val = ov.long_value();
|
||||
return SWIG_OK;
|
||||
}
|
||||
}
|
||||
|
||||
// unsigned long
|
||||
|
||||
%fragment(SWIG_From_frag(unsigned long),"header") {
|
||||
SWIGINTERNINLINE octave_value SWIG_From_dec(unsigned long) (unsigned long value)
|
||||
{
|
||||
return octave_value(value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
%fragment(SWIG_AsVal_frag(unsigned long),"header") {
|
||||
SWIGINTERN int SWIG_AsVal_dec(unsigned long)(const octave_value& ov, unsigned long* val)
|
||||
{
|
||||
if (!ov.is_scalar_type())
|
||||
return SWIG_TypeError;
|
||||
if (ov.is_double_type()||ov.is_single_type()) {
|
||||
double v=ov.double_value();
|
||||
if (v<0)
|
||||
return SWIG_OverflowError;
|
||||
if (v!=floor(v))
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
if (ov.is_int8_type()||ov.is_int16_type()||
|
||||
ov.is_int32_type()) {
|
||||
long v=ov.long_value();
|
||||
if (v<0)
|
||||
return SWIG_OverflowError;
|
||||
}
|
||||
if (ov.is_int64_type()) {
|
||||
long long v=ov.int64_scalar_value().value();
|
||||
if (v<0)
|
||||
return SWIG_OverflowError;
|
||||
}
|
||||
if (val)
|
||||
*val = ov.ulong_value();
|
||||
return SWIG_OK;
|
||||
}
|
||||
}
|
||||
|
||||
// long long
|
||||
|
||||
%fragment(SWIG_From_frag(long long),"header") {
|
||||
SWIGINTERNINLINE octave_value SWIG_From_dec(long long) (long long value)
|
||||
{
|
||||
return octave_int64(value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
%fragment(SWIG_AsVal_frag(long long),"header") {
|
||||
SWIGINTERN int SWIG_AsVal_dec(long long)(const octave_value& ov, long long* val)
|
||||
{
|
||||
if (!ov.is_scalar_type())
|
||||
return SWIG_TypeError;
|
||||
if (ov.is_double_type()||ov.is_single_type()) {
|
||||
double v=ov.double_value();
|
||||
if (v!=floor(v))
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
if (val)
|
||||
*val = ov.int64_scalar_value().value();
|
||||
return SWIG_OK;
|
||||
}
|
||||
}
|
||||
|
||||
%fragment(SWIG_From_frag(unsigned long long),"header") {
|
||||
SWIGINTERNINLINE octave_value SWIG_From_dec(unsigned long long) (unsigned long long value)
|
||||
{
|
||||
return octave_uint64(value);
|
||||
}
|
||||
}
|
||||
|
||||
%fragment(SWIG_AsVal_frag(unsigned long long),"header") {
|
||||
SWIGINTERN int SWIG_AsVal_dec(unsigned long long)(const octave_value& ov, unsigned long long* val)
|
||||
{
|
||||
if (!ov.is_scalar_type())
|
||||
return SWIG_TypeError;
|
||||
if (ov.is_double_type()||ov.is_single_type()) {
|
||||
double v=ov.double_value();
|
||||
if (v<0)
|
||||
return SWIG_OverflowError;
|
||||
if (v!=floor(v))
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
if (ov.is_int8_type()||ov.is_int16_type()||
|
||||
ov.is_int32_type()) {
|
||||
long v=ov.long_value();
|
||||
if (v<0)
|
||||
return SWIG_OverflowError;
|
||||
}
|
||||
if (ov.is_int64_type()) {
|
||||
long long v=ov.int64_scalar_value().value();
|
||||
if (v<0)
|
||||
return SWIG_OverflowError;
|
||||
}
|
||||
if (val)
|
||||
*val = ov.uint64_scalar_value().value();
|
||||
return SWIG_OK;
|
||||
}
|
||||
}
|
||||
|
||||
// double
|
||||
|
||||
%fragment(SWIG_From_frag(double),"header") {
|
||||
SWIGINTERNINLINE octave_value SWIG_From_dec(double) (double value)
|
||||
{
|
||||
return octave_value(value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
%fragment(SWIG_AsVal_frag(double),"header") {
|
||||
SWIGINTERN int SWIG_AsVal_dec(double)(const octave_value& ov, double* val)
|
||||
{
|
||||
if (!ov.is_scalar_type())
|
||||
return SWIG_TypeError;
|
||||
if (val)
|
||||
*val = ov.double_value();
|
||||
return SWIG_OK;
|
||||
}
|
||||
}
|
||||
|
||||
// const char* (strings)
|
||||
|
||||
%fragment("SWIG_AsCharPtrAndSize","header") {
|
||||
SWIGINTERN int
|
||||
SWIG_AsCharPtrAndSize(const octave_value& ov, char** cptr, size_t* psize, int *alloc)
|
||||
{
|
||||
if (!ov.is_string())
|
||||
return SWIG_TypeError;
|
||||
|
||||
std::string str=ov.string_value();
|
||||
size_t len=str.size();
|
||||
char* cstr=(char*)str.c_str();
|
||||
if (alloc) {
|
||||
%#if defined(SWIG_OCTAVE_SAFE_CSTRINGS)
|
||||
if (*alloc != SWIG_OLDOBJ)
|
||||
%#else
|
||||
if (*alloc == SWIG_NEWOBJ)
|
||||
%#endif
|
||||
{
|
||||
*cptr = %new_copy_array(cstr, len + 1, char);
|
||||
*alloc = SWIG_NEWOBJ;
|
||||
} else {
|
||||
*cptr = cstr;
|
||||
*alloc = SWIG_OLDOBJ;
|
||||
}
|
||||
} else if (cptr)
|
||||
*cptr = cstr;
|
||||
if (psize)
|
||||
*psize = len + 1;
|
||||
return SWIG_OK;
|
||||
}
|
||||
}
|
||||
|
||||
%fragment("SWIG_FromCharPtrAndSize","header",fragment="SWIG_pchar_descriptor") {
|
||||
SWIGINTERNINLINE octave_value
|
||||
SWIG_FromCharPtrAndSize(const char* carray, size_t size)
|
||||
{
|
||||
return std::string(carray,carray+size);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
1146
Lib/octave/octrun.swg
Normal file
1146
Lib/octave/octrun.swg
Normal file
File diff suppressed because it is too large
Load diff
76
Lib/octave/octruntime.swg
Normal file
76
Lib/octave/octruntime.swg
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
%insert(runtime) %{
|
||||
#include <octave/oct.h>
|
||||
#include <octave/ov-fcn-handle.h>
|
||||
#include <octave/Cell.h>
|
||||
%}
|
||||
|
||||
%insert(runtime) "swigrun.swg";
|
||||
%insert(runtime) "swigerrors.swg";
|
||||
%insert(runtime) "octrun.swg";
|
||||
|
||||
%insert(initbeforefunc) "swiginit.swg"
|
||||
|
||||
%insert(initbeforefunc) %{
|
||||
|
||||
void SWIG_init_user(octave_swig_type* module_ns);
|
||||
|
||||
DEFUN_DLD (SWIG_name,args,nargout,SWIG_name_d) {
|
||||
static bool already_init=false;
|
||||
if (already_init)
|
||||
return octave_value_list();
|
||||
already_init=true;
|
||||
|
||||
octave_swig_ref::register_type ();
|
||||
octave_swig_packed::register_type ();
|
||||
SWIG_InitializeModule(0);
|
||||
SWIG_PropagateClientData();
|
||||
|
||||
install_builtin_function(swig_type,"swig_type",std::string());
|
||||
install_builtin_function(swig_typequery,"swig_typequery",std::string());
|
||||
install_builtin_function(swig_this,"swig_this",std::string());
|
||||
install_builtin_function(swig_subclass,"subclass",std::string());
|
||||
|
||||
bool global_option=true; // * swig cli option should control this default
|
||||
for (int j=0;j<args.length();++j)
|
||||
if (args(j).is_string()&&args(j).string_value()=="noglobal")
|
||||
global_option=true;
|
||||
else if (args(j).is_string()&&args(j).string_value()=="noglobal")
|
||||
global_option=false;
|
||||
|
||||
octave_swig_type* cvar_ns=new octave_swig_type;
|
||||
for (int j=0;swig_globals[j].name;++j)
|
||||
if (swig_globals[j].get_method)
|
||||
cvar_ns->assign(swig_globals[j].name,&swig_globals[j]);
|
||||
|
||||
octave_swig_type* module_ns=new octave_swig_type;
|
||||
module_ns->assign("cvar",Swig::swig_value_ref(cvar_ns));
|
||||
for (int j=0;swig_globals[j].name;++j)
|
||||
if (swig_globals[j].method)
|
||||
module_ns->assign(swig_globals[j].name,&swig_globals[j]);
|
||||
|
||||
link_to_global_variable(curr_sym_tab->lookup(SWIG_name_d,true));
|
||||
set_global_value(SWIG_name_d,Swig::swig_value_ref(module_ns));
|
||||
|
||||
// * need better solution here; swig_type -> octave_class mapping is
|
||||
// * really n-to-1, in some cases such as template partial spec, etc.
|
||||
// * see failing tests.
|
||||
for (int j=0;swig_types[j];++j)
|
||||
if (swig_types[j]->clientdata) {
|
||||
swig_octave_class* c=(swig_octave_class*)swig_types[j]->clientdata;
|
||||
module_ns->assign(c->name,
|
||||
Swig::swig_value_ref
|
||||
(new octave_swig_type(0,swig_types[j])));
|
||||
}
|
||||
|
||||
SWIG_init_user(module_ns);
|
||||
|
||||
swig_install_ops(octave_swig_ref::static_type_id());
|
||||
|
||||
if (global_option)
|
||||
module_ns->install_global();
|
||||
|
||||
return octave_value_list();
|
||||
}
|
||||
|
||||
%}
|
||||
|
||||
226
Lib/octave/octstdcommon.swg
Normal file
226
Lib/octave/octstdcommon.swg
Normal file
|
|
@ -0,0 +1,226 @@
|
|||
%fragment("StdTraits","header",fragment="StdTraitsCommon")
|
||||
{
|
||||
namespace swig {
|
||||
// Traits that provides the from method
|
||||
template <class Type> struct traits_from_ptr {
|
||||
static octave_value from(Type *val, int owner = 0) {
|
||||
return SWIG_NewPointerObj(val, type_info<Type>(), owner);
|
||||
}
|
||||
};
|
||||
|
||||
template <class Type> struct traits_from {
|
||||
static octave_value from(const Type& val) {
|
||||
return traits_from_ptr<Type>::from(new Type(val), 1);
|
||||
}
|
||||
};
|
||||
|
||||
template <class Type> struct traits_from<Type *> {
|
||||
static octave_value from(Type* val) {
|
||||
return traits_from_ptr<Type>::from(val, 0);
|
||||
}
|
||||
};
|
||||
|
||||
template <class Type> struct traits_from<const Type *> {
|
||||
static octave_value from(const Type* val) {
|
||||
return traits_from_ptr<Type>::from(const_cast<Type*>(val), 0);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <class Type>
|
||||
inline octave_value from(const Type& val) {
|
||||
return traits_from<Type>::from(val);
|
||||
}
|
||||
|
||||
template <class Type>
|
||||
inline octave_value from_ptr(Type* val, int owner) {
|
||||
return traits_from_ptr<Type>::from(val, owner);
|
||||
}
|
||||
|
||||
// Traits that provides the asval/as/check method
|
||||
template <class Type>
|
||||
struct traits_asptr {
|
||||
static int asptr(octave_value obj, Type **val) {
|
||||
Type *p;
|
||||
int res = (SWIG_ConvertPtr(obj, (void**)&p, type_info<Type>(), 0) == SWIG_OK) ? SWIG_OLDOBJ : 0;
|
||||
if (SWIG_IsOK(res)) {
|
||||
if (val) *val = p;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
};
|
||||
|
||||
template <class Type>
|
||||
inline int asptr(octave_value obj, Type **vptr) {
|
||||
return traits_asptr<Type>::asptr(obj, vptr);
|
||||
}
|
||||
|
||||
template <class Type>
|
||||
struct traits_asval {
|
||||
static int asval(octave_value obj, Type *val) {
|
||||
if (val) {
|
||||
Type *p = 0;
|
||||
int res = traits_asptr<Type>::asptr(obj, &p);
|
||||
if (!SWIG_IsOK(res)) return res;
|
||||
if (p) {
|
||||
typedef typename noconst_traits<Type>::noconst_type noconst_type;
|
||||
*(const_cast<noconst_type*>(val)) = *p;
|
||||
if (SWIG_IsNewObj(res)){
|
||||
%delete(p);
|
||||
res = SWIG_DelNewMask(res);
|
||||
}
|
||||
return res;
|
||||
} else {
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
} else {
|
||||
return traits_asptr<Type>::asptr(obj, (Type **)(0));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <class Type> struct traits_asval<Type*> {
|
||||
static int asval(octave_value obj, Type **val) {
|
||||
if (val) {
|
||||
typedef typename noconst_traits<Type>::noconst_type noconst_type;
|
||||
noconst_type *p = 0;
|
||||
int res = traits_asptr<noconst_type>::asptr(obj, &p);
|
||||
if (SWIG_IsOK(res)) {
|
||||
*(const_cast<noconst_type**>(val)) = p;
|
||||
}
|
||||
return res;
|
||||
} else {
|
||||
return traits_asptr<Type>::asptr(obj, (Type **)(0));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <class Type>
|
||||
inline int asval(octave_value obj, Type *val) {
|
||||
return traits_asval<Type>::asval(obj, val);
|
||||
}
|
||||
|
||||
template <class Type>
|
||||
struct traits_as<Type, value_category> {
|
||||
static Type as(octave_value obj, bool throw_error) {
|
||||
Type v;
|
||||
int res = asval(obj, &v);
|
||||
if (!obj.is_defined() || !SWIG_IsOK(res)) {
|
||||
if (!Octave_Error_Occurred()) {
|
||||
%type_error(swig::type_name<Type>());
|
||||
}
|
||||
if (throw_error) throw std::invalid_argument("bad type");
|
||||
}
|
||||
return v;
|
||||
}
|
||||
};
|
||||
|
||||
template <class Type>
|
||||
struct traits_as<Type, pointer_category> {
|
||||
static Type as(octave_value obj, bool throw_error) {
|
||||
Type *v = 0;
|
||||
int res = (obj ? traits_asptr<Type>::asptr(obj, &v) : SWIG_ERROR);
|
||||
if (SWIG_IsOK(res) && v) {
|
||||
if (SWIG_IsNewObj(res)) {
|
||||
Type r(*v);
|
||||
%delete(v);
|
||||
return r;
|
||||
} else {
|
||||
return *v;
|
||||
}
|
||||
} else {
|
||||
// Uninitialized return value, no Type() constructor required.
|
||||
static Type *v_def = (Type*) malloc(sizeof(Type));
|
||||
if (!Octave_Error_Occurred()) {
|
||||
%type_error(swig::type_name<Type>());
|
||||
}
|
||||
if (throw_error) throw std::invalid_argument("bad type");
|
||||
memset(v_def,0,sizeof(Type));
|
||||
return *v_def;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <class Type>
|
||||
struct traits_as<Type*, pointer_category> {
|
||||
static Type* as(octave_value obj, bool throw_error) {
|
||||
Type *v = 0;
|
||||
int res = (obj ? traits_asptr<Type>::asptr(obj, &v) : SWIG_ERROR);
|
||||
if (SWIG_IsOK(res)) {
|
||||
return v;
|
||||
} else {
|
||||
if (!Octave_Error_Occurred()) {
|
||||
%type_error(swig::type_name<Type>());
|
||||
}
|
||||
if (throw_error) throw std::invalid_argument("bad type");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <class Type>
|
||||
inline Type as(octave_value obj, bool te = false) {
|
||||
return traits_as<Type, typename traits<Type>::category>::as(obj, te);
|
||||
}
|
||||
|
||||
template <class Type>
|
||||
struct traits_check<Type, value_category> {
|
||||
static bool check(octave_value obj) {
|
||||
int res = obj ? asval(obj, (Type *)(0)) : SWIG_ERROR;
|
||||
return SWIG_IsOK(res) ? true : false;
|
||||
}
|
||||
};
|
||||
|
||||
template <class Type>
|
||||
struct traits_check<Type, pointer_category> {
|
||||
static bool check(octave_value obj) {
|
||||
int res = obj ? asptr(obj, (Type **)(0)) : SWIG_ERROR;
|
||||
return SWIG_IsOK(res) ? true : false;
|
||||
}
|
||||
};
|
||||
|
||||
template <class Type>
|
||||
inline bool check(octave_value obj) {
|
||||
return traits_check<Type, typename traits<Type>::category>::check(obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
%define %specialize_std_container(Type,Check,As,From)
|
||||
%{
|
||||
namespace swig {
|
||||
template <> struct traits_asval<Type > {
|
||||
typedef Type value_type;
|
||||
static int asval(octave_value obj, value_type *val) {
|
||||
if (Check(obj)) {
|
||||
if (val) *val = As(obj);
|
||||
return SWIG_OK;
|
||||
}
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
};
|
||||
template <> struct traits_from<Type > {
|
||||
typedef Type value_type;
|
||||
static octave_value from(const value_type& val) {
|
||||
return From(val);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct traits_check<Type, value_category> {
|
||||
static int check(octave_value obj) {
|
||||
int res = Check(obj);
|
||||
return obj && res ? res : 0;
|
||||
}
|
||||
};
|
||||
}
|
||||
%}
|
||||
%enddef
|
||||
|
||||
|
||||
#define specialize_std_vector(Type,Check,As,From) %specialize_std_container(%arg(Type),Check,As,From)
|
||||
#define specialize_std_list(Type,Check,As,From) %specialize_std_container(%arg(Type),Check,As,From)
|
||||
#define specialize_std_deque(Type,Check,As,From) %specialize_std_container(%arg(Type),Check,As,From)
|
||||
#define specialize_std_set(Type,Check,As,From) %specialize_std_container(%arg(Type),Check,As,From)
|
||||
#define specialize_std_multiset(Type,Check,As,From) %specialize_std_container(%arg(Type),Check,As,From)
|
||||
|
||||
35
Lib/octave/octtypemaps.swg
Normal file
35
Lib/octave/octtypemaps.swg
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
|
||||
// Include fundamental fragemt definitions
|
||||
%include <typemaps/fragments.swg>
|
||||
|
||||
// Look for user fragments file.
|
||||
%include <octfragments.swg>
|
||||
|
||||
// Octave fragments for primitive types
|
||||
%include <octprimtypes.swg>
|
||||
|
||||
// Octave fragments for char* strings
|
||||
//%include <octstrings.swg>
|
||||
|
||||
|
||||
#ifndef SWIG_DIRECTOR_TYPEMAPS
|
||||
#define SWIG_DIRECTOR_TYPEMAPS
|
||||
#endif
|
||||
|
||||
// Octave types
|
||||
#define SWIG_Object octave_value
|
||||
#define VOID_Object octave_value()
|
||||
|
||||
|
||||
// append output
|
||||
#define SWIG_AppendOutput(result, obj) SWIG_Octave_AppendOutput(result, obj)
|
||||
|
||||
// set constant
|
||||
#define SWIG_SetConstant(name, obj) SWIG_Octave_SetConstant(module_ns,name,obj)
|
||||
|
||||
// raise
|
||||
#define SWIG_Octave_Raise(obj, type, desc) error("c++-side threw an exception")
|
||||
#define SWIG_Raise(obj, type, desc) SWIG_Octave_Raise(obj, type, desc)
|
||||
|
||||
// Include the unified typemap library
|
||||
%include <typemaps/swigtypemaps.swg>
|
||||
1
Lib/octave/std_alloc.i
Normal file
1
Lib/octave/std_alloc.i
Normal file
|
|
@ -0,0 +1 @@
|
|||
%include <std/std_alloc.i>
|
||||
103
Lib/octave/std_basic_string.i
Normal file
103
Lib/octave/std_basic_string.i
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
#if !defined(SWIG_STD_STRING)
|
||||
#define SWIG_STD_BASIC_STRING
|
||||
|
||||
%include <octcontainer.swg>
|
||||
|
||||
#define %swig_basic_string(Type...) %swig_sequence_methods_val(Type)
|
||||
|
||||
|
||||
%fragment(SWIG_AsPtr_frag(std::basic_string<char>),"header",
|
||||
fragment="SWIG_AsCharPtrAndSize") {
|
||||
SWIGINTERN int
|
||||
SWIG_AsPtr(std::basic_string<char>)(PyObject* obj, std::string **val)
|
||||
{
|
||||
static swig_type_info* string_info =
|
||||
SWIG_TypeQuery("std::basic_string<char> *");
|
||||
std::string *vptr;
|
||||
if (SWIG_ConvertPtr(obj, (void**)&vptr, string_info, 0) == SWIG_OK) {
|
||||
if (val) *val = vptr;
|
||||
return SWIG_OLDOBJ;
|
||||
} else {
|
||||
PyErr_Clear();
|
||||
char* buf = 0 ; size_t size = 0; int alloc = 0;
|
||||
if (SWIG_AsCharPtrAndSize(obj, &buf, &size, &alloc) == SWIG_OK) {
|
||||
if (buf) {
|
||||
if (val) *val = new std::string(buf, size - 1);
|
||||
if (alloc == SWIG_NEWOBJ) %delete_array(buf);
|
||||
return SWIG_NEWOBJ;
|
||||
}
|
||||
} else {
|
||||
PyErr_Clear();
|
||||
}
|
||||
if (val) {
|
||||
SWIG_PYTHON_THREAD_BEGIN_BLOCK;
|
||||
PyErr_SetString(PyExc_TypeError,"a string is expected");
|
||||
SWIG_PYTHON_THREAD_END_BLOCK;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
%fragment(SWIG_From_frag(std::basic_string<char>),"header",
|
||||
fragment="SWIG_FromCharPtrAndSize") {
|
||||
SWIGINTERNINLINE PyObject*
|
||||
SWIG_From(std::basic_string<char>)(const std::string& s)
|
||||
{
|
||||
return SWIG_FromCharPtrAndSize(s.data(), s.size());
|
||||
}
|
||||
}
|
||||
|
||||
%include <std/std_basic_string.i>
|
||||
%typemaps_asptrfromn(%checkcode(STRING), std::basic_string<char>);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#if !defined(SWIG_STD_WSTRING)
|
||||
|
||||
%fragment(SWIG_AsPtr_frag(std::basic_string<wchar_t>),"header",
|
||||
fragment="SWIG_AsWCharPtrAndSize") {
|
||||
SWIGINTERN int
|
||||
SWIG_AsPtr(std::basic_string<wchar_t>)(PyObject* obj, std::wstring **val)
|
||||
{
|
||||
static swig_type_info* string_info =
|
||||
SWIG_TypeQuery("std::basic_string<wchar_t> *");
|
||||
std::wstring *vptr;
|
||||
if (SWIG_ConvertPtr(obj, (void**)&vptr, string_info, 0) == SWIG_OK) {
|
||||
if (val) *val = vptr;
|
||||
return SWIG_OLDOBJ;
|
||||
} else {
|
||||
PyErr_Clear();
|
||||
wchar_t *buf = 0 ; size_t size = 0; int alloc = 0;
|
||||
if (SWIG_AsWCharPtrAndSize(obj, &buf, &size, &alloc) == SWIG_OK) {
|
||||
if (buf) {
|
||||
if (val) *val = new std::wstring(buf, size - 1);
|
||||
if (alloc == SWIG_NEWOBJ) %delete_array(buf);
|
||||
return SWIG_NEWOBJ;
|
||||
}
|
||||
} else {
|
||||
PyErr_Clear();
|
||||
}
|
||||
if (val) {
|
||||
SWIG_PYTHON_THREAD_BEGIN_BLOCK;
|
||||
PyErr_SetString(PyExc_TypeError,"a wstring is expected");
|
||||
SWIG_PYTHON_THREAD_END_BLOCK;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
%fragment(SWIG_From_frag(std::basic_string<wchar_t>),"header",
|
||||
fragment="SWIG_FromWCharPtrAndSize") {
|
||||
SWIGINTERNINLINE PyObject*
|
||||
SWIG_From(std::basic_string<wchar_t>)(const std::wstring& s)
|
||||
{
|
||||
return SWIG_FromWCharPtrAndSize(s.data(), s.size());
|
||||
}
|
||||
}
|
||||
|
||||
%typemaps_asptrfromn(%checkcode(UNISTRING), std::basic_string<wchar_t>);
|
||||
|
||||
#endif
|
||||
56
Lib/octave/std_carray.i
Normal file
56
Lib/octave/std_carray.i
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
%include <pycontainer.swg>
|
||||
|
||||
/*
|
||||
%fragment("StdCarrayTraits","header",fragment="StdSequenceTraits")
|
||||
{
|
||||
namespace swig {
|
||||
template <class T, size_t S>
|
||||
struct traits_asptr<std::carray<T, S> > {
|
||||
static int asptr(PyObject *obj, std::carray<T, S> **array) {
|
||||
return traits_asptr_stdseq<std::carray<T, S> >::asptr(obj, array);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
%warnfilter(SWIGWARN_IGNORE_OPERATOR_INDEX) std::carray::operator[];
|
||||
|
||||
%extend std::carray {
|
||||
%fragment(SWIG_Traits_frag(std::carray<_Type, _Size >), "header",
|
||||
fragment="PySwigIterator_T",
|
||||
fragment=SWIG_Traits_frag(_Type),
|
||||
fragment="StdCarrayTraits") {
|
||||
namespace swig {
|
||||
template <> struct traits<std::carray<_Type, _Size > > {
|
||||
typedef pointer_category category;
|
||||
static const char* type_name() {
|
||||
return "std::carray<" #_Type "," #_Size " >";
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
%typemaps_asptr(SWIG_TYPECHECK_VECTOR, swig::asptr,
|
||||
SWIG_Traits_frag(std::carray<_Type, _Size >),
|
||||
std::carray<_Type, _Size >);
|
||||
|
||||
%typemap(out,noblock=1) iterator, const_iterator {
|
||||
$result = SWIG_NewPointerObj(swig::make_output_iterator((const $type &)$1),
|
||||
swig::PySwigIterator::descriptor(),SWIG_POINTER_OWN);
|
||||
}
|
||||
|
||||
inline size_t __len__() const { return self->size(); }
|
||||
|
||||
inline const _Type& __getitem__(size_t i) const { return (*self)[i]; }
|
||||
|
||||
inline void __setitem__(size_t i, const _Type& v) { (*self)[i] = v; }
|
||||
|
||||
|
||||
swig::PySwigIterator* __iter__(PyObject **PYTHON_SELF) {
|
||||
return swig::make_output_iterator(self->begin(), self->begin(), self->end(), *PYTHON_SELF);
|
||||
}
|
||||
}
|
||||
|
||||
%include <std/std_carray.swg>
|
||||
*/
|
||||
|
||||
1
Lib/octave/std_char_traits.i
Normal file
1
Lib/octave/std_char_traits.i
Normal file
|
|
@ -0,0 +1 @@
|
|||
%include <std/std_char_traits.i>
|
||||
41
Lib/octave/std_common.i
Normal file
41
Lib/octave/std_common.i
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
%include <std/std_except.i>
|
||||
%include <octstdcommon.swg>
|
||||
|
||||
|
||||
// Generate the traits for a 'primitive' type, such as 'double',
|
||||
// for which the SWIG_AsVal and SWIG_From methods are already defined.
|
||||
|
||||
%define %traits_ptypen(Type...)
|
||||
%fragment(SWIG_Traits_frag(Type),"header",
|
||||
fragment=SWIG_AsVal_frag(Type),
|
||||
fragment=SWIG_From_frag(Type),
|
||||
fragment="StdTraits") {
|
||||
namespace swig {
|
||||
template <> struct traits<Type > {
|
||||
typedef value_category category;
|
||||
static const char* type_name() { return #Type; }
|
||||
};
|
||||
template <> struct traits_asval<Type > {
|
||||
typedef Type value_type;
|
||||
static int asval(octave_value obj, value_type *val) {
|
||||
return SWIG_AsVal(Type)(obj, val);
|
||||
}
|
||||
};
|
||||
template <> struct traits_from<Type > {
|
||||
typedef Type value_type;
|
||||
static octave_value from(const value_type& val) {
|
||||
return SWIG_From(Type)(val);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
%enddef
|
||||
|
||||
%include <std/std_common.i>
|
||||
|
||||
//
|
||||
// Generates the traits for all the known primitive
|
||||
// C++ types (int, double, ...)
|
||||
//
|
||||
%apply_cpptypes(%traits_ptypen);
|
||||
|
||||
22
Lib/octave/std_complex.i
Normal file
22
Lib/octave/std_complex.i
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
/*
|
||||
* STD C++ complex typemaps
|
||||
*/
|
||||
|
||||
%include <octcomplex.swg>
|
||||
|
||||
%{
|
||||
#include <complex>
|
||||
%}
|
||||
|
||||
/* defining the complex as/from converters */
|
||||
|
||||
%swig_cplxdbl_convn(std::complex<double>, std::complex<double>, std::real, std::imag)
|
||||
%swig_cplxflt_convn(std::complex<float>, std::complex<float>, std::real, std::imag)
|
||||
|
||||
/* defining the typemaps */
|
||||
|
||||
%typemaps_primitive(%checkcode(CPLXDBL), std::complex<double>);
|
||||
%typemaps_primitive(%checkcode(CPLXFLT), std::complex<float>);
|
||||
|
||||
|
||||
|
||||
2
Lib/octave/std_container.i
Normal file
2
Lib/octave/std_container.i
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
%include <octcontainer.swg>
|
||||
%include <std/std_container.i>
|
||||
25
Lib/octave/std_deque.i
Normal file
25
Lib/octave/std_deque.i
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
// Deques
|
||||
|
||||
%fragment("StdDequeTraits","header",fragment="StdSequenceTraits")
|
||||
%{
|
||||
namespace swig {
|
||||
template <class T>
|
||||
struct traits_asptr<std::deque<T> > {
|
||||
static int asptr(octave_value obj, std::deque<T> **vec) {
|
||||
return traits_asptr_stdseq<std::deque<T> >::asptr(obj, vec);
|
||||
}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct traits_from<std::deque<T> > {
|
||||
static octave_value from(const std::deque<T> & vec) {
|
||||
return traits_from_stdseq<std::deque<T> >::from(vec);
|
||||
}
|
||||
};
|
||||
}
|
||||
%}
|
||||
|
||||
#define %swig_deque_methods(Type...) %swig_sequence_methods(Type)
|
||||
#define %swig_deque_methods_val(Type...) %swig_sequence_methods_val(Type);
|
||||
|
||||
%include <std/std_deque.i>
|
||||
1
Lib/octave/std_except.i
Normal file
1
Lib/octave/std_except.i
Normal file
|
|
@ -0,0 +1 @@
|
|||
%include <typemaps/std_except.swg>
|
||||
151
Lib/octave/std_map.i
Normal file
151
Lib/octave/std_map.i
Normal file
|
|
@ -0,0 +1,151 @@
|
|||
// Maps
|
||||
|
||||
%include <octcontainer.swg>
|
||||
|
||||
%fragment("StdMapTraits","header",fragment="StdSequenceTraits")
|
||||
{
|
||||
namespace swig {
|
||||
template <class OctSeq, class K, class T >
|
||||
inline void
|
||||
assign(const OctSeq& octseq, std::map<K,T > *map) {
|
||||
typedef typename std::map<K,T>::value_type value_type;
|
||||
typename OctSeq::const_iterator it = octseq.begin();
|
||||
for (;it != octseq.end(); ++it) {
|
||||
map->insert(value_type(it->first, it->second));
|
||||
}
|
||||
}
|
||||
|
||||
template <class K, class T>
|
||||
struct traits_asptr<std::map<K,T> > {
|
||||
typedef std::map<K,T> map_type;
|
||||
static int asptr(octave_value obj, map_type **val) {
|
||||
/*
|
||||
int res = SWIG_ERROR;
|
||||
if (PyDict_Check(obj)) {
|
||||
PyObject_var items = PyObject_CallMethod(obj,(char *)"items",NULL);
|
||||
res = traits_asptr_stdseq<std::map<K,T>, std::pair<K, T> >::asptr(items, val);
|
||||
} else {
|
||||
map_type *p;
|
||||
res = SWIG_ConvertPtr(obj,(void**)&p,swig::type_info<map_type>(),0);
|
||||
if (SWIG_IsOK(res) && val) *val = p;
|
||||
}
|
||||
return res;
|
||||
*/
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
};
|
||||
|
||||
template <class K, class T >
|
||||
struct traits_from<std::map<K,T> > {
|
||||
typedef std::map<K,T> map_type;
|
||||
typedef typename map_type::const_iterator const_iterator;
|
||||
typedef typename map_type::size_type size_type;
|
||||
|
||||
static octave_value from(const map_type& map) {
|
||||
/*
|
||||
swig_type_info *desc = swig::type_info<map_type>();
|
||||
if (desc && desc->clientdata) {
|
||||
return SWIG_NewPointerObj(new map_type(map), desc, SWIG_POINTER_OWN);
|
||||
} else {
|
||||
size_type size = map.size();
|
||||
int pysize = (size <= (size_type) INT_MAX) ? (int) size : -1;
|
||||
if (pysize < 0) {
|
||||
SWIG_PYTHON_THREAD_BEGIN_BLOCK;
|
||||
PyErr_SetString(PyExc_OverflowError,
|
||||
"map size not valid in python");
|
||||
SWIG_PYTHON_THREAD_END_BLOCK;
|
||||
return NULL;
|
||||
}
|
||||
PyObject *obj = PyDict_New();
|
||||
for (const_iterator i= map.begin(); i!= map.end(); ++i) {
|
||||
swig::PyObject_var key = swig::from(i->first);
|
||||
swig::PyObject_var val = swig::from(i->second);
|
||||
PyDict_SetItem(obj, key, val);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
*/
|
||||
return octave_value();
|
||||
}
|
||||
};
|
||||
|
||||
template <class ValueType>
|
||||
struct from_key_oper
|
||||
{
|
||||
typedef const ValueType& argument_type;
|
||||
typedef octave_value result_type;
|
||||
result_type operator()(argument_type v) const
|
||||
{
|
||||
return swig::from(v.first);
|
||||
}
|
||||
};
|
||||
|
||||
template <class ValueType>
|
||||
struct from_value_oper
|
||||
{
|
||||
typedef const ValueType& argument_type;
|
||||
typedef octave_value result_type;
|
||||
result_type operator()(argument_type v) const
|
||||
{
|
||||
return swig::from(v.second);
|
||||
}
|
||||
};
|
||||
|
||||
template<class OutIterator, class FromOper, class ValueType = typename OutIterator::value_type>
|
||||
struct OctMapIterator_T : PySwigIteratorClosed_T<OutIterator, ValueType, FromOper>
|
||||
{
|
||||
OctMapIterator_T(OutIterator curr, OutIterator first, OutIterator last, octave_value seq)
|
||||
: PySwigIteratorClosed_T<OutIterator,ValueType,FromOper>(curr, first, last, seq)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template<class OutIterator,
|
||||
class FromOper = from_key_oper<typename OutIterator::value_type> >
|
||||
struct OctMapKeyIterator_T : OctMapIterator_T<OutIterator, FromOper>
|
||||
{
|
||||
OctMapKeyIterator_T(OutIterator curr, OutIterator first, OutIterator last, octave_value seq)
|
||||
: OctMapIterator_T<OutIterator, FromOper>(curr, first, last, seq)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
template<typename OutIter>
|
||||
inline PySwigIterator*
|
||||
make_output_key_iterator(const OutIter& current, const OutIter& begin, const OutIter& end, octave_value seq = octave_value())
|
||||
{
|
||||
return new OctMapKeyIterator_T<OutIter>(current, begin, end, seq);
|
||||
}
|
||||
|
||||
template<class OutIterator,
|
||||
class FromOper = from_value_oper<typename OutIterator::value_type> >
|
||||
struct OctMapValueIterator_T : OctMapIterator_T<OutIterator, FromOper>
|
||||
{
|
||||
OctMapValueIterator_T(OutIterator curr, OutIterator first, OutIterator last, octave_value seq)
|
||||
: OctMapIterator_T<OutIterator, FromOper>(curr, first, last, seq)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template<typename OutIter>
|
||||
inline PySwigIterator*
|
||||
make_output_value_iterator(const OutIter& current, const OutIter& begin, const OutIter& end, octave_value seq = 0)
|
||||
{
|
||||
return new OctMapValueIterator_T<OutIter>(current, begin, end, seq);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
%define %swig_map_common(Map...)
|
||||
%swig_sequence_iterator(Map);
|
||||
%swig_container_methods(Map);
|
||||
%enddef
|
||||
|
||||
%define %swig_map_methods(Map...)
|
||||
%swig_map_common(Map)
|
||||
%enddef
|
||||
|
||||
|
||||
%include <std/std_map.i>
|
||||
129
Lib/octave/std_pair.i
Normal file
129
Lib/octave/std_pair.i
Normal file
|
|
@ -0,0 +1,129 @@
|
|||
// Pairs
|
||||
|
||||
%include <octstdcommon.swg>
|
||||
|
||||
//#define SWIG_STD_PAIR_ASVAL
|
||||
|
||||
%fragment("StdPairTraits","header",fragment="StdTraits") {
|
||||
namespace swig {
|
||||
#ifdef SWIG_STD_PAIR_ASVAL
|
||||
template <class T, class U >
|
||||
struct traits_asval<std::pair<T,U> > {
|
||||
typedef std::pair<T,U> value_type;
|
||||
|
||||
static int get_pair(const octave_value& first, octave_value second,
|
||||
std::pair<T,U> *val)
|
||||
{
|
||||
if (val) {
|
||||
T *pfirst = &(val->first);
|
||||
int res1 = swig::asval(first, pfirst);
|
||||
if (!SWIG_IsOK(res1))
|
||||
return res1;
|
||||
U *psecond = &(val->second);
|
||||
int res2 = swig::asval(second, psecond);
|
||||
if (!SWIG_IsOK(res2))
|
||||
return res2;
|
||||
return res1 > res2 ? res1 : res2;
|
||||
} else {
|
||||
T *pfirst = 0;
|
||||
int res1 = swig::asval(first, pfirst);
|
||||
if (!SWIG_IsOK(res1))
|
||||
return res1;
|
||||
U *psecond = 0;
|
||||
int res2 = swig::asval((PyObject*)second, psecond);
|
||||
if (!SWIG_IsOK(res2))
|
||||
return res2;
|
||||
return res1 > res2 ? res1 : res2;
|
||||
}
|
||||
}
|
||||
|
||||
static int asval(const octave_value& obj, std::pair<T,U> *val) {
|
||||
if (obj.is_cell()) {
|
||||
Cell c=obj.cell_value();
|
||||
if (c.numel()<2) {
|
||||
error("pair from Cell array requires at least two elements");
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
return get_pair(c(0),c(1),val);
|
||||
} else {
|
||||
value_type *p;
|
||||
int res = SWIG_ConvertPtr(obj,(void**)&p,swig::type_info<value_type>(),0);
|
||||
if (SWIG_IsOK(res) && val)
|
||||
*val = *p;
|
||||
return res;
|
||||
}
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
};
|
||||
|
||||
#else
|
||||
template <class T, class U >
|
||||
struct traits_asptr<std::pair<T,U> > {
|
||||
typedef std::pair<T,U> value_type;
|
||||
|
||||
static int get_pair(const octave_value& first, octave_value second,
|
||||
std::pair<T,U> **val)
|
||||
{
|
||||
if (val) {
|
||||
value_type *vp = %new_instance(std::pair<T,U>);
|
||||
T *pfirst = &(vp->first);
|
||||
int res1 = swig::asval(first, pfirst);
|
||||
if (!SWIG_IsOK(res1))
|
||||
return res1;
|
||||
U *psecond = &(vp->second);
|
||||
int res2 = swig::asval(second, psecond);
|
||||
if (!SWIG_IsOK(res2))
|
||||
return res2;
|
||||
*val = vp;
|
||||
return SWIG_AddNewMask(res1 > res2 ? res1 : res2);
|
||||
} else {
|
||||
T *pfirst = 0;
|
||||
int res1 = swig::asval(first, pfirst);
|
||||
if (!SWIG_IsOK(res1))
|
||||
return res1;
|
||||
U *psecond = 0;
|
||||
int res2 = swig::asval(second, psecond);
|
||||
if (!SWIG_IsOK(res2))
|
||||
return res2;
|
||||
return res1 > res2 ? res1 : res2;
|
||||
}
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
|
||||
static int asptr(const octave_value& obj, std::pair<T,U> **val) {
|
||||
if (obj.is_cell()) {
|
||||
Cell c=obj.cell_value();
|
||||
if (c.numel()<2) {
|
||||
error("pair from Cell array requires at least two elements");
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
return get_pair(c(0),c(1),val);
|
||||
} else {
|
||||
value_type *p;
|
||||
int res = SWIG_ConvertPtr(obj,(void**)&p,swig::type_info<value_type>(),0);
|
||||
if (SWIG_IsOK(res) && val)
|
||||
*val = p;
|
||||
return res;
|
||||
}
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
template <class T, class U >
|
||||
struct traits_from<std::pair<T,U> > {
|
||||
static octave_value from(const std::pair<T,U>& val) {
|
||||
Cell c(1,2);
|
||||
c(0)=swig::from(val.first);
|
||||
c(1)=swig::from(val.second);
|
||||
return c;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
%define %swig_pair_methods(pair...)
|
||||
%enddef
|
||||
|
||||
%include <std/std_pair.i>
|
||||
|
||||
1
Lib/octave/std_string.i
Normal file
1
Lib/octave/std_string.i
Normal file
|
|
@ -0,0 +1 @@
|
|||
%include <typemaps/std_string.swg>
|
||||
28
Lib/octave/std_vector.i
Normal file
28
Lib/octave/std_vector.i
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
// Vectors
|
||||
|
||||
%fragment("StdVectorTraits","header",fragment="StdSequenceTraits")
|
||||
%{
|
||||
namespace swig {
|
||||
/*
|
||||
template <class T>
|
||||
struct traits_asptr<std::vector<T> > {
|
||||
static int asptr(PyObject *obj, std::vector<T> **vec) {
|
||||
return traits_asptr_stdseq<std::vector<T> >::asptr(obj, vec);
|
||||
}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct traits_from<std::vector<T> > {
|
||||
static PyObject *from(const std::vector<T>& vec) {
|
||||
return traits_from_stdseq<std::vector<T> >::from(vec);
|
||||
}
|
||||
};
|
||||
*/
|
||||
}
|
||||
%}
|
||||
|
||||
#define %swig_vector_methods(Type...) %swig_sequence_methods(Type)
|
||||
#define %swig_vector_methods_val(Type...) %swig_sequence_methods_val(Type);
|
||||
|
||||
%include <std/std_vector.i>
|
||||
|
||||
6
Lib/octave/stl.i
Normal file
6
Lib/octave/stl.i
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
/* initial STL definition. extended as needed in each language */
|
||||
%include <std_common.i>
|
||||
%include <std_string.i>
|
||||
%include <std_vector.i>
|
||||
%include <std_map.i>
|
||||
%include <std_pair.i>
|
||||
1
Lib/octave/typemaps.i
Normal file
1
Lib/octave/typemaps.i
Normal file
|
|
@ -0,0 +1 @@
|
|||
%include <typemaps/typemaps.swg>
|
||||
Loading…
Add table
Add a link
Reference in a new issue