isolate language independent STD/STL/C++ code + more documentation + cleaning

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@6382 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Marcelo Matus 2004-10-10 06:42:15 +00:00
commit dc4409a1f1
50 changed files with 3502 additions and 3408 deletions

View file

@ -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