added wchar_t type
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@5835 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
de65a09e6c
commit
8a2343f31d
5 changed files with 45 additions and 9 deletions
|
|
@ -18,8 +18,6 @@ SWIG_define(SWIG_From(int), PyInt_FromLong);
|
|||
SWIG_define(SWIG_From(long), PyInt_FromLong);
|
||||
SWIG_define(SWIG_From(float), PyFloat_FromDouble);
|
||||
SWIG_define(SWIG_From(double), PyFloat_FromDouble);
|
||||
SWIG_define(SWIG_From(float), PyFloat_FromDouble);
|
||||
SWIG_define(SWIG_From(double), PyFloat_FromDouble);
|
||||
}
|
||||
|
||||
%fragment("<limits.h>","header") %{
|
||||
|
|
@ -499,6 +497,38 @@ SWIGSTATICINLINE(int)
|
|||
}
|
||||
}
|
||||
|
||||
%fragment(SWIG_From_frag(wchar_t),"header") {
|
||||
SWIGSTATICINLINE(PyObject*)
|
||||
SWIG_From(wchar_t)(wchar_t c)
|
||||
{
|
||||
return PyUnicode_FromWideChar(&c, 1);
|
||||
}
|
||||
}
|
||||
|
||||
%fragment(SWIG_AsVal_frag(wchar_t),"header",
|
||||
fragment="SWIG_AsWCharArray",
|
||||
fragment="SWIG_CheckLongInRange",
|
||||
fragment=SWIG_AsVal_frag(long)) {
|
||||
#include <wchar.h>
|
||||
SWIGSTATICINLINE(int)
|
||||
SWIG_AsVal(wchar_t)(PyObject *obj, wchar_t *val)
|
||||
{
|
||||
const char* errmsg = val ? "wchar_t" : 0;
|
||||
long v;
|
||||
if (SWIG_AsVal(long)(obj, &v)) {
|
||||
if (SWIG_CheckLongInRange(v, WCHAR_MIN, WCHAR_MAX, errmsg)) {
|
||||
if (val) *val = v;
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
PyErr_Clear();
|
||||
return SWIG_AsWCharArray(obj, val, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
%fragment(SWIG_From_frag(bool),"header") {
|
||||
SWIGSTATICINLINE(PyObject*)
|
||||
SWIG_From(bool)(bool value)
|
||||
|
|
@ -529,7 +559,7 @@ SWIGSTATICINLINE(int)
|
|||
return 1;
|
||||
}
|
||||
if (val) {
|
||||
PyErr_SetString(PyExc_TypeError, "a float is expected");
|
||||
PyErr_SetString(PyExc_TypeError, "a bool is expected");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -576,6 +606,7 @@ _apply_macro(Macro, unsigned long long , __VA_ARGS__);
|
|||
_apply_macro(Macro, float , __VA_ARGS__);
|
||||
_apply_macro(Macro, double , __VA_ARGS__);
|
||||
_apply_macro(Macro, char , __VA_ARGS__);
|
||||
_apply_macro(Macro, wchar_t , __VA_ARGS__);
|
||||
%enddef
|
||||
|
||||
/* apply the Macro(Type) to all the C++ types */
|
||||
|
|
@ -606,6 +637,7 @@ Macro(SWIG_CCode(UINT128), unsigned long long);
|
|||
Macro(SWIG_CCode(FLOAT), float);
|
||||
Macro(SWIG_CCode(DOUBLE), double);
|
||||
Macro(SWIG_CCode(CHAR), char);
|
||||
Macro(SWIG_CCode(UNICHAR), wchar_t);
|
||||
%enddef
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@
|
|||
%include "pyvoid.swg"
|
||||
%include "pyobject.swg"
|
||||
%include "pystrings.swg"
|
||||
%include "pywstrings.swg"
|
||||
%include "pyvaltypes.swg"
|
||||
%include "pyptrtypes.swg"
|
||||
%include "pyprimtypes.swg"
|
||||
|
|
|
|||
|
|
@ -241,7 +241,7 @@ SWIG_FromWCharArray(const wchar_t * carray, size_t size)
|
|||
|
||||
/* typecheck */
|
||||
|
||||
%typemap(typecheck,precedence=SWIG_TYPECHECK_STRING,
|
||||
%typemap(typecheck,precedence=SWIG_TYPECHECK_UNISTRING,
|
||||
fragment="SWIG_AsWCharPtr")
|
||||
wchar_t *, wchar_t const*, wchar_t *const, wchar_t const *const,
|
||||
wchar_t const*&, wchar_t *const&, wchar_t const *const &
|
||||
|
|
@ -335,7 +335,7 @@ SWIG_FromWCharArray(const wchar_t * carray, size_t size)
|
|||
|
||||
/* typecheck */
|
||||
|
||||
%typemap(typecheck,precedence=SWIG_TYPECHECK_STRING,
|
||||
%typemap(typecheck,precedence=SWIG_TYPECHECK_UNISTRING,
|
||||
fragment="SWIG_AsWCharArray")
|
||||
wchar_t [ANY], const wchar_t[ANY]
|
||||
{
|
||||
|
|
|
|||
|
|
@ -465,8 +465,6 @@ namespace swigpy {
|
|||
%swig_equal_type(std::complex<double>);
|
||||
|
||||
/* the operators <,>,<=,=> can used with these types */
|
||||
%swig_order_type(std::string);
|
||||
%swig_order_type(std::basic_string<char>);
|
||||
%swig_order_type(signed char);
|
||||
%swig_order_type(unsigned char);
|
||||
%swig_order_type(short);
|
||||
|
|
@ -480,6 +478,11 @@ namespace swigpy {
|
|||
%swig_order_type(float);
|
||||
%swig_order_type(double);
|
||||
%swig_order_type(char);
|
||||
%swig_order_type(wchar_t);
|
||||
%swig_order_type(std::string);
|
||||
%swig_order_type(std::basic_string<char>);
|
||||
%swig_order_type(std::wstring);
|
||||
%swig_order_type(std::basic_string<wchar_t>);
|
||||
|
||||
//
|
||||
// Backward compatibility
|
||||
|
|
|
|||
|
|
@ -82,5 +82,5 @@ SWIGSTATICINLINE(int)
|
|||
}
|
||||
}
|
||||
|
||||
%typemap_asptrfromn(SWIG_CCode(STRING), std::basic_string<wchar_t>);
|
||||
%typemap_asptrfromn(SWIG_CCode(STRING), std::wstring);
|
||||
%typemap_asptrfromn(SWIG_CCode(UNISTRING), std::basic_string<wchar_t>);
|
||||
%typemap_asptrfromn(SWIG_CCode(UNISTRING), std::wstring);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue