diff --git a/SWIG/Lib/python/README b/SWIG/Lib/python/README new file mode 100644 index 000000000..af092953b --- /dev/null +++ b/SWIG/Lib/python/README @@ -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 \ No newline at end of file diff --git a/SWIG/Lib/python/argcargv.i b/SWIG/Lib/python/argcargv.i index 36304ea04..a2fd0718e 100644 --- a/SWIG/Lib/python/argcargv.i +++ b/SWIG/Lib/python/argcargv.i @@ -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 diff --git a/SWIG/Lib/python/ccomplex.i b/SWIG/Lib/python/ccomplex.i index 49cbc76d5..721123d9b 100644 --- a/SWIG/Lib/python/ccomplex.i +++ b/SWIG/Lib/python/ccomplex.i @@ -10,32 +10,15 @@ #include %} -/* -*** 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); diff --git a/SWIG/Lib/python/implicit.i b/SWIG/Lib/python/implicit.i index eab268e8f..8ef687e31 100644 --- a/SWIG/Lib/python/implicit.i +++ b/SWIG/Lib/python/implicit.i @@ -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 { 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"; } diff --git a/SWIG/Lib/python/pyapi.swg b/SWIG/Lib/python/pyapi.swg index 6cade6ad3..a97100a0e 100644 --- a/SWIG/Lib/python/pyapi.swg +++ b/SWIG/Lib/python/pyapi.swg @@ -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(a) -#define SWIG_static_cast(a,Type) static_cast(a) -#define SWIG_reinterpret_cast(a,Type) reinterpret_cast(a) -#define SWIG_new_copy(ptr,Type) (new Type(*ptr)) -#define SWIG_numeric_cast(a,Type) static_cast(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 - diff --git a/SWIG/Lib/python/pycomplex.swg b/SWIG/Lib/python/pycomplex.swg index c484ea3bc..b99722403 100644 --- a/SWIG/Lib/python/pycomplex.swg +++ b/SWIG/Lib/python/pycomplex.swg @@ -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 diff --git a/SWIG/Lib/python/pycontainer.swg b/SWIG/Lib/python/pycontainer.swg index fea8b010d..60e0165f9 100644 --- a/SWIG/Lib/python/pycontainer.swg +++ b/SWIG/Lib/python/pycontainer.swg @@ -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 -namespace swigpy +namespace swig { template 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(item, true); + return swig::as(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(), item); + SWIG_type_error(swig::type_name(), item); } SWIG_append_errmsg(msg); throw; @@ -151,7 +151,7 @@ namespace swigpy PySequence_Ref& operator=(const T& v) { - PySequence_SetItem(_seq, _index, swigpy::from(v)); + PySequence_SetItem(_seq, _index, swig::from(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(item)) { + swig::PyObject_var item = PySequence_GetItem(_seq, i); + if (!swig::check(item)) { if (set_err) { char msg[1024]; sprintf(msg,"in sequence element %d", i); - SWIG_type_error(swigpy::type_name(), item); + SWIG_type_error(swig::type_name(), 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 + 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 + 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 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(),0) != -1) { + if (seq) *seq = p; + return 1; + } + } + if (seq) { + PyErr_Format(PyExc_TypeError, "a %s is expected", + swig::type_name()); + } + 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 + 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(*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 +%} diff --git a/SWIG/Lib/python/pymacros.swg b/SWIG/Lib/python/pymacros.swg index e4b38765c..8fcc50400 100644 --- a/SWIG/Lib/python/pymacros.swg +++ b/SWIG/Lib/python/pymacros.swg @@ -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(a) +#define SWIG_static_cast(a,Type...) static_cast(a) +#define SWIG_reinterpret_cast(a,Type...) reinterpret_cast(a) +#define SWIG_new_copy(ptr,Type...) (new Type(*ptr)) +#define SWIG_numeric_cast(a,Type...) static_cast(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 diff --git a/SWIG/Lib/python/pyrun.swg b/SWIG/Lib/python/pyrun.swg index 982be8d65..3da4cd810 100644 --- a/SWIG/Lib/python/pyrun.swg +++ b/SWIG/Lib/python/pyrun.swg @@ -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); diff --git a/SWIG/Lib/python/pystdcommon.swg b/SWIG/Lib/python/pystdcommon.swg new file mode 100644 index 000000000..f0b936746 --- /dev/null +++ b/SWIG/Lib/python/pystdcommon.swg @@ -0,0 +1,230 @@ +%include + +%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 struct traits_from_ptr { + static PyObject *from(Type *val, int owner = 0) { + return SWIG_NewPointerObj(val, type_info(), owner); + } + }; + + template struct traits_from { + static PyObject *from(const Type& val) { + return traits_from_ptr::from(new Type(val), 1); + } + }; + + template struct traits_from { + static PyObject *from(Type* val) { + return traits_from_ptr::from(val, 0); + } + }; + + template + inline PyObject *from(const Type& val) { + return traits_from::from(val); + } + + template + inline PyObject *from_ptr(Type* val, int owner) { + return traits_from_ptr::from(val, owner); + } + + /* + Traits that provides the asval/as/check method + */ + template + struct traits_asptr { + static int asptr(PyObject *obj, Type **val) { + Type *p; + int res = (SWIG_ConvertPtr(obj, (void**)&p, type_info(), 0) != -1) + ? SWIG_OLDOBJ : 0; + if (res) { + if (val) { + *val = p; + } + } else { + SWIG_type_error(type_name(), obj); + } + return res; + } + }; + + template + inline int asptr(PyObject *obj, Type **vptr) { + return traits_asptr::asptr(obj, vptr); + } + + template + struct traits_asval { + static bool asval(PyObject *obj, Type *val) { + if (val) { + Type *p = 0; + int res = traits_asptr::asptr(obj, &p); + if (res && p) { + typedef typename noconst_traits::noconst_type noconst_type; + *(const_cast(val)) = *p; + if (res == SWIG_NEWOBJ) delete p; + return true; + } else { + return false; + } + } else { + return traits_asptr::asptr(obj, (Type **)(0)); + } + } + }; + + template struct traits_asval { + static bool asval(PyObject *obj, Type **val) { + if (val) { + Type *p = 0; + int res = traits_asptr::asptr(obj, &p); + if (res) { + typedef typename noconst_traits::noconst_type noconst_type; + *(const_cast(val)) = p; + return true; + } else { + return false; + } + } else { + return traits_asptr::asptr(obj, (Type **)(0)); + } + } + }; + + template + inline bool asval(PyObject *obj, Type *val) { + return traits_asval::asval(obj, val); + } + + template + struct traits_as { + static Type as(PyObject *obj, bool throw_error) { + Type v; + if (!obj || !asval(obj, &v)) { + if (!PyErr_Occurred()) { + SWIG_type_error(swig::type_name(), obj); + } + if (throw_error) throw std::invalid_argument("bad type"); + } + return v; + } + }; + + template + struct traits_as { + static Type as(PyObject *obj, bool throw_error) { + Type *v = 0; + int res = (obj ? traits_asptr::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(), obj); + } + if (throw_error) throw std::invalid_argument("bad type"); + memset(v_def,0,sizeof(Type)); + return *v_def; + } + } + }; + + template + struct traits_as { + static Type* as(PyObject *obj, bool throw_error) { + Type *v = 0; + int res = (obj ? traits_asptr::asptr(obj, &v) : 0); + if (res) { + return v; + } else { + if (!PyErr_Occurred()) { + SWIG_type_error(swig::type_name(), obj); + } + if (throw_error) throw std::invalid_argument("bad type"); + return 0; + } + } + }; + + template + inline Type as(PyObject *obj, bool te = false) { + return traits_as::category>::as(obj, te); + } + + template + struct traits_check { + static bool check(PyObject *obj) { + return obj && asval(obj, (Type *)(0)); + } + }; + + template + struct traits_check { + static bool check(PyObject *obj) { + return obj && asptr(obj, (Type **)(0)); + } + }; + + template + inline bool check(PyObject *obj) { + return traits_check::category>::check(obj); + } +} +%} + +// +// Backward compatibility +// + +#ifdef SWIG_PYTHON_BACKWARD_COMP +%{ +#include + +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 + + diff --git a/SWIG/Lib/python/pystrings.swg b/SWIG/Lib/python/pystrings.swg index 514362298..24eebeacc 100644 --- a/SWIG/Lib/python/pystrings.swg +++ b/SWIG/Lib/python/pystrings.swg @@ -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 * diff --git a/SWIG/Lib/python/pyvaltypes.swg b/SWIG/Lib/python/pyvaltypes.swg index 42b3a25a9..dae39d569 100644 --- a/SWIG/Lib/python/pyvaltypes.swg +++ b/SWIG/Lib/python/pyvaltypes.swg @@ -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 diff --git a/SWIG/Lib/python/pyvoid.swg b/SWIG/Lib/python/pyvoid.swg index 194e5072f..639a74eaf 100644 --- a/SWIG/Lib/python/pyvoid.swg +++ b/SWIG/Lib/python/pyvoid.swg @@ -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 */ diff --git a/SWIG/Lib/python/pywstrings.swg b/SWIG/Lib/python/pywstrings.swg index c62e522e9..6875d59eb 100644 --- a/SWIG/Lib/python/pywstrings.swg +++ b/SWIG/Lib/python/pywstrings.swg @@ -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 diff --git a/SWIG/Lib/python/std_basic_string.i b/SWIG/Lib/python/std_basic_string.i index 97e4e6fc8..d2d74c5b9 100644 --- a/SWIG/Lib/python/std_basic_string.i +++ b/SWIG/Lib/python/std_basic_string.i @@ -1,251 +1,4 @@ -%include -%include -%include - -%{ -#include -%} - -namespace std { - template - 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 +#define %swig_basic_string(Type...) %swig_sequence_methods_val(Type) +%include diff --git a/SWIG/Lib/python/std_char_traits.i b/SWIG/Lib/python/std_char_traits.i index 920fee50b..bf4e6c47d 100644 --- a/SWIG/Lib/python/std_char_traits.i +++ b/SWIG/Lib/python/std_char_traits.i @@ -1,132 +1 @@ -%include -%include - -namespace std -{ - - /// 21.1.2 Basis for explicit _Traits specialization - /// NB: That for any given actual character type this definition is - /// probably wrong. - template - struct char_traits - { - }; - - - /// 21.1.4 char_traits specializations - template<> - struct char_traits { - 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 - { - 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; -%template() char_traits; -#else -%template(char_traits_c) char_traits; -%template(char_traits_w) char_traits; -#endif -} +%include diff --git a/SWIG/Lib/python/std_common.i b/SWIG/Lib/python/std_common.i index 517303065..c80f7bba6 100644 --- a/SWIG/Lib/python/std_common.i +++ b/SWIG/Lib/python/std_common.i @@ -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 +%include -// 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, std::vector, etc) -// for all the primitive C++ types (int, double, etc). -// -// Note that this is equivalent to do something similar to -// -// %template() std::vector; -// -// but for all the std and basic C++ types, ie, no wrapping is -// generated for std::vector, 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 -%{ -#include -#include -%} - - -%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 struct traits { }; - - template - inline const char* type_name() { - return traits::type_name(); - } - - template - 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()); - return info; - } - }; - - template - inline swig_type_info *type_info() { - return traits_info::type_info(); - } - - /* - Partial specialization for pointers - */ - template struct traits { - 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()); - return name.c_str(); - } - }; - - /* - Traits that provides the from method - */ - template struct traits_from_ptr { - static PyObject *from(Type *val, int owner = 0) { - return SWIG_NewPointerObj(val, type_info(), owner); - } - }; - - template struct traits_from { - static PyObject *from(const Type& val) { - return traits_from_ptr::from(new Type(val), 1); - } - }; - - template struct traits_from { - static PyObject *from(Type* val) { - return traits_from_ptr::from(val, 0); - } - }; - - template - inline PyObject *from(const Type& val) { - return traits_from::from(val); - } - - template - inline PyObject *from_ptr(Type* val, int owner) { - return traits_from_ptr::from(val, owner); - } - - /* - Traits that provides the asval/as/check method - */ - template - struct traits_asptr { - static int asptr(PyObject *obj, Type **val) { - Type *p; - int res = (SWIG_ConvertPtr(obj, (void**)&p, type_info(), 0) != -1) - ? SWIG_OLDOBJ : 0; - if (res) { - if (val) { - *val = p; - } - } else { - SWIG_type_error(type_name(), obj); - } - return res; - } - }; - - template - inline int asptr(PyObject *obj, Type **vptr) { - return traits_asptr::asptr(obj, vptr); - } - - template - struct noconst_traits { - typedef Type noconst_type; - }; - - template - struct noconst_traits { - typedef Type noconst_type; - }; - - template - struct traits_asval { - static bool asval(PyObject *obj, Type *val) { - if (val) { - Type *p = 0; - int res = traits_asptr::asptr(obj, &p); - if (res && p) { - typedef typename noconst_traits::noconst_type noconst_type; - *(const_cast(val)) = *p; - if (res == SWIG_NEWOBJ) delete p; - return true; - } else { - return false; - } - } else { - return traits_asptr::asptr(obj, (Type **)(0)); - } - } - }; - - template struct traits_asval { - static bool asval(PyObject *obj, Type **val) { - if (val) { - Type *p = 0; - int res = traits_asptr::asptr(obj, &p); - if (res) { - typedef typename noconst_traits::noconst_type noconst_type; - *(const_cast(val)) = p; - return true; - } else { - return false; - } - } else { - return traits_asptr::asptr(obj, (Type **)(0)); - } - } - }; - - template - inline bool asval(PyObject *obj, Type *val) { - return traits_asval::asval(obj, val); - } - - template - struct traits_as { }; - - template - struct traits_as { - static Type as(PyObject *obj, bool throw_error) { - Type v; - if (!obj || !asval(obj, &v)) { - if (!PyErr_Occurred()) { - SWIG_type_error(swigpy::type_name(), obj); - } - if (throw_error) throw std::invalid_argument("bad type"); - } - return v; - } - }; - - template - struct traits_as { - static Type as(PyObject *obj, bool throw_error) { - Type *v = 0; - int res = (obj ? traits_asptr::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(), obj); - } - if (throw_error) throw std::invalid_argument("bad type"); - memset(v_def,0,sizeof(Type)); - return *v_def; - } - } - }; - - template - struct traits_as { - static Type* as(PyObject *obj, bool throw_error) { - Type *v = 0; - int res = (obj ? traits_asptr::asptr(obj, &v) : 0); - if (res) { - return v; - } else { - if (!PyErr_Occurred()) { - SWIG_type_error(swigpy::type_name(), obj); - } - if (throw_error) throw std::invalid_argument("bad type"); - return 0; - } - } - }; - - template - inline Type as(PyObject *obj, bool te = false) { - return traits_as::category>::as(obj, te); - } - - template - struct traits_check { }; - - template - struct traits_check { - static bool check(PyObject *obj) { - return obj && asval(obj, (Type *)(0)); - } - }; - - template - struct traits_check { - static bool check(PyObject *obj) { - return obj && asptr(obj, (Type **)(0)); - } - }; - - template - inline bool check(PyObject *obj) { - return traits_check::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)) - %evalif(SWIG_OrderType(T), %std_order_methods(std::Class)) -%enddef -%define %_std_extcomp_2(Class,T,U) - %evalif_2(SWIG_EqualType(T),SWIG_EqualType(U),%std_equal_methods(std::Class)) - %evalif_2(SWIG_OrderType(T),SWIG_EqualType(U),%std_order_methods(std::Class)) -%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); -%swig_equal_type(std::complex); - -/* 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); -%swig_order_type(std::wstring); -%swig_order_type(std::basic_string); - -// -// Backward compatibility -// - -#ifdef SWIG_STD_BACKWARD_COMP -%{ -#include - -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 diff --git a/SWIG/Lib/python/std_container.i b/SWIG/Lib/python/std_container.i index 583891d68..d24c1570f 100644 --- a/SWIG/Lib/python/std_container.i +++ b/SWIG/Lib/python/std_container.i @@ -1,198 +1,2 @@ %include -%include -%include - -%{ -#include -%} - -// 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 - 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 - 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 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(),0) != -1) { - if (seq) *seq = p; - return 1; - } - } - if (seq) { - PyErr_Format(PyExc_TypeError, "a %s is expected", - swigpy::type_name()); - } - return 0; - } - }; - - template - 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(*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 diff --git a/SWIG/Lib/python/std_deque.i b/SWIG/Lib/python/std_deque.i index 7a89b1244..b19375633 100644 --- a/SWIG/Lib/python/std_deque.i +++ b/SWIG/Lib/python/std_deque.i @@ -1,57 +1,10 @@ -// -// std::deque -// Python implementation - -%include - -// 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), f(const std::deque&): -// the parameter being read-only, either a Python sequence or a -// previously wrapped std::deque can be passed. -// -- f(std::deque&), f(std::deque*): -// the parameter may be modified; therefore, only a wrapped std::deque -// can be passed. -// -- std::deque f(), const std::deque& 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& f(), std::deque* f(): -// the deque is returned by reference; therefore, a wrapped std::deque -// is returned -// -- const std::deque* f(), f(const std::deque*): -// for consistency, they expect and return a plain deque pointer. -// ------------------------------------------------------------------------ - -%{ -#include -%} +/* + Deques +*/ %fragment("StdDequeTraits","header",fragment="StdSequenceTraits") %{ - namespace swigpy { + namespace swig { template struct traits_asptr > { static int asptr(PyObject *obj, std::deque **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 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), "header", - fragment=SWIG_Traits_frag(T), - fragment="StdDequeTraits") { - namespace swigpy { - template <> struct traits > { - typedef pointer_category category; - static const char* type_name() { - return "std::deque<" #T " >"; - } - }; - } - } - - %typemap_traits_ptr(SWIG_CCode(DEQUE), std::deque); - - %std_deque_methods(deque); - %pysequence_methods(std::deque); - }; - - template 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 value_type const_reference; - - %traits_swigtype(T); - - %fragment(SWIG_Traits_frag(std::deque), "header", - fragment=SWIG_Traits_frag(T), - fragment="StdDequeTraits") { - namespace swigpy { - template <> struct traits > { - typedef value_category category; - static const char* type_name() { - return "std::deque<" #T " * >"; - } - }; - } - } - - %typemap_traits_ptr(SWIG_CCode(DEQUE), std::deque); - - %std_deque_methods_val(std::deque); - %pysequence_methods_val(std::deque); - }; - -} - -%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 diff --git a/SWIG/Lib/python/std_except.i b/SWIG/Lib/python/std_except.i index 690224979..d85c60337 100644 --- a/SWIG/Lib/python/std_except.i +++ b/SWIG/Lib/python/std_except.i @@ -1,79 +1 @@ -%include -%include - -%{ -#include -%} - -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 diff --git a/SWIG/Lib/python/std_ios.i b/SWIG/Lib/python/std_ios.i index 7ea6eba68..aa6f0994d 100644 --- a/SWIG/Lib/python/std_ios.i +++ b/SWIG/Lib/python/std_ios.i @@ -1,251 +1,3 @@ -%include -%include -%{ -#include -%} - -#ifdef SWIGPYTHON %rename(ios_base_in) std::ios_base::in; -#endif -namespace std { - - template > - class basic_streambuf; - - template > - class basic_istream; - - template > - 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 - 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 >; - %template(wios) basic_ios >; -} - - +%include diff --git a/SWIG/Lib/python/std_iostream.i b/SWIG/Lib/python/std_iostream.i index 468a562d1..8ceb23d6a 100644 --- a/SWIG/Lib/python/std_iostream.i +++ b/SWIG/Lib/python/std_iostream.i @@ -1,334 +1,8 @@ -%include -%include -%include - -%{ -#include -%} - namespace std { - // 27.6.2.1 Template class basic_ostream - template - 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 - 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 - 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 > ostream ; - typedef basic_istream > istream; - typedef basic_iostream > iostream; - - typedef basic_ostream > wostream; - typedef basic_istream > wistream; - typedef basic_iostream > wiostream; -} - - -namespace std { - %template(ostream) basic_ostream >; - %template(istream) basic_istream >; - %template(iostream) basic_iostream >; - - %template(wostream) basic_ostream >; - %template(wistream) basic_istream >; - %template(wiostream) basic_iostream >; -} - -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 - std::basic_ostream<_CharT, _Traits>& - endl(std::basic_ostream<_CharT, _Traits>&); - - template - std::basic_ostream<_CharT, _Traits>& - ends(std::basic_ostream<_CharT, _Traits>&); - - template - std::basic_ostream<_CharT, _Traits>& - flush(std::basic_ostream<_CharT, _Traits>&); - -%pythoncallback(1); - - - %template(endl) endl >; - %template(ends) ends >; - %template(flush) flush >; - - %template(wendl) endl >; - %template(wends) ends >; - %template(wflush) flush >; - -%pythoncallback(0); - - -} +%include diff --git a/SWIG/Lib/python/std_list.i b/SWIG/Lib/python/std_list.i index 15c7b4422..baf66d914 100644 --- a/SWIG/Lib/python/std_list.i +++ b/SWIG/Lib/python/std_list.i @@ -1,68 +1,10 @@ -// -// std::list -// Python implementation - -%include - -// 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), f(const std::list&): -// the parameter being read-only, either a Python sequence or a -// previously wrapped std::list can be passed. -// -- f(std::list&), f(std::list*): -// the parameter may be modified; therefore, only a wrapped std::list -// can be passed. -// -- std::list f(), const std::list& 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& f(), std::list* f(): -// the list is returned by reference; therefore, a wrapped std::list -// is returned -// -- const std::list* f(), f(const std::list*): -// for consistency, they expect and return a plain list pointer. -// ------------------------------------------------------------------------ - -%{ -#include -%} +/* + Lists +*/ %fragment("StdListTraits","header",fragment="StdSequenceTraits") %{ - namespace swigpy { + namespace swig { template struct traits_asptr > { static int asptr(PyObject *obj, std::list **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 - template 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), "header", - fragment=SWIG_Traits_frag(T), - fragment="StdListTraits") { - namespace swigpy { - template <> struct traits > { - typedef pointer_category category; - static const char* type_name() { - return "std::list<" #T " >"; - } - }; - } - } - - %typemap_traits_ptr(SWIG_CCode(LIST), std::list); - - %std_list_methods(list); - %pysequence_methods(std::list); - }; - - template 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 value_type const_reference; - - %traits_swigtype(T); - - %fragment(SWIG_Traits_frag(std::list), "header", - fragment=SWIG_Traits_frag(T), - fragment="StdListTraits") { - namespace swigpy { - template <> struct traits > { - typedef value_category category; - static const char* type_name() { - return "std::list<" #T " * >"; - } - }; - } - } - - %typemap_traits_ptr(SWIG_CCode(LIST), std::list); - - %std_list_methods_val(list); - %pysequence_methods_val(std::list); - }; - -} - -%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 diff --git a/SWIG/Lib/python/std_map.i b/SWIG/Lib/python/std_map.i index d2b18a9b5..bfc4fb201 100644 --- a/SWIG/Lib/python/std_map.i +++ b/SWIG/Lib/python/std_map.i @@ -1,89 +1,10 @@ -// -// std::map -// Python implementation - -%include -%include - -%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; -// %template(map_ii) std::map; -// -// or -// -// %template() std::pair; -// %template(map_ii) std::map; -// -// **** 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), f(const std::map&): -// the parameter being read-only, either a Python sequence or a -// previously wrapped std::map can be passed. -// -- f(std::map&), f(std::map*): -// the parameter may be modified; therefore, only a wrapped std::map -// can be passed. -// -- std::map f(), const std::map& 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& f(), std::map* f(): -// the map is returned by reference; therefore, a wrapped std::map -// is returned -// -- const std::map* f(), f(const std::map*): -// for consistency, they expect and return a plain map pointer. -// ------------------------------------------------------------------------ - -%{ -#include -#include -#include -%} - -// exported class +/* + Maps +*/ %fragment("StdMapTraits","header",fragment="StdSequenceTraits") { - namespace swigpy { + namespace swig { template inline void assign(const PySeq& pyseq, std::map *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 map { - public: - typedef size_t size_type; - typedef ptrdiff_t difference_type; - typedef K key_type; - typedef T mapped_type; - typedef std::pair 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), "header", - fragment=SWIG_Traits_frag(std::pair), - fragment="StdMapTraits") { - namespace swigpy { - template <> struct traits > { - 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); - - %std_map_methods(map); - %pydict_methods(SWIG_arg(std::map)); - }; - -} - -%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 diff --git a/SWIG/Lib/python/std_multimap.i b/SWIG/Lib/python/std_multimap.i index 780c63639..e5b941b34 100644 --- a/SWIG/Lib/python/std_multimap.i +++ b/SWIG/Lib/python/std_multimap.i @@ -1,51 +1,11 @@ -// -// std::map -// Python implementation - +/* + Multimaps +*/ %include - -%define %std_multimap_methods(...) - %std_map_methods_common(SWIG_arg(__VA_ARGS__)); - - #ifdef SWIG_EXPORT_ITERATOR_METHODS - pair insert(const value_type& x); - pair equal_range(const key_type& x); - pair 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), f(const std::multimap&): -// the parameter being read-only, either a Python sequence or a -// previously wrapped std::multimap can be passed. -// -- f(std::multimap&), f(std::multimap*): -// the parameter may be modified; therefore, only a wrapped std::multimap -// can be passed. -// -- std::multimap f(), const std::multimap& 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& f(), std::multimap* f(): -// the map is returned by reference; therefore, a wrapped std::multimap -// is returned -// -- const std::multimap* f(), f(const std::multimap*): -// for consistency, they expect and return a plain map pointer. -// ------------------------------------------------------------------------ - - -// exported class - %fragment("StdMultimapTraits","header",fragment="StdSequenceTraits") { - namespace swigpy { + namespace swig { template void assign(const PySeq& pyseq, std::multimap *multimap) { typedef typename std::map::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 multimap { - public: - typedef size_t size_type; - typedef ptrdiff_t difference_type; - typedef K key_type; - typedef T mapped_type; - typedef std::pair 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 - %traits_swigtype(K); - %traits_swigtype(T); - - %fragment(SWIG_Traits_frag(std::multimap), "header", - fragment=SWIG_Traits_frag(std::pair), - fragment="StdMultimapTraits") { - namespace swigpy { - - template <> struct traits > { - typedef value_category category; - static const char* type_name() { - return "std::multimap<" #K "," #T " >"; - } - }; - } - } - - %typemap_traits_ptr(SWIG_CCode(MULTIMAP), std::multimap); - - %std_multimap_methods(multimap); - %pydict_methods(SWIG_arg(std::multimap)); - }; -} - -%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 diff --git a/SWIG/Lib/python/std_multiset.i b/SWIG/Lib/python/std_multiset.i index 3c3d3246e..b85f5bfb6 100644 --- a/SWIG/Lib/python/std_multiset.i +++ b/SWIG/Lib/python/std_multiset.i @@ -1,47 +1,12 @@ -// -// std::set -// Python implementation +/* + Multisets +*/ %include -// Multiset - -%define %std_multiset_methods(multiset) - %std_set_methods_common(multiset); - #ifdef SWIG_EXPORT_ITERATOR_METHODS - pair 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), f(const std::multiset&): -// the parameter being read-only, either a Python sequence or a -// previously wrapped std::multiset can be passed. -// -- f(std::multiset&), f(std::multiset*): -// the parameter may be modified; therefore, only a wrapped std::multiset -// can be passed. -// -- std::multiset f(), const std::multiset& 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& f(), std::multiset* f(): -// the set is returned by reference; therefore, a wrapped std::multiset -// is returned -// -- const std::multiset* f(), f(const std::multiset*): -// for consistency, they expect and return a plain set pointer. -// ------------------------------------------------------------------------ - %fragment("StdMultisetTraits","header",fragment="StdSequenceTraits") %{ - namespace swigpy { + namespace swig { template void assign(const PySeq& pyseq, std::multiset* 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 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), "header", - fragment=SWIG_Traits_frag(T), - fragment="StdMultisetTraits") { - namespace swigpy { - template <> struct traits > { - typedef pointer_category category; - static const char* type_name() { - return "std::multiset<" #T " >"; - } - }; - } - } - - %typemap_traits_ptr(SWIG_CCode(MULTISET), std::multiset); - - %std_multiset_methods(multiset); - %pycontainer_methods(std::multiset); - }; - -} - -%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 diff --git a/SWIG/Lib/python/std_pair.i b/SWIG/Lib/python/std_pair.i index f427613ab..f2f0d2a70 100644 --- a/SWIG/Lib/python/std_pair.i +++ b/SWIG/Lib/python/std_pair.i @@ -1,11 +1,57 @@ -%include +/* + Pairs +*/ +%fragment("StdPairTraits","header", + fragment="StdTraits",fragment="PyObject_var") { + namespace swig { + template + struct traits_asptr > { + static int asptr(PyObject *obj, std::pair **val) { + typedef std::pair 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; + 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(),0) != -1) { + if (val) *val = p; + return SWIG_OLDOBJ; + } + } + if (val) { + PyErr_Format(PyExc_TypeError, "a %s is expected", + swig::type_name()); + } + return 0; + } + }; -%{ -#include -%} + template + struct traits_from > { + static PyObject *from(const std::pair& 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 - struct traits_asptr > { - static int asptr(PyObject *obj, std::pair **val) { - typedef std::pair 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; - 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(),0) != -1) { - if (val) *val = p; - return SWIG_OLDOBJ; - } - } - if (val) { - PyErr_Format(PyExc_TypeError, "a %s is expected", - swigpy::type_name()); - } - return 0; - } - }; - template - struct traits_from > { - static PyObject *from(const std::pair& 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 -namespace std { - template struct pair { - typedef T fisrt_type; - typedef U second_type; - - %traits_swigtype(T); - %traits_swigtype(U); - - %fragment(SWIG_Traits_frag(std::pair), "header", - fragment=SWIG_Traits_frag(T), - fragment=SWIG_Traits_frag(U), - fragment="StdPairTraits") { - namespace swigpy { - template <> struct traits > { - typedef pointer_category category; - static const char* type_name() { - return "std::pair<" #T "," #U " >"; - } - }; - } - } - - %typemap_traits_ptr(SWIG_CCode(PAIR), std::pair); - - 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 struct pair { - typedef T fisrt_type; - typedef U* second_type; - - %traits_swigtype(T); - %traits_swigtype(U); - - %fragment(SWIG_Traits_frag(std::pair), "header", - fragment=SWIG_Traits_frag(T), - fragment=SWIG_Traits_frag(U), - fragment="StdPairTraits") { - namespace swigpy { - template <> struct traits > { - typedef pointer_category category; - static const char* type_name() { - return "std::pair<" #T "," #U " * >"; - } - }; - } - } - - %typemap_traits_ptr(SWIG_CCode(PAIR), std::pair); - - pair(); - pair(T __a, U* __b); - pair(const pair& __p); - - T first; - U* second; - - %pypair_methods(pair) - }; - - template struct pair { - typedef T* fisrt_type; - typedef U second_type; - - %traits_swigtype(T); - %traits_swigtype(U); - - %fragment(SWIG_Traits_frag(std::pair), "header", - fragment=SWIG_Traits_frag(T), - fragment=SWIG_Traits_frag(U), - fragment="StdPairTraits") { - namespace swigpy { - template <> struct traits > { - typedef pointer_category category; - static const char* type_name() { - return "std::pair<" #T " *," #U " >"; - } - }; - } - } - - %typemap_traits_ptr(SWIG_CCode(PAIR), std::pair); - - pair(); - pair(T* __a, U __b); - pair(const pair& __p); - - T* first; - U second; - - %pypair_methods(pair) - }; - - template struct pair { - typedef T* fisrt_type; - typedef U* second_type; - - %traits_swigtype(T); - %traits_swigtype(U); - - %fragment(SWIG_Traits_frag(std::pair), "header", - fragment=SWIG_Traits_frag(T), - fragment=SWIG_Traits_frag(U), - fragment="StdPairTraits") { - namespace swigpy { - template <> struct traits > { - typedef pointer_category category; - static const char* type_name() { - return "std::pair<" #T " *," #U " * >"; - } - }; - } - } - - %typemap_traits(SWIG_CCode(PAIR), std::pair); - - 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 diff --git a/SWIG/Lib/python/std_set.i b/SWIG/Lib/python/std_set.i index 4d4394170..31eb9651e 100644 --- a/SWIG/Lib/python/std_set.i +++ b/SWIG/Lib/python/std_set.i @@ -1,87 +1,10 @@ -// -// std::set -// Python implementation - -%include - -// 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 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 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), f(const std::set&): -// the parameter being read-only, either a Python sequence or a -// previously wrapped std::set can be passed. -// -- f(std::set&), f(std::set*): -// the parameter may be modified; therefore, only a wrapped std::set -// can be passed. -// -- std::set f(), const std::set& 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& f(), std::set* f(): -// the set is returned by reference; therefore, a wrapped std::set -// is returned -// -- const std::set* f(), f(const std::set*): -// for consistency, they expect and return a plain set pointer. -// ------------------------------------------------------------------------ - -%{ -#include -%} +/* + Sets +*/ %fragment("StdSetTraits","header",fragment="StdSequenceTraits") %{ - namespace swigpy { + namespace swig { template void assign(const PySeq& pyseq, std::set* 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 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), "header", - fragment=SWIG_Traits_frag(T), - fragment="StdSetTraits") { - namespace swigpy { - template <> struct traits > { - typedef pointer_category category; - static const char* type_name() { - return "std::set<" #T " >"; - } - }; - } - } - - %typemap_traits_ptr(SWIG_CCode(SET), std::set); + %extend { + void append(value_type x) { + self->insert(x); + } - %std_set_methods(set); - %pyset_methods(std::set); - }; -} - -%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 diff --git a/SWIG/Lib/python/std_string.i b/SWIG/Lib/python/std_string.i index 711cdb09d..736da6299 100644 --- a/SWIG/Lib/python/std_string.i +++ b/SWIG/Lib/python/std_string.i @@ -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 %include diff --git a/SWIG/Lib/python/std_vector.i b/SWIG/Lib/python/std_vector.i index c39381ad1..3f04a30c7 100644 --- a/SWIG/Lib/python/std_vector.i +++ b/SWIG/Lib/python/std_vector.i @@ -1,60 +1,10 @@ -// -// std::vector -// Python implementation +/* + Vectors +*/ -%include - -// 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), f(const std::vector&): -// the parameter being read-only, either a Python sequence or a -// previously wrapped std::vector can be passed. -// -- f(std::vector&), f(std::vector*): -// the parameter may be modified; therefore, only a wrapped std::vector -// can be passed. -// -- std::vector f(), const std::vector& 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& f(), std::vector* f(): -// the vector is returned by reference; therefore, a wrapped std::vector -// is returned -// -- const std::vector* f(), f(const std::vector*): -// for consistency, they expect and return a plain vector pointer. -// ------------------------------------------------------------------------ - -%{ -#include -%} - - %fragment("StdVectorTraits","header",fragment="StdSequenceTraits") %{ - namespace swigpy { + namespace swig { template struct traits_asptr > { static int asptr(PyObject *obj, std::vector **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::flip(); -#endif - -namespace std { - - template 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), "header", - fragment=SWIG_Traits_frag(T), - fragment="StdVectorTraits") { - namespace swigpy { - template <> struct traits > { - typedef pointer_category category; - static const char* type_name() { - return "std::vector<" #T " >"; - } - }; - } - } - - %typemap_traits_ptr(SWIG_CCode(VECTOR), std::vector); - - %std_vector_methods(vector); - %pysequence_methods(std::vector); - }; - - // bool specialization - %extend vector { - void flip() - { - self->flip(); - } - } - - - // *** - // This specialization should dissapear or get simplified when - // a 'const SWIGTYPE*&' can be defined - // *** - template 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 value_type reference; - typedef value_type const_reference; - - %traits_swigtype(T); - - %fragment(SWIG_Traits_frag(std::vector), "header", - fragment=SWIG_Traits_frag(T), - fragment="StdVectorTraits") { - namespace swigpy { - template <> struct traits > { - typedef value_category category; - static const char* type_name() { - return "std::vector<" #T " * >"; - } - }; - } - } - - %typemap_traits_ptr(SWIG_CCode(VECTOR), std::vector); - - %std_vector_methods_val(vector); - %pysequence_methods_val(std::vector); - }; - - // *** - // *** - template class vector { - 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), "header", - fragment=SWIG_Traits_frag(bool), - fragment="StdVectorTraits") { - namespace swigpy { - template <> struct traits > { - typedef value_category category; - static const char* type_name() { - return "std::vector"; - } - }; - } - } - - %typemap_traits_ptr(SWIG_CCode(VECTOR), std::vector); - - %std_vector_methods_val(vector); - %pysequence_methods_val(std::vector); - }; - -} - -%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 diff --git a/SWIG/Lib/python/std_vectora.i b/SWIG/Lib/python/std_vectora.i index b211aced2..3f084bd7d 100644 --- a/SWIG/Lib/python/std_vectora.i +++ b/SWIG/Lib/python/std_vectora.i @@ -1,65 +1,10 @@ -// -// std::vector -// 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 - -// 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), f(const std::vector&): -// the parameter being read-only, either a Python sequence or a -// previously wrapped std::vector can be passed. -// -- f(std::vector&), f(std::vector*): -// the parameter may be modified; therefore, only a wrapped std::vector -// can be passed. -// -- std::vector f(), const std::vector& 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& f(), std::vector* f(): -// the vector is returned by reference; therefore, a wrapped std::vector -// is returned -// -- const std::vector* f(), f(const std::vector*): -// for consistency, they expect and return a plain vector pointer. -// ------------------------------------------------------------------------ +/* + Vectors + allocators +*/ +%fragment("StdVectorATraits","header",fragment="StdSequenceTraits") %{ -#include -%} - - -%fragment("StdVectorTraits","header",fragment="StdSequenceTraits") -%{ - namespace swigpy { + namespace swig { template struct traits_asptr > { typedef std::vector 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 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), "header", - fragment=SWIG_Traits_frag(T), - fragment="StdVectorTraits") { - namespace swigpy { - template <> struct traits > { - typedef pointer_category category; - static const char* type_name() { - return "std::vector<" #T "," #A " >"; - } - }; - } - } - - %typemap_traits(SWIG_CCode(VECTOR), std::vector); - - %std_vector_methods(SWIG_arg(vector)); - %pysequence_methods(SWIG_arg(std::vector)); - }; - - - // *** - // This pointer especialization should dissapears or get - // simplified when a 'const SWIGTYPE*&' can be be defined. - // *** - template > - 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 value_type reference; - typedef value_type const_reference; - - %traits_swigtype(T); - - %fragment(SWIG_Traits_frag(std::vector), "header", - fragment="StdVectorTraits") { - namespace swigpy { - template <> struct traits > { - typedef value_category category; - static const char* type_name() { - return "std::vector<" #T " *,"#A" >"; - } - }; - } - } - - %typemap_traits(SWIG_CCode(VECTOR), std::vector); - - %std_vector_methods_val(vector); - %pysequence_methods_val(SWIG_arg(std::vector)); - }; - - - // bool specialization - %extend vector > { - 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 and std::vector > 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 diff --git a/SWIG/Lib/python/std_wstring.i b/SWIG/Lib/python/std_wstring.i index ff4b848bb..93ce67f55 100644 --- a/SWIG/Lib/python/std_wstring.i +++ b/SWIG/Lib/python/std_wstring.i @@ -1,4 +1,9 @@ -%include +// +// std::wstring +// + + +%include %include /* wide strings */ diff --git a/SWIG/Lib/std/README b/SWIG/Lib/std/README new file mode 100644 index 000000000..5cd759dda --- /dev/null +++ b/SWIG/Lib/std/README @@ -0,0 +1,22 @@ +/* ----------------------------------------------------------------------------- + * C++ STD + STL + * ----------------------------------------------------------------------------- */ + +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_vector.i vector +std_vectora.i vector + allocator diff --git a/SWIG/Lib/std/std_basic_string.i b/SWIG/Lib/std/std_basic_string.i new file mode 100644 index 000000000..1e035f05f --- /dev/null +++ b/SWIG/Lib/std/std_basic_string.i @@ -0,0 +1,252 @@ +%include +%include +%include + +%{ +#include +%} + +namespace std { + template + 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(); + %swig_basic_string(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; + } + } + + }; +} + diff --git a/SWIG/Lib/std/std_char_traits.i b/SWIG/Lib/std/std_char_traits.i new file mode 100644 index 000000000..920fee50b --- /dev/null +++ b/SWIG/Lib/std/std_char_traits.i @@ -0,0 +1,132 @@ +%include +%include + +namespace std +{ + + /// 21.1.2 Basis for explicit _Traits specialization + /// NB: That for any given actual character type this definition is + /// probably wrong. + template + struct char_traits + { + }; + + + /// 21.1.4 char_traits specializations + template<> + struct char_traits { + 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 + { + 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; +%template() char_traits; +#else +%template(char_traits_c) char_traits; +%template(char_traits_w) char_traits; +#endif +} diff --git a/SWIG/Lib/std/std_common.i b/SWIG/Lib/std/std_common.i new file mode 100644 index 000000000..51ab41f4f --- /dev/null +++ b/SWIG/Lib/std/std_common.i @@ -0,0 +1,236 @@ +// +// 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 + +// 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 + +%} + +// +// Common code for supporting the STD C++ namespace +// + +%{ +#include +#include +%} + + +%apply size_t { std::size_t }; +%apply const size_t& { const std::size_t& }; +%apply ptrdiff_t { std::ptrdiff_t } +%apply const ptrdiff_t& { const std::ptrdiff_t& } + + +%fragment("StdTraitsCommon","header") +%{ +namespace swig { + /* + type categories + */ + struct pointer_category { }; + struct value_category { }; + + /* + General traits that provides type_name and type_info + */ + template struct traits { }; + + template + inline const char* type_name() { + return traits::type_name(); + } + + template + 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()); + return info; + } + }; + + template + inline swig_type_info *type_info() { + return traits_info::type_info(); + } + + /* + Partial specialization for pointers + */ + template struct traits { + 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(swig::type_name()); + return name.c_str(); + } + }; + + template + struct noconst_traits { + typedef Type noconst_type; + }; + + template + struct noconst_traits { + typedef Type noconst_type; + }; + + template + struct traits_as { }; + + template + struct traits_check { }; + +} +%} + +/* + Generate the traits for a swigtype +*/ + +%define %traits_swigtype(Type...) +%fragment(SWIG_Traits_frag(Type),"header",fragment="StdTraits") { + namespace swig { + template <> struct traits { + typedef pointer_category category; + static const char* type_name() { return #Type; } + }; + } +} +%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(Type...) + %fragment(SWIG_Traits_frag(Type),"header", + fragment=SWIG_AsVal_frag(Type), + fragment=SWIG_From_frag(Type), + fragment="StdTraits") { +namespace swig { + template <> struct traits { + typedef value_category category; + static const char* type_name() { return #Type; } + }; + template <> struct traits_asval { + typedef Type value_type; + static int asval(PyObject *obj, value_type *val) { + return SWIG_AsVal(Type)(obj, val); + } + }; + template <> struct traits_from { + typedef Type value_type; + static PyObject *from(const value_type& val) { + return SWIG_From(Type)(val); + } + }; +} +} +%enddef + +%apply_cpptypes(%traits_ptypen); + +/* + Generate the typemaps for a class that has 'value' traits +*/ + +%define %typemap_traits(Code,Type...) + %typemap_ascheckfrom(SWIG_arg(Code), + SWIG_arg(swig::as), + SWIG_arg(swig::check), + SWIG_arg(swig::from), + SWIG_arg(SWIG_Traits_frag(Type)), + SWIG_arg(SWIG_Traits_frag(Type)), + SWIG_arg(SWIG_Traits_frag(Type)), + Type); +%enddef + +/* + Generate the typemaps for a class that behaves more like a 'pointer' or + plain wrapped Swigtype. +*/ + +%define %typemap_traits_ptr(Code,Type...) + %typemap_asptrfrom(SWIG_arg(Code), + SWIG_arg(swig::asptr), + SWIG_arg(swig::from), + SWIG_arg(SWIG_Traits_frag(Type)), + SWIG_arg(SWIG_Traits_frag(Type)), + Type); +%enddef + + +/* + Equality methods +*/ +%define %std_equal_methods(Type...) +%extend Type { + bool operator == (const Type& v) { + return *self == v; + } + + bool operator != (const Type& v) { + return *self != v; + } +} + +%enddef + +/* + Order methods +*/ + +%define %std_order_methods(Type...) +%extend Type { + bool operator > (const Type& v) { + return *self > v; + } + + bool operator < (const Type& v) { + return *self < v; + } + + bool operator >= (const Type& v) { + return *self >= v; + } + + bool operator <= (const Type& v) { + return *self <= v; + } +} +%enddef + +/* + Comparison methods +*/ + +%define %std_comp_methods(Type...) +%std_equal_methods(Type ) +%std_order_methods(Type ) +%enddef + + diff --git a/SWIG/Lib/std/std_container.i b/SWIG/Lib/std/std_container.i new file mode 100644 index 000000000..05146dd7f --- /dev/null +++ b/SWIG/Lib/std/std_container.i @@ -0,0 +1,106 @@ +%include +%include + +%{ +#include +%} + +// 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 + + +// +// Ignore member methods for Type with no default constructor +// +%define %std_nodefconst_type(Type...) +%feature("ignore") std::vector::vector(size_type size); +%feature("ignore") std::vector::resize(size_type size); +%feature("ignore") std::deque::deque(size_type size); +%feature("ignore") std::deque::resize(size_type size); +%feature("ignore") std::list::list(size_type size); +%feature("ignore") std::list::resize(size_type size); +%enddef diff --git a/SWIG/Lib/std/std_deque.i b/SWIG/Lib/std/std_deque.i new file mode 100644 index 000000000..01bc4fee3 --- /dev/null +++ b/SWIG/Lib/std/std_deque.i @@ -0,0 +1,115 @@ +// +// std::deque + +%include + +// 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 +// +// const declarations are used to guess the intent of the function being +// exported; therefore, the following rationale is applied: +// +// -- f(std::deque), f(const std::deque&): +// the parameter being read-only, either a sequence or a +// previously wrapped std::deque can be passed. +// -- f(std::deque&), f(std::deque*): +// the parameter may be modified; therefore, only a wrapped std::deque +// can be passed. +// -- std::deque f(), const std::deque& f(): +// the deque is returned by copy; therefore, a sequence of T:s +// is returned which is most easily used in other functions +// -- std::deque& f(), std::deque* f(): +// the deque is returned by reference; therefore, a wrapped std::deque +// is returned +// -- const std::deque* f(), f(const std::deque*): +// for consistency, they expect and return a plain deque pointer. +// ------------------------------------------------------------------------ + +%{ +#include +%} + +// exported classes + +namespace std { + + template 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), "header", + fragment=SWIG_Traits_frag(T), + fragment="StdDequeTraits") { + namespace swig { + template <> struct traits > { + typedef pointer_category category; + static const char* type_name() { + return "std::deque<" #T " >"; + } + }; + } + } + + %typemap_traits_ptr(SWIG_TYPECHECK_DEQUE, std::deque); + + %std_deque_methods(deque); + %swig_deque_methods(std::deque); + }; + + template 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 value_type const_reference; + + %traits_swigtype(T); + + %fragment(SWIG_Traits_frag(std::deque), "header", + fragment=SWIG_Traits_frag(T), + fragment="StdDequeTraits") { + namespace swig { + template <> struct traits > { + typedef value_category category; + static const char* type_name() { + return "std::deque<" #T " * >"; + } + }; + } + } + + %typemap_traits_ptr(SWIG_TYPECHECK_DEQUE, std::deque); + + %std_deque_methods_val(std::deque); + %swig_deque_methods_val(std::deque); + }; + +} + diff --git a/SWIG/Lib/std/std_except.i b/SWIG/Lib/std/std_except.i new file mode 100644 index 000000000..690224979 --- /dev/null +++ b/SWIG/Lib/std/std_except.i @@ -0,0 +1,79 @@ +%include +%include + +%{ +#include +%} + +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); + }; +} + diff --git a/SWIG/Lib/std/std_ios.i b/SWIG/Lib/std/std_ios.i new file mode 100644 index 000000000..a8b57c847 --- /dev/null +++ b/SWIG/Lib/std/std_ios.i @@ -0,0 +1,247 @@ +%include +%include +%{ +#include +%} + +namespace std { + + template > + class basic_streambuf; + + template > + class basic_istream; + + template > + 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 + 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 >; + %template(wios) basic_ios >; +} + + diff --git a/SWIG/Lib/std/std_iostream.i b/SWIG/Lib/std/std_iostream.i new file mode 100644 index 000000000..6f04d783e --- /dev/null +++ b/SWIG/Lib/std/std_iostream.i @@ -0,0 +1,328 @@ +%include +%include +%include + +%{ +#include +%} + +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 +{ + // 27.6.2.1 Template class basic_ostream + template + 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 + 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.3 basic_istream::operator>> + basic_istream<_CharT, _Traits>& + operator>>(basic_istream<_CharT, _Traits>& (*__pf)(basic_istream<_CharT, _Traits>&)); + + basic_istream<_CharT, _Traits>& + operator>>(basic_ios<_CharT, _Traits>& (*__pf)(basic_ios<_CharT, _Traits>&)); + + basic_istream<_CharT, _Traits>& + operator>>(ios_base& (*__pf)(ios_base&)); + + // 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 + 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(); + }; + + typedef basic_ostream > ostream ; + typedef basic_istream > istream; + typedef basic_iostream > iostream; + + typedef basic_ostream > wostream; + typedef basic_istream > wistream; + typedef basic_iostream > wiostream; + + 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 + std::basic_ostream<_CharT, _Traits>& + endl(std::basic_ostream<_CharT, _Traits>&); + + template + std::basic_ostream<_CharT, _Traits>& + ends(std::basic_ostream<_CharT, _Traits>&); + + template + std::basic_ostream<_CharT, _Traits>& + flush(std::basic_ostream<_CharT, _Traits>&); +} + +namespace std { + %template(ostream) basic_ostream >; + %template(istream) basic_istream >; + %template(iostream) basic_iostream >; + + %template(wostream) basic_ostream >; + %template(wistream) basic_istream >; + %template(wiostream) basic_iostream >; + + %template(endl) endl >; + %template(ends) ends >; + %template(flush) flush >; + + %template(wendl) endl >; + %template(wends) ends >; + %template(wflush) flush >; +} + diff --git a/SWIG/Lib/std/std_list.i b/SWIG/Lib/std/std_list.i new file mode 100644 index 000000000..5f772043f --- /dev/null +++ b/SWIG/Lib/std/std_list.i @@ -0,0 +1,136 @@ +// +// std::list +// + +%include + +// 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 +// +// const declarations are used to guess the intent of the function being +// exported; therefore, the following rationale is applied: +// +// -- f(std::list), f(const std::list&): +// the parameter being read-only, either a sequence or a +// previously wrapped std::list can be passed. +// -- f(std::list&), f(std::list*): +// the parameter may be modified; therefore, only a wrapped std::list +// can be passed. +// -- std::list f(), const std::list& f(): +// the list is returned by copy; therefore, a sequence of T:s +// is returned which is most easily used in other functions +// -- std::list& f(), std::list* f(): +// the list is returned by reference; therefore, a wrapped std::list +// is returned +// -- const std::list* f(), f(const std::list*): +// for consistency, they expect and return a plain list pointer. +// ------------------------------------------------------------------------ + +%{ +#include +%} + +// exported classes + +namespace std { + + template 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), "header", + fragment=SWIG_Traits_frag(T), + fragment="StdListTraits") { + namespace swig { + template <> struct traits > { + typedef pointer_category category; + static const char* type_name() { + return "std::list<" #T " >"; + } + }; + } + } + + %typemap_traits_ptr(SWIG_TYPECHECK_LIST, std::list); + + %std_list_methods(list); + %swig_list_methods(std::list); + }; + + template 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 value_type const_reference; + + %traits_swigtype(T); + + %fragment(SWIG_Traits_frag(std::list), "header", + fragment=SWIG_Traits_frag(T), + fragment="StdListTraits") { + namespace swig { + template <> struct traits > { + typedef value_category category; + static const char* type_name() { + return "std::list<" #T " * >"; + } + }; + } + } + + %typemap_traits_ptr(SWIG_TYPECHECK_LIST, std::list); + + %std_list_methods_val(list); + %swig_list_methods_val(std::list); + }; + +} + +%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 + diff --git a/SWIG/Lib/std/std_map.i b/SWIG/Lib/std/std_map.i new file mode 100644 index 000000000..f1b533f56 --- /dev/null +++ b/SWIG/Lib/std/std_map.i @@ -0,0 +1,118 @@ +// +// std::map +// + +%include +%include + +%define %std_map_methods_common(map...) + %std_container_methods(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(map...) + %std_map_methods_common(map); + + #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; +// %template(map_ii) std::map; +// +// or +// +// %template() std::pair; +// %template(map_ii) std::map; +// +// **** Note **** +// ------------------------------------------------------------------------ +// std::map +// +// const declarations are used to guess the intent of the function being +// exported; therefore, the following rationale is applied: +// +// -- f(std::map), f(const std::map&): +// the parameter being read-only, either a sequence or a +// previously wrapped std::map can be passed. +// -- f(std::map&), f(std::map*): +// the parameter may be modified; therefore, only a wrapped std::map +// can be passed. +// -- std::map f(), const std::map& f(): +// the map is returned by copy; therefore, a sequence of T:s +// is returned which is most easily used in other functions +// -- std::map& f(), std::map* f(): +// the map is returned by reference; therefore, a wrapped std::map +// is returned +// -- const std::map* f(), f(const std::map*): +// for consistency, they expect and return a plain map pointer. +// ------------------------------------------------------------------------ + +%{ +#include +#include +#include +%} + +// exported class + +namespace std { + + template class map { + public: + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef K key_type; + typedef T mapped_type; + typedef std::pair 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), "header", + fragment=SWIG_Traits_frag(std::pair), + fragment="StdMapTraits") { + namespace swig { + template <> struct traits > { + typedef pointer_category category; + static const char* type_name() { + return "std::map<" #K "," #T " >"; + } + }; + } + } + + %typemap_traits_ptr(SWIG_TYPECHECK_MAP, std::map); + + %std_map_methods(map); + %swig_map_methods(std::map); + }; + +} diff --git a/SWIG/Lib/std/std_multimap.i b/SWIG/Lib/std/std_multimap.i new file mode 100644 index 000000000..7b581ded8 --- /dev/null +++ b/SWIG/Lib/std/std_multimap.i @@ -0,0 +1,80 @@ +// +// std::map +// + +%include + + +%define %std_multimap_methods(mmap...) + %std_map_methods_common(mmap); + +#ifdef SWIG_EXPORT_ITERATOR_METHODS + pair insert(const value_type& x); + pair equal_range(const key_type& x); + pair equal_range(const key_type& x) const; +#endif +%enddef + +// ------------------------------------------------------------------------ +// std::multimap +// +// const declarations are used to guess the intent of the function being +// exported; therefore, the following rationale is applied: +// +// -- f(std::multimap), f(const std::multimap&): +// the parameter being read-only, either a sequence or a +// previously wrapped std::multimap can be passed. +// -- f(std::multimap&), f(std::multimap*): +// the parameter may be modified; therefore, only a wrapped std::multimap +// can be passed. +// -- std::multimap f(), const std::multimap& f(): +// the map is returned by copy; therefore, a sequence of T:s +// is returned which is most easily used in other functions +// -- std::multimap& f(), std::multimap* f(): +// the map is returned by reference; therefore, a wrapped std::multimap +// is returned +// -- const std::multimap* f(), f(const std::multimap*): +// for consistency, they expect and return a plain map pointer. +// ------------------------------------------------------------------------ + + +// exported class + + +namespace std { + template class multimap { + public: + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef K key_type; + typedef T mapped_type; + typedef std::pair 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::multimap), "header", + fragment=SWIG_Traits_frag(std::pair), + fragment="StdMultimapTraits") { + namespace swig { + + template <> struct traits > { + typedef value_category category; + static const char* type_name() { + return "std::multimap<" #K "," #T " >"; + } + }; + } + } + + %typemap_traits_ptr(SWIG_TYPECHECK_MULTIMAP, std::multimap); + + %std_multimap_methods(multimap); + %swig_multimap_methods(std::multimap); + }; +} diff --git a/SWIG/Lib/std/std_multiset.i b/SWIG/Lib/std/std_multiset.i new file mode 100644 index 000000000..bb7b79939 --- /dev/null +++ b/SWIG/Lib/std/std_multiset.i @@ -0,0 +1,78 @@ +// +// std::set +// + +%include + +// Multiset + +%define %std_multiset_methods(multiset) + %std_set_methods_common(multiset); + #ifdef SWIG_EXPORT_ITERATOR_METHODS + pair insert(iterator pos); + #endif +%enddef + + +// ------------------------------------------------------------------------ +// std::multiset +// +// const declarations are used to guess the intent of the function being +// exported; therefore, the following rationale is applied: +// +// -- f(std::multiset), f(const std::multiset&): +// the parameter being read-only, either a sequence or a +// previously wrapped std::multiset can be passed. +// -- f(std::multiset&), f(std::multiset*): +// the parameter may be modified; therefore, only a wrapped std::multiset +// can be passed. +// -- std::multiset f(), const std::multiset& f(): +// the set is returned by copy; therefore, a sequence of T:s +// is returned which is most easily used in other functions +// -- std::multiset& f(), std::multiset* f(): +// the set is returned by reference; therefore, a wrapped std::multiset +// is returned +// -- const std::multiset* f(), f(const std::multiset*): +// for consistency, they expect and return a plain set pointer. +// ------------------------------------------------------------------------ + + +// exported classes + +namespace std { + + //multiset + + template 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), "header", + fragment=SWIG_Traits_frag(T), + fragment="StdMultisetTraits") { + namespace swig { + template <> struct traits > { + typedef pointer_category category; + static const char* type_name() { + return "std::multiset<" #T " >"; + } + }; + } + } + + %typemap_traits_ptr(SWIG_TYPECHECK_MULTISET, std::multiset); + + %std_multiset_methods(multiset); + %swig_container_methods(std::multiset); + }; + +} diff --git a/SWIG/Lib/std/std_pair.i b/SWIG/Lib/std/std_pair.i new file mode 100644 index 000000000..6dc5a1186 --- /dev/null +++ b/SWIG/Lib/std/std_pair.i @@ -0,0 +1,145 @@ +%include + +%{ +#include +%} + + +namespace std { + template struct pair { + typedef T fisrt_type; + typedef U second_type; + + %traits_swigtype(T); + %traits_swigtype(U); + + %fragment(SWIG_Traits_frag(std::pair), "header", + fragment=SWIG_Traits_frag(T), + fragment=SWIG_Traits_frag(U), + fragment="StdPairTraits") { + namespace swig { + template <> struct traits > { + typedef pointer_category category; + static const char* type_name() { + return "std::pair<" #T "," #U " >"; + } + }; + } + } + + %typemap_traits_ptr(SWIG_TYPECHECK_PAIR, std::pair); + + pair(); + pair(T __a, U __b); + pair(const pair& __p); + + T first; + U second; + + %swig_pair_methods(std::pair) + }; + + // *** + // The following specializations should dissapear or get + // simplified when a 'const SWIGTYPE*&' can be defined + // *** + template struct pair { + typedef T fisrt_type; + typedef U* second_type; + + %traits_swigtype(T); + %traits_swigtype(U); + + %fragment(SWIG_Traits_frag(std::pair), "header", + fragment=SWIG_Traits_frag(T), + fragment=SWIG_Traits_frag(U), + fragment="StdPairTraits") { + namespace swig { + template <> struct traits > { + typedef pointer_category category; + static const char* type_name() { + return "std::pair<" #T "," #U " * >"; + } + }; + } + } + + %typemap_traits_ptr(SWIG_TYPECHECK_PAIR, std::pair); + + pair(); + pair(T __a, U* __b); + pair(const pair& __p); + + T first; + U* second; + + %swig_pair_methods(std::pair) + }; + + template struct pair { + typedef T* fisrt_type; + typedef U second_type; + + %traits_swigtype(T); + %traits_swigtype(U); + + %fragment(SWIG_Traits_frag(std::pair), "header", + fragment=SWIG_Traits_frag(T), + fragment=SWIG_Traits_frag(U), + fragment="StdPairTraits") { + namespace swig { + template <> struct traits > { + typedef pointer_category category; + static const char* type_name() { + return "std::pair<" #T " *," #U " >"; + } + }; + } + } + + %typemap_traits_ptr(SWIG_TYPECHECK_PAIR, std::pair); + + pair(); + pair(T* __a, U __b); + pair(const pair& __p); + + T* first; + U second; + + %swig_pair_methods(std::pair) + }; + + template struct pair { + typedef T* fisrt_type; + typedef U* second_type; + + %traits_swigtype(T); + %traits_swigtype(U); + + %fragment(SWIG_Traits_frag(std::pair), "header", + fragment=SWIG_Traits_frag(T), + fragment=SWIG_Traits_frag(U), + fragment="StdPairTraits") { + namespace swig { + template <> struct traits > { + typedef pointer_category category; + static const char* type_name() { + return "std::pair<" #T " *," #U " * >"; + } + }; + } + } + + %typemap_traits(SWIG_TYPECHECK_PAIR, std::pair); + + pair(); + pair(T* __a, U* __b); + pair(const pair& __p); + + T* first; + U* second; + + %swig_pair_methods(std::pair) + }; + +} diff --git a/SWIG/Lib/std/std_set.i b/SWIG/Lib/std/std_set.i new file mode 100644 index 000000000..fd053ea2a --- /dev/null +++ b/SWIG/Lib/std/std_set.i @@ -0,0 +1,98 @@ +// +// std::set +// + +%include + +// 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 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 insert(const value_type& __x); + iterator insert(iterator pos); +#endif +%enddef + +// ------------------------------------------------------------------------ +// std::set +// +// const declarations are used to guess the intent of the function being +// exported; therefore, the following rationale is applied: +// +// -- f(std::set), f(const std::set&): +// the parameter being read-only, either a sequence or a +// previously wrapped std::set can be passed. +// -- f(std::set&), f(std::set*): +// the parameter may be modified; therefore, only a wrapped std::set +// can be passed. +// -- std::set f(), const std::set& f(): +// the set is returned by copy; therefore, a sequence of T:s +// is returned which is most easily used in other functions +// -- std::set& f(), std::set* f(): +// the set is returned by reference; therefore, a wrapped std::set +// is returned +// -- const std::set* f(), f(const std::set*): +// for consistency, they expect and return a plain set pointer. +// ------------------------------------------------------------------------ + +%{ +#include +%} + +// exported classes + +namespace std { + + template 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), "header", + fragment=SWIG_Traits_frag(T), + fragment="StdSetTraits") { + namespace swig { + template <> struct traits > { + typedef pointer_category category; + static const char* type_name() { + return "std::set<" #T " >"; + } + }; + } + } + + %typemap_traits_ptr(SWIG_TYPECHECK_SET, std::set); + + %std_set_methods(set); + %swig_set_methods(std::set); + }; +} diff --git a/SWIG/Lib/std/std_streambuf.i b/SWIG/Lib/std/std_streambuf.i new file mode 100644 index 000000000..f48860c62 --- /dev/null +++ b/SWIG/Lib/std/std_streambuf.i @@ -0,0 +1,87 @@ +%include +%{ +#include +%} + +namespace std { + + template + class basic_streambuf + { + public: + // Types: + typedef _CharT char_type; + typedef _Traits traits_type; + typedef typename traits_type::int_type int_type; + typedef typename traits_type::pos_type pos_type; + typedef typename traits_type::off_type off_type; + + typedef basic_streambuf __streambuf_type; + + public: + virtual + ~basic_streambuf(); + + // Locales: + locale + pubimbue(const locale &__loc); + + locale + getloc() const; + + // Buffer and positioning: + __streambuf_type* + pubsetbuf(char_type* __s, streamsize __n); + + pos_type + pubseekoff(off_type __off, ios_base::seekdir __way, + ios_base::openmode __mode = std::ios_base::in | std::ios_base::out); + + pos_type + pubseekpos(pos_type __sp, + ios_base::openmode __mode = std::ios_base::in | std::ios_base::out); + + int + pubsync() ; + + // Get and put areas: + // Get area: + streamsize + in_avail(); + + int_type + snextc(); + + int_type + sbumpc(); + + int_type + sgetc(); + + streamsize + sgetn(char_type* __s, streamsize __n); + + // Putback: + int_type + sputbackc(char_type __c); + + int_type + sungetc(); + + // Put area: + int_type + sputc(char_type __c); + + streamsize + sputn(const char_type* __s, streamsize __n); + + protected: + basic_streambuf(); + + }; +} + +namespace std { + %template(streambuf) basic_streambuf >; + %template(wstreambuf) basic_streambuf >; +} diff --git a/SWIG/Lib/std/std_vector.i b/SWIG/Lib/std/std_vector.i new file mode 100644 index 000000000..2cc77c4d2 --- /dev/null +++ b/SWIG/Lib/std/std_vector.i @@ -0,0 +1,170 @@ +// +// std::vector +// + +%include + +// 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 +// as much as possible, namely, to allow the user to pass and +// be returned 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), f(const std::vector&): +// the parameter being read-only, either a sequence or a +// previously wrapped std::vector can be passed. +// -- f(std::vector&), f(std::vector*): +// the parameter may be modified; therefore, only a wrapped std::vector +// can be passed. +// -- std::vector f(), const std::vector& f(): +// the vector is returned by copy; therefore, a sequence of T:s +// is returned which is most easily used in other functions +// -- std::vector& f(), std::vector* f(): +// the vector is returned by reference; therefore, a wrapped std::vector +// is returned +// -- const std::vector* f(), f(const std::vector*): +// for consistency, they expect and return a plain vector pointer. +// ------------------------------------------------------------------------ + +%{ +#include +%} + +// exported classes + +#if !defined(SWIG_STD_MODERN_STL) || defined(SWIG_STD_NOMODERN_STL) +%ignore std::vector::flip(); +#endif + +namespace std { + + template 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), "header", + fragment=SWIG_Traits_frag(T), + fragment="StdVectorTraits") { + namespace swig { + template <> struct traits > { + typedef pointer_category category; + static const char* type_name() { + return "std::vector<" #T " >"; + } + }; + } + } + + %typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector); + + %std_vector_methods(vector); + %swig_vector_methods(std::vector); + }; + + // bool specialization + %extend vector { + void flip() + { + self->flip(); + } + } + + + // *** + // This specialization should dissapear or get simplified when + // a 'const SWIGTYPE*&' can be defined + // *** + template 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 value_type reference; + typedef value_type const_reference; + + %traits_swigtype(T); + + %fragment(SWIG_Traits_frag(std::vector), "header", + fragment=SWIG_Traits_frag(T), + fragment="StdVectorTraits") { + namespace swig { + template <> struct traits > { + typedef value_category category; + static const char* type_name() { + return "std::vector<" #T " * >"; + } + }; + } + } + + %typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector); + + %std_vector_methods_val(vector); + %swig_vector_methods_val(std::vector); + }; + + // *** + // *** + template class vector { + 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), "header", + fragment=SWIG_Traits_frag(bool), + fragment="StdVectorTraits") { + namespace swig { + template <> struct traits > { + typedef value_category category; + static const char* type_name() { + return "std::vector"; + } + }; + } + } + + %typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector); + + %std_vector_methods_val(vector); + %swig_vector_methods_val(std::vector); + }; + +} diff --git a/SWIG/Lib/std/std_vectora.i b/SWIG/Lib/std/std_vectora.i new file mode 100644 index 000000000..27ea03500 --- /dev/null +++ b/SWIG/Lib/std/std_vectora.i @@ -0,0 +1,137 @@ +// +// std::vector +// +// +// 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 + +// 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 +// +// const declarations are used to guess the intent of the function being +// exported; therefore, the following rationale is applied: +// +// -- f(std::vector), f(const std::vector&): +// the parameter being read-only, either a sequence or a +// previously wrapped std::vector can be passed. +// -- f(std::vector&), f(std::vector*): +// the parameter may be modified; therefore, only a wrapped std::vector +// can be passed. +// -- std::vector f(), const std::vector& f(): +// the vector is returned by copy; therefore, a sequence of T:s +// is returned which is most easily used in other functions +// -- std::vector& f(), std::vector* f(): +// the vector is returned by reference; therefore, a wrapped std::vector +// is returned +// -- const std::vector* f(), f(const std::vector*): +// for consistency, they expect and return a plain vector pointer. +// ------------------------------------------------------------------------ + +%{ +#include +%} + +// exported classes + +namespace std { + + template > + 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), "header", + fragment=SWIG_Traits_frag(T), + fragment="StdVectorATraits") { + namespace swig { + template <> struct traits > { + typedef pointer_category category; + static const char* type_name() { + return "std::vector<" #T "," #A " >"; + } + }; + } + } + + %typemap_traits(SWIG_TYPECHECK_VECTOR, std::vector); + + %std_vector_methods(vector); + %swig_vector_methods(std::vector); + }; + + + // *** + // This pointer especialization should dissapears or get + // simplified when a 'const SWIGTYPE*&' can be be defined. + // *** + template > + 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 value_type reference; + typedef value_type const_reference; + + %traits_swigtype(T); + + %fragment(SWIG_Traits_frag(std::vector), "header", + fragment="StdVectorATraits") { + namespace swig { + template <> struct traits > { + typedef value_category category; + static const char* type_name() { + return "std::vector<" #T " *,"#A" >"; + } + }; + } + } + + %typemap_traits(SWIG_TYPECHECK_VECTOR, std::vector); + + %std_vector_methods_val(vector); + %swig_vector_methods_val(std::vector); + }; + + + // bool specialization + %extend vector > { + void flip() + { + self->flip(); + } + } +} +