massive typemap unification

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@7676 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Marcelo Matus 2005-10-18 13:24:15 +00:00
commit 7e5e4fd1f9
144 changed files with 6378 additions and 7248 deletions

View file

@ -8,74 +8,18 @@
%{
#include <string>
%}
%include <pystrings.swg>
namespace std
{
class string;
}
%include <typemaps/std_string.swg>
%include <pystrings.swg>
/* defining the std::string asptr/from methods */
%fragment(SWIG_AsPtr_frag(std::string),"header",
fragment="SWIG_AsCharPtrAndSize") {
SWIGINTERN int
SWIG_AsPtr(std::string)(PyObject* obj, std::string **val)
{
static swig_type_info* string_info = SWIG_TypeQuery("std::string *");
std::string *vptr;
if (SWIG_ConvertPtr(obj, (void**)&vptr, string_info, 0) != -1) {
if (val) *val = vptr;
return SWIG_OLDOBJ;
} else {
PyErr_Clear();
char* buf = 0 ; size_t size = 0;
if (SWIG_AsCharPtrAndSize(obj, &buf, &size)) {
if (buf) {
if (val) *val = new std::string(buf, size - 1);
return SWIG_NEWOBJ;
}
} else {
PyErr_Clear();
}
if (val) {
PyErr_SetString(PyExc_TypeError,"a string is expected");
}
return 0;
}
}
}
%fragment(SWIG_From_frag(std::string),"header",
fragment="SWIG_FromCharArray") {
SWIGINTERNINLINE PyObject*
SWIG_From(std::string)(const std::string& s)
{
return SWIG_FromCharArray(s.data(), s.size());
}
}
%fragment(SWIG_AsVal_frag(std::string),"header",
fragment=SWIG_AsPtr_frag(std::string)) {
SWIGINTERN int
SWIG_AsVal(std::string)(PyObject* obj, std::string *val)
{
std::string* s;
int res = SWIG_AsPtr(std::string)(obj, &s);
if ((res != 0) && s) {
if (val) *val = *s;
if (res == SWIG_NEWOBJ) delete s;
return res;
}
if (val) {
PyErr_SetString(PyExc_TypeError,"a string is expected");
}
return 0;
}
}
%std_string_asptr(std::string, char, SWIG_AsCharPtrAndSize)
%std_string_from(std::string, SWIG_FromCharPtrAndSize)
%std_string_asval(std::string)
%typemap_asptrfromn(SWIG_CCode(STRING), std::string);