using <> when including lib files, fix char{ANY], add char FIXSIZE[ANY], fix pyfragments.swg, fixing *.swg and *.i names
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@6250 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
7cc6470fe6
commit
b9bfda7868
29 changed files with 181 additions and 82 deletions
|
|
@ -1,11 +1,11 @@
|
|||
|
||||
%include complex_common.i
|
||||
|
||||
/*
|
||||
* C complex wrap
|
||||
* C complex typemaps
|
||||
* ISO C99: 7.3 Complex arithmetic <complex.h>
|
||||
*/
|
||||
|
||||
|
||||
%include <pycomplex.swg>
|
||||
|
||||
%{
|
||||
#include <complex.h>
|
||||
%}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
* some way.
|
||||
*/
|
||||
|
||||
%include "pytuplehlp.swg"
|
||||
%include <pytuplehlp.swg>
|
||||
|
||||
/* %cstring_input_binary(TYPEMAP, SIZE)
|
||||
*
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
%include std_common.i
|
||||
%include <std_common.i>
|
||||
|
||||
/*
|
||||
The %implict macro allows a SwigType to be accepted
|
||||
|
|
|
|||
102
SWIG/Lib/python/pycomplex.swg
Normal file
102
SWIG/Lib/python/pycomplex.swg
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
/*
|
||||
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")
|
||||
%{
|
||||
SWIGSTATICINLINE(PyObject*)
|
||||
SWIG_From(Type)(SWIG_cplusplus(const Type&, Type) c)
|
||||
{
|
||||
return PyComplex_FromDoubles(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))
|
||||
%{
|
||||
SWIGSTATICINLINE(int)
|
||||
SWIG_AsVal(Type) (PyObject *o, Type* val)
|
||||
{
|
||||
if (PyComplex_Check(o)) {
|
||||
if (val) *val = Constructor(PyComplex_RealAsDouble(o),
|
||||
PyComplex_ImagAsDouble(o));
|
||||
return 1;
|
||||
} else {
|
||||
double d;
|
||||
if (SWIG_AsVal(double)(o, &d)) {
|
||||
if (val) *val = Constructor(d, 0);
|
||||
return 1;
|
||||
} else {
|
||||
PyErr_Clear();
|
||||
}
|
||||
}
|
||||
if (val) {
|
||||
PyErr_SetString(PyExc_TypeError, "a Type is expected");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
%}
|
||||
%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_CheckDoubleInRange",
|
||||
fragment=SWIG_AsVal_frag(float))
|
||||
%{
|
||||
SWIGSTATICINLINE(int)
|
||||
SWIG_AsVal(Type)(PyObject *o, Type *val)
|
||||
{
|
||||
const char* errmsg = val ? #Type : 0;
|
||||
if (PyComplex_Check(o)) {
|
||||
double re = PyComplex_RealAsDouble(o);
|
||||
double im = PyComplex_ImagAsDouble(o);
|
||||
if (SWIG_CheckDoubleInRange(re, -FLT_MAX, FLT_MAX, errmsg)
|
||||
&& SWIG_CheckDoubleInRange(im, -FLT_MAX, FLT_MAX, errmsg)) {
|
||||
if (val) *val = Constructor(swig_numeric_cast(re, float),
|
||||
swig_numeric_cast(im, float));
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
double re;
|
||||
if (SWIG_AsVal(double)(o, &re)) {
|
||||
if (SWIG_CheckDoubleInRange(re, -FLT_MAX, FLT_MAX, errmsg)) {
|
||||
if (val) *val = Constructor(swig_numeric_cast(re,float), 0);
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
PyErr_Clear();
|
||||
}
|
||||
}
|
||||
if (val) {
|
||||
PyErr_SetString(PyExc_TypeError, "a Type is expected");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
%}
|
||||
%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)
|
||||
|
||||
|
||||
558
SWIG/Lib/python/pycontainer.swg
Normal file
558
SWIG/Lib/python/pycontainer.swg
Normal file
|
|
@ -0,0 +1,558 @@
|
|||
//
|
||||
// Python sequence <-> C++ container wrapper
|
||||
//
|
||||
// This wrapper, and its iterator, allows a general use (and reuse) of
|
||||
// the the mapping between C++ and Python, thanks to the C++
|
||||
// templates.
|
||||
//
|
||||
// Of course, it needs the C++ compiler to support templates, but
|
||||
// since we will use this wrapper with the STL containers, that should
|
||||
// be the case.
|
||||
//
|
||||
|
||||
|
||||
/**** The PySequence C++ Wrap ***/
|
||||
|
||||
%insert(header) %{
|
||||
#if PY_VERSION_HEX < 0x02000000
|
||||
#define PySequence_Size PySequence_Length
|
||||
#endif
|
||||
#include <stdexcept>
|
||||
%}
|
||||
|
||||
%fragment("PySequence_Base","header")
|
||||
%{
|
||||
namespace swigpy {
|
||||
inline size_t
|
||||
check_index(ptrdiff_t i, size_t size) {
|
||||
if ( i < 0 ) {
|
||||
if ((size_t) (-i) <= size)
|
||||
return (size_t) (i + size);
|
||||
} else if ( (size_t) i < size ) {
|
||||
return (size_t) i;
|
||||
}
|
||||
throw std::out_of_range("index out of range");
|
||||
}
|
||||
|
||||
inline size_t
|
||||
slice_index(ptrdiff_t i, size_t size) {
|
||||
if ( i < 0 ) {
|
||||
return ((size_t) (-i) <= size) ? (size_t) (i + size) : 0;
|
||||
} else {
|
||||
return ( (size_t) i < size ) ? ((size_t) i)
|
||||
: (size ? (size_t)(size - 1) : 0);
|
||||
}
|
||||
}
|
||||
|
||||
template <class Sequence, class Difference>
|
||||
inline typename Sequence::iterator
|
||||
getpos(Sequence* self, Difference i) {
|
||||
typename Sequence::iterator pos = self->begin();
|
||||
std::advance(pos, swigpy::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, swigpy::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 = swigpy::slice_index(i, size);
|
||||
typename Sequence::size_type jj = swigpy::slice_index(j, size);
|
||||
if (jj > ii) {
|
||||
return new Sequence(cgetpos(self, ii), cgetpos(self, jj));
|
||||
} 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 = swigpy::slice_index(i, size);
|
||||
typename Sequence::size_type jj = swigpy::slice_index(j, size);
|
||||
if (jj < ii) jj = ii;
|
||||
typename InputSeq::const_iterator vmid = cgetpos(&v, jj - ii);
|
||||
self->insert(std::copy(v.begin(), vmid, getpos(self,ii)), vmid, 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 = swigpy::slice_index(i, size);
|
||||
typename Sequence::size_type jj = swigpy::slice_index(j, size);
|
||||
if (jj > ii) {
|
||||
self->erase(getpos(self,ii), getpos(self,jj));
|
||||
}
|
||||
}
|
||||
}
|
||||
%}
|
||||
|
||||
%fragment("PySequence_Cont","header",
|
||||
fragment="StdTraits",
|
||||
fragment="PySequence_Base",
|
||||
fragment="PyObject_var")
|
||||
%{
|
||||
#include <iterator>
|
||||
namespace swigpy
|
||||
{
|
||||
template <class T>
|
||||
struct PySequence_Ref
|
||||
{
|
||||
PySequence_Ref(PyObject* seq, int index)
|
||||
: _seq(seq), _index(index)
|
||||
{
|
||||
}
|
||||
|
||||
operator T () const
|
||||
{
|
||||
swigpy::PyObject_var item = PySequence_GetItem(_seq, _index);
|
||||
try {
|
||||
return swigpy::as<T>(item, true);
|
||||
} catch (std::exception& e) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"error in sequence element %d: %s", _index, e.what());
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
PySequence_Ref& operator=(const T& v)
|
||||
{
|
||||
PySequence_SetItem(_seq, _index, swigpy::from<T>(v));
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
PyObject* _seq;
|
||||
int _index;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct PySequence_ArrowProxy
|
||||
{
|
||||
PySequence_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 PySequence_Iter
|
||||
{
|
||||
typedef PySequence_Iter<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;
|
||||
|
||||
PySequence_Iter()
|
||||
{
|
||||
}
|
||||
|
||||
PySequence_Iter(PyObject* seq, int index)
|
||||
: _seq(seq), _index(index)
|
||||
{
|
||||
}
|
||||
|
||||
reference operator*() const
|
||||
{
|
||||
return reference(_seq, _index);
|
||||
}
|
||||
|
||||
PySequence_ArrowProxy<T>
|
||||
operator->() const {
|
||||
return PySequence_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;
|
||||
}
|
||||
|
||||
reference
|
||||
operator[](difference_type n) const
|
||||
{
|
||||
return reference(_seq, _index + n);
|
||||
}
|
||||
|
||||
private:
|
||||
PyObject* _seq;
|
||||
int _index;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct PySequence_Cont
|
||||
{
|
||||
typedef PySequence_Ref<T> reference;
|
||||
typedef const PySequence_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 PySequence_Iter<T, reference> iterator;
|
||||
typedef PySequence_Iter<T, const_reference> const_iterator;
|
||||
|
||||
PySequence_Cont(PyObject* seq) : _seq(0)
|
||||
{
|
||||
if (!PySequence_Check(seq)) {
|
||||
throw std::invalid_argument("a sequence is expected");
|
||||
}
|
||||
_seq = seq;
|
||||
Py_INCREF(_seq);
|
||||
}
|
||||
|
||||
~PySequence_Cont()
|
||||
{
|
||||
if (_seq) Py_DECREF(_seq);
|
||||
}
|
||||
|
||||
size_type size() const
|
||||
{
|
||||
return PySequence_Size(_seq);
|
||||
}
|
||||
|
||||
bool empty() const
|
||||
{
|
||||
return size() == 0;
|
||||
}
|
||||
|
||||
iterator begin()
|
||||
{
|
||||
return iterator(_seq, 0);
|
||||
}
|
||||
|
||||
const_iterator begin() const
|
||||
{
|
||||
return const_iterator(_seq, 0);
|
||||
}
|
||||
|
||||
iterator end()
|
||||
{
|
||||
return iterator(_seq, size());
|
||||
}
|
||||
|
||||
const_iterator end() const
|
||||
{
|
||||
return const_iterator(_seq, size());
|
||||
}
|
||||
|
||||
reference operator[](difference_type n)
|
||||
{
|
||||
return reference(_seq, n);
|
||||
}
|
||||
|
||||
const_reference operator[](difference_type n) const
|
||||
{
|
||||
return const_reference(_seq, n);
|
||||
}
|
||||
|
||||
bool check(bool set_err = true) const
|
||||
{
|
||||
int s = size();
|
||||
for (int i = 0; i < s; ++i) {
|
||||
swigpy::PyObject_var item = PySequence_GetItem(_seq, i);
|
||||
if (!swigpy::check<value_type>(item)) {
|
||||
if (set_err) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"element %d is not of type '%s' as expected",
|
||||
i, swigpy::type_name<value_type>());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
private:
|
||||
PyObject* _seq;
|
||||
};
|
||||
|
||||
}
|
||||
%}
|
||||
|
||||
|
||||
/**** The python container methods ****/
|
||||
|
||||
|
||||
%define %pycontainer_methods(Container)
|
||||
// __getitem__ is required to raise an IndexError for for-loops to work
|
||||
// other methods which can raise are made to throw an IndexError as well
|
||||
%exception __getitem__ {
|
||||
try { $action }
|
||||
catch (std::out_of_range& e) {
|
||||
SWIG_exception(SWIG_IndexError,const_cast<char*>(e.what()));
|
||||
}
|
||||
}
|
||||
|
||||
%exception __setitem__ {
|
||||
try { $action }
|
||||
catch (std::out_of_range& e) {
|
||||
SWIG_exception(SWIG_IndexError,const_cast<char*>(e.what()));
|
||||
}
|
||||
}
|
||||
|
||||
%exception __setslice__ {
|
||||
try { $action }
|
||||
catch (std::invalid_argument& e) {
|
||||
SWIG_exception(SWIG_TypeError,const_cast<char*>(e.what()));
|
||||
}
|
||||
}
|
||||
|
||||
%exception __delitem__ {
|
||||
try { $action }
|
||||
catch (std::out_of_range& e) {
|
||||
SWIG_exception(SWIG_IndexError,const_cast<char*>(e.what()));
|
||||
}
|
||||
}
|
||||
|
||||
%exception pop {
|
||||
try { $action }
|
||||
catch (std::out_of_range& e) {
|
||||
SWIG_exception(SWIG_IndexError,const_cast<char*>(e.what()));
|
||||
}
|
||||
}
|
||||
|
||||
%newobject __getslice__;
|
||||
|
||||
%extend {
|
||||
bool __nonzero__() const {
|
||||
return !(self->empty());
|
||||
}
|
||||
|
||||
size_type __len__() const {
|
||||
return self->size();
|
||||
}
|
||||
}
|
||||
%enddef
|
||||
|
||||
%define %pysequence_methods_common(Sequence)
|
||||
%pycontainer_methods(SWIG_arg(Sequence))
|
||||
%fragment("PySequence_Base");
|
||||
|
||||
%extend {
|
||||
value_type pop() {
|
||||
if (self->size() == 0)
|
||||
throw std::out_of_range("pop from empty container");
|
||||
Sequence::value_type x = self->back();
|
||||
self->pop_back();
|
||||
return x;
|
||||
}
|
||||
|
||||
Sequence* __getslice__(difference_type i, difference_type j) {
|
||||
return swigpy::getslice(self, i, j);
|
||||
}
|
||||
|
||||
void __setslice__(difference_type i, difference_type j, const Sequence& v) {
|
||||
swigpy::setslice(self, i, j, v);
|
||||
}
|
||||
|
||||
void __delslice__(difference_type i, difference_type j) {
|
||||
swigpy::delslice(self, i, j);
|
||||
}
|
||||
|
||||
void __delitem__(difference_type i) {
|
||||
self->erase(swigpy::getpos(self,i));
|
||||
}
|
||||
}
|
||||
%enddef
|
||||
|
||||
%define %pysequence_methods(Sequence)
|
||||
%pysequence_methods_common(SWIG_arg(Sequence))
|
||||
%extend {
|
||||
const value_type& __getitem__(difference_type i) const {
|
||||
return *(swigpy::cgetpos(self, i));
|
||||
}
|
||||
|
||||
void __setitem__(difference_type i, const value_type& x) {
|
||||
*(swigpy::getpos(self,i)) = x;
|
||||
}
|
||||
|
||||
void append(const value_type& x) {
|
||||
self->push_back(x);
|
||||
}
|
||||
}
|
||||
%enddef
|
||||
|
||||
%define %pysequence_methods_val(Sequence)
|
||||
%pysequence_methods_common(SWIG_arg(Sequence))
|
||||
%extend {
|
||||
value_type __getitem__(difference_type i) {
|
||||
return *(swigpy::cgetpos(self, i));
|
||||
}
|
||||
|
||||
void __setitem__(difference_type i, value_type x) {
|
||||
*(swigpy::getpos(self,i)) = x;
|
||||
}
|
||||
|
||||
void append(value_type x) {
|
||||
self->push_back(x);
|
||||
}
|
||||
}
|
||||
%enddef
|
||||
|
||||
|
||||
%define %pydict_methods(Dict)
|
||||
%pycontainer_methods(SWIG_arg(Dict))
|
||||
|
||||
%extend {
|
||||
mapped_type __getitem__(const key_type& key) const {
|
||||
Dict::const_iterator i = self->find(key);
|
||||
if (i != self->end())
|
||||
return i->second;
|
||||
else
|
||||
throw std::out_of_range("key not found");
|
||||
}
|
||||
|
||||
void __setitem__(const key_type& key, const mapped_type& x) {
|
||||
self->insert(Dict::value_type(key,x));
|
||||
}
|
||||
|
||||
void __delitem__(const key_type& key) {
|
||||
Dict::iterator i = self->find(key);
|
||||
if (i != self->end())
|
||||
self->erase(i);
|
||||
else
|
||||
throw std::out_of_range("key not found");
|
||||
}
|
||||
|
||||
bool has_key(const key_type& key) const {
|
||||
Dict::const_iterator i = self->find(key);
|
||||
return i != self->end();
|
||||
}
|
||||
|
||||
PyObject* keys() {
|
||||
Dict::size_type size = self->size();
|
||||
int pysize = size <= INT_MAX ? (int) size : 0;
|
||||
if (!pysize) {
|
||||
PyErr_SetString(PyExc_OverflowError,
|
||||
"map size not valid in python");
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
PyObject* keyList = PyList_New(pysize);
|
||||
Dict::const_iterator i = self->begin();
|
||||
for (int j = 0; j < pysize; ++i, ++j) {
|
||||
PyList_SetItem(keyList, j, swigpy::from(i->first));
|
||||
}
|
||||
return keyList;
|
||||
}
|
||||
|
||||
PyObject* values() {
|
||||
Dict::size_type size = self->size();
|
||||
int pysize = size <= INT_MAX ? (int) size : 0;
|
||||
if (!pysize) {
|
||||
PyErr_SetString(PyExc_OverflowError,
|
||||
"map size not valid in python");
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
PyObject* valList = PyTuple_New(pysize);
|
||||
Dict::const_iterator i = self->begin();
|
||||
for (int j = 0; j < pysize; ++i, ++j) {
|
||||
PyTuple_SetItem(valList, j, swigpy::from(i->second));
|
||||
}
|
||||
return valList;
|
||||
}
|
||||
|
||||
PyObject* items() {
|
||||
Dict::size_type size = self->size();
|
||||
int pysize = size <= INT_MAX ? (int) size : 0;
|
||||
if (!pysize) {
|
||||
PyErr_SetString(PyExc_OverflowError,
|
||||
"map size not valid in python");
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
PyObject* itemList = PyTuple_New(pysize);
|
||||
Dict::const_iterator i = self->begin();
|
||||
for (int j = 0; j < pysize; ++i, ++j) {
|
||||
PyTuple_SetItem(itemList, j, swigpy::from(*i));
|
||||
}
|
||||
return itemList;
|
||||
}
|
||||
|
||||
// Python 2.2 methods
|
||||
bool __contains__(const key_type& key) {
|
||||
return self->find(key) != self->end();
|
||||
}
|
||||
|
||||
PyObject* __iter__() {
|
||||
Dict::size_type size = self->size();
|
||||
int pysize = size <= INT_MAX ? (int) size : 0;
|
||||
if (!pysize) {
|
||||
PyErr_SetString(PyExc_OverflowError,
|
||||
"map size not valid in python");
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
PyObject* keyTuple = PyTuple_New(pysize);
|
||||
Dict::const_iterator i = self->begin();
|
||||
for (int j = 0; j < pysize; ++i, ++j) {
|
||||
PyTuple_SetItem(keyTuple, j, swigpy::from(i->first));
|
||||
}
|
||||
%#if PY_VERSION_HEX >= 0x02020000
|
||||
PyObject* iter = PyObject_GetIter(keyTuple);
|
||||
Py_DECREF(keyTuple);
|
||||
return iter;
|
||||
%#else
|
||||
return keyTuple;
|
||||
%#endif
|
||||
}
|
||||
}
|
||||
%enddef
|
||||
23
SWIG/Lib/python/pyfragments.swg
Normal file
23
SWIG/Lib/python/pyfragments.swg
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
|
||||
Create a file with this name, 'fragments.i', in your working
|
||||
directory and add all the %fragments you want to take precedence
|
||||
over the ones defined by default by swig.
|
||||
|
||||
For example, if you add:
|
||||
|
||||
%fragment(SWIG_AsVal_frag(int),"header") {
|
||||
SWIGSTATICINLINE(int)
|
||||
SWIG_AsVal(int)(PyObject *obj, int *val)
|
||||
{
|
||||
<your code here>;
|
||||
}
|
||||
}
|
||||
|
||||
this will replace the code used to retreive an integer value for all
|
||||
the typemaps that need it, including:
|
||||
|
||||
int, std::vector<int>, std::list<std::pair<int,int> >, etc.
|
||||
|
||||
|
||||
*/
|
||||
|
|
@ -123,7 +123,7 @@ output values.
|
|||
// Author: Robin Dunn
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
%include pytuplehlp.swg
|
||||
%include <pytuplehlp.swg>
|
||||
|
||||
%define _PYVAL_OUTPUT_TYPEMAP(from_meth, from_frag, Type)
|
||||
%typemap(in,numinputs=0) Type *OUTPUT ($*1_ltype temp, int res = 0),
|
||||
|
|
|
|||
|
|
@ -8,18 +8,42 @@
|
|||
methods. In the other cases, some extra work is needed.
|
||||
*/
|
||||
|
||||
|
||||
%insert(header) {
|
||||
SWIG_define(SWIG_From(signed char), PyInt_FromLong)
|
||||
SWIG_define(SWIG_From(unsigned char), PyInt_FromLong)
|
||||
SWIG_define(SWIG_From(short), PyInt_FromLong)
|
||||
SWIG_define(SWIG_From(unsigned short), PyInt_FromLong)
|
||||
SWIG_define(SWIG_From(int), PyInt_FromLong)
|
||||
SWIG_define(SWIG_From(long), PyInt_FromLong)
|
||||
SWIG_define(SWIG_From(float), PyFloat_FromDouble)
|
||||
SWIG_define(SWIG_From(double), PyFloat_FromDouble)
|
||||
%fragment(SWIG_From_frag(signed char),"header") {
|
||||
SWIG_define(SWIG_From(signed char), PyInt_FromLong)
|
||||
}
|
||||
|
||||
%fragment(SWIG_From_frag(unsigned char),"header") {
|
||||
SWIG_define(SWIG_From(unsigned char), PyInt_FromLong)
|
||||
}
|
||||
|
||||
%fragment(SWIG_From_frag(short),"header") {
|
||||
SWIG_define(SWIG_From(short), PyInt_FromLong)
|
||||
}
|
||||
|
||||
%fragment(SWIG_From_frag(unsigned short),"header") {
|
||||
SWIG_define(SWIG_From(unsigned short), PyInt_FromLong)
|
||||
}
|
||||
|
||||
%fragment(SWIG_From_frag(int),"header") {
|
||||
SWIG_define(SWIG_From(int), PyInt_FromLong)
|
||||
}
|
||||
|
||||
%fragment(SWIG_From_frag(long),"header") {
|
||||
SWIG_define(SWIG_From(long), PyInt_FromLong)
|
||||
}
|
||||
|
||||
%fragment(SWIG_From_frag(float),"header") {
|
||||
SWIG_define(SWIG_From(float), PyFloat_FromDouble)
|
||||
}
|
||||
|
||||
%fragment(SWIG_From_frag(double),"header") {
|
||||
SWIG_define(SWIG_From(double), PyFloat_FromDouble)
|
||||
}
|
||||
|
||||
/*
|
||||
Here, we have all the complex AsVal/From methods
|
||||
*/
|
||||
|
||||
%fragment("<limits.h>","header") %{
|
||||
#include <limits.h>
|
||||
%}
|
||||
|
|
@ -87,7 +111,7 @@ SWIGSTATICINLINE(int)
|
|||
if (value > max_value) {
|
||||
if (errmsg) {
|
||||
PyErr_Format(PyExc_OverflowError,
|
||||
"value %ld is greater than '%s' minimum %ld",
|
||||
"value %lud is greater than '%s' minimum %lud",
|
||||
value, errmsg, max_value);
|
||||
}
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
//
|
||||
// Use this macro if you prefer to preserve the size of char
|
||||
// arrays, ie
|
||||
// Use the macro SWIG_PRESERVE_CARRAY_SIZE if you prefer to preserve
|
||||
// the size of char arrays, ie
|
||||
// ------------------------------------------
|
||||
// C Side => Python Side
|
||||
// ------------------------------------------
|
||||
|
|
@ -176,9 +176,14 @@
|
|||
}
|
||||
|
||||
%typemap(out,fragment=#SWIG_FromCharArray)
|
||||
Char [ANY], const Char[ANY]
|
||||
"$result = SWIG_FromCharArray($1, $1_dim0);";
|
||||
|
||||
Char [ANY], const Char[ANY]
|
||||
{
|
||||
size_t size = $1_dim0;
|
||||
%#ifndef SWIG_PRESERVE_CARRAY_SIZE
|
||||
while (size && ($1[size - 1] == '\0')) --size;
|
||||
%#endif
|
||||
$result = SWIG_FromCharArray($1, size);
|
||||
}
|
||||
|
||||
/* varin */
|
||||
|
||||
|
|
@ -197,9 +202,9 @@
|
|||
Char [ANY], const Char [ANY]
|
||||
{
|
||||
size_t size = $1_dim0;
|
||||
#ifndef SWIG_PRESERVE_CARRAY_SIZE
|
||||
%#ifndef SWIG_PRESERVE_CARRAY_SIZE
|
||||
while (size && ($1[size - 1] == '\0')) --size;
|
||||
#endif
|
||||
%#endif
|
||||
$result = SWIG_FromCharArray($1, size);
|
||||
}
|
||||
|
||||
|
|
@ -207,13 +212,25 @@
|
|||
|
||||
%typemap(constcode,fragment=#SWIG_FromCharArray)
|
||||
Char [ANY], const Char [ANY]
|
||||
"PyDict_SetItemString(d,\"$symname\", SWIG_FromCharArray($value, $value_dim0));";
|
||||
{
|
||||
size_t size = $value_dim0;
|
||||
%#ifndef SWIG_PRESERVE_CARRAY_SIZE
|
||||
while (size && ($value[size - 1] == '\0')) --size;
|
||||
%#endif
|
||||
PyDict_SetItemString(d,"$symname", SWIG_FromCharArray($value,size));
|
||||
}
|
||||
|
||||
/* directorin */
|
||||
|
||||
%typemap(directorin,fragment=#SWIG_FromCharArray)
|
||||
Char [ANY], const Char [ANY]
|
||||
"$input = SWIG_FromCharArray($1_name, $1_dim0);";
|
||||
{
|
||||
size_t size = $1_dim0;
|
||||
%#ifndef SWIG_PRESERVE_CARRAY_SIZE
|
||||
while (size && ($1_name[size - 1] == '\0')) --size;
|
||||
%#endif
|
||||
$input = SWIG_FromCharArray($1_name, size);
|
||||
}
|
||||
|
||||
/* directorout */
|
||||
|
||||
|
|
@ -238,11 +255,53 @@
|
|||
%typemap(throws,fragment=#SWIG_FromCharArray)
|
||||
Char [ANY], const Char[ANY]
|
||||
{
|
||||
PyErr_SetObject(PyExc_RuntimeError, SWIG_FromCharArray($1, $1_dim0));
|
||||
size_t size = $1_dim0;
|
||||
%#ifndef SWIG_PRESERVE_CARRAY_SIZE
|
||||
while (size && ($1[size - 1] == '\0')) --size;
|
||||
%#endif
|
||||
PyErr_SetObject(PyExc_RuntimeError, SWIG_FromCharArray($1, size));
|
||||
SWIG_fail;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------
|
||||
* --- Really fix size Char arrays, including '\0'chars at the end ---
|
||||
* ------------------------------------------------------------------- */
|
||||
|
||||
%typemap(varout,fragment=#SWIG_FromCharArray)
|
||||
Char FIXSIZE[ANY], const Char FIXSIZE[ANY]
|
||||
{
|
||||
size_t size = $1_dim0;
|
||||
$result = SWIG_FromCharArray($1, size);
|
||||
}
|
||||
|
||||
%typemap(out,fragment=#SWIG_FromCharArray)
|
||||
Char FIXSIZE[ANY], const Char FIXSIZE[ANY]
|
||||
{
|
||||
size_t size = $1_dim0;
|
||||
$result = SWIG_FromCharArray($1, size);
|
||||
}
|
||||
|
||||
%typemap(constcode,fragment=#SWIG_FromCharArray)
|
||||
Char FIXSIZE[ANY], const Char FIXSIZE[ANY]
|
||||
{
|
||||
size_t size = $value_dim0;
|
||||
PyDict_SetItemString(d,"$symname", SWIG_FromCharArray($value,size));
|
||||
}
|
||||
|
||||
%typemap(directorin,fragment=#SWIG_FromCharArray)
|
||||
Char FIXSIZE[ANY], const Char FIXSIZE[ANY]
|
||||
{
|
||||
size_t size = $1_dim0;
|
||||
$input = SWIG_FromCharArray($1_name, size);
|
||||
}
|
||||
|
||||
%typemap(throws,fragment=#SWIG_FromCharArray)
|
||||
Char FIXSIZE[ANY], const Char FIXSIZE[ANY]
|
||||
{
|
||||
size_t size = $1_dim0;
|
||||
PyErr_SetObject(PyExc_RuntimeError, SWIG_FromCharArray($1, size));
|
||||
SWIG_fail;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* --- String & length ---
|
||||
|
|
|
|||
|
|
@ -126,14 +126,14 @@ SWIG_AsCharArray(PyObject *obj, char *val, size_t size)
|
|||
}
|
||||
if (val) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"a char array of maximum size %ld is expected",
|
||||
size);
|
||||
"a char array of maximum size %lud is expected",
|
||||
(unsigned long) size);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
%}
|
||||
|
||||
%fragment("SWIG_FromCharArray","header") %{
|
||||
%fragment("SWIG_FromCharArray","header") {
|
||||
SWIGSTATICINLINE(PyObject *)
|
||||
SWIG_FromCharArray(const char* carray, size_t size)
|
||||
{
|
||||
|
|
@ -144,7 +144,7 @@ SWIG_FromCharArray(const char* carray, size_t size)
|
|||
return PyString_FromStringAndSize(carray, swig_numeric_cast(size,int));
|
||||
}
|
||||
}
|
||||
%}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* The plain char * handling
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
/* Python.h has to appear first */
|
||||
|
||||
%insert(runtime) %{
|
||||
#include "Python.h"
|
||||
#include <Python.h>
|
||||
%}
|
||||
|
||||
%insert(runtime) "precommon.swg";
|
||||
|
|
@ -19,46 +19,46 @@
|
|||
#define %shadow %insert("shadow")
|
||||
#define %pythoncode %insert("python")
|
||||
|
||||
%include "pymacros.swg"
|
||||
%include <pymacros.swg>
|
||||
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Look for user fragments.i file. If not found, include empty system one.
|
||||
* Look for user fragments file. If not found, include empty system one.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
%include "fragments.i"
|
||||
%include "pyfragments.swg"
|
||||
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* SWIGTYPE typemaps
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
%include "pyswigtype.swg"
|
||||
%include <pyswigtype.swg>
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Typemap specializations
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
%include "pyinout.swg"
|
||||
%include "pyvoid.swg"
|
||||
%include "pyobject.swg"
|
||||
%include "pystrbase.swg"
|
||||
%include "pystrings.swg"
|
||||
%include "pyvaltypes.swg"
|
||||
%include "pyptrtypes.swg"
|
||||
%include "pyprimtypes.swg"
|
||||
%include "pymisctypes.swg"
|
||||
%include "pyenum.swg"
|
||||
%include <pyinout.swg>
|
||||
%include <pyvoid.swg>
|
||||
%include <pyobject.swg>
|
||||
%include <pystrbase.swg>
|
||||
%include <pystrings.swg>
|
||||
%include <pyvaltypes.swg>
|
||||
%include <pyptrtypes.swg>
|
||||
%include <pyprimtypes.swg>
|
||||
%include <pymisctypes.swg>
|
||||
%include <pyenum.swg>
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* Overloaded operator support
|
||||
* ------------------------------------------------------------ */
|
||||
%include "pyopers.swg"
|
||||
%include <pyopers.swg>
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* Warnings for Python keywords
|
||||
* ------------------------------------------------------------ */
|
||||
%include "pythonkw.swg"
|
||||
%include <pythonkw.swg>
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* The start of the Python initialization function
|
||||
|
|
|
|||
|
|
@ -122,7 +122,7 @@ SWIG_AsWCharArray(PyObject *obj, wchar_t *val, size_t size)
|
|||
}
|
||||
if (val) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"a wchar_t array of maximum size %ld is expected",
|
||||
"a wchar_t array of maximum size %lud is expected",
|
||||
size);
|
||||
}
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
%include exception.i
|
||||
%include std_container.i
|
||||
%include <exception.i>
|
||||
%include <std_container.i>
|
||||
|
||||
%{
|
||||
#include <string>
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@
|
|||
|
||||
#if defined(__SUNPRO_CC)
|
||||
#define SWIG_STD_NOASSIGN_STL
|
||||
#define SWIG_STD_NOINSERT_TEMPLATE_STL
|
||||
#endif
|
||||
|
||||
%}
|
||||
|
|
@ -50,7 +51,7 @@
|
|||
// Common code for supporting the STD C++ namespace
|
||||
//
|
||||
|
||||
%include pyptrtypes.swg
|
||||
%include <pyptrtypes.swg>
|
||||
%{
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
#ifndef SWIG_STD_COMPLEX_I_
|
||||
#define SWIG_STD_COMPLEX_I_
|
||||
/*
|
||||
* STD C++ complex typemaps
|
||||
*/
|
||||
|
||||
%include complex_common.i
|
||||
%include <pycomplex.swg>
|
||||
|
||||
%{
|
||||
#include <complex>
|
||||
|
|
@ -19,5 +20,3 @@
|
|||
%typemap_primitive(SWIG_CCode(CPLXDBL), std::complex<double>);
|
||||
%typemap_primitive(SWIG_CCode(CPLXFLT), std::complex<float>);
|
||||
|
||||
|
||||
#endif //SWIG_STD_COMPLEX_I_
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
%include std_common.i
|
||||
%include pycontainer.i
|
||||
%include exception.i
|
||||
%include <pycontainer.swg>
|
||||
%include <std_common.i>
|
||||
%include <exception.i>
|
||||
|
||||
%{
|
||||
#include <algorithm>
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
// std::deque
|
||||
// Python implementation
|
||||
|
||||
%include std_container.i
|
||||
%include <std_container.i>
|
||||
|
||||
// Deque
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
// std::list
|
||||
// Python implementation
|
||||
|
||||
%include std_container.i
|
||||
%include <std_container.i>
|
||||
|
||||
// List
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@
|
|||
// std::map
|
||||
// Python implementation
|
||||
|
||||
%include std_pair.i
|
||||
%include std_container.i
|
||||
%include <std_pair.i>
|
||||
%include <std_container.i>
|
||||
|
||||
%define %std_map_methods_common(map)
|
||||
%std_container_methods(SWIG_arg(map));
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
// std::map
|
||||
// Python implementation
|
||||
|
||||
%include std_map.i
|
||||
%include <std_map.i>
|
||||
|
||||
|
||||
%define %std_multimap_methods(...)
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue