adding more missing typemaps

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@7785 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Marcelo Matus 2005-11-03 11:11:21 +00:00
commit b301617976
7 changed files with 67 additions and 1 deletions

View file

@ -27,6 +27,11 @@ namespace std
%template(paircA2) pair<const int, const A*>;
%template(pairiiA) pair<int,pair<int, A*> >;
%template(pairiiAc) pair<int,const pair<int, A*> >;
%template() pair<PyObject *, PyObject *>;
%template(pymap) map<PyObject *, PyObject*>;
}

View file

@ -31,3 +31,11 @@ for k in m:
pm = li_std_map.pymap()
pm[1] = (1,2)
pm["foo"] = "hello"
for k in pm:
print pm[k]

View file

@ -121,3 +121,6 @@ std::vector<std::string> vecStr(std::vector<std::string> v) {
%pointer_class(int,PtrInt)
%array_functions(int,ArrInt)
%template(pyvector) std::vector<PyObject*>;

View file

@ -94,3 +94,10 @@ v = vecStr(["hello ", "world"])
if v[0] != 'hello world':
raise RuntimeError,"bad std::string+std::vector"
pv = pyvector([1, "hello", (1,2)])
if pv[1] != "hello":
raise RuntimeError

View file

@ -26,6 +26,27 @@
%fragment("PySequence_Base","header")
{
namespace swig {
template <> struct traits<PyObject *> {
typedef value_category category;
static const char* type_name() { return "PyObject *"; }
};
template <> struct traits_asval<PyObject * > {
typedef PyObject * value_type;
static int asval(PyObject *obj, value_type *val) {
if (val) *val = obj;
return SWIG_OK;
}
};
template <> struct traits_from<PyObject *> {
typedef PyObject * value_type;
static PyObject *from(const value_type& val) {
Py_XINCREF(val);
return val;
}
};
}
namespace swig {
inline size_t

View file

@ -73,6 +73,17 @@
%typemap(in,numinputs=0) PyObject **PYTHON_SELF "$1 = &obj0;";
/* For output, we increase the reference object */
%typemap(out,noblock=1) PyObject * {
Py_XINCREF($1);
$result = $1;
}
%typemap(out,noblock=1) PyObject * const & {
Py_XINCREF(*$1);
$result = *$1;
}
/* Consttab, needed for callbacks, it should be removed later */
%typemap(consttab) SWIGTYPE ((*)(ANY))
@ -82,3 +93,5 @@

View file

@ -3,11 +3,20 @@
* ------------------------------------------------------------ */
%typemap(in) SWIG_Object "$1 = $input;";
%typemap(freearg) SWIG_Object "";
%typemap(out,noblock=1) SWIG_Object {
%typemap(in) SWIG_Object const & "$1 = &$input;";
%typemap(freearg) SWIG_Object const & "";
%typemap(out,noblock=1) SWIG_Object {
$result = $1;
}
%typemap(out,noblock=1) SWIG_Object const & {
$result = *$1;
}
%typecheck(SWIG_TYPECHECK_POINTER) SWIG_Object "$1 = ($input != 0);";
%typemap(throws,noblock=1) SWIG_Object {