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
50 changed files with 3502 additions and 3408 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>

View file

@ -1,251 +1,3 @@
%include <std_except.i>
%include <std_char_traits.i>
%{
#include <ios>
%}
#ifdef SWIGPYTHON
%rename(ios_base_in) std::ios_base::in;
#endif
namespace std {
template<typename _CharT, typename _Traits = char_traits<_CharT> >
class basic_streambuf;
template<typename _CharT, typename _Traits = char_traits<_CharT> >
class basic_istream;
template<typename _CharT, typename _Traits = char_traits<_CharT> >
class basic_ostream;
// 27.4.2 Class ios_base
typedef size_t streamsize;
class locale;
class ios_base
{
public:
#ifdef SWIG_NESTED_CLASSES
// 27.4.2.1.1 Class ios_base::failure
class failure : public exception
{
public:
explicit failure(const string& __str) throw();
};
#endif
// 27.4.2.1.2 Type ios_base::fmtflags
typedef int fmtflags;
// 27.4.2.1.2 Type fmtflags
static const fmtflags boolalpha ;
static const fmtflags dec ;
static const fmtflags fixed ;
static const fmtflags hex ;
static const fmtflags internal ;
static const fmtflags left ;
static const fmtflags oct ;
static const fmtflags right ;
static const fmtflags scientific ;
static const fmtflags showbase ;
static const fmtflags showpoint ;
static const fmtflags showpos ;
static const fmtflags skipws ;
static const fmtflags unitbuf ;
static const fmtflags uppercase ;
static const fmtflags adjustfield ;
static const fmtflags basefield ;
static const fmtflags floatfield ;
// 27.4.2.1.3 Type ios_base::iostate
typedef int iostate;
static const iostate badbit ;
static const iostate eofbit ;
static const iostate failbit ;
static const iostate goodbit ;
// 27.4.2.1.4 Type openmode
typedef int openmode;
static const openmode app ;
static const openmode ate ;
static const openmode binary ;
static const openmode in ;
static const openmode out ;
static const openmode trunc ;
// 27.4.2.1.5 Type seekdir
typedef int seekdir;
static const seekdir beg ;
static const seekdir cur ;
static const seekdir end ;
// Callbacks;
enum event
{
erase_event,
imbue_event,
copyfmt_event
};
typedef void (*event_callback) (event, ios_base&, int);
void
register_callback(event_callback __fn, int __index);
// Fmtflags state:
inline fmtflags
flags() const ;
inline fmtflags
flags(fmtflags __fmtfl);
inline fmtflags
setf(fmtflags __fmtfl);
inline fmtflags
setf(fmtflags __fmtfl, fmtflags __mask);
inline void
unsetf(fmtflags __mask) ;
inline streamsize
precision() const ;
inline streamsize
precision(streamsize __prec);
inline streamsize
width() const ;
inline streamsize
width(streamsize __wide);
static bool
sync_with_stdio(bool __sync = true);
// Locales:
locale
imbue(const locale& __loc);
inline locale
getloc() const { return _M_ios_locale; }
// Storage:
static int
xalloc() throw();
inline long&
iword(int __ix);
inline void*&
pword(int __ix);
// Destructor
~ios_base();
protected:
ios_base();
};
template<typename _CharT, typename _Traits >
class basic_ios : public ios_base
{
public:
// Types:
typedef _CharT char_type;
typedef typename _Traits::int_type int_type;
typedef typename _Traits::pos_type pos_type;
typedef typename _Traits::off_type off_type;
typedef _Traits traits_type;
public:
iostate
rdstate() const;
void
clear(iostate __state = goodbit);
void
setstate(iostate __state);
bool
good() const;
bool
eof() const;
bool
fail() const;
bool
bad() const;
iostate
exceptions() const;
void
exceptions(iostate __except);
// Constructor/destructor:
explicit
basic_ios(basic_streambuf<_CharT, _Traits>* __sb) : ios_base();
virtual
~basic_ios() ;
// Members:
basic_ostream<_CharT, _Traits>*
tie() const;
basic_ostream<_CharT, _Traits>*
tie(basic_ostream<_CharT, _Traits>* __tiestr);
basic_streambuf<_CharT, _Traits>*
rdbuf() const;
basic_streambuf<_CharT, _Traits>*
rdbuf(basic_streambuf<_CharT, _Traits>* __sb);
basic_ios&
copyfmt(const basic_ios& __rhs);
char_type
fill() const;
char_type
fill(char_type __ch);
// Locales:
locale
imbue(const locale& __loc);
char
narrow(char_type __c, char __dfault) const;
char_type
widen(char __c) const;
protected:
// 27.4.5.1 basic_ios constructors
basic_ios();
private:
ios_base(const ios_base&);
ios_base&
operator=(const ios_base&);
};
}
namespace std {
%template(ios) basic_ios<char, std::char_traits<char> >;
%template(wios) basic_ios<wchar_t, std::char_traits<wchar_t> >;
}
%include <std/std_ios.i>

View file

@ -1,334 +1,8 @@
%include <std_ios.i>
%include <std_string.i>
%include <std_wstring.i>
%{
#include <iostream>
%}
namespace std
{
// 27.6.2.1 Template class basic_ostream
template<typename _CharT, typename _Traits>
class basic_ostream : virtual public basic_ios<_CharT, _Traits>
{
public:
// Types (inherited from basic_ios (27.4.4)):
typedef _CharT char_type;
typedef typename _Traits::int_type int_type;
typedef typename _Traits::pos_type pos_type;
typedef typename _Traits::off_type off_type;
typedef _Traits traits_type;
// 27.6.2.2 Constructor/destructor:
explicit
basic_ostream(basic_streambuf<_CharT, _Traits>* __sb);
virtual
~basic_ostream();
// 27.6.2.5 Formatted output:
// 27.6.2.5.3 basic_ostream::operator<<
basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<_CharT, _Traits>& (*__pf)(basic_ostream<_CharT, _Traits>&));
basic_ostream<_CharT, _Traits>&
operator<<(basic_ios<_CharT, _Traits>& (*__pf)(basic_ios<_CharT, _Traits>&));
basic_ostream<_CharT, _Traits>&
operator<<(ios_base& (*__pf) (ios_base&));
// 27.6.2.5.2 Arithmetic Inserters
basic_ostream<_CharT, _Traits>&
operator<<(long __n);
basic_ostream<_CharT, _Traits>&
operator<<(unsigned long __n);
basic_ostream<_CharT, _Traits>&
operator<<(bool __n);
basic_ostream<_CharT, _Traits>&
operator<<(short __n);
basic_ostream<_CharT, _Traits>&
operator<<(unsigned short __n);
basic_ostream<_CharT, _Traits>&
operator<<(int __n);
basic_ostream<_CharT, _Traits>&
operator<<(unsigned int __n);
basic_ostream<_CharT, _Traits>&
operator<<(long long __n);
basic_ostream<_CharT, _Traits>&
operator<<(unsigned long long __n);
basic_ostream<_CharT, _Traits>&
operator<<(double __f);
basic_ostream<_CharT, _Traits>&
operator<<(float __f);
basic_ostream<_CharT, _Traits>&
operator<<(long double __f);
basic_ostream<_CharT, _Traits>&
operator<<(const void* __p);
basic_ostream<_CharT, _Traits>&
operator<<(basic_streambuf<_CharT, _Traits>* __sb);
// Unformatted output:
basic_ostream<_CharT, _Traits>&
put(char_type __c);
basic_ostream<_CharT, _Traits>&
write(const char_type* __s, streamsize __n);
basic_ostream<_CharT, _Traits>&
flush();
// Seeks:
pos_type
tellp();
basic_ostream<_CharT, _Traits>&
seekp(pos_type);
basic_ostream<_CharT, _Traits>&
seekp(off_type, ios_base::seekdir);
%extend {
std::basic_ostream<_CharT, _Traits>&
operator<<(const std::basic_string<_CharT>& s)
{
*self << s;
return *self;
}
}
};
// 27.6.1.1 Template class basic_istream
template<typename _CharT, typename _Traits>
class basic_istream : virtual public basic_ios<_CharT, _Traits>
{
public:
// Types (inherited from basic_ios (27.4.4)):
typedef _CharT char_type;
typedef typename _Traits::int_type int_type;
typedef typename _Traits::pos_type pos_type;
typedef typename _Traits::off_type off_type;
typedef _Traits traits_type;
public:
// 27.6.1.1.1 Constructor/destructor:
explicit
basic_istream(basic_streambuf<_CharT, _Traits>* __sb);
virtual
~basic_istream();
// 27.6.1.2.2 Arithmetic Extractors
basic_istream<_CharT, _Traits>&
operator>>(bool& __n);
basic_istream<_CharT, _Traits>&
operator>>(short& __n);
basic_istream<_CharT, _Traits>&
operator>>(unsigned short& __n);
basic_istream<_CharT, _Traits>&
operator>>(int& __n);
basic_istream<_CharT, _Traits>&
operator>>(unsigned int& __n);
basic_istream<_CharT, _Traits>&
operator>>(long& __n);
basic_istream<_CharT, _Traits>&
operator>>(unsigned long& __n);
basic_istream<_CharT, _Traits>&
operator>>(long long& __n);
basic_istream<_CharT, _Traits>&
operator>>(unsigned long long& __n);
basic_istream<_CharT, _Traits>&
operator>>(float& __f);
basic_istream<_CharT, _Traits>&
operator>>(double& __f);
basic_istream<_CharT, _Traits>&
operator>>(long double& __f);
basic_istream<_CharT, _Traits>&
operator>>(void*& __p);
basic_istream<_CharT, _Traits>&
operator>>(basic_streambuf<_CharT, _Traits>* __sb);
// 27.6.1.3 Unformatted input:
inline streamsize
gcount(void) const;
int_type
get(void);
basic_istream<_CharT, _Traits>&
get(char_type& __c);
basic_istream<_CharT, _Traits>&
get(char_type* __s, streamsize __n, char_type __delim);
inline basic_istream<_CharT, _Traits>&
get(char_type* __s, streamsize __n);
basic_istream<_CharT, _Traits>&
get(basic_streambuf<_CharT, _Traits>& __sb, char_type __delim);
inline basic_istream<_CharT, _Traits>&
get(basic_streambuf<_CharT, _Traits>& __sb);
basic_istream<_CharT, _Traits>&
getline(char_type* __s, streamsize __n, char_type __delim);
inline basic_istream<_CharT, _Traits>&
getline(char_type* __s, streamsize __n);
basic_istream<_CharT, _Traits>&
ignore(streamsize __n = 1, int_type __delim = _Traits::eof());
int_type
peek(void);
basic_istream<_CharT, _Traits>&
read(char_type* __s, streamsize __n);
streamsize
readsome(char_type* __s, streamsize __n);
basic_istream<_CharT, _Traits>&
putback(char_type __c);
basic_istream<_CharT, _Traits>&
unget(void);
int
sync(void);
pos_type
tellg(void);
basic_istream<_CharT, _Traits>&
seekg(pos_type);
basic_istream<_CharT, _Traits>&
seekg(off_type, ios_base::seekdir);
};
// 27.6.1.5 Template class basic_iostream
template<typename _CharT, typename _Traits>
class basic_iostream
: public basic_istream<_CharT, _Traits>,
public basic_ostream<_CharT, _Traits>
{
public:
typedef _CharT char_type;
typedef typename _Traits::int_type int_type;
typedef typename _Traits::pos_type pos_type;
typedef typename _Traits::off_type off_type;
typedef _Traits traits_type;
explicit
basic_iostream(basic_streambuf<_CharT, _Traits>* __sb);
virtual
~basic_iostream();
};
%pythoncallback(1) endl;
%pythoncallback(1) ends;
%pythoncallback(1) flush;
}
namespace std {
typedef basic_ostream<char, std::char_traits<char> > ostream ;
typedef basic_istream<char, std::char_traits<char> > istream;
typedef basic_iostream<char, std::char_traits<char> > iostream;
typedef basic_ostream<wchar_t, std::char_traits<wchar_t> > wostream;
typedef basic_istream<wchar_t, std::char_traits<wchar_t> > wistream;
typedef basic_iostream<wchar_t, std::char_traits<wchar_t> > wiostream;
}
namespace std {
%template(ostream) basic_ostream<char, std::char_traits<char> >;
%template(istream) basic_istream<char, std::char_traits<char> >;
%template(iostream) basic_iostream<char, std::char_traits<char> >;
%template(wostream) basic_ostream<wchar_t, std::char_traits<wchar_t> >;
%template(wistream) basic_istream<wchar_t, std::char_traits<wchar_t> >;
%template(wiostream) basic_iostream<wchar_t, std::char_traits<wchar_t> >;
}
namespace std
{
%feature("immutable") cin;
%feature("immutable") cout;
%feature("immutable") cerr;
%feature("immutable") clog;
%feature("immutable") wcin;
%feature("immutable") wcout;
%feature("immutable") wcerr;
%feature("immutable") wclog;
}
namespace std
{
extern std::istream cin;
extern std::ostream cout;
extern std::ostream cerr;
extern std::ostream clog;
extern std::wistream wcin;
extern std::wostream wcout;
extern std::wostream wcerr;
extern std::wostream wclog;
template<typename _CharT, typename _Traits>
std::basic_ostream<_CharT, _Traits>&
endl(std::basic_ostream<_CharT, _Traits>&);
template<typename _CharT, typename _Traits>
std::basic_ostream<_CharT, _Traits>&
ends(std::basic_ostream<_CharT, _Traits>&);
template<typename _CharT, typename _Traits>
std::basic_ostream<_CharT, _Traits>&
flush(std::basic_ostream<_CharT, _Traits>&);
%pythoncallback(1);
%template(endl) endl<char, std::char_traits<char> >;
%template(ends) ends<char, std::char_traits<char> >;
%template(flush) flush<char, std::char_traits<char> >;
%template(wendl) endl<wchar_t, std::char_traits<wchar_t> >;
%template(wends) ends<wchar_t, std::char_traits<wchar_t> >;
%template(wflush) flush<wchar_t, std::char_traits<wchar_t> >;
%pythoncallback(0);
}
%include <std/std_iostream.i>

View file

@ -1,68 +1,10 @@
//
// std::list
// Python implementation
%include <std_container.i>
// List
%define %std_list_methods(list)
%std_sequence_methods(list)
void pop_front();
void push_front(const value_type& x);
void reverse();
%enddef
%define %std_list_methods_val(list)
%std_sequence_methods_val(list)
void pop_front();
void push_front(value_type x);
void remove(value_type x);
void unique();
void reverse();
void sort();
void merge(list& x);
%enddef
// ------------------------------------------------------------------------
// std::list
//
// The aim of all that follows would be to integrate std::list 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::list<T>), f(const std::list<T>&):
// the parameter being read-only, either a Python sequence or a
// previously wrapped std::list<T> can be passed.
// -- f(std::list<T>&), f(std::list<T>*):
// the parameter may be modified; therefore, only a wrapped std::list
// can be passed.
// -- std::list<T> f(), const std::list<T>& f():
// the list is returned by copy; therefore, a Python sequence of T:s
// is returned which is most easily used in other Python functions
// -- std::list<T>& f(), std::list<T>* f():
// the list is returned by reference; therefore, a wrapped std::list
// is returned
// -- const std::list<T>* f(), f(const std::list<T>*):
// for consistency, they expect and return a plain list pointer.
// ------------------------------------------------------------------------
%{
#include <list>
%}
/*
Lists
*/
%fragment("StdListTraits","header",fragment="StdSequenceTraits")
%{
namespace swigpy {
namespace swig {
template <class T >
struct traits_asptr<std::list<T> > {
static int asptr(PyObject *obj, std::list<T> **lis) {
@ -79,90 +21,8 @@
}
%}
// exported classes
#define %swig_list_methods(Type...) %swig_sequence_methods(Type)
#define %swig_list_methods_val(Type...) %swig_sequence_methods_val(Type);
namespace std {
%include <std/std_list.i>
template<class T > class list {
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::list<T >), "header",
fragment=SWIG_Traits_frag(T),
fragment="StdListTraits") {
namespace swigpy {
template <> struct traits<std::list<T > > {
typedef pointer_category category;
static const char* type_name() {
return "std::list<" #T " >";
}
};
}
}
%typemap_traits_ptr(SWIG_CCode(LIST), std::list<T >);
%std_list_methods(list);
%pysequence_methods(std::list<T >);
};
template<class T > class list<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::list<T* >), "header",
fragment=SWIG_Traits_frag(T),
fragment="StdListTraits") {
namespace swigpy {
template <> struct traits<std::list<T* > > {
typedef value_category category;
static const char* type_name() {
return "std::list<" #T " * >";
}
};
}
}
%typemap_traits_ptr(SWIG_CCode(LIST), std::list<T* >);
%std_list_methods_val(list);
%pysequence_methods_val(std::list<T* >);
};
}
%define %std_extequal_list(...)
%extend std::list<__VA_ARGS__ > {
void remove(const value_type& x) { self->remove(x); }
void merge(std::list<__VA_ARGS__ >& x){ self->merge(x); }
void unique() { self->unique(); }
void sort() { self->sort(); }
}
%enddef
%define %std_list_ptypen(...)
%std_extcomp(list, __VA_ARGS__);
%std_definst(list, __VA_ARGS__);
%evalif(SWIG_EqualType(__VA_ARGS__),
SWIG_arg(%std_extequal_list(__VA_ARGS__)));
%enddef
#if defined(SWIG_STD_EXTEND_COMPARISON) || defined(SWIG_STD_DEFAULT_INSTANTIATION)
%apply_cpptypes(%std_list_ptypen);
#endif

View file

@ -1,89 +1,10 @@
//
// std::map
// Python implementation
%include <std_pair.i>
%include <std_container.i>
%define %std_map_methods_common(map)
%std_container_methods(SWIG_arg(map));
size_type erase(const key_type& x);
size_type count(const key_type& x) const;
#ifdef SWIG_EXPORT_ITERATOR_METHODS
iterator insert(iterator position, const value_type& x);
void erase(iterator position);
void erase(iterator first, iterator last);
iterator find(const key_type& x);
const_iterator find(const key_type& x) const;
iterator lower_bound(const key_type& x);
const_iterator lower_bound(const key_type& x) const;
iterator upper_bound(const key_type& x);
const_iterator upper_bound(const key_type& x) const;
#endif
%enddef
%define %std_map_methods(...)
%std_map_methods_common(SWIG_arg(__VA_ARGS__));
#ifdef SWIG_EXPORT_ITERATOR_METHODS
iterator insert(const value_type& x);
#endif
%enddef
// **** Note ****
//
// If you are going to use a map, you need to instantiate both the
// map and the pair class:
//
// %template(pair_ii) std::pair<int, int>;
// %template(map_ii) std::map<int, int>;
//
// or
//
// %template() std::pair<int, int>;
// %template(map_ii) std::map<int, int>;
//
// **** Note ****
// ------------------------------------------------------------------------
// std::map
//
// The aim of all that follows would be to integrate std::map with
// Python as much as possible, namely, to allow the user to pass and
// be returned Python tuples or maps.
// const declarations are used to guess the intent of the function being
// exported; therefore, the following rationale is applied:
//
// -- f(std::map<T>), f(const std::map<T>&):
// the parameter being read-only, either a Python sequence or a
// previously wrapped std::map<T> can be passed.
// -- f(std::map<T>&), f(std::map<T>*):
// the parameter may be modified; therefore, only a wrapped std::map
// can be passed.
// -- std::map<T> f(), const std::map<T>& f():
// the map is returned by copy; therefore, a Python sequence of T:s
// is returned which is most easily used in other Python functions
// -- std::map<T>& f(), std::map<T>* f():
// the map is returned by reference; therefore, a wrapped std::map
// is returned
// -- const std::map<T>* f(), f(const std::map<T>*):
// for consistency, they expect and return a plain map pointer.
// ------------------------------------------------------------------------
%{
#include <map>
#include <algorithm>
#include <stdexcept>
%}
// exported class
/*
Maps
*/
%fragment("StdMapTraits","header",fragment="StdSequenceTraits")
{
namespace swigpy {
namespace swig {
template <class PySeq, class K, class T >
inline void
assign(const PySeq& pyseq, std::map<K,T > *map) {
@ -128,8 +49,8 @@
PyObject *obj = PyDict_New();
for (const_iterator i= map.begin(); i!= map.end(); ++i) {
PyDict_SetItem(obj,
swigpy::from(i->first),
swigpy::from(i->second));
swig::from(i->first),
swig::from(i->second));
}
return obj;
}
@ -137,50 +58,115 @@
}
}
namespace std {
%define %swig_map_methods(Map...)
%swig_container_methods(Map)
template<class K, class T> class map {
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef K key_type;
typedef T mapped_type;
typedef std::pair<const K, 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(K);
%traits_swigtype(T);
%fragment(SWIG_Traits_frag(std::map<K, T >), "header",
fragment=SWIG_Traits_frag(std::pair<K, T >),
fragment="StdMapTraits") {
namespace swigpy {
template <> struct traits<std::map<K, T > > {
typedef pointer_category category;
static const char* type_name() {
return "std::map<" #K "," #T " >";
}
};
%extend {
mapped_type __getitem__(const key_type& key) const {
Map::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(Map::value_type(key,x));
}
void __delitem__(const key_type& key) {
Map::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 {
Map::const_iterator i = self->find(key);
return i != self->end();
}
PyObject* keys() {
Map::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);
Map::const_iterator i = self->begin();
for (int j = 0; j < pysize; ++i, ++j) {
PyList_SetItem(keyList, j, swig::from(i->first));
}
return keyList;
}
PyObject* values() {
Map::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);
Map::const_iterator i = self->begin();
for (int j = 0; j < pysize; ++i, ++j) {
PyTuple_SetItem(valList, j, swig::from(i->second));
}
return valList;
}
PyObject* items() {
Map::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);
Map::const_iterator i = self->begin();
for (int j = 0; j < pysize; ++i, ++j) {
PyTuple_SetItem(itemList, j, swig::from(*i));
}
return itemList;
}
// Python 2.2 methods
bool __contains__(const key_type& key) {
return self->find(key) != self->end();
}
%typemap_traits_ptr(SWIG_CCode(MAP), std::map<K, T >);
%std_map_methods(map);
%pydict_methods(SWIG_arg(std::map<K, T >));
};
}
%define %std_map_ptypen(...)
%std_extcomp_2(map, __VA_ARGS__);
%std_definst_2(map, __VA_ARGS__);
PyObject* __iter__() {
Map::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);
Map::const_iterator i = self->begin();
for (int j = 0; j < pysize; ++i, ++j) {
PyTuple_SetItem(keyTuple, j, swig::from(i->first));
}
%#if PY_VERSION_HEX >= 0x02020000
PyObject* iter = PyObject_GetIter(keyTuple);
Py_DECREF(keyTuple);
return iter;
%#else
return keyTuple;
%#endif
}
}
%enddef
#if defined(SWIG_STD_EXTEND_COMPARISON) || defined(SWIG_STD_DEFAULT_INSTANTIATION)
%apply_cpptypes_2(%std_map_ptypen);
#endif
%include <std/std_map.i>

View file

@ -1,51 +1,11 @@
//
// std::map
// Python implementation
/*
Multimaps
*/
%include <std_map.i>
%define %std_multimap_methods(...)
%std_map_methods_common(SWIG_arg(__VA_ARGS__));
#ifdef SWIG_EXPORT_ITERATOR_METHODS
pair<iterator,bool> insert(const value_type& x);
pair<iterator,iterator> equal_range(const key_type& x);
pair<const_iterator,const_iterator> equal_range(const key_type& x) const;
#endif
%enddef
// ------------------------------------------------------------------------
// std::multimap
//
// The aim of all that follows would be to integrate std::multimap with
// Python as much as possible, namely, to allow the user to pass and
// be returned Python tuples or maps.
// const declarations are used to guess the intent of the function being
// exported; therefore, the following rationale is applied:
//
// -- f(std::multimap<T>), f(const std::multimap<T>&):
// the parameter being read-only, either a Python sequence or a
// previously wrapped std::multimap<T> can be passed.
// -- f(std::multimap<T>&), f(std::multimap<T>*):
// the parameter may be modified; therefore, only a wrapped std::multimap
// can be passed.
// -- std::multimap<T> f(), const std::multimap<T>& f():
// the map is returned by copy; therefore, a Python sequence of T:s
// is returned which is most easily used in other Python functions
// -- std::multimap<T>& f(), std::multimap<T>* f():
// the map is returned by reference; therefore, a wrapped std::multimap
// is returned
// -- const std::multimap<T>* f(), f(const std::multimap<T>*):
// for consistency, they expect and return a plain map pointer.
// ------------------------------------------------------------------------
// exported class
%fragment("StdMultimapTraits","header",fragment="StdSequenceTraits")
{
namespace swigpy {
namespace swig {
template <class PySeq, class K, class T >
void assign(const PySeq& pyseq, std::multimap<K,T > *multimap) {
typedef typename std::map<K,T>::value_type value_type;
@ -88,8 +48,8 @@
PyObject *obj = PyDict_New();
for (const_iterator i= multimap.begin(); i!= multimap.end(); ++i) {
PyDict_SetItem(obj,
swigpy::from(i->first),
swigpy::from(i->second));
swig::from(i->first),
swig::from(i->second));
}
return obj;
}
@ -97,49 +57,7 @@
}
}
namespace std {
template<class K, class T> class multimap {
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef K key_type;
typedef T mapped_type;
typedef std::pair<const K, T> value_type;
#define %swig_multimap_methods(Type...) %swig_map_methods(Type)
typedef value_type* pointer;
typedef const value_type* const_pointer;
typedef value_type& reference;
typedef const value_type& const_reference;
%include <std/std_multimap.i>
%traits_swigtype(K);
%traits_swigtype(T);
%fragment(SWIG_Traits_frag(std::multimap<K, T >), "header",
fragment=SWIG_Traits_frag(std::pair<K, T >),
fragment="StdMultimapTraits") {
namespace swigpy {
template <> struct traits<std::multimap<K, T > > {
typedef value_category category;
static const char* type_name() {
return "std::multimap<" #K "," #T " >";
}
};
}
}
%typemap_traits_ptr(SWIG_CCode(MULTIMAP), std::multimap<K, T >);
%std_multimap_methods(multimap);
%pydict_methods(SWIG_arg(std::multimap<K, T >));
};
}
%define %std_multimap_ptypen(...)
%std_extcomp_2(multimap, __VA_ARGS__);
%std_definst_2(multimap, __VA_ARGS__);
%enddef
#if defined(SWIG_STD_EXTEND_COMPARISON) || defined(SWIG_STD_DEFAULT_INSTANTIATION)
%apply_cpptypes_2(%std_multimap_ptypen);
#endif

View file

@ -1,47 +1,12 @@
//
// std::set
// Python implementation
/*
Multisets
*/
%include <std_set.i>
// Multiset
%define %std_multiset_methods(multiset)
%std_set_methods_common(multiset);
#ifdef SWIG_EXPORT_ITERATOR_METHODS
pair<iterator,bool> insert(iterator pos);
#endif
%enddef
// ------------------------------------------------------------------------
// std::multiset
//
// The aim of all that follows would be to integrate std::multiset with
// Python as much as possible, namely, to allow the user to pass and
// be returned Python tuples or sets.
// const declarations are used to guess the intent of the function being
// exported; therefore, the following rationale is applied:
//
// -- f(std::multiset<T>), f(const std::multiset<T>&):
// the parameter being read-only, either a Python sequence or a
// previously wrapped std::multiset<T> can be passed.
// -- f(std::multiset<T>&), f(std::multiset<T>*):
// the parameter may be modified; therefore, only a wrapped std::multiset
// can be passed.
// -- std::multiset<T> f(), const std::multiset<T>& f():
// the set is returned by copy; therefore, a Python sequence of T:s
// is returned which is most easily used in other Python functions
// -- std::multiset<T>& f(), std::multiset<T>* f():
// the set is returned by reference; therefore, a wrapped std::multiset
// is returned
// -- const std::multiset<T>* f(), f(const std::multiset<T>*):
// for consistency, they expect and return a plain set pointer.
// ------------------------------------------------------------------------
%fragment("StdMultisetTraits","header",fragment="StdSequenceTraits")
%{
namespace swigpy {
namespace swig {
template <class PySeq, class T>
void assign(const PySeq& pyseq, std::multiset<T>* seq) {
#ifdef SWIG_STD_NOINSERT_TEMPLATE_STL
@ -71,51 +36,8 @@
}
%}
// exported classes
#define %swig_multiset_methods(Set...) %swig_set_methods(Set)
namespace std {
//multiset
template<class T > class multiset {
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef T value_type;
typedef T key_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::multiset<T >), "header",
fragment=SWIG_Traits_frag(T),
fragment="StdMultisetTraits") {
namespace swigpy {
template <> struct traits<std::multiset<T > > {
typedef pointer_category category;
static const char* type_name() {
return "std::multiset<" #T " >";
}
};
}
}
%typemap_traits_ptr(SWIG_CCode(MULTISET), std::multiset<T >);
%std_multiset_methods(multiset);
%pycontainer_methods(std::multiset<T >);
};
}
%define %std_multiset_ptypen(...)
%std_extcomp(multiset, __VA_ARGS__);
%std_definst(multiset, __VA_ARGS__);
%enddef
#if defined(SWIG_STD_EXTEND_COMPARISON) || defined(SWIG_STD_DEFAULT_INSTANTIATION)
%apply_cpptypes(%std_multiset_ptypen);
#endif
%include <std/std_multiset.i>

View file

@ -1,11 +1,57 @@
%include <std_common.i>
/*
Pairs
*/
%fragment("StdPairTraits","header",
fragment="StdTraits",fragment="PyObject_var") {
namespace swig {
template <class T, class U >
struct traits_asptr<std::pair<T,U> > {
static int asptr(PyObject *obj, std::pair<T,U> **val) {
typedef std::pair<T,U> value_type;
if (PySequence_Check(obj) && (PySequence_Size(obj) == 2)) {
swig::PyObject_var first = PySequence_GetItem(obj,0);
swig::PyObject_var second = PySequence_GetItem(obj,1);
T *pfirst = 0;
U *psecond = 0;
if (val) {
*val = new std::pair<T,U>;
pfirst = &((*val)->first);
psecond = &((*val)->second);
}
if (swig::asval(first,pfirst) && swig::asval(second,psecond)) {
return SWIG_NEWOBJ;
} else {
delete *val;
}
} else {
value_type *p;
if (SWIG_ConvertPtr(obj,(void**)&p,
swig::type_info<value_type>(),0) != -1) {
if (val) *val = p;
return SWIG_OLDOBJ;
}
}
if (val) {
PyErr_Format(PyExc_TypeError, "a %s is expected",
swig::type_name<value_type>());
}
return 0;
}
};
%{
#include <utility>
%}
template <class T, class U >
struct traits_from<std::pair<T,U> > {
static PyObject *from(const std::pair<T,U>& val) {
PyObject* obj = PyTuple_New(2);
PyTuple_SetItem(obj,0,swig::from(val.first));
PyTuple_SetItem(obj,1,swig::from(val.second));
return obj;
}
};
}
}
%define %pypair_methods(pair)
%define %swig_pair_methods(pair...)
%extend {
%pythoncode {
def __len__(self):
@ -26,200 +72,6 @@ def __repr__(self):
}
%enddef
%fragment("StdPairTraits","header",
fragment="StdTraits",fragment="PyObject_var") {
namespace swigpy {
template <class T, class U >
struct traits_asptr<std::pair<T,U> > {
static int asptr(PyObject *obj, std::pair<T,U> **val) {
typedef std::pair<T,U> value_type;
if (PySequence_Check(obj) && (PySequence_Size(obj) == 2)) {
swigpy::PyObject_var first = PySequence_GetItem(obj,0);
swigpy::PyObject_var second = PySequence_GetItem(obj,1);
T *pfirst = 0;
U *psecond = 0;
if (val) {
*val = new std::pair<T,U>;
pfirst = &((*val)->first);
psecond = &((*val)->second);
}
if (swigpy::asval(first,pfirst) && swigpy::asval(second,psecond)) {
return SWIG_NEWOBJ;
} else {
delete *val;
}
} else {
value_type *p;
if (SWIG_ConvertPtr(obj,(void**)&p,
swigpy::type_info<value_type>(),0) != -1) {
if (val) *val = p;
return SWIG_OLDOBJ;
}
}
if (val) {
PyErr_Format(PyExc_TypeError, "a %s is expected",
swigpy::type_name<value_type>());
}
return 0;
}
};
template <class T, class U >
struct traits_from<std::pair<T,U> > {
static PyObject *from(const std::pair<T,U>& val) {
PyObject* obj = PyTuple_New(2);
PyTuple_SetItem(obj,0,swigpy::from(val.first));
PyTuple_SetItem(obj,1,swigpy::from(val.second));
return obj;
}
};
}
}
%include <std/std_pair.i>
namespace std {
template <class T, class U > struct pair {
typedef T fisrt_type;
typedef U second_type;
%traits_swigtype(T);
%traits_swigtype(U);
%fragment(SWIG_Traits_frag(std::pair<T,U >), "header",
fragment=SWIG_Traits_frag(T),
fragment=SWIG_Traits_frag(U),
fragment="StdPairTraits") {
namespace swigpy {
template <> struct traits<std::pair<T,U > > {
typedef pointer_category category;
static const char* type_name() {
return "std::pair<" #T "," #U " >";
}
};
}
}
%typemap_traits_ptr(SWIG_CCode(PAIR), std::pair<T,U >);
pair();
pair(T __a, U __b);
pair(const pair& __p);
T first;
U second;
%pypair_methods(pair)
};
// ***
// The following specializations should dissapear or get
// simplified when a 'const SWIGTYPE*&' can be defined
// ***
template <class T, class U > struct pair<T, U*> {
typedef T fisrt_type;
typedef U* second_type;
%traits_swigtype(T);
%traits_swigtype(U);
%fragment(SWIG_Traits_frag(std::pair<T,U* >), "header",
fragment=SWIG_Traits_frag(T),
fragment=SWIG_Traits_frag(U),
fragment="StdPairTraits") {
namespace swigpy {
template <> struct traits<std::pair<T,U* > > {
typedef pointer_category category;
static const char* type_name() {
return "std::pair<" #T "," #U " * >";
}
};
}
}
%typemap_traits_ptr(SWIG_CCode(PAIR), std::pair<T,U* >);
pair();
pair(T __a, U* __b);
pair(const pair& __p);
T first;
U* second;
%pypair_methods(pair)
};
template <class T, class U > struct pair<T*, U> {
typedef T* fisrt_type;
typedef U second_type;
%traits_swigtype(T);
%traits_swigtype(U);
%fragment(SWIG_Traits_frag(std::pair<T*,U >), "header",
fragment=SWIG_Traits_frag(T),
fragment=SWIG_Traits_frag(U),
fragment="StdPairTraits") {
namespace swigpy {
template <> struct traits<std::pair<T*,U > > {
typedef pointer_category category;
static const char* type_name() {
return "std::pair<" #T " *," #U " >";
}
};
}
}
%typemap_traits_ptr(SWIG_CCode(PAIR), std::pair<T*,U >);
pair();
pair(T* __a, U __b);
pair(const pair& __p);
T* first;
U second;
%pypair_methods(pair)
};
template <class T, class U > struct pair<T*, U*> {
typedef T* fisrt_type;
typedef U* second_type;
%traits_swigtype(T);
%traits_swigtype(U);
%fragment(SWIG_Traits_frag(std::pair<T*,U* >), "header",
fragment=SWIG_Traits_frag(T),
fragment=SWIG_Traits_frag(U),
fragment="StdPairTraits") {
namespace swigpy {
template <> struct traits<std::pair<T*,U* > > {
typedef pointer_category category;
static const char* type_name() {
return "std::pair<" #T " *," #U " * >";
}
};
}
}
%typemap_traits(SWIG_CCode(PAIR), std::pair<T*,U* >);
pair();
pair(T* __a, U* __b);
pair(const pair& __p);
T* first;
U* second;
%pypair_methods(pair)
};
}
%define %std_pair_ptypen(...)
%std_extcomp_2(pair, __VA_ARGS__);
%std_definst_2(pair, __VA_ARGS__);
%enddef
#if defined(SWIG_STD_EXTEND_COMPARISON) || defined(SWIG_STD_DEFAULT_INSTANTIATION)
%apply_cpptypes_2(%std_pair_ptypen);
#endif

View file

@ -1,87 +1,10 @@
//
// std::set
// Python implementation
%include <std_container.i>
// Set
%define %std_set_methods_common(set)
%std_container_methods(set);
size_type erase(const key_type& x);
size_type count(const key_type& x) const;
#ifdef SWIG_EXPORT_ITERATOR_METHODS
iterator insert(iterator pos, const value_type& x);
void insert(iterator pos, size_type n, const value_type& x);
iterator erase(iterator pos);
iterator erase(iterator first, iterator last);
iterator find(const key_type& x) const;
iterator lower_bound(const key_type& x) const;
iterator upper_bound(const key_type& x) const;
std::pair<iterator,iterator> equal_range(const key_type& x);
iterator begin() const;
iterator end() const;
#endif
%enddef
%define %std_set_methods(set)
%std_set_methods_common(set);
#ifdef SWIG_EXPORT_ITERATOR_METHODS
pair<iterator,bool> insert(const value_type& __x);
iterator insert(iterator pos);
#endif
%enddef
%define %pyset_methods(set)
%pycontainer_methods(set);
%extend {
void append(value_type x) {
self->insert(x);
}
bool __contains__(value_type x) {
return self->find(x) != self->end();
}
};
%enddef
// ------------------------------------------------------------------------
// std::set
//
// The aim of all that follows would be to integrate std::set with
// Python as much as possible, namely, to allow the user to pass and
// be returned Python tuples or sets.
// const declarations are used to guess the intent of the function being
// exported; therefore, the following rationale is applied:
//
// -- f(std::set<T>), f(const std::set<T>&):
// the parameter being read-only, either a Python sequence or a
// previously wrapped std::set<T> can be passed.
// -- f(std::set<T>&), f(std::set<T>*):
// the parameter may be modified; therefore, only a wrapped std::set
// can be passed.
// -- std::set<T> f(), const std::set<T>& f():
// the set is returned by copy; therefore, a Python sequence of T:s
// is returned which is most easily used in other Python functions
// -- std::set<T>& f(), std::set<T>* f():
// the set is returned by reference; therefore, a wrapped std::set
// is returned
// -- const std::set<T>* f(), f(const std::set<T>*):
// for consistency, they expect and return a plain set pointer.
// ------------------------------------------------------------------------
%{
#include <set>
%}
/*
Sets
*/
%fragment("StdSetTraits","header",fragment="StdSequenceTraits")
%{
namespace swigpy {
namespace swig {
template <class PySeq, class T>
void assign(const PySeq& pyseq, std::set<T>* seq) {
#ifdef SWIG_STD_NOINSERT_TEMPLATE_STL
@ -111,49 +34,18 @@
}
%}
%define %swig_set_methods(set)
%swig_container_methods(set);
// exported classes
namespace std {
template<class T > class set {
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef T value_type;
typedef T key_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::set<T >), "header",
fragment=SWIG_Traits_frag(T),
fragment="StdSetTraits") {
namespace swigpy {
template <> struct traits<std::set<T > > {
typedef pointer_category category;
static const char* type_name() {
return "std::set<" #T " >";
}
};
}
}
%typemap_traits_ptr(SWIG_CCode(SET), std::set<T >);
%extend {
void append(value_type x) {
self->insert(x);
}
%std_set_methods(set);
%pyset_methods(std::set<T >);
};
}
%define %std_set_ptypen(...)
%std_extcomp(set, __VA_ARGS__);
%std_definst(set, __VA_ARGS__);
bool __contains__(value_type x) {
return self->find(x) != self->end();
}
};
%enddef
#if defined(SWIG_STD_EXTEND_COMPARISON) || defined(SWIG_STD_DEFAULT_INSTANTIATION)
%apply_cpptypes(%std_set_ptypen);
#endif
%include <std/std_set.i>

View file

@ -1,16 +1,7 @@
//
// SWIG typemaps for std::string
// Luigi Ballabio
// Apr 8, 2002
// std::string
//
// Python implementation
// ------------------------------------------------------------------------
// std::string is typemapped by value
// This can prevent exporting methods which return a string
// in order for the user to modify it.
// However, I think I'll wait until someone asks for it...
// ------------------------------------------------------------------------
%include <pystrings.swg>
%include <std_basic_string.i>

View file

@ -1,60 +1,10 @@
//
// std::vector
// Python implementation
/*
Vectors
*/
%include <std_container.i>
// Vector
%define %std_vector_methods(vector)
%std_sequence_methods(vector)
void reserve(size_type n);
size_type capacity() const;
%enddef
%define %std_vector_methods_val(vector)
%std_sequence_methods_val(vector)
void reserve(size_type n);
size_type capacity() const;
%enddef
// ------------------------------------------------------------------------
// std::vector
//
// The aim of all that follows would be to integrate std::vector 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::vector<T>), f(const std::vector<T>&):
// the parameter being read-only, either a Python sequence or a
// previously wrapped std::vector<T> can be passed.
// -- f(std::vector<T>&), f(std::vector<T>*):
// the parameter may be modified; therefore, only a wrapped std::vector
// can be passed.
// -- std::vector<T> f(), const std::vector<T>& f():
// the vector is returned by copy; therefore, a Python sequence of T:s
// is returned which is most easily used in other Python functions
// -- std::vector<T>& f(), std::vector<T>* f():
// the vector is returned by reference; therefore, a wrapped std::vector
// is returned
// -- const std::vector<T>* f(), f(const std::vector<T>*):
// for consistency, they expect and return a plain vector pointer.
// ------------------------------------------------------------------------
%{
#include <vector>
%}
%fragment("StdVectorTraits","header",fragment="StdSequenceTraits")
%{
namespace swigpy {
namespace swig {
template <class T>
struct traits_asptr<std::vector<T> > {
static int asptr(PyObject *obj, std::vector<T> **vec) {
@ -71,129 +21,7 @@
}
%}
// exported classes
#define %swig_vector_methods(Type...) %swig_sequence_methods(Type)
#define %swig_vector_methods_val(Type...) %swig_sequence_methods_val(Type);
#if !defined(SWIG_STD_MODERN_STL) || defined(SWIG_STD_NOMODERN_STL)
%ignore std::vector<bool>::flip();
#endif
namespace std {
template<class T > class vector {
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 T& reference;
typedef const T& const_reference;
%traits_swigtype(T);
%fragment(SWIG_Traits_frag(std::vector<T >), "header",
fragment=SWIG_Traits_frag(T),
fragment="StdVectorTraits") {
namespace swigpy {
template <> struct traits<std::vector<T > > {
typedef pointer_category category;
static const char* type_name() {
return "std::vector<" #T " >";
}
};
}
}
%typemap_traits_ptr(SWIG_CCode(VECTOR), std::vector<T >);
%std_vector_methods(vector);
%pysequence_methods(std::vector<T >);
};
// bool specialization
%extend vector<bool> {
void flip()
{
self->flip();
}
}
// ***
// This specialization should dissapear or get simplified when
// a 'const SWIGTYPE*&' can be defined
// ***
template<class T > class vector<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::vector<T* >), "header",
fragment=SWIG_Traits_frag(T),
fragment="StdVectorTraits") {
namespace swigpy {
template <> struct traits<std::vector<T* > > {
typedef value_category category;
static const char* type_name() {
return "std::vector<" #T " * >";
}
};
}
}
%typemap_traits_ptr(SWIG_CCode(VECTOR), std::vector<T* >);
%std_vector_methods_val(vector);
%pysequence_methods_val(std::vector<T* >);
};
// ***
// ***
template<class T > class vector<bool> {
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef bool value_type;
typedef value_type* pointer;
typedef const value_type* const_pointer;
typedef value_type reference;
typedef value_type const_reference;
%traits_swigtype(bool);
%fragment(SWIG_Traits_frag(std::vector<bool>), "header",
fragment=SWIG_Traits_frag(bool),
fragment="StdVectorTraits") {
namespace swigpy {
template <> struct traits<std::vector<bool> > {
typedef value_category category;
static const char* type_name() {
return "std::vector<bool>";
}
};
}
}
%typemap_traits_ptr(SWIG_CCode(VECTOR), std::vector<bool>);
%std_vector_methods_val(vector<bool>);
%pysequence_methods_val(std::vector<bool>);
};
}
%define %std_vector_ptypen(...)
%std_extcomp(vector, __VA_ARGS__);
%std_definst(vector, __VA_ARGS__);
%enddef
#if defined(SWIG_STD_EXTEND_COMPARISON) || defined(SWIG_STD_DEFAULT_INSTANTIATION)
%apply_cpptypes(%std_vector_ptypen);
#endif
%include <std/std_vector.i>

View file

@ -1,65 +1,10 @@
//
// std::vector<T,A>
// Python implementation
//
// First attemp to add allocators. Still, the plain version
// works much better. So, if tyou don't need allocators, use
// std_vector.i instead.
//
%include <std_container.i>
// Vector
%define %std_vector_methods(vector)
%std_sequence_methods(SWIG_arg(vector))
void reserve(size_type n);
size_type capacity() const;
%enddef
%define %std_vector_methods_val(vector)
%std_sequence_methods_val(SWIG_arg(vector))
void reserve(size_type n);
size_type capacity() const;
%enddef
// ------------------------------------------------------------------------
// std::vector
//
// The aim of all that follows would be to integrate std::vector 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::vector<T,A>), f(const std::vector<T,A>&):
// the parameter being read-only, either a Python sequence or a
// previously wrapped std::vector<T,A> can be passed.
// -- f(std::vector<T,A>&), f(std::vector<T,A>*):
// the parameter may be modified; therefore, only a wrapped std::vector
// can be passed.
// -- std::vector<T,A> f(), const std::vector<T,A>& f():
// the vector is returned by copy; therefore, a Python sequence of T:s
// is returned which is most easily used in other Python functions
// -- std::vector<T,A>& f(), std::vector<T,A>* f():
// the vector is returned by reference; therefore, a wrapped std::vector
// is returned
// -- const std::vector<T,A>* f(), f(const std::vector<T,A>*):
// for consistency, they expect and return a plain vector pointer.
// ------------------------------------------------------------------------
/*
Vectors + allocators
*/
%fragment("StdVectorATraits","header",fragment="StdSequenceTraits")
%{
#include <vector>
%}
%fragment("StdVectorTraits","header",fragment="StdSequenceTraits")
%{
namespace swigpy {
namespace swig {
template <class T, class A>
struct traits_asptr<std::vector<T,A> > {
typedef std::vector<T,A> vector_type;
@ -79,112 +24,8 @@
}
%}
// exported classes
namespace std {
#define %swig_vector_methods(Type...) %swig_sequence_methods(Type)
#define %swig_vector_methods_val(Type...) %swig_sequence_methods_val(Type);
template<class T, class A = std::allocator<T > >
class vector {
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 T& reference;
typedef const T& const_reference;
%traits_swigtype(T);
%fragment(SWIG_Traits_frag(std::vector<T,A >), "header",
fragment=SWIG_Traits_frag(T),
fragment="StdVectorTraits") {
namespace swigpy {
template <> struct traits<std::vector<T,A > > {
typedef pointer_category category;
static const char* type_name() {
return "std::vector<" #T "," #A " >";
}
};
}
}
%typemap_traits(SWIG_CCode(VECTOR), std::vector<T,A >);
%std_vector_methods(SWIG_arg(vector<T,A >));
%pysequence_methods(SWIG_arg(std::vector<T,A >));
};
// ***
// This pointer especialization should dissapears or get
// simplified when a 'const SWIGTYPE*&' can be be defined.
// ***
template<class T, class A = std::allocator<T*> >
class vector<T*,A> {
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::vector<T*,A >), "header",
fragment="StdVectorTraits") {
namespace swigpy {
template <> struct traits<std::vector<T*,A > > {
typedef value_category category;
static const char* type_name() {
return "std::vector<" #T " *,"#A" >";
}
};
}
}
%typemap_traits(SWIG_CCode(VECTOR), std::vector<T*,A >);
%std_vector_methods_val(vector);
%pysequence_methods_val(SWIG_arg(std::vector<T*,A >));
};
// bool specialization
%extend vector<bool,std::allocator<bool> > {
void flip()
{
self->flip();
}
}
}
#ifdef SWIG_STD_DEFAULT_INSTANTIATION
%define %std_vector_ptypen(...)
namespace std {
%template() vector<__VA_ARGS__, std::allocator<__VA_ARGS__ > >;
//
// These extra %apply are needed since swig doesn't try
// std::vector<int> and std::vector<int, std::allocator<int> > as
// the same type yet. When this get fixed, these %apply should be
// removed (and maybe we will be able to have an unique std_vector.i
// definition too).
//
#if 1
%apply vector<__VA_ARGS__, std::allocator<__VA_ARGS__ > > {
vector<__VA_ARGS__ >
}
%apply const vector<__VA_ARGS__, std::allocator<__VA_ARGS__ > >& {
const vector<__VA_ARGS__ >&
}
#endif
}
%enddef
%apply_cpptypes(%std_vector_ptypen);
#endif
%include <std/std_vectora.i>

View file

@ -1,4 +1,9 @@
%include <wchar.i>
//
// std::wstring
//
%include <pywstrings.swg>
%include <std_basic_string.i>
/* wide strings */