isolate language independent STD/STL/C++ code + more documentation + cleaning

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@6382 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Marcelo Matus 2004-10-10 06:42:15 +00:00
commit dc4409a1f1
32 changed files with 3478 additions and 3384 deletions

80
Lib/python/README Normal file
View file

@ -0,0 +1,80 @@
/* -----------------------------------------------------------------------------
* Basic files
* ----------------------------------------------------------------------------- */
python.swg Main language file, it just includes what is needed.
pyuserdir.swg User visible directives (%pythonnondynamic, etc)
pymacros.swg Internal macros used for typemaps
pyfragments.swg Allow the user to overload the default fragments
pyopers.swg Python operations (+=, *=, etc)
pythonkw.swg Python keywords and special names
pyinit.swg Python Init method
/* -----------------------------------------------------------------------------
* The runtime part
* ----------------------------------------------------------------------------- */
pyruntime.swg Main runtime file definition
pyapi.swg SWIG/Pyton API declarations
pyrun.swg Python run-time code
/* -----------------------------------------------------------------------------
* Internal typemap specializations
* ----------------------------------------------------------------------------- */
pyswigtype.swg SWIGTYPE
pyvoid.swg void *
pyobject.swg PyObject
pystrbase.swg String base
pystrings.swg Char strings (char *)
pywstrings.swg Wchar Strings (wchar_t *)
pyprimtypes.swg Primitive types (shot,int,double,etc)
pymisctypes.swg Miscellaneos types (size_t, ptrdiff_t, etc)
pyenum.swg enum especializations
pycomplex.swg PyComplex and helper for C/C++ complex types
pydocs.swg Typemaps documentation
/* -----------------------------------------------------------------------------
* Special types or user helpers
* ----------------------------------------------------------------------------- */
file.i FILE C type
wchar.i wchar_t C type
ccomplex.i complex C type
cstring.i Various forms of C character string handling
argcargv.i Handler for (int argc, char **argv)
attribute.i Convert a pair of set/get methods into a "native" python attribute
implicit.i Allow the use of implicit C++ constructors
/* -----------------------------------------------------------------------------
* C++ STD + STL
* ----------------------------------------------------------------------------- */
pycontainer.swg python container iterators
std_common.i general common code
std_container.i general container code
std_basic_string.i basic string
std_char_traits.i char traits
std_complex.i complex
std_deque.i deque
std_except.i exceptions
std_ios.i ios
std_iostream.i istream/ostream
std_list.i list
std_map.i map
std_multimap.i multimap
std_multiset.i multiset
std_pair.i pair
std_set.i set
std_streambuf.i streambuf
std_string.i string
std_vector.i vector
std_vectora.i vector + allocator
std_wstring.i wstring
/* -----------------------------------------------------------------------------
* Backward compatibility
* ----------------------------------------------------------------------------- */
embed15.i embedding the Python interpreter in something else
embed.i embedding the Python interpreter in something else
defarg.swg for processing default arguments with shadow classes
typemaps.i old in/out typemaps

View file

@ -3,7 +3,7 @@
* ------------------------------------------------------------ */
%fragment("SWIG_AsArgcArgv","header",
fragment="SWIG_AsCharPtr") %{
fragment="SWIG_AsCharPtr") {
SWIGINTERN char**
SWIG_AsArgcArgv(PyObject* input,
swig_type_info* ppchar_info,
@ -40,7 +40,7 @@ SWIGINTERN char**
return argv;
}
}
%}
}
/*
This typemap works with either a char**, a python list or a python

View file

@ -10,32 +10,15 @@
#include <complex.h>
%}
/*
*** swig workaround ***
the %{}% around these typedefs must be removed once
swig parser supports 'float complex'...
*/
%{
typedef float complex float_complex;
typedef double complex double_complex;
%}
/* C complex constructor */
#define CCplxConst(r, i) ((r) + I*(i))
%swig_cplxflt_convn(float_complex, CCplxConst, creal, cimag);
%swig_cplxdbl_convn(double_complex, CCplxConst, creal, cimag);
%swig_cplxflt_convn(float complex, CCplxConst, creal, cimag);
%swig_cplxdbl_convn(double complex, CCplxConst, creal, cimag);
%swig_cplxdbl_convn(complex, CCplxConst, creal, cimag);
/* declaring the typemaps */
%typemap_primitive(SWIG_TYPECHECK_CPLXFLT, float_complex);
%typemap_primitive(SWIG_TYPECHECK_CPLXDBL, double_complex);
/* empty complex. hack in the meantime */
%apply double_complex { complex };
%apply const double_complex& { const complex& };
%apply double_complex& { complex& };
%apply double_complex* { complex* };
%typemap_primitive(SWIG_TYPECHECK_CPLXFLT, float complex);
%typemap_primitive(SWIG_TYPECHECK_CPLXDBL, double complex);
%typemap_primitive(SWIG_TYPECHECK_CPLXDBL, complex);

View file

@ -45,8 +45,8 @@
%define %implicit_frag(...) ,fragment=SWIG_Traits_frag(__VA_ARGS__) %enddef
%define %implicit_code(...)
if (swigpy::check<__VA_ARGS__ >(obj)) {
if (val) *val = new value_type(swigpy::as<__VA_ARGS__ >(obj));
if (swig::check<__VA_ARGS__ >(obj)) {
if (val) *val = new value_type(swig::as<__VA_ARGS__ >(obj));
return SWIG_NEWOBJ;
}
%enddef
@ -60,7 +60,7 @@
%fragment(SWIG_Traits_frag(Type),"header",
fragment="StdTraits"
%formacro_1(%implicit_frag,__VA_ARGS__)) %{
namespace swigpy {
namespace swig {
template <> struct traits<Type > {
typedef pointer_category category;
static const char* type_name() { return "Type"; }
@ -99,7 +99,7 @@ namespace swigpy {
%fragment(SWIG_Traits_frag(Type),"header",
fragment="StdTraits",
fragment=SWIG_Traits_frag(Imp1)) %{
namespace swigpy {
namespace swig {
template <> struct traits< Type > {
typedef pointer_category category;
static const char* type_name() { return "Type"; }
@ -140,7 +140,7 @@ namespace swigpy {
fragment="StdTraits",
fragment=SWIG_Traits_frag(Imp1),
fragment=SWIG_Traits_frag(Imp2)) %{
namespace swigpy {
namespace swig {
template <> struct traits< Type > {
typedef pointer_category category;
static const char* type_name() { return "Type"; }
@ -184,7 +184,7 @@ namespace swigpy {
fragment=SWIG_Traits_frag(Imp1),
fragment=SWIG_Traits_frag(Imp2),
fragment=SWIG_Traits_frag(Imp3)) %{
namespace swigpy {
namespace swig {
template <> struct traits< Type > {
typedef pointer_category category;
static const char* type_name() { return "Type"; }

View file

@ -1,3 +1,7 @@
/* -----------------------------------------------------------------------------
* SWIG API. Portion that goes into the runtime
* ----------------------------------------------------------------------------- */
#ifdef __cplusplus
extern "C" {
#endif
@ -18,9 +22,6 @@ extern "C" {
#endif /* __cplusplus */
#endif
/* -----------------------------------------------------------------------------
* SWIG API.
* ----------------------------------------------------------------------------- */
/* Common SWIG API */
#define SWIG_ConvertPtr(obj, pp, type, flags) SWIG_Python_ConvertPtr(obj, pp, type, flags)
@ -34,27 +35,6 @@ extern "C" {
#define SWIG_NewPackedObj(ptr, sz, type) SWIG_Python_NewPackedObj(ptr, sz, type)
#define SWIG_InstallConstants(d, constants) SWIG_Python_InstallConstants(d, constants)
/* Internal C/C++ API */
#ifdef __cplusplus
#define SWIG_new_array(size,Type) (new Type[(size)])
#define SWIG_delete(cptr) delete cptr
#define SWIG_delete_array(cptr) delete[] cptr
#define SWIG_const_cast(a,Type) const_cast<Type >(a)
#define SWIG_static_cast(a,Type) static_cast<Type >(a)
#define SWIG_reinterpret_cast(a,Type) reinterpret_cast<Type >(a)
#define SWIG_new_copy(ptr,Type) (new Type(*ptr))
#define SWIG_numeric_cast(a,Type) static_cast<Type >(a)
#else /* C case */
#define SWIG_new_array(size,Type) ((Type*) malloc((size)*sizeof(Type)))
#define SWIG_delete(cptr) free((char*)cptr)
#define SWIG_delete_array(cptr) free((char*)cptr)
#define SWIG_const_cast(a,Type) (Type)(a)
#define SWIG_static_cast(a,Type) (Type)(a)
#define SWIG_reinterpret_cast(a,Type) (Type)(a)
#define SWIG_numeric_cast(a,Type) (Type)(a)
#define SWIG_new_copy(ptr,Type) ((Type*)memcpy(malloc(sizeof(Type)),ptr,sizeof(Type)))
#endif /* __cplusplus */
/*
Exception handling in wrappers
*/
@ -119,4 +99,3 @@ typedef struct swig_const_info {
}
#endif

View file

@ -53,8 +53,7 @@ SWIGINTERN int
%define %swig_cplxflt_conv(Type, Constructor, Real, Imag)
%fragment(SWIG_AsVal_frag(Type),"header",
fragment="SWIG_CheckDoubleInRange",
fragment=SWIG_AsVal_frag(float))
%{
fragment=SWIG_AsVal_frag(float)) {
SWIGINTERN int
SWIG_AsVal(Type)(PyObject *o, Type *val)
{
@ -88,7 +87,8 @@ SWIGINTERN int
}
return 0;
}
%}
}
%swig_fromcplx_conv(Type, Real, Imag);
%enddef

View file

@ -24,7 +24,7 @@
%fragment("PySequence_Base","header")
%{
namespace swigpy {
namespace swig {
inline size_t
check_index(ptrdiff_t i, size_t size, bool insert = false) {
if ( i < 0 ) {
@ -72,8 +72,8 @@ namespace swigpy {
inline Sequence*
getslice(const Sequence* self, Difference i, Difference j) {
typename Sequence::size_type size = self->size();
typename Sequence::size_type ii = swigpy::check_index(i, size);
typename Sequence::size_type jj = swigpy::slice_index(j, 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();
@ -90,8 +90,8 @@ namespace swigpy {
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::check_index(i, size, true);
typename Sequence::size_type jj = swigpy::slice_index(j, 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;
typename Sequence::iterator sb = self->begin();
typename InputSeq::const_iterator vmid = v.begin();
@ -104,8 +104,8 @@ namespace swigpy {
inline void
delslice(Sequence* self, Difference i, Difference j) {
typename Sequence::size_type size = self->size();
typename Sequence::size_type ii = swigpy::check_index(i, size, true);
typename Sequence::size_type jj = swigpy::slice_index(j, 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();
@ -123,7 +123,7 @@ namespace swigpy {
fragment="PyObject_var")
%{
#include <iterator>
namespace swigpy
namespace swig
{
template <class T>
struct PySequence_Ref
@ -135,14 +135,14 @@ namespace swigpy
operator T () const
{
swigpy::PyObject_var item = PySequence_GetItem(_seq, _index);
swig::PyObject_var item = PySequence_GetItem(_seq, _index);
try {
return swigpy::as<T>(item, true);
return swig::as<T>(item, true);
} catch (std::exception& e) {
char msg[1024];
sprintf(msg,"in sequence element %d", _index);
if (!PyErr_Occurred()) {
SWIG_type_error(swigpy::type_name<T>(), item);
SWIG_type_error(swig::type_name<T>(), item);
}
SWIG_append_errmsg(msg);
throw;
@ -151,7 +151,7 @@ namespace swigpy
PySequence_Ref& operator=(const T& v)
{
PySequence_SetItem(_seq, _index, swigpy::from<T>(v));
PySequence_SetItem(_seq, _index, swig::from<T>(v));
return *this;
}
@ -330,12 +330,12 @@ namespace swigpy
{
int s = size();
for (int i = 0; i < s; ++i) {
swigpy::PyObject_var item = PySequence_GetItem(_seq, i);
if (!swigpy::check<value_type>(item)) {
swig::PyObject_var item = PySequence_GetItem(_seq, i);
if (!swig::check<value_type>(item)) {
if (set_err) {
char msg[1024];
sprintf(msg,"in sequence element %d", i);
SWIG_type_error(swigpy::type_name<value_type>(), item);
SWIG_type_error(swig::type_name<value_type>(), item);
SWIG_append_errmsg(msg);
}
return 0;
@ -355,7 +355,7 @@ namespace swigpy
/**** The python container methods ****/
%define %pycontainer_methods(Container)
%define %swig_container_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__ {
@ -463,8 +463,8 @@ namespace swigpy
}
%enddef
%define %pysequence_methods_common(Sequence)
%pycontainer_methods(SWIG_arg(Sequence))
%define %swig_sequence_methods_common(Sequence...)
%swig_container_methods(SWIG_arg(Sequence))
%fragment("PySequence_Base");
%extend {
@ -477,32 +477,32 @@ namespace swigpy
}
Sequence* __getslice__(difference_type i, difference_type j) {
return swigpy::getslice(self, i, j);
return swig::getslice(self, i, j);
}
void __setslice__(difference_type i, difference_type j, const Sequence& v) {
swigpy::setslice(self, i, j, v);
swig::setslice(self, i, j, v);
}
void __delslice__(difference_type i, difference_type j) {
swigpy::delslice(self, i, j);
swig::delslice(self, i, j);
}
void __delitem__(difference_type i) {
self->erase(swigpy::getpos(self,i));
self->erase(swig::getpos(self,i));
}
}
%enddef
%define %pysequence_methods(Sequence)
%pysequence_methods_common(SWIG_arg(Sequence))
%define %swig_sequence_methods(Sequence...)
%swig_sequence_methods_common(SWIG_arg(Sequence))
%extend {
const value_type& __getitem__(difference_type i) const {
return *(swigpy::cgetpos(self, i));
return *(swig::cgetpos(self, i));
}
void __setitem__(difference_type i, const value_type& x) {
*(swigpy::getpos(self,i)) = x;
*(swig::getpos(self,i)) = x;
}
void append(const value_type& x) {
@ -511,15 +511,15 @@ namespace swigpy
}
%enddef
%define %pysequence_methods_val(Sequence)
%pysequence_methods_common(SWIG_arg(Sequence))
%define %swig_sequence_methods_val(Sequence...)
%swig_sequence_methods_common(SWIG_arg(Sequence))
%extend {
value_type __getitem__(difference_type i) {
return *(swigpy::cgetpos(self, i));
return *(swig::cgetpos(self, i));
}
void __setitem__(difference_type i, value_type x) {
*(swigpy::getpos(self,i)) = x;
*(swig::getpos(self,i)) = x;
}
void append(value_type x) {
@ -529,112 +529,93 @@ namespace swigpy
%enddef
%define %pydict_methods(Dict)
%pycontainer_methods(SWIG_arg(Dict))
//
// Common fragments
//
%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;
%fragment("StdSequenceTraits","header",
fragment="StdTraits",fragment="PyObject_var",
fragment="PySequence_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));
}
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();
#else
seq->assign(pyseq.begin(), pyseq.end());
#endif
}
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;
template <class Seq, class T = typename Seq::value_type >
struct traits_asptr_stdseq {
typedef Seq sequence;
typedef T value_type;
static int asptr(PyObject *obj, sequence **seq) {
if (PySequence_Check(obj)) {
try {
PySequence_Cont<value_type> pyseq(obj);
if (seq) {
sequence *pseq = new sequence();
assign(pyseq, pseq);
*seq = pseq;
return SWIG_NEWOBJ;
} else {
return pyseq.check();
}
} catch (std::exception& e) {
if (seq) {
if (!PyErr_Occurred())
PyErr_SetString(PyExc_TypeError, e.what());
}
return 0;
}
} else {
sequence *p;
if (SWIG_ConvertPtr(obj,(void**)&p,
swig::type_info<sequence>(),0) != -1) {
if (seq) *seq = p;
return 1;
}
}
if (seq) {
PyErr_Format(PyExc_TypeError, "a %s is expected",
swig::type_name<sequence>());
}
return 0;
}
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));
};
template <class Seq, class T = typename Seq::value_type >
struct traits_from_stdseq {
typedef Seq sequence;
typedef T value_type;
typedef typename Seq::size_type size_type;
typedef typename sequence::const_iterator const_iterator;
static PyObject *from(const sequence& seq) {
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");
Py_INCREF(Py_None);
return Py_None;
}
}
%#if PY_VERSION_HEX >= 0x02020000
PyObject* iter = PyObject_GetIter(keyTuple);
Py_DECREF(keyTuple);
return iter;
%#else
return keyTuple;
%#endif
}
};
}
%enddef
%}

View file

@ -1,34 +1,69 @@
/* -----------------------------------------------------------------------------
* SWIG API. Portion only visible from SWIG
* ----------------------------------------------------------------------------- */
#define SWIG_arg(Arg...) Arg
#define SWIG_str(Type...) #Type
#define SWIG_Mangle(Type...) #@Type
#define SWIG_Descriptor(Type...) SWIGTYPE_ ## #@Type
#define SWIG_NameType(Name, Type...) SWIG_ ## Name ## _ ## #@Type
#define SWIG_StringType(Name, Type...) "SWIG_" #Name "_" {Type}
#define SWIG_AsVal(Type...) SWIG_NameType(AsVal, Type)
#define SWIG_AsPtr(Type...) SWIG_NameType(AsPtr, Type)
#define SWIG_As(Type...) SWIG_NameType(As, Type)
#define SWIG_From(Type...) SWIG_NameType(From, Type)
#define SWIG_Check(Type...) SWIG_NameType(Check, Type)
#define SWIG_CCode(Type...) SWIG_NameType(TYPECHECK, Type)
#define SWIG_OrderType(Type...) SWIG_NameType(OrderType, Type)
#define SWIG_EqualType(Type...) SWIG_NameType(EqualType, Type)
#define SWIG_Traits_frag(Type...) SWIG_StringType(Traits, Type)
#define SWIG_AsPtr_frag(Type...) SWIG_StringType(AsPtr, Type)
#define SWIG_AsVal_frag(Type...) SWIG_StringType(AsVal, Type)
#define SWIG_As_frag(Type...) SWIG_StringType(As, Type)
#define SWIG_From_frag(Type...) SWIG_StringType(From, Type)
#define SWIG_Check_frag(Type...) SWIG_StringType(Check, Type)
#define SWIG_CCode_frag(Type...) SWIG_StringType(TYPECHECK, Type)
/* Internal C/C++ API */
#ifndef SWIG_NO_CPLUSPLUS_CAST
/* -----------------------------------------------------------------------------
* Enable 'modern' cplusplus casting operators
* ----------------------------------------------------------------------------- */
#ifndef SWIG_CPLUSPLUS_CAST
#define SWIG_CPLUSPLUS_CAST
#endif
#endif
#if defined(__cplusplus) && defined(SWIG_CPLUSPLUS_CAST)
#define SWIG_new_array(size,Type...) (new Type[(size)])
#define SWIG_delete(cptr) delete cptr
#define SWIG_delete_array(cptr) delete[] cptr
#define SWIG_const_cast(a,Type...) const_cast<Type >(a)
#define SWIG_static_cast(a,Type...) static_cast<Type >(a)
#define SWIG_reinterpret_cast(a,Type...) reinterpret_cast<Type >(a)
#define SWIG_new_copy(ptr,Type...) (new Type(*ptr))
#define SWIG_numeric_cast(a,Type...) static_cast<Type >(a)
#else /* C case */
#define SWIG_new_array(size,Type) ((Type*) malloc((size)*sizeof(Type)))
#define SWIG_delete(cptr) free((char*)cptr)
#define SWIG_delete_array(cptr) free((char*)cptr)
#define SWIG_const_cast(a,Type) (Type)(a)
#define SWIG_static_cast(a,Type) (Type)(a)
#define SWIG_reinterpret_cast(a,Type) (Type)(a)
#define SWIG_numeric_cast(a,Type) (Type)(a)
#define SWIG_new_copy(ptr,Type) ((Type*)memcpy(malloc(sizeof(Type)),ptr,sizeof(Type)))
#endif /* __cplusplus */
/* -----------------------------------------------------------------------------
* Auxiliar swig macros used to write typemaps
* ----------------------------------------------------------------------------- */
#define SWIG_arg(...) __VA_ARGS__
#define SWIG_str(...) #__VA_ARGS__
#define SWIG_Mangle(...) #@__VA_ARGS__
#define SWIG_Descriptor(...) SWIGTYPE_ ## #@__VA_ARGS__
#define SWIG_NameType(Name, ...) SWIG_ ## Name ## _ ## #@__VA_ARGS__
#define SWIG_StringType(Name, ...) "SWIG_" #Name "_" {__VA_ARGS__}
#define SWIG_AsVal(...) SWIG_NameType(AsVal, __VA_ARGS__)
#define SWIG_AsPtr(...) SWIG_NameType(AsPtr, __VA_ARGS__)
#define SWIG_As(...) SWIG_NameType(As, __VA_ARGS__)
#define SWIG_From(...) SWIG_NameType(From, __VA_ARGS__)
#define SWIG_Check(...) SWIG_NameType(Check, __VA_ARGS__)
#define SWIG_CCode(...) SWIG_NameType(TYPECHECK, __VA_ARGS__)
#define SWIG_OrderType(...) SWIG_NameType(OrderType, __VA_ARGS__)
#define SWIG_EqualType(...) SWIG_NameType(EqualType, __VA_ARGS__)
#define SWIG_Traits_frag(...) SWIG_StringType(Traits, __VA_ARGS__)
#define SWIG_AsPtr_frag(...) SWIG_StringType(AsPtr, __VA_ARGS__)
#define SWIG_AsVal_frag(...) SWIG_StringType(AsVal, __VA_ARGS__)
#define SWIG_As_frag(...) SWIG_StringType(As, __VA_ARGS__)
#define SWIG_From_frag(...) SWIG_StringType(From, __VA_ARGS__)
#define SWIG_Check_frag(...) SWIG_StringType(Check, __VA_ARGS__)
#define SWIG_CCode_frag(...) SWIG_StringType(TYPECHECK, __VA_ARGS__)
/* define a new macro */
%define SWIG_define(Def, Val)
%#define Def Val

View file

@ -280,19 +280,6 @@ SWIG_Python_ConvertPtr(PyObject *obj, void **ptr, swig_type_info *ty, int flags)
return 0;
}
if (PyCFunction_Check(obj)) {
/* here we get the method pointer for callbacks.*/
c = strstr((((PyCFunctionObject *)obj) -> m_ml -> ml_doc), "swig_ptr: ");
if (c) {
c += 10;
if (*c == '_') {
c++;
c = SWIG_UnpackData(c,ptr,sizeof(void *));
goto type_check;
}
}
goto type_error;
}
#ifdef SWIG_COBJECT_TYPES
if (!(PyCObject_Check(obj))) {
if (!SWIG_this)
@ -355,6 +342,29 @@ type_check:
type_error:
PyErr_Clear();
if (pyobj && !obj) {
obj = pyobj;
if (PyCFunction_Check(obj)) {
/* here we get the method pointer for callbacks */
c = strstr((((PyCFunctionObject *)obj) -> m_ml -> ml_doc), "swig_ptr: ");
if (c) {
c += 10;
if (*c == '_') {
c++;
c = SWIG_UnpackData(c,ptr,sizeof(void *));
goto type_check;
}
}
}
if (PyInt_Check(obj)) {
/* here we check for the only accepted zero value */
long v = PyInt_AsLong(obj);
if (v == 0) {
*ptr = 0;
return 0;
}
}
}
if (flags & SWIG_POINTER_EXCEPTION) {
if (ty) {
SWIG_Python_TypeError(SWIG_TypePrettyName(ty), obj);

230
Lib/python/pystdcommon.swg Normal file
View file

@ -0,0 +1,230 @@
%include <pyptrtypes.swg>
%fragment("PyObject_var","header")
%{
namespace swig {
struct PyObject_var {
PyObject* ptr;
PyObject_var(PyObject* obj = 0) : ptr(obj) { }
~PyObject_var() { if (ptr) Py_DECREF(ptr); }
operator PyObject*() { return ptr; }
PyObject* operator->() const { return ptr; }
};
}
%}
%fragment("StdTraits","header",fragment="StdTraitsCommon")
%{
namespace swig {
/*
Traits that provides the from method
*/
template <class Type> struct traits_from_ptr {
static PyObject *from(Type *val, int owner = 0) {
return SWIG_NewPointerObj(val, type_info<Type>(), owner);
}
};
template <class Type> struct traits_from {
static PyObject *from(const Type& val) {
return traits_from_ptr<Type>::from(new Type(val), 1);
}
};
template <class Type> struct traits_from<Type *> {
static PyObject *from(Type* val) {
return traits_from_ptr<Type>::from(val, 0);
}
};
template <class Type>
inline PyObject *from(const Type& val) {
return traits_from<Type>::from(val);
}
template <class Type>
inline PyObject *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(PyObject *obj, Type **val) {
Type *p;
int res = (SWIG_ConvertPtr(obj, (void**)&p, type_info<Type>(), 0) != -1)
? SWIG_OLDOBJ : 0;
if (res) {
if (val) {
*val = p;
}
} else {
SWIG_type_error(type_name<Type>(), obj);
}
return res;
}
};
template <class Type>
inline int asptr(PyObject *obj, Type **vptr) {
return traits_asptr<Type>::asptr(obj, vptr);
}
template <class Type>
struct traits_asval {
static bool asval(PyObject *obj, Type *val) {
if (val) {
Type *p = 0;
int res = traits_asptr<Type>::asptr(obj, &p);
if (res && p) {
typedef typename noconst_traits<Type>::noconst_type noconst_type;
*(const_cast<noconst_type*>(val)) = *p;
if (res == SWIG_NEWOBJ) delete p;
return true;
} else {
return false;
}
} else {
return traits_asptr<Type>::asptr(obj, (Type **)(0));
}
}
};
template <class Type> struct traits_asval<Type*> {
static bool asval(PyObject *obj, Type **val) {
if (val) {
Type *p = 0;
int res = traits_asptr<Type>::asptr(obj, &p);
if (res) {
typedef typename noconst_traits<Type*>::noconst_type noconst_type;
*(const_cast<noconst_type*>(val)) = p;
return true;
} else {
return false;
}
} else {
return traits_asptr<Type>::asptr(obj, (Type **)(0));
}
}
};
template <class Type>
inline bool asval(PyObject *obj, Type *val) {
return traits_asval<Type>::asval(obj, val);
}
template <class Type>
struct traits_as<Type, value_category> {
static Type as(PyObject *obj, bool throw_error) {
Type v;
if (!obj || !asval(obj, &v)) {
if (!PyErr_Occurred()) {
SWIG_type_error(swig::type_name<Type>(), obj);
}
if (throw_error) throw std::invalid_argument("bad type");
}
return v;
}
};
template <class Type>
struct traits_as<Type, pointer_category> {
static Type as(PyObject *obj, bool throw_error) {
Type *v = 0;
int res = (obj ? traits_asptr<Type>::asptr(obj, &v) : 0) && v;
if (res) {
if (res == SWIG_NEWOBJ) {
Type r(*v);
delete v;
return r;
} else {
return *v;
}
} else {
// Uninitialized return value, no Type() constructor required.
static Type *v_def = (Type*) malloc(sizeof(Type));
if (!PyErr_Occurred()) {
SWIG_type_error(swig::type_name<Type>(), obj);
}
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(PyObject *obj, bool throw_error) {
Type *v = 0;
int res = (obj ? traits_asptr<Type>::asptr(obj, &v) : 0);
if (res) {
return v;
} else {
if (!PyErr_Occurred()) {
SWIG_type_error(swig::type_name<Type>(), obj);
}
if (throw_error) throw std::invalid_argument("bad type");
return 0;
}
}
};
template <class Type>
inline Type as(PyObject *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(PyObject *obj) {
return obj && asval(obj, (Type *)(0));
}
};
template <class Type>
struct traits_check<Type, pointer_category> {
static bool check(PyObject *obj) {
return obj && asptr(obj, (Type **)(0));
}
};
template <class Type>
inline bool check(PyObject *obj) {
return traits_check<Type, typename traits<Type>::category>::check(obj);
}
}
%}
//
// Backward compatibility
//
#ifdef SWIG_PYTHON_BACKWARD_COMP
%{
#include <string>
PyObject* SwigInt_FromBool(bool b) {
return PyInt_FromLong(b ? 1L : 0L);
}
double SwigNumber_Check(PyObject* o) {
return PyFloat_Check(o) || PyInt_Check(o) || PyLong_Check(o);
}
double SwigNumber_AsDouble(PyObject* o) {
return PyFloat_Check(o) ? PyFloat_AsDouble(o)
: (PyInt_Check(o) ? double(PyInt_AsLong(o))
: double(PyLong_AsLong(o)));
}
PyObject* SwigString_FromString(const std::string& s) {
return PyString_FromStringAndSize(s.data(),s.size());
}
std::string SwigString_AsString(PyObject* o) {
return std::string(PyString_AsString(o));
}
%}
#endif

View file

@ -4,7 +4,7 @@
* ------------------------------------------------------------ */
%types(char *);
%fragment("SWIG_AsCharPtrAndSize","header") %{
%fragment("SWIG_AsCharPtrAndSize","header") {
/* returns SWIG_OLDOBJ if the input is a raw char*, SWIG_PYSTR if is a PyString */
SWIGINTERN int
SWIG_AsCharPtrAndSize(PyObject *obj, char** cptr, size_t* psize)
@ -33,10 +33,10 @@ SWIG_AsCharPtrAndSize(PyObject *obj, char** cptr, size_t* psize)
}
return 0;
}
%}
}
%fragment("SWIG_AsCharPtr","header",
fragment="SWIG_AsCharPtrAndSize") %{
fragment="SWIG_AsCharPtrAndSize") {
SWIGINTERNSHORT int
SWIG_AsCharPtr(PyObject *obj, char **val)
{
@ -50,9 +50,9 @@ SWIG_AsCharPtr(PyObject *obj, char **val)
}
return 0;
}
%}
}
%fragment("SWIG_FromCharPtr","header") %{
%fragment("SWIG_FromCharPtr","header") {
SWIGINTERN PyObject *
SWIG_FromCharPtr(const char* cptr)
{
@ -72,10 +72,10 @@ SWIG_FromCharPtr(const char* cptr)
Py_INCREF(Py_None);
return Py_None;
}
%}
}
%fragment("SWIG_AsNewCharPtr","header",
fragment="SWIG_AsCharPtrAndSize") %{
fragment="SWIG_AsCharPtrAndSize") {
SWIGINTERN int
SWIG_AsNewCharPtr(PyObject *obj, char **val)
{
@ -101,10 +101,10 @@ SWIG_AsNewCharPtr(PyObject *obj, char **val)
}
return 0;
}
%}
}
%fragment("SWIG_AsCharArray","header",
fragment="SWIG_AsCharPtrAndSize") %{
fragment="SWIG_AsCharPtrAndSize") {
SWIGINTERN int
SWIG_AsCharArray(PyObject *obj, char *val, size_t size)
{
@ -132,7 +132,7 @@ SWIG_AsCharArray(PyObject *obj, char *val, size_t size)
}
return 0;
}
%}
}
%fragment("SWIG_FromCharArray","header") {
SWIGINTERNSHORT PyObject *

View file

@ -1,35 +1,39 @@
/*
Value typemaps (Type, const Type&) for value types, such as
fundamental types (int, double), that define the As/AsVal/From
methods.
*/
/*---------------------------------------------------------------------
* Value typemaps (Type, const Type&) for value types, such as
* fundamental types (int, double), that define the As/AsVal/From
* methods.
*---------------------------------------------------------------------*/
/* in */
%define PYVAL_IN_TYPEMAP(as_meth,pyfrag,...)
%typemap(in,fragment=pyfrag) __VA_ARGS__
"$1 = ($ltype)as_meth($input);
if (SWIG_arg_fail($argnum)) SWIG_fail;";
%typemap(in,fragment=pyfrag) const __VA_ARGS__ & ($basetype temp)
"temp = ($basetype) as_meth($input);
%define PYVAL_IN_TYPEMAP(as_meth,pyfrag,Type...)
%typemap(in,fragment=pyfrag) Type {
$1 = SWIG_static_cast(SWIG_arg(as_meth($input)),$type);
if (SWIG_arg_fail($argnum)) SWIG_fail;
}
%typemap(in,fragment=pyfrag) const Type & ($basetype temp) {
temp = SWIG_static_cast(SWIG_arg(as_meth($input)),$basetype);
if (SWIG_arg_fail($argnum)) SWIG_fail;
$1 = &temp;";
$1 = &temp;
}
%enddef
/* out */
%define PYVAL_OUT_TYPEMAP(from_meth,pyfrag,...)
%typemap(out,fragment=pyfrag) __VA_ARGS__
"$result = from_meth((__VA_ARGS__)($basetype)($1));";
%typemap(out,fragment=pyfrag) const __VA_ARGS__&
"$result = from_meth((__VA_ARGS__)($basetype)(*$1));";
%define PYVAL_OUT_TYPEMAP(from_meth,pyfrag,Type...)
%typemap(out,fragment=pyfrag) Type
{ $result = from_meth(SWIG_static_cast($1,$basetype)); }
%typemap(out,fragment=pyfrag) const Type&
{ $result = from_meth(SWIG_static_cast(*$1,$basetype)); }
%enddef
/* varin */
%define PYVAL_VARIN_TYPEMAP(as_meth,pyfrag,...)
%typemap(varin,fragment=pyfrag) __VA_ARGS__ {
$1_type temp = ($1_type) as_meth($input);
%define PYVAL_VARIN_TYPEMAP(as_meth,pyfrag,Type...)
%typemap(varin,fragment=pyfrag) Type {
$1_type temp = SWIG_static_cast(SWIG_arg(as_meth($input)),$1_type);
if (PyErr_Occurred()) {
SWIG_append_errmsg("C/C++ variable '$name ($1_ltype)'");
return 1;
@ -40,163 +44,163 @@
/* varout */
%define PYVAL_VAROUT_TYPEMAP(from_meth,pyfrag,...)
%typemap(varout,fragment=pyfrag) __VA_ARGS__, const __VA_ARGS__&
"$result = from_meth((__VA_ARGS__)($basetype)$1);";
%define PYVAL_VAROUT_TYPEMAP(from_meth,pyfrag,Type...)
%typemap(varout,fragment=pyfrag) Type, const Type&
{ $result = from_meth(SWIG_static_cast($1,$basetype)); }
%enddef
/* constant installation code */
%define PYVAL_CONSTCODE_TYPEMAP(from_meth,pyfrag,...)
%typemap(constcode,fragment=pyfrag) __VA_ARGS__
"PyDict_SetItemString(d,\"$symname\", from_meth((__VA_ARGS__)($basetype)$value));";
%enddef
%define PYVAL_CONSTCODE_TYPEMAP(from_meth,pyfrag,Type...)
%typemap(constcode,fragment=pyfrag) Type
{ PyDict_SetItemString(d,"$symname", from_meth(SWIG_static_cast($value,$basetype))); }
%enddef
/* directorin */
%define PYVAL_DIRECTORIN_TYPEMAP(from_meth,pyfrag,...)
%typemap(directorin,fragment=pyfrag) __VA_ARGS__ *DIRECTORIN
"$input = from_meth((__VA_ARGS__)($basetype)*$1_name);";
%typemap(directorin,fragment=pyfrag) __VA_ARGS__, const __VA_ARGS__&
"$input = from_meth((__VA_ARGS__)($basetype)$1_name);";
%define PYVAL_DIRECTORIN_TYPEMAP(from_meth,pyfrag,Type...)
%typemap(directorin,fragment=pyfrag) Type *DIRECTORIN
{ $input = from_meth(SWIG_static_cast(*$1_name,$basetype)); }
%typemap(directorin,fragment=pyfrag) Type, const Type&
{ $input = from_meth(SWIG_static_cast($1_name,$basetype)); }
%enddef
/* directorout */
%define PYVAL_DIRECTOROUT_TYPEMAP(as_meth,pyfrag,...)
%typemap(directorargout,fragment=pyfrag) __VA_ARGS__ *DIRECTOROUT
"*$result = ($basetype) as_meth($input);
if (PyErr_Occurred()) throw Swig::DirectorTypeMismatchException(\"Error converting Python object using as_meth\");";
%typemap(directorout,fragment=pyfrag) __VA_ARGS__
"$result = ($basetype) as_meth($input);
if (PyErr_Occurred()) throw Swig::DirectorTypeMismatchException(\"Error converting Python object using as_meth\");";
%typemap(directorout,fragment=pyfrag) const __VA_ARGS__&
"$basetype temp = ($basetype) as_meth($input);
$result = &temp;
if (PyErr_Occurred()) throw Swig::DirectorTypeMismatchException(\"Error converting Python object using as_meth\");";
%typemap(directorout,fragment=pyfrag) __VA_ARGS__ &DIRECTOROUT = __VA_ARGS__
%define PYVAL_DIRECTOROUT_TYPEMAP(as_meth,pyfrag,Type...)
%typemap(directorargout,fragment=pyfrag) Type *DIRECTOROUT {
*$result = SWIG_static_cast(SWIG_arg(as_meth($input)),$type);
if (PyErr_Occurred())
throw Swig::DirectorTypeMismatchException("Error converting Python object using as_meth");
}
%typemap(directorout,fragment=pyfrag) Type {
$result = SWIG_static_cast(SWIG_arg(as_meth($input)),$type);
if (PyErr_Occurred())
throw Swig::DirectorTypeMismatchException("Error converting Python object using as_meth");
}
%typemap(directorout,fragment=pyfrag) const Type& {
$basetype temp = SWIG_static_cast(SWIG_arg(as_meth($input)),$basetype);
$result = &temp;
if (PyErr_Occurred())
throw Swig::DirectorTypeMismatchException("Error converting Python object using as_meth");
}
%typemap(directorout,fragment=pyfrag) Type &DIRECTOROUT = Type
%enddef
/* throws */
%define PYVAL_THROWS_TYPEMAP(from_meth,pyfrag,...)
%typemap(throws,fragment=pyfrag) __VA_ARGS__
"PyErr_SetObject(PyExc_RuntimeError, from_meth((__VA_ARGS__)($basetype)$1));
SWIG_fail;";
%define PYVAL_THROWS_TYPEMAP(from_meth,pyfrag,Type...)
%typemap(throws,fragment=pyfrag) Type {
PyErr_SetObject(PyExc_RuntimeError, from_meth(SWIG_static_cast($1,$basetype)));
SWIG_fail;
}
%enddef
/* typecheck */
%define PYVAL_TYPECHECK_TYPEMAP(check,pyobj_check,pyfrag,...)
%define PYVAL_TYPECHECK_TYPEMAP(check,pyobj_check,pyfrag,Type...)
%typemap(typecheck,precedence=check,fragment=pyfrag)
__VA_ARGS__, const __VA_ARGS__&
Type, const Type&
"$1 = pyobj_check($input);";
%enddef
/*
typemap definition for types with As/Check methods
*/
/*---------------------------------------------------------------------
* typemap definition for types with As/Check methods
*---------------------------------------------------------------------*/
%define %typemap_ascheck(CheckCode, AsMeth, CheckMeth,
AsFrag, CheckFrag, ...)
PYVAL_IN_TYPEMAP(SWIG_arg(AsMeth), SWIG_arg(AsFrag), __VA_ARGS__);
PYVAL_VARIN_TYPEMAP(SWIG_arg(AsMeth), SWIG_arg(AsFrag), __VA_ARGS__);
PYVAL_DIRECTOROUT_TYPEMAP(SWIG_arg(AsMeth), SWIG_arg(AsFrag), __VA_ARGS__);
AsFrag, CheckFrag, Type...)
PYVAL_IN_TYPEMAP(SWIG_arg(AsMeth), SWIG_arg(AsFrag), Type);
PYVAL_VARIN_TYPEMAP(SWIG_arg(AsMeth), SWIG_arg(AsFrag), Type);
PYVAL_DIRECTOROUT_TYPEMAP(SWIG_arg(AsMeth), SWIG_arg(AsFrag), Type);
PYVAL_TYPECHECK_TYPEMAP(SWIG_arg(CheckCode), SWIG_arg(CheckMeth),
SWIG_arg(CheckFrag), __VA_ARGS__);
SWIG_arg(CheckFrag), Type);
PYVAL_INPUT_TYPEMAP(SWIG_arg(CheckCode), SWIG_arg(AsMeth), SWIG_arg(CheckMeth),
SWIG_arg(AsFrag), SWIG_arg(CheckFrag), __VA_ARGS__);
SWIG_arg(AsFrag), SWIG_arg(CheckFrag), Type);
%enddef
/*
typemap definition for types with AsVal method
*/
%define %typemap_asvaln(CheckCode, ...)
%fragment(SWIG_As_frag(__VA_ARGS__),"header",
fragment=SWIG_AsVal_frag(__VA_ARGS__)) %{
SWIGINTERNSHORT __VA_ARGS__
SWIG_As(__VA_ARGS__)(PyObject* obj)
/*---------------------------------------------------------------------
* typemap definition for types with AsVal method
*---------------------------------------------------------------------*/
%define %typemap_asvaln(CheckCode, Type...)
%fragment(SWIG_As_frag(Type),"header",
fragment=SWIG_AsVal_frag(Type)) %{
SWIGINTERNSHORT Type
SWIG_As(Type)(PyObject* obj)
{
__VA_ARGS__ v;
if (!SWIG_AsVal(__VA_ARGS__)(obj, &v)) {
Type v;
if (!SWIG_AsVal(Type)(obj, &v)) {
/*
this is needed to make valgrind/purify happier. the other
solution is throw an exception, but since this code should work
with plain C ....
this is needed to make valgrind/purify happier.
*/
memset((void*)&v, 0, sizeof(__VA_ARGS__));
memset((void*)&v, 0, sizeof(Type));
}
return v;
}
%}
%fragment(SWIG_Check_frag(__VA_ARGS__),"header",
fragment=SWIG_AsVal_frag(__VA_ARGS__)) %{
%fragment(SWIG_Check_frag(Type),"header",
fragment=SWIG_AsVal_frag(Type)) %{
SWIGINTERNSHORT int
SWIG_Check(__VA_ARGS__)(PyObject* obj)
SWIG_Check(Type)(PyObject* obj)
{
return SWIG_AsVal(__VA_ARGS__)(obj, (__VA_ARGS__*)0);
return SWIG_AsVal(Type)(obj, (Type*)0);
}
%}
%typemap_ascheck(SWIG_arg(CheckCode),
SWIG_As(__VA_ARGS__),
SWIG_Check(__VA_ARGS__),
SWIG_arg(SWIG_As_frag(__VA_ARGS__)),
SWIG_arg(SWIG_Check_frag(__VA_ARGS__)),
__VA_ARGS__);
SWIG_As(Type),
SWIG_Check(Type),
SWIG_arg(SWIG_As_frag(Type)),
SWIG_arg(SWIG_Check_frag(Type)),
Type);
%enddef
/*
typemap definition for types with from method
*/
%define %typemap_from(FromMeth, FromFrag, ...)
PYVAL_OUT_TYPEMAP(SWIG_arg(FromMeth), SWIG_arg(FromFrag), __VA_ARGS__);
PYVAL_VAROUT_TYPEMAP(SWIG_arg(FromMeth), SWIG_arg(FromFrag), __VA_ARGS__);
PYVAL_CONSTCODE_TYPEMAP(SWIG_arg(FromMeth), SWIG_arg(FromFrag), __VA_ARGS__);
PYVAL_DIRECTORIN_TYPEMAP(SWIG_arg(FromMeth), SWIG_arg(FromFrag), __VA_ARGS__);
PYVAL_THROWS_TYPEMAP(SWIG_arg(FromMeth), SWIG_arg(FromFrag),__VA_ARGS__);
PYVAL_OUTPUT_TYPEMAP(SWIG_arg(FromMeth), SWIG_arg(FromFrag), __VA_ARGS__);
/*---------------------------------------------------------------------
* typemap definition for types with from method
*---------------------------------------------------------------------*/
%define %typemap_from(FromMeth, FromFrag, Type...)
PYVAL_OUT_TYPEMAP(SWIG_arg(FromMeth), SWIG_arg(FromFrag), Type);
PYVAL_VAROUT_TYPEMAP(SWIG_arg(FromMeth), SWIG_arg(FromFrag), Type);
PYVAL_CONSTCODE_TYPEMAP(SWIG_arg(FromMeth), SWIG_arg(FromFrag), Type);
PYVAL_DIRECTORIN_TYPEMAP(SWIG_arg(FromMeth), SWIG_arg(FromFrag), Type);
PYVAL_THROWS_TYPEMAP(SWIG_arg(FromMeth), SWIG_arg(FromFrag), Type);
PYVAL_OUTPUT_TYPEMAP(SWIG_arg(FromMeth), SWIG_arg(FromFrag), Type);
%enddef
%define %typemap_ascheckfrom(CheckCode, AsMeth, CheckMeth, FromMeth,
AsFrag, CheckFrag, FromFrag, ...)
AsFrag, CheckFrag, FromFrag, Type...)
%typemap_ascheck(SWIG_arg(CheckCode), SWIG_arg(AsMeth), SWIG_arg(CheckMeth),
SWIG_arg(AsFrag), SWIG_arg(CheckFrag), __VA_ARGS__);
%typemap_from(SWIG_arg(FromMeth), SWIG_arg(FromFrag), __VA_ARGS__);
SWIG_arg(AsFrag), SWIG_arg(CheckFrag), Type);
%typemap_from(SWIG_arg(FromMeth), SWIG_arg(FromFrag), Type);
PYVAL_INOUT_TYPEMAP(__VA_ARGS__);
PYVAL_INOUT_TYPEMAP(Type);
%enddef
/*---------------------------------------------------------------------
* typemap definition for types with asval/from method
*---------------------------------------------------------------------*/
%define %typemap_asvalfromn(CheckCode, Type...)
%typemap_asvaln(SWIG_arg(CheckCode), Type);
%typemap_from(SWIG_arg(SWIG_From(Type)),
SWIG_arg(SWIG_From_frag(Type)),
Type);
/*
typemap definition for types with asval/from method
*/
%define %typemap_asvalfromn(CheckCode, ...)
%typemap_asvaln(SWIG_arg(CheckCode), __VA_ARGS__);
%typemap_from(SWIG_arg(SWIG_From(__VA_ARGS__)),
SWIG_arg(SWIG_From_frag(__VA_ARGS__)),
__VA_ARGS__);
PYVAL_INOUT_TYPEMAP(__VA_ARGS__);
PYVAL_INOUT_TYPEMAP(Type);
%enddef
/*
typemap definition for types with as/check/from method
*/
%define %typemap_ascheckfromn(CheckCode, ...)
/*---------------------------------------------------------------------
* typemap definition for types with as/check/from method
*---------------------------------------------------------------------*/
%define %typemap_ascheckfromn(CheckCode, Type...)
%typemap_ascheckfrom(SWIG_arg(CheckCode),
SWIG_As(__VA_ARGS__),
SWIG_From(__VA_ARGS__),
SWIG_Check(__VA_ARGS__),
SWIG_arg(SWIG_As_frag(__VA_ARGS__)),
SWIG_arg(SWIG_From_frag(__VA_ARGS__)),
SWIG_arg(SWIG_Check_frag(__VA_ARGS__)),
__VA_ARGS__);
SWIG_As(Type),
SWIG_From(Type),
SWIG_Check(Type),
SWIG_arg(SWIG_As_frag(Type)),
SWIG_arg(SWIG_From_frag(Type)),
SWIG_arg(SWIG_Check_frag(Type)),
Type);
%enddef

View file

@ -4,8 +4,17 @@
/* in */
%typemap(in) void *
"if ((SWIG_ConvertPtr($input,&$1,0,SWIG_POINTER_EXCEPTION | $disown)) == -1) {SWIG_arg_fail($argnum);SWIG_fail;}";
%typemap(in) void * {
if ((SWIG_ConvertPtr($input,SWIG_reinterpret_cast(&$1,void **),0,SWIG_POINTER_EXCEPTION|$disown))== -1) {
SWIG_arg_fail($argnum);SWIG_fail;
}
}
%typemap(in) const void *& ($basetype temp) {
SWIG_ConvertPtr($input,SWIG_reinterpret_cast(&temp,void **),0,SWIG_POINTER_EXCEPTION|$disown);
if (SWIG_arg_fail($argnum)) SWIG_fail;
$1 = &temp;
}
/* out */
@ -16,7 +25,7 @@
%typemap(varin) void * {
void * temp;
if ((SWIG_ConvertPtr($input, &temp, 0,
if ((SWIG_ConvertPtr($input, SWIG_static_cast(&temp,void **), 0,
SWIG_POINTER_EXCEPTION | SWIG_POINTER_DISOWN)) == -1) {
SWIG_append_errmsg("C/C++ variable '$name'");
return 1;
@ -30,10 +39,12 @@
/* directorout */
%typemap(directorout) void *
"if ((SWIG_ConvertPtr($input,(void **)(&$result),
%typemap(directorout) void * {
if ((SWIG_ConvertPtr($input,(void **)(&$result),
0, SWIG_POINTER_EXCEPTION | $disown )) == -1)
throw Swig::DirectorTypeMismatchException(\"Pointer conversion failed.\");";
throw Swig::DirectorTypeMismatchException("Pointer conversion failed.");
}
/* typecheck */

View file

@ -3,7 +3,7 @@
* utility methods for wchar_t strings
* ------------------------------------------------------------ */
%fragment("SWIG_AsWCharPtrAndSize","header") %{
%fragment("SWIG_AsWCharPtrAndSize","header") {
SWIGINTERN int
SWIG_AsWCharPtrAndSize(PyObject *obj, wchar_t **cptr, size_t *psize)
{
@ -37,10 +37,10 @@ SWIG_AsWCharPtrAndSize(PyObject *obj, wchar_t **cptr, size_t *psize)
}
return 0;
}
%}
}
%fragment("SWIG_AsWCharPtr","header",
fragment="SWIG_AsWCharPtrAndSize") %{
fragment="SWIG_AsWCharPtrAndSize") {
SWIGINTERN int
SWIG_AsWCharPtr(PyObject *obj, wchar_t **val)
{
@ -55,9 +55,9 @@ SWIG_AsWCharPtr(PyObject *obj, wchar_t **val)
}
return 0;
}
%}
}
%fragment("SWIG_FromWCharPtr","header") %{
%fragment("SWIG_FromWCharPtr","header") {
SWIGINTERN PyObject *
SWIG_FromWCharPtr(const wchar_t * cptr)
{
@ -73,10 +73,10 @@ SWIG_FromWCharPtr(const wchar_t * cptr)
Py_INCREF(Py_None);
return Py_None;
}
%}
}
%fragment("SWIG_AsNewWCharPtr","header",
fragment="SWIG_AsWCharPtrAndSize") %{
fragment="SWIG_AsWCharPtrAndSize") {
SWIGINTERN int
SWIG_AsNewWCharPtr(PyObject *obj, wchar_t **val)
{
@ -102,10 +102,10 @@ SWIG_AsNewWCharPtr(PyObject *obj, wchar_t **val)
}
return 0;
}
%}
}
%fragment("SWIG_AsWCharArray","header",
fragment="SWIG_AsWCharPtrAndSize") %{
fragment="SWIG_AsWCharPtrAndSize") {
SWIGINTERN int
SWIG_AsWCharArray(PyObject *obj, wchar_t *val, size_t size)
{
@ -127,9 +127,9 @@ SWIG_AsWCharArray(PyObject *obj, wchar_t *val, size_t size)
}
return 0;
}
%}
}
%fragment("SWIG_FromWCharArray","header") %{
%fragment("SWIG_FromWCharArray","header") {
SWIGINTERNSHORT PyObject *
SWIG_FromWCharArray(const wchar_t * carray, size_t size)
{
@ -140,7 +140,7 @@ SWIG_FromWCharArray(const wchar_t * carray, size_t size)
return PyUnicode_FromWideChar(carray, SWIG_numeric_cast(size,int));
}
}
%}
}
/* ------------------------------------------------------------
* The plain wchar_t * handling

View file

@ -1,251 +1,4 @@
%include <exception.i>
%include <std_container.i>
%include <std_char_traits.i>
%{
#include <string>
%}
namespace std {
template <class _CharT>
class basic_string
{
#if !defined(SWIG_STD_MODERN_STL) || defined(SWIG_STD_NOMODERN_STL)
%ignore push_back;
%ignore clear;
%ignore compare;
%ignore append;
#endif
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef _CharT value_type;
typedef value_type reference;
typedef value_type const_reference;
static const size_type npos;
basic_string(const _CharT* __s, size_type __n);
// Capacity:
size_type length() const;
size_type max_size() const;
size_type capacity() const;
void reserve(size_type __res_arg = 0);
// Modifiers:
basic_string&
append(const basic_string& __str);
basic_string&
append(const basic_string& __str, size_type __pos, size_type __n);
basic_string&
append(const _CharT* __s, size_type __n);
basic_string&
append(size_type __n, _CharT __c);
basic_string&
assign(const basic_string& __str);
basic_string&
assign(const basic_string& __str, size_type __pos, size_type __n);
basic_string&
assign(const _CharT* __s, size_type __n);
basic_string&
insert(size_type __pos1, const basic_string& __str);
basic_string&
insert(size_type __pos1, const basic_string& __str,
size_type __pos2, size_type __n);
basic_string&
insert(size_type __pos, const _CharT* __s, size_type __n);
basic_string&
insert(size_type __pos, size_type __n, _CharT __c);
basic_string&
erase(size_type __pos = 0, size_type __n = npos);
basic_string&
replace(size_type __pos, size_type __n, const basic_string& __str);
basic_string&
replace(size_type __pos1, size_type __n1, const basic_string& __str,
size_type __pos2, size_type __n2);
basic_string&
replace(size_type __pos, size_type __n1, const _CharT* __s,
size_type __n2);
basic_string&
replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c);
size_type
copy(_CharT* __s, size_type __n, size_type __pos = 0) const;
// String operations:
const _CharT* c_str() const;
size_type
find(const _CharT* __s, size_type __pos, size_type __n) const;
size_type
find(const basic_string& __str, size_type __pos = 0) const;
size_type
find(_CharT __c, size_type __pos = 0) const;
size_type
rfind(const basic_string& __str, size_type __pos = npos) const;
size_type
rfind(const _CharT* __s, size_type __pos, size_type __n) const;
size_type
rfind(_CharT __c, size_type __pos = npos) const;
size_type
find_first_of(const basic_string& __str, size_type __pos = 0) const;
size_type
find_first_of(const _CharT* __s, size_type __pos, size_type __n) const;
size_type
find_first_of(_CharT __c, size_type __pos = 0) const;
size_type
find_last_of(const basic_string& __str, size_type __pos = npos) const;
size_type
find_last_of(const _CharT* __s, size_type __pos, size_type __n) const;
size_type
find_last_of(_CharT __c, size_type __pos = npos) const;
size_type
find_first_not_of(const basic_string& __str, size_type __pos = 0) const;
size_type
find_first_not_of(const _CharT* __s, size_type __pos,
size_type __n) const;
size_type
find_first_not_of(_CharT __c, size_type __pos = 0) const;
size_type
find_last_not_of(const basic_string& __str, size_type __pos = npos) const;
size_type
find_last_not_of(const _CharT* __s, size_type __pos,
size_type __n) const;
size_type
find_last_not_of(_CharT __c, size_type __pos = npos) const;
basic_string
substr(size_type __pos = 0, size_type __n = npos) const;
int
compare(const basic_string& __str) const;
int
compare(size_type __pos, size_type __n, const basic_string& __str) const;
int
compare(size_type __pos1, size_type __n1, const basic_string& __str,
size_type __pos2, size_type __n2) const;
%ignore pop_back();
%ignore front() const;
%ignore back() const;
%ignore basic_string(size_type n);
%std_sequence_methods_val(basic_string);
%ignore pop();
%pysequence_methods_val(std::basic_string<_CharT>);
#ifdef SWIG_EXPORT_ITERATOR_METHODS
iterator
insert(iterator __p, _CharT __c = _CharT());
iterator
erase(iterator __position);
iterator
erase(iterator __first, iterator __last);
void
insert(iterator __p, size_type __n, _CharT __c);
basic_string&
replace(iterator __i1, iterator __i2, const basic_string& __str);
basic_string&
replace(iterator __i1, iterator __i2,
const _CharT* __s, size_type __n);
basic_string&
replace(iterator __i1, iterator __i2, const _CharT* __s);
basic_string&
replace(iterator __i1, iterator __i2, size_type __n, _CharT __c);
basic_string&
replace(iterator __i1, iterator __i2, _CharT* __k1, _CharT* __k2);
basic_string&
replace(iterator __i1, iterator __i2, const _CharT* __k1, const _CharT* __k2);
basic_string&
replace(iterator __i1, iterator __i2, iterator __k1, iterator __k2);
basic_string&
replace(iterator __i1, iterator __i2, const_iterator __k1, const_iterator __k2);
#endif
std::basic_string<_CharT>& operator +=(const basic_string& v);
%newobject __add__;
%newobject __radd__;
%extend {
std::basic_string<_CharT>* __add__(const basic_string& v) {
std::basic_string<_CharT>* res = new std::basic_string<_CharT>(*self);
*res += v;
return res;
}
std::basic_string<_CharT>* __radd__(const basic_string& v) {
std::basic_string<_CharT>* res = new std::basic_string<_CharT>(v);
*res += *self;
return res;
}
const std::basic_string<_CharT>& __str__() {
return *self;
}
std::basic_ostream<_CharT, std::char_traits<_CharT> >&
__rlshift__(std::basic_ostream<_CharT, std::char_traits<_CharT> >& out) {
out << *self;
return out;
}
}
};
}
%include <pycontainer.swg>
#define %swig_basic_string(Type...) %swig_sequence_methods_val(Type)
%include <std/std_basic_string.i>

View file

@ -1,132 +1 @@
%include <std_common.i>
%include <wchar.i>
namespace std
{
/// 21.1.2 Basis for explicit _Traits specialization
/// NB: That for any given actual character type this definition is
/// probably wrong.
template<class _CharT>
struct char_traits
{
};
/// 21.1.4 char_traits specializations
template<>
struct char_traits<char> {
typedef char char_type;
typedef int int_type;
typedef streampos pos_type;
typedef streamoff off_type;
typedef mbstate_t state_type;
static void
assign(char_type& __c1, const char_type& __c2);
static bool
eq(const char_type& __c1, const char_type& __c2);
static bool
lt(const char_type& __c1, const char_type& __c2);
static int
compare(const char_type* __s1, const char_type* __s2, size_t __n);
static size_t
length(const char_type* __s);
static const char_type*
find(const char_type* __s, size_t __n, const char_type& __a);
static char_type*
move(char_type* __s1, const char_type* __s2, size_t __n);
static char_type*
copy(char_type* __s1, const char_type* __s2, size_t __n);
static char_type*
assign(char_type* __s, size_t __n, char_type __a);
static char_type
to_char_type(const int_type& __c);
// To keep both the byte 0xff and the eof symbol 0xffffffff
// from ending up as 0xffffffff.
static int_type
to_int_type(const char_type& __c);
static bool
eq_int_type(const int_type& __c1, const int_type& __c2);
static int_type
eof() ;
static int_type
not_eof(const int_type& __c);
};
template<>
struct char_traits<wchar_t>
{
typedef wchar_t char_type;
typedef wint_t int_type;
typedef streamoff off_type;
typedef wstreampos pos_type;
typedef mbstate_t state_type;
static void
assign(char_type& __c1, const char_type& __c2);
static bool
eq(const char_type& __c1, const char_type& __c2);
static bool
lt(const char_type& __c1, const char_type& __c2);
static int
compare(const char_type* __s1, const char_type* __s2, size_t __n);
static size_t
length(const char_type* __s);
static const char_type*
find(const char_type* __s, size_t __n, const char_type& __a);
static char_type*
move(char_type* __s1, const char_type* __s2, int_type __n);
static char_type*
copy(char_type* __s1, const char_type* __s2, size_t __n);
static char_type*
assign(char_type* __s, size_t __n, char_type __a);
static char_type
to_char_type(const int_type& __c) ;
static int_type
to_int_type(const char_type& __c) ;
static bool
eq_int_type(const int_type& __c1, const int_type& __c2);
static int_type
eof() ;
static int_type
not_eof(const int_type& __c);
};
}
namespace std {
#ifndef SWIG_STL_WRAP_TRAITS
%template() char_traits<char>;
%template() char_traits<wchar_t>;
#else
%template(char_traits_c) char_traits<char>;
%template(char_traits_w) char_traits<wchar_t>;
#endif
}
%include <std/std_char_traits.i>

View file

@ -1,538 +1,3 @@
//
// Use the following macro with modern STL implementations
//
//#define SWIG_STD_MODERN_STL
//
// Use this to deactive the previous definition, when using gcc-2.95
// or similar old compilers.
//
//#define SWIG_STD_NOMODERN_STL
%include <pystdcommon.swg>
%include <std/std_common.i>
// Here, we identify compilers we now have problems with STL.
%{
#if defined(__SUNPRO_CC)
#define SWIG_STD_NOASSIGN_STL
#define SWIG_STD_NOINSERT_TEMPLATE_STL
#endif
%}
//
// Define or uncomment the following macro to instantiate by default
// all the basic std typemaps (std::pair<T,U>, std::vector<T>, etc)
// for all the primitive C++ types (int, double, etc).
//
// Note that this is equivalent to do something similar to
//
// %template() std::vector<int>;
//
// but for all the std and basic C++ types, ie, no wrapping is
// generated for std::vector<int>, only the basic typemaps
// (in, out, typecheck, throw, input, etc.).
//
//#define SWIG_STD_DEFAULT_INSTANTIATION
//
// Use the following macro to enable the generation of the
// comparison methods, ie, ==, !=, <=, >=, <,>, whenever is needed,
// for the primitive types (int,double, etc.)
//
//#define SWIG_STD_EXTEND_COMPARISON
//
// Use the following macro if you need the old common
// methods (SwigInt_FromBool,SwigNumber_Check,...).
//
// #define SWIG_STD_BACKWARD_COMP
//
// Common code for supporting the STD C++ namespace
//
%include <pyptrtypes.swg>
%{
#include <string>
#include <stdexcept>
%}
%apply size_t { std::size_t };
%apply ptrdiff_t { std::ptrdiff_t }
%fragment("PyObject_var","header")
%{
namespace swigpy {
struct PyObject_var {
PyObject* ptr;
PyObject_var(PyObject* obj = 0) : ptr(obj) { }
~PyObject_var() { if (ptr) Py_DECREF(ptr); }
operator PyObject*() { return ptr; }
PyObject* operator->() const { return ptr; }
};
}
%}
%fragment("StdTraits","header")
%{
namespace swigpy {
/*
type categories
*/
struct pointer_category { };
struct value_category { };
/*
General traits that provides type_name and type_info
*/
template <class Type> struct traits { };
template <class Type>
inline const char* type_name() {
return traits<Type>::type_name();
}
template <class Type>
struct traits_info {
static swig_type_info *type_query(std::string name) {
name += " *";
return SWIG_TypeQuery(name.c_str());
}
static swig_type_info *type_info() {
static swig_type_info *info = type_query(type_name<Type>());
return info;
}
};
template <class Type>
inline swig_type_info *type_info() {
return traits_info<Type>::type_info();
}
/*
Partial specialization for pointers
*/
template <class Type> struct traits <Type *> {
typedef pointer_category category;
static std::string make_ptr_name(const char* name) {
std::string ptrname = name;
ptrname += " *";
return ptrname;
}
static const char* type_name() {
static std::string name = make_ptr_name(swigpy::type_name<Type>());
return name.c_str();
}
};
/*
Traits that provides the from method
*/
template <class Type> struct traits_from_ptr {
static PyObject *from(Type *val, int owner = 0) {
return SWIG_NewPointerObj(val, type_info<Type>(), owner);
}
};
template <class Type> struct traits_from {
static PyObject *from(const Type& val) {
return traits_from_ptr<Type>::from(new Type(val), 1);
}
};
template <class Type> struct traits_from<Type *> {
static PyObject *from(Type* val) {
return traits_from_ptr<Type>::from(val, 0);
}
};
template <class Type>
inline PyObject *from(const Type& val) {
return traits_from<Type>::from(val);
}
template <class Type>
inline PyObject *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(PyObject *obj, Type **val) {
Type *p;
int res = (SWIG_ConvertPtr(obj, (void**)&p, type_info<Type>(), 0) != -1)
? SWIG_OLDOBJ : 0;
if (res) {
if (val) {
*val = p;
}
} else {
SWIG_type_error(type_name<Type>(), obj);
}
return res;
}
};
template <class Type>
inline int asptr(PyObject *obj, Type **vptr) {
return traits_asptr<Type>::asptr(obj, vptr);
}
template <class Type>
struct noconst_traits {
typedef Type noconst_type;
};
template <class Type>
struct noconst_traits<const Type> {
typedef Type noconst_type;
};
template <class Type>
struct traits_asval {
static bool asval(PyObject *obj, Type *val) {
if (val) {
Type *p = 0;
int res = traits_asptr<Type>::asptr(obj, &p);
if (res && p) {
typedef typename noconst_traits<Type>::noconst_type noconst_type;
*(const_cast<noconst_type*>(val)) = *p;
if (res == SWIG_NEWOBJ) delete p;
return true;
} else {
return false;
}
} else {
return traits_asptr<Type>::asptr(obj, (Type **)(0));
}
}
};
template <class Type> struct traits_asval<Type*> {
static bool asval(PyObject *obj, Type **val) {
if (val) {
Type *p = 0;
int res = traits_asptr<Type>::asptr(obj, &p);
if (res) {
typedef typename noconst_traits<Type*>::noconst_type noconst_type;
*(const_cast<noconst_type*>(val)) = p;
return true;
} else {
return false;
}
} else {
return traits_asptr<Type>::asptr(obj, (Type **)(0));
}
}
};
template <class Type>
inline bool asval(PyObject *obj, Type *val) {
return traits_asval<Type>::asval(obj, val);
}
template <class Type, class Category>
struct traits_as { };
template <class Type>
struct traits_as<Type, value_category> {
static Type as(PyObject *obj, bool throw_error) {
Type v;
if (!obj || !asval(obj, &v)) {
if (!PyErr_Occurred()) {
SWIG_type_error(swigpy::type_name<Type>(), obj);
}
if (throw_error) throw std::invalid_argument("bad type");
}
return v;
}
};
template <class Type>
struct traits_as<Type, pointer_category> {
static Type as(PyObject *obj, bool throw_error) {
Type *v = 0;
int res = (obj ? traits_asptr<Type>::asptr(obj, &v) : 0) && v;
if (res) {
if (res == SWIG_NEWOBJ) {
Type r(*v);
delete v;
return r;
} else {
return *v;
}
} else {
// Uninitialized return value, no Type() constructor required.
static Type *v_def = (Type*) malloc(sizeof(Type));
if (!PyErr_Occurred()) {
SWIG_type_error(swigpy::type_name<Type>(), obj);
}
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(PyObject *obj, bool throw_error) {
Type *v = 0;
int res = (obj ? traits_asptr<Type>::asptr(obj, &v) : 0);
if (res) {
return v;
} else {
if (!PyErr_Occurred()) {
SWIG_type_error(swigpy::type_name<Type>(), obj);
}
if (throw_error) throw std::invalid_argument("bad type");
return 0;
}
}
};
template <class Type>
inline Type as(PyObject *obj, bool te = false) {
return traits_as<Type, typename traits<Type>::category>::as(obj, te);
}
template <class Type, class Category>
struct traits_check { };
template <class Type>
struct traits_check<Type, value_category> {
static bool check(PyObject *obj) {
return obj && asval(obj, (Type *)(0));
}
};
template <class Type>
struct traits_check<Type, pointer_category> {
static bool check(PyObject *obj) {
return obj && asptr(obj, (Type **)(0));
}
};
template <class Type>
inline bool check(PyObject *obj) {
return traits_check<Type, typename traits<Type>::category>::check(obj);
}
}
%}
/*
Generate the traits for a swigtype
*/
%define %traits_swigtype(...)
%fragment(SWIG_Traits_frag(__VA_ARGS__),"header",fragment="StdTraits") {
namespace swigpy {
template <> struct traits<__VA_ARGS__ > {
typedef pointer_category category;
static const char* type_name() { return #__VA_ARGS__; }
};
}
}
%enddef
/*
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(...)
%fragment(SWIG_Traits_frag(__VA_ARGS__),"header",
fragment=SWIG_AsVal_frag(__VA_ARGS__),
fragment=SWIG_From_frag(__VA_ARGS__),
fragment="StdTraits") {
namespace swigpy {
template <> struct traits<__VA_ARGS__ > {
typedef value_category category;
static const char* type_name() { return #__VA_ARGS__; }
};
template <> struct traits_asval<__VA_ARGS__ > {
typedef __VA_ARGS__ value_type;
static int asval(PyObject *obj, value_type *val) {
return SWIG_AsVal(__VA_ARGS__)(obj, val);
}
};
template <> struct traits_from<__VA_ARGS__ > {
typedef __VA_ARGS__ value_type;
static PyObject *from(const value_type& val) {
return SWIG_From(__VA_ARGS__)(val);
}
};
}
}
%enddef
%apply_cpptypes(%traits_ptypen);
/*
Generate the typemaps for a class that has 'value' traits
*/
%define %typemap_traits(Code,...)
%typemap_ascheckfrom(SWIG_arg(Code),
SWIG_arg(swigpy::as<__VA_ARGS__ >),
SWIG_arg(swigpy::check<__VA_ARGS__ >),
SWIG_arg(swigpy::from),
SWIG_arg(SWIG_Traits_frag(__VA_ARGS__)),
SWIG_arg(SWIG_Traits_frag(__VA_ARGS__)),
SWIG_arg(SWIG_Traits_frag(__VA_ARGS__)),
__VA_ARGS__);
%enddef
/*
Generate the typemaps for a class that behaves more like a 'pointer' or
plain wrapped Swigtype.
*/
%define %typemap_traits_ptr(Code,...)
%typemap_asptrfrom(SWIG_arg(Code),
SWIG_arg(swigpy::asptr),
SWIG_arg(swigpy::from),
SWIG_arg(SWIG_Traits_frag(__VA_ARGS__)),
SWIG_arg(SWIG_Traits_frag(__VA_ARGS__)),
__VA_ARGS__);
%enddef
/*
Equality methods
*/
%define %std_equal_methods(...)
%extend __VA_ARGS__ {
bool operator == (const __VA_ARGS__& v) {
return *self == v;
}
bool operator != (const __VA_ARGS__& v) {
return *self != v;
}
}
%enddef
/*
Order methods
*/
%define %std_order_methods(...)
%extend __VA_ARGS__ {
bool operator > (const __VA_ARGS__& v) {
return *self > v;
}
bool operator < (const __VA_ARGS__& v) {
return *self < v;
}
bool operator >= (const __VA_ARGS__& v) {
return *self >= v;
}
bool operator <= (const __VA_ARGS__& v) {
return *self <= v;
}
}
%enddef
/*
Comparison methods
*/
%define %std_comp_methods(...)
%std_equal_methods(__VA_ARGS__ )
%std_order_methods(__VA_ARGS__ )
%enddef
#if defined(SWIG_STD_EXTEND_COMPARISON)
%define %std_extcomp(Class,T)
%evalif(SWIG_EqualType(T), %std_equal_methods(std::Class<T >))
%evalif(SWIG_OrderType(T), %std_order_methods(std::Class<T >))
%enddef
%define %_std_extcomp_2(Class,T,U)
%evalif_2(SWIG_EqualType(T),SWIG_EqualType(U),%std_equal_methods(std::Class<T,U >))
%evalif_2(SWIG_OrderType(T),SWIG_EqualType(U),%std_order_methods(std::Class<T,U >))
%enddef
%define %std_extcomp_2(Class,T,...)
%_std_extcomp_2(Class,T,__VA_ARGS__)
%enddef
#else
#define %std_extcomp(Class,...)
#define %std_extcomp_2(Class,...)
#endif
#ifdef SWIG_STD_DEFAULT_INSTANTIATION
#define %std_definst(Class,...) %template() std::Class< __VA_ARGS__ >;
#define %std_definst_2(Class,...) %template() std::Class< __VA_ARGS__ >;
#else
#define %std_definst(Class,...)
#define %std_definst_2(Class,...)
#endif
/* ------------------------------------------------------------
* equal and order types definition.
* these are needed to decide when we the comparison
* operators ==, !=, <=, etc, can be used.
* ------------------------------------------------------------ */
/* the operators ==, != can used with these types */
%swig_equal_type(bool);
%swig_equal_type(std::complex<float>);
%swig_equal_type(std::complex<double>);
/* the operators <,>,<=,=> can used with these types */
%swig_order_type(signed char);
%swig_order_type(unsigned char);
%swig_order_type(short);
%swig_order_type(unsigned short);
%swig_order_type(int);
%swig_order_type(unsigned int);
%swig_order_type(long);
%swig_order_type(unsigned long);
%swig_order_type(long long);
%swig_order_type(unsigned long long);
%swig_order_type(float);
%swig_order_type(double);
%swig_order_type(char);
%swig_order_type(wchar_t);
%swig_order_type(std::string);
%swig_order_type(std::basic_string<char>);
%swig_order_type(std::wstring);
%swig_order_type(std::basic_string<wchar_t>);
//
// Backward compatibility
//
#ifdef SWIG_STD_BACKWARD_COMP
%{
#include <string>
PyObject* SwigInt_FromBool(bool b) {
return PyInt_FromLong(b ? 1L : 0L);
}
double SwigNumber_Check(PyObject* o) {
return PyFloat_Check(o) || PyInt_Check(o) || PyLong_Check(o);
}
double SwigNumber_AsDouble(PyObject* o) {
return PyFloat_Check(o) ? PyFloat_AsDouble(o)
: (PyInt_Check(o) ? double(PyInt_AsLong(o))
: double(PyLong_AsLong(o)));
}
PyObject* SwigString_FromString(const std::string& s) {
return PyString_FromStringAndSize(s.data(),s.size());
}
std::string SwigString_AsString(PyObject* o) {
return std::string(PyString_AsString(o));
}
%}
#endif

View file

@ -1,198 +1,2 @@
%include <pycontainer.swg>
%include <std_common.i>
%include <exception.i>
%{
#include <algorithm>
%}
// Common container methods
%define %std_container_methods(container)
container();
container(const container&);
bool empty() const;
size_type size() const;
void clear();
void swap(container& v);
#ifdef SWIG_EXPORT_ITERATOR_METHODS
iterator begin();
const_iterator begin() const;
iterator end();
const_iterator end() const;
reverse_iterator rbegin();
const_reverse_iterator rbegin() const;
reverse_iterator rend();
const_reverse_iterator rend() const;
#endif
%enddef
// Common sequence
%define %std_sequence_methods_common(sequence)
%std_container_methods(SWIG_arg(sequence));
sequence(size_type size);
void pop_back();
void resize(size_type new_size);
#ifdef SWIG_EXPORT_ITERATOR_METHODS
iterator insert(iterator pos);
iterator erase(iterator pos);
iterator erase(iterator first, iterator last);
#endif
%enddef
%define %std_sequence_methods(sequence)
%std_sequence_methods_common(SWIG_arg(sequence));
sequence(size_type size, const value_type& value);
void push_back(const value_type& x);
const value_type& front() const;
const value_type& back() const;
void assign(size_type n, const value_type& x);
void resize(size_type new_size, const value_type& x);
#ifdef SWIG_EXPORT_ITERATOR_METHODS
iterator insert(iterator pos, const value_type& x);
void insert(iterator pos, size_type n, const value_type& x);
#endif
%enddef
%define %std_sequence_methods_val(sequence)
%std_sequence_methods_common(SWIG_arg(sequence));
sequence(size_type size, value_type value);
void push_back(value_type x);
value_type front() const;
value_type back() const;
void assign(size_type n, value_type x);
void resize(size_type new_size, value_type x);
#ifdef SWIG_EXPORT_ITERATOR_METHODS
iterator insert(iterator pos, value_type x);
void insert(iterator pos, size_type n, value_type x);
#endif
%enddef
//
// Common fragments
//
%fragment("StdSequenceTraits","header",
fragment="StdTraits",fragment="PyObject_var",
fragment="PySequence_Cont")
%{
namespace swigpy {
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(PyObject *obj, sequence **seq) {
if (PySequence_Check(obj)) {
try {
PySequence_Cont<value_type> pyseq(obj);
if (seq) {
sequence *pseq = new sequence();
assign(pyseq, pseq);
*seq = pseq;
return SWIG_NEWOBJ;
} else {
return pyseq.check();
}
} catch (std::exception& e) {
if (seq) {
if (!PyErr_Occurred())
PyErr_SetString(PyExc_TypeError, e.what());
}
return 0;
}
} else {
sequence *p;
if (SWIG_ConvertPtr(obj,(void**)&p,
swigpy::type_info<sequence>(),0) != -1) {
if (seq) *seq = p;
return 1;
}
}
if (seq) {
PyErr_Format(PyExc_TypeError, "a %s is expected",
swigpy::type_name<sequence>());
}
return 0;
}
};
template <class Seq, class T = typename Seq::value_type >
struct traits_from_stdseq {
typedef Seq sequence;
typedef T value_type;
typedef typename Seq::size_type size_type;
typedef typename sequence::const_iterator const_iterator;
static PyObject *from(const sequence& seq) {
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,swigpy::from<value_type>(*it));
}
return obj;
} else {
PyErr_SetString(PyExc_OverflowError,
"sequence size not valid in python");
Py_INCREF(Py_None);
return Py_None;
}
}
};
}
%}
//
// Ignore member methods for Type with no default constructor
//
%define %std_nodefconst_type(...)
%feature("ignore") std::vector<__VA_ARGS__ >::vector(size_type size);
%feature("ignore") std::vector<__VA_ARGS__ >::resize(size_type size);
%feature("ignore") std::deque<__VA_ARGS__ >::deque(size_type size);
%feature("ignore") std::deque<__VA_ARGS__ >::resize(size_type size);
%feature("ignore") std::list<__VA_ARGS__ >::list(size_type size);
%feature("ignore") std::list<__VA_ARGS__ >::resize(size_type size);
%enddef
%include <std/std_container.i>

View file

@ -1,57 +1,10 @@
//
// std::deque
// Python implementation
%include <std_container.i>
// Deque
%define %std_deque_methods(deque)
%std_sequence_methods(deque)
void pop_front();
void push_front(const value_type& x);
%enddef
%define %std_deque_methods_val(deque)
%std_sequence_methods_val(deque)
void pop_front();
void push_front(value_type x);
%enddef
// ------------------------------------------------------------------------
// std::deque
//
// The aim of all that follows would be to integrate std::deque with
// Python as much as possible, namely, to allow the user to pass and
// be returned Python tuples or lists.
// const declarations are used to guess the intent of the function being
// exported; therefore, the following rationale is applied:
//
// -- f(std::deque<T>), f(const std::deque<T>&):
// the parameter being read-only, either a Python sequence or a
// previously wrapped std::deque<T> can be passed.
// -- f(std::deque<T>&), f(std::deque<T>*):
// the parameter may be modified; therefore, only a wrapped std::deque
// can be passed.
// -- std::deque<T> f(), const std::deque<T>& f():
// the deque is returned by copy; therefore, a Python sequence of T:s
// is returned which is most easily used in other Python functions
// -- std::deque<T>& f(), std::deque<T>* f():
// the deque is returned by reference; therefore, a wrapped std::deque
// is returned
// -- const std::deque<T>* f(), f(const std::deque<T>*):
// for consistency, they expect and return a plain deque pointer.
// ------------------------------------------------------------------------
%{
#include <deque>
%}
/*
Deques
*/
%fragment("StdDequeTraits","header",fragment="StdSequenceTraits")
%{
namespace swigpy {
namespace swig {
template <class T>
struct traits_asptr<std::deque<T> > {
static int asptr(PyObject *obj, std::deque<T> **vec) {
@ -68,79 +21,7 @@
}
%}
// exported classes
#define %swig_deque_methods(Type...) %swig_sequence_methods(Type)
#define %swig_deque_methods_val(Type...) %swig_sequence_methods_val(Type);
namespace std {
template<class T > class deque {
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef T value_type;
typedef value_type* pointer;
typedef const value_type* const_pointer;
typedef value_type& reference;
typedef const value_type& const_reference;
%traits_swigtype(T);
%fragment(SWIG_Traits_frag(std::deque<T >), "header",
fragment=SWIG_Traits_frag(T),
fragment="StdDequeTraits") {
namespace swigpy {
template <> struct traits<std::deque<T > > {
typedef pointer_category category;
static const char* type_name() {
return "std::deque<" #T " >";
}
};
}
}
%typemap_traits_ptr(SWIG_CCode(DEQUE), std::deque<T >);
%std_deque_methods(deque);
%pysequence_methods(std::deque<T >);
};
template<class T > class deque<T*> {
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef T* value_type;
typedef value_type* pointer;
typedef const value_type* const_pointer;
typedef value_type reference;
typedef value_type const_reference;
%traits_swigtype(T);
%fragment(SWIG_Traits_frag(std::deque<T* >), "header",
fragment=SWIG_Traits_frag(T),
fragment="StdDequeTraits") {
namespace swigpy {
template <> struct traits<std::deque<T* > > {
typedef value_category category;
static const char* type_name() {
return "std::deque<" #T " * >";
}
};
}
}
%typemap_traits_ptr(SWIG_CCode(DEQUE), std::deque<T* >);
%std_deque_methods_val(std::deque<T* >);
%pysequence_methods_val(std::deque<T* >);
};
}
%define %std_deque_ptypen(...)
%std_extcomp(deque, __VA_ARGS__);
%std_definst(deque, __VA_ARGS__);
%enddef
#if defined(SWIG_STD_EXTEND_COMPARISON) || defined(SWIG_STD_DEFAULT_INSTANTIATION)
%apply_cpptypes(%std_deque_ptypen);
#endif
%include <std/std_deque.i>

View file

@ -1,79 +1 @@
%include <std_string.i>
%include <exception.i>
%{
#include <stdexcept>
%}
namespace std {
/* Mark all of them as exception classes */
%feature("exceptionclass") exception;
%feature("exceptionclass") bad_exception;
%feature("exceptionclass") logic_error;
%feature("exceptionclass") domain_error;
%feature("exceptionclass") invalid_argument;
%feature("exceptionclass") length_error;
%feature("exceptionclass") out_of_range;
%feature("exceptionclass") runtime_error;
%feature("exceptionclass") range_error;
%feature("exceptionclass") overflow_error;
%feature("exceptionclass") underflow_error;
}
namespace std {
struct exception
{
virtual ~exception() throw();
virtual const char* what() const throw();
};
struct bad_exception : exception
{
};
struct logic_error : exception
{
logic_error(const string& msg);
};
struct domain_error : logic_error
{
domain_error(const string& msg);
};
struct invalid_argument : logic_error
{
invalid_argument(const string& msg);
};
struct length_error : logic_error
{
length_error(const string& msg);
};
struct out_of_range : logic_error
{
out_of_range(const string& msg);
};
struct runtime_error : exception
{
runtime_error(const string& msg);
};
struct range_error : runtime_error
{
range_error(const string& msg);
};
struct overflow_error : runtime_error
{
overflow_error(const string& msg);
};
struct underflow_error : runtime_error
{
underflow_error(const string& msg);
};
}
%include <std/std_except.i>

Some files were not shown because too many files have changed in this diff Show more