more docs/split and cleaning

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@6421 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Marcelo Matus 2004-10-18 00:31:24 +00:00
commit 09608bc2c5
9 changed files with 177 additions and 75 deletions

View file

@ -111,7 +111,7 @@ SWIGINTERNSHORT int
if (value > max_value) { if (value > max_value) {
if (errmsg) { if (errmsg) {
PyErr_Format(PyExc_OverflowError, PyErr_Format(PyExc_OverflowError,
"value %lud is greater than '%s' minimum %lud", "value %lu is greater than '%s' minimum %lu",
value, errmsg, max_value); value, errmsg, max_value);
} }
return 0; return 0;

View file

@ -95,12 +95,12 @@ namespace swig {
template <class Type> struct traits_asval<Type*> { template <class Type> struct traits_asval<Type*> {
static bool asval(PyObject *obj, Type **val) { static bool asval(PyObject *obj, Type **val) {
if (val) { if (val) {
Type *p = 0; typedef typename noconst_traits<Type>::noconst_type noconst_type;
int res = traits_asptr<Type>::asptr(obj, &p); noconst_type *p = 0;
if (res) { int res = traits_asptr<noconst_type>::asptr(obj, &p);
typedef typename noconst_traits<Type*>::noconst_type noconst_type; if (res) {
*(const_cast<noconst_type*>(val)) = p; *(const_cast<noconst_type**>(val)) = p;
return true; return true;
} else { } else {
return false; return false;
} }

View file

@ -137,8 +137,7 @@
%apply Char* { Char [] }; %apply Char* { Char [] };
%apply const Char* { const Char [] }; %apply const Char* { const Char [] };
%typemap(varin,fragment=#SWIG_AsCharArray, %typemap(varin,warning="462:Unable to set variable of type Char []") Char []
warning="462:Unable to set variable of type Char []") Char []
{ {
PyErr_SetString(PyExc_AttributeError, "C/C++ variable '$name' is read-only"); PyErr_SetString(PyExc_AttributeError, "C/C++ variable '$name' is read-only");
return 1; return 1;
@ -173,6 +172,12 @@
$1 = temp; $1 = temp;
} }
%typemap(in,fragment=#SWIG_AsCharArray) const Char (&)[ANY] (Char temp[$1_dim0])
{
if (!SWIG_AsCharArray($input, temp, $1_dim0)) {SWIG_arg_fail($argnum);SWIG_fail;}
$1 = &temp;
}
%typemap(out,fragment=#SWIG_FromCharArray) %typemap(out,fragment=#SWIG_FromCharArray)
Char [ANY], const Char[ANY] Char [ANY], const Char[ANY]
{ {

View file

@ -8,6 +8,12 @@
"SWIG_Python_ConvertPtr($input, (void **)&$1, $descriptor, SWIG_POINTER_EXCEPTION | $disown); "SWIG_Python_ConvertPtr($input, (void **)&$1, $descriptor, SWIG_POINTER_EXCEPTION | $disown);
if (SWIG_arg_fail($argnum)) SWIG_fail;"; if (SWIG_arg_fail($argnum)) SWIG_fail;";
%typemap(in) SWIGTYPE* const& ($*ltype temp)
"SWIG_Python_ConvertPtr($input, (void **)&temp, $*descriptor, SWIG_POINTER_EXCEPTION | $disown);
if (SWIG_arg_fail($argnum)) SWIG_fail;
$1 = &temp;
";
%typemap(in) SWIGTYPE *DISOWN %typemap(in) SWIGTYPE *DISOWN
"SWIG_Python_ConvertPtr($input, (void **)&$1, $descriptor, SWIG_POINTER_EXCEPTION | SWIG_POINTER_DISOWN); "SWIG_Python_ConvertPtr($input, (void **)&$1, $descriptor, SWIG_POINTER_EXCEPTION | SWIG_POINTER_DISOWN);
if (SWIG_arg_fail($argnum)) SWIG_fail;"; if (SWIG_arg_fail($argnum)) SWIG_fail;";
@ -22,14 +28,17 @@
if (SWIG_arg_fail($argnum)) SWIG_fail;"; if (SWIG_arg_fail($argnum)) SWIG_fail;";
/* Object passed by value. Convert to a pointer */ /* Object passed by value. Convert to a pointer */
%typemap(in) SWIGTYPE ($&ltype argp) %typemap(in) SWIGTYPE {
"SWIG_Python_ConvertPtr($input, (void **)&argp, $&descriptor, SWIG_POINTER_EXCEPTION); $&ltype argp;
SWIG_Python_ConvertPtr($input, (void **)&argp, $&descriptor, SWIG_POINTER_EXCEPTION);
if (SWIG_arg_fail($argnum)) SWIG_fail; if (SWIG_arg_fail($argnum)) SWIG_fail;
if (argp == NULL) { if (argp == NULL) {
SWIG_null_ref(SWIG_TypePrettyName($descriptor)); SWIG_null_ref(SWIG_TypePrettyName($&descriptor));
} }
if (SWIG_arg_fail($argnum)) SWIG_fail; if (SWIG_arg_fail($argnum)) SWIG_fail;
$1 = *argp;"; $1 = *argp;
}
/* Pointer to a class member */ /* Pointer to a class member */
%typemap(in) SWIGTYPE (CLASS::*) %typemap(in) SWIGTYPE (CLASS::*)
@ -46,7 +55,10 @@
/* Pointers, references, and arrays */ /* Pointers, references, and arrays */
%typemap(out) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] %typemap(out) SWIGTYPE *, SWIGTYPE &, SWIGTYPE []
"$result = SWIG_NewPointerObj((void*)($1), $1_descriptor, $owner);"; "$result = SWIG_NewPointerObj((void*)($1), $descriptor, $owner);";
%typemap(out) SWIGTYPE* const&
"$result = SWIG_NewPointerObj((void*)(*$1), $*descriptor, $owner);";
/* Dynamic casts */ /* Dynamic casts */
@ -57,23 +69,23 @@
/* Member pointer */ /* Member pointer */
%typemap(out) SWIGTYPE (CLASS::*) %typemap(out) SWIGTYPE (CLASS::*)
"$result = SWIG_NewPackedObj((void*)(&$1), sizeof($1_type), $1_descriptor);"; "$result = SWIG_NewPackedObj((void*)(&$1), sizeof($type), $descriptor);";
/* Primitive types--return by value */ /* Primitive types--return by value */
#ifdef __cplusplus #ifdef __cplusplus
%typemap(out) SWIGTYPE %typemap(out) SWIGTYPE
{ {
$&1_ltype resultptr; $&1_ltype resultptr;
resultptr = new $1_ltype(static_cast<$1_type &>($1)); resultptr = new $ltype(SWIG_static_cast($1,$type &));
$result = SWIG_NewPointerObj((void *)(resultptr), $&1_descriptor, 1); $result = SWIG_NewPointerObj((void *)(resultptr), $&descriptor, 1);
} }
#else #else
%typemap(out /* warning="452:Default return typemap could be unsafe" */) SWIGTYPE %typemap(out /* warning="452:Default return typemap could be unsafe" */) SWIGTYPE
{ {
$&1_ltype resultptr; $&ltype resultptr;
resultptr = ($&1_ltype) malloc(sizeof($1_type)); resultptr = ($&ltype) malloc(sizeof($type));
memmove(resultptr, &$1, sizeof($1_type)); memmove(resultptr, &$1, sizeof($type));
$result = SWIG_NewPointerObj((void *)(resultptr), $&1_descriptor, 1); $result = SWIG_NewPointerObj((void *)(resultptr), $&descriptor, 1);
} }
#endif #endif
@ -99,13 +111,19 @@
%typemap(varin) SWIGTYPE * { %typemap(varin) SWIGTYPE * {
void *temp; void *temp;
if ((SWIG_ConvertPtr($input, &temp, $1_descriptor, SWIG_POINTER_EXCEPTION | SWIG_POINTER_DISOWN)) == -1) { if ((SWIG_ConvertPtr($input, &temp, $descriptor, SWIG_POINTER_EXCEPTION | SWIG_POINTER_DISOWN)) == -1) {
SWIG_append_errmsg("C/C++ variable '$name'"); SWIG_append_errmsg("C/C++ variable '$name'");
return 1; return 1;
} }
$1 = ($ltype) temp; $1 = ($ltype) temp;
} }
%typemap(varin,warning="462:Unable to set dimensionless array variable") SWIGTYPE []
{
PyErr_SetString(PyExc_AttributeError, "C/C++ variable '$name' is read-only");
return 1;
}
%typemap(varin) SWIGTYPE & { %typemap(varin) SWIGTYPE & {
void *temp; void *temp;
if ((SWIG_ConvertPtr($input, &temp, $descriptor, SWIG_POINTER_EXCEPTION)) == -1 || temp == NULL) { if ((SWIG_ConvertPtr($input, &temp, $descriptor, SWIG_POINTER_EXCEPTION)) == -1 || temp == NULL) {
@ -191,7 +209,8 @@
* --- Typechecking rules --- * --- Typechecking rules ---
* ------------------------------------------------------------ */ * ------------------------------------------------------------ */
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] %typecheck(SWIG_TYPECHECK_POINTER)
SWIGTYPE *, SWIGTYPE &, SWIGTYPE []
{ {
void *ptr; void *ptr;
if (SWIG_ConvertPtr($input, &ptr, $descriptor, 0) == -1) { if (SWIG_ConvertPtr($input, &ptr, $descriptor, 0) == -1) {

View file

@ -22,7 +22,7 @@
/* out */ /* out */
%define PYVAL_OUT_TYPEMAP(from_meth,pyfrag,Type...) %define PYVAL_OUT_TYPEMAP(from_meth,pyfrag,Type...)
%typemap(out,fragment=pyfrag) Type %typemap(out,fragment=pyfrag) Type, const Type
{ $result = from_meth(SWIG_static_cast($1,$basetype)); } { $result = from_meth(SWIG_static_cast($1,$basetype)); }
%typemap(out,fragment=pyfrag) const Type& %typemap(out,fragment=pyfrag) const Type&

View file

@ -10,8 +10,8 @@
} }
} }
%typemap(in) const void *& ($basetype temp) { %typemap(in) const void *& ($*ltype temp) {
SWIG_ConvertPtr($input,SWIG_reinterpret_cast(&temp,void **),0,SWIG_POINTER_EXCEPTION|$disown); SWIG_ConvertPtr($input,(void **)&temp,0,SWIG_POINTER_EXCEPTION|$disown);
if (SWIG_arg_fail($argnum)) SWIG_fail; if (SWIG_arg_fail($argnum)) SWIG_fail;
$1 = &temp; $1 = &temp;
} }

View file

@ -1,4 +1,97 @@
#if !defined(SWIG_STD_STRING) && !defined(SWIG_STD_WSTRING)
#define SWIG_STD_BASIC_STRING
%include <pycontainer.swg> %include <pycontainer.swg>
#define %swig_basic_string(Type...) %swig_sequence_methods_val(Type) #define %swig_basic_string(Type...) %swig_sequence_methods_val(Type)
%fragment(SWIG_AsPtr_frag(std::basic_string<char>),"header",
fragment="SWIG_AsCharPtrAndSize") {
SWIGINTERN int
SWIG_AsPtr(std::basic_string<char>)(PyObject* obj, std::string **val)
{
static swig_type_info* string_info =
SWIG_TypeQuery("std::basic_string<char> *");
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::basic_string<char>),"header",
fragment="SWIG_FromCharArray") {
SWIGINTERNSHORT PyObject*
SWIG_From(std::basic_string<char>)(const std::string& s)
{
return SWIG_FromCharArray(s.data(), s.size());
}
}
%fragment(SWIG_AsPtr_frag(std::basic_string<wchar_t>),"header",
fragment="SWIG_AsWCharPtrAndSize") {
SWIGINTERN int
SWIG_AsPtr(std::basic_string<wchar_t>)(PyObject* obj, std::wstring **val)
{
static swig_type_info* string_info =
SWIG_TypeQuery("std::basic_string<wchar_t> *");
std::wstring *vptr;
if (SWIG_ConvertPtr(obj, (void**)&vptr, string_info, 0) != -1) {
if (val) *val = vptr;
return SWIG_OLDOBJ;
} else {
PyErr_Clear();
wchar_t *buf = 0 ; size_t size = 0;
int res = 0;
if ((res = SWIG_AsWCharPtrAndSize(obj, &buf, &size))) {
if (buf) {
if (val) *val = new std::wstring(buf, size - 1);
if (res == SWIG_NEWOBJ) SWIG_delete_array(buf);
return SWIG_NEWOBJ;
}
} else {
PyErr_Clear();
}
if (val) {
PyErr_SetString(PyExc_TypeError,"a wstring is expected");
}
return 0;
}
}
}
%fragment(SWIG_From_frag(std::basic_string<wchar_t>),"header",
fragment="SWIG_FromWCharArray") {
SWIGINTERNSHORT PyObject*
SWIG_From(std::basic_string<wchar_t>)(const std::wstring& s)
{
return SWIG_FromWCharArray(s.data(), s.size());
}
}
%include <std/std_basic_string.i> %include <std/std_basic_string.i>
%typemap_asptrfromn(SWIG_CCode(STRING), std::basic_string<char>);
%typemap_asptrfromn(SWIG_CCode(UNISTRING), std::basic_string<wchar_t>);
#endif

View file

@ -2,24 +2,25 @@
// std::string // std::string
// //
#ifndef SWIG_STD_BASIC_STRING
#define SWIG_STD_STRING
%include <pystrings.swg> %include <pystrings.swg>
%include <std_basic_string.i>
/* plain strings */
namespace std namespace std
{ {
%std_comp_methods(basic_string<char>); %feature("novaluewrapper") string;
typedef basic_string<char> string; class string;
} }
/* defining the std::string asptr/from methods */ /* defining the std::string asptr/from methods */
%fragment(SWIG_AsPtr_frag(std::basic_string<char>),"header",
%fragment(SWIG_AsPtr_frag(std::string),"header",
fragment="SWIG_AsCharPtrAndSize") { fragment="SWIG_AsCharPtrAndSize") {
SWIGINTERN int SWIGINTERN int
SWIG_AsPtr(std::basic_string<char>)(PyObject* obj, std::string **val) SWIG_AsPtr(std::string)(PyObject* obj, std::string **val)
{ {
static swig_type_info* string_info = SWIG_TypeQuery("std::string *"); static swig_type_info* string_info = SWIG_TypeQuery("std::string *");
std::string *vptr; std::string *vptr;
@ -43,37 +44,24 @@ namespace std
return 0; return 0;
} }
} }
SWIGINTERNSHORT int
SWIG_AsPtr(std::string)(PyObject* obj, std::string **val)
{
return SWIG_AsPtr(std::basic_string<char>)(obj, val);
}
} }
%fragment(SWIG_From_frag(std::basic_string<char>),"header", %fragment(SWIG_From_frag(std::string),"header",
fragment="SWIG_FromCharArray") { fragment="SWIG_FromCharArray") {
SWIGINTERNSHORT PyObject*
SWIG_From(std::basic_string<char>)(const std::string& s)
{
return SWIG_FromCharArray(s.data(), s.size());
}
SWIGINTERNSHORT PyObject* SWIGINTERNSHORT PyObject*
SWIG_From(std::string)(const std::string& s) SWIG_From(std::string)(const std::string& s)
{ {
return SWIG_From(std::basic_string<char>)(s); return SWIG_FromCharArray(s.data(), s.size());
} }
} }
%fragment(SWIG_AsVal_frag(std::string),"header", %fragment(SWIG_AsVal_frag(std::string),"header",
fragment=SWIG_AsPtr_frag(std::basic_string<char>)) { fragment=SWIG_AsPtr_frag(std::string)) {
SWIGINTERN int SWIGINTERN int
SWIG_AsVal(std::string)(PyObject* obj, std::string *val) SWIG_AsVal(std::string)(PyObject* obj, std::string *val)
{ {
std::string* s; std::string* s;
int res = SWIG_AsPtr(std::basic_string<char>)(obj, &s); int res = SWIG_AsPtr(std::string)(obj, &s);
if (res && s) { if (res && s) {
if (val) *val = *s; if (val) *val = *s;
if (res == SWIG_NEWOBJ) delete s; if (res == SWIG_NEWOBJ) delete s;
@ -86,6 +74,10 @@ SWIGINTERN int
} }
} }
%typemap_asptrfromn(SWIG_CCode(STRING), std::basic_string<char>);
%typemap_asptrfromn(SWIG_CCode(STRING), std::string); %typemap_asptrfromn(SWIG_CCode(STRING), std::string);
#else
%include <std/std_string.i>
#endif

View file

@ -2,24 +2,23 @@
// std::wstring // std::wstring
// //
#ifndef SWIG_STD_BASIC_STRING
#define SWIG_STD_WSTRING
%include <pywstrings.swg> %include <pywstrings.swg>
%include <std_basic_string.i>
/* wide strings */
namespace std namespace std
{ {
%std_comp_methods(basic_string<wchar_t>); %feature("novaluewrapper") wstring;
typedef basic_string<wchar_t> wstring; class wstring;
} }
/* defining the std::string asptr/from methods */ /* defining the std::string asptr/from methods */
%fragment(SWIG_AsPtr_frag(std::basic_string<wchar_t>),"header", %fragment(SWIG_AsPtr_frag(std::wstring),"header",
fragment="SWIG_AsWCharPtrAndSize") { fragment="SWIG_AsWCharPtrAndSize") {
SWIGINTERN int SWIGINTERN int
SWIG_AsPtr(std::basic_string<wchar_t>)(PyObject* obj, std::wstring **val) SWIG_AsPtr(std::wstring)(PyObject* obj, std::wstring **val)
{ {
static swig_type_info* string_info = SWIG_TypeQuery("std::wstring *"); static swig_type_info* string_info = SWIG_TypeQuery("std::wstring *");
std::wstring *vptr; std::wstring *vptr;
@ -46,36 +45,25 @@ SWIGINTERN int
} }
} }
SWIGINTERNSHORT int
SWIG_AsPtr(std::wstring)(PyObject* obj, std::wstring **val)
{
return SWIG_AsPtr(std::basic_string<wchar_t>)(obj, val);
}
} }
%fragment(SWIG_From_frag(std::basic_string<wchar_t>),"header", %fragment(SWIG_From_frag(std::wstring),"header",
fragment="SWIG_FromWCharArray") { fragment="SWIG_FromWCharArray") {
SWIGINTERNSHORT PyObject*
SWIG_From(std::basic_string<wchar_t>)(const std::wstring& s)
{
return SWIG_FromWCharArray(s.data(), s.size());
}
SWIGINTERNSHORT PyObject* SWIGINTERNSHORT PyObject*
SWIG_From(std::wstring)(const std::wstring& s) SWIG_From(std::wstring)(const std::wstring& s)
{ {
return SWIG_From(std::basic_string<wchar_t>)(s); return SWIG_FromWCharArray(s.data(), s.size());
} }
} }
%fragment(SWIG_AsVal_frag(std::wstring),"header", %fragment(SWIG_AsVal_frag(std::wstring),"header",
fragment=SWIG_AsPtr_frag(std::basic_string<wchar_t>)) { fragment=SWIG_AsPtr_frag(std::wstring)) {
SWIGINTERN int SWIGINTERN int
SWIG_AsVal(std::wstring)(PyObject* obj, std::wstring *val) SWIG_AsVal(std::wstring)(PyObject* obj, std::wstring *val)
{ {
std::wstring *s; std::wstring *s;
int res = SWIG_AsPtr(std::basic_string<wchar_t>)(obj, &s); int res = SWIG_AsPtr(std::wstring)(obj, &s);
if (res && s) { if (res && s) {
if (val) *val = *s; if (val) *val = *s;
if (res == SWIG_NEWOBJ) delete s; if (res == SWIG_NEWOBJ) delete s;
@ -88,5 +76,10 @@ SWIGINTERN int
} }
} }
%typemap_asptrfromn(SWIG_CCode(UNISTRING), std::basic_string<wchar_t>);
%typemap_asptrfromn(SWIG_CCode(UNISTRING), std::wstring); %typemap_asptrfromn(SWIG_CCode(UNISTRING), std::wstring);
#else
%include <std/std_wstring.i>
#endif