Perl added to the Unified typemap library, cleaner way to use the library, and 'normalized' macro names

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@7707 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Marcelo Matus 2005-10-24 14:59:05 +00:00
commit 3c65cea431
112 changed files with 3262 additions and 3375 deletions

View file

@ -2,68 +2,89 @@
* Value typemaps (Type, const Type&) for value types, such as
* fundamental types (int, double), that define the AsVal/From
* methods.
*
* To apply them, just use one of the following macros:
*
* %typemaps_from(FromMeth, FromFrag, Type)
* %typemaps_asval(CheckCode, AsValMeth, AsValFrag, Type)
* %typemaps_asvalfrom(CheckCode, AsValMeth, FromMeth, AsValFrag, FromFrag, Type)
*
* or the simpler and normalize form:
*
* %typemaps_asvalfromn(CheckCode, Type)
*
* Also, you can use the individual typemap definitions:
*
* %value_in_typemap(asval_meth,frag,Type)
* %value_varin_typemap(asval_meth,frag,Type)
* %value_typecheck_typemap(checkcode,asval_meth,frag,Type)
* %value_directorout_typemap(asval_meth,frag,Type)
*
* %value_out_typemap(from_meth,frag,Type)
* %value_varout_typemap(from_meth,frag,Type)
* %value_constcode_typemap(from_meth,frag,Type)
* %value_directorin_typemap(from_meth,frag,Type)
* %value_throws_typemap(from_meth,frag,Type)
*
*---------------------------------------------------------------------*/
/* in */
%define SWIG_VALUE_IN_TYPEMAP(asval_meth,frag,Type...)
%define %value_in_typemap(asval_meth,frag,Type...)
%typemap(in,noblock=1,fragment=frag) Type (Type val, int ecode = 0) {
ecode = asval_meth($input, &val);
if (ecode != SWIG_OK) {
SWIG_arg_fail(ecode, "$ltype", $argnum);
} else {
$1 = SWIG_static_cast(val,$ltype);
}
%argument_fail(ecode, "$ltype", $argnum);
}
$1 = %static_cast(val,$ltype);
}
%typemap(in,noblock=1,fragment=frag) const Type & ($*ltype temp, Type val, int ecode = 0) {
ecode = asval_meth($input, &val);
if (ecode != SWIG_OK) {
SWIG_arg_fail(ecode, "$*ltype", $argnum);
} else {
temp = SWIG_static_cast(val, $*ltype);
$1 = &temp;
}
%argument_fail(ecode, "$*ltype", $argnum);
}
temp = %static_cast(val, $*ltype);
$1 = &temp;
}
%enddef
/* out */
%define SWIG_VALUE_OUT_TYPEMAP(from_meth,frag,Type...)
%define %value_out_typemap(from_meth,frag,Type...)
%typemap(out,noblock=1,fragment=frag) Type, const Type {
SWIG_set_result(from_meth(SWIG_static_cast($1,Type)));
%set_output(from_meth(%static_cast($1,Type)));
}
%typemap(out,noblock=1,fragment=frag) const Type& {
SWIG_set_result(from_meth(SWIG_static_cast(*$1,Type)));
%set_output(from_meth(%static_cast(*$1,Type)));
}
%enddef
/* varin */
%define SWIG_VALUE_VARIN_TYPEMAP(asval_meth,frag,Type...)
%define %value_varin_typemap(asval_meth,frag,Type...)
%typemap(varin,noblock=1,fragment=frag) Type {
Type val;
int res = asval_meth($input, &val);
if (res != SWIG_OK) {
SWIG_var_fail(res, "$type", "$name");
} else {
$1 = SWIG_static_cast(val,$ltype);
%variable_fail(res, "$type", "$name");
}
$1 = %static_cast(val,$ltype);
}
%enddef
/* varout */
%define SWIG_VALUE_VAROUT_TYPEMAP(from_meth,frag,Type...)
%define %value_varout_typemap(from_meth,frag,Type...)
%typemap(varout,noblock=1,fragment=frag) Type, const Type& {
$result = from_meth(SWIG_static_cast($1,$basetype));
%set_varoutput(from_meth(%static_cast($1,$basetype)));
}
%enddef
/* constant installation code */
%define SWIG_VALUE_CONSTCODE_TYPEMAP(from_meth,frag,Type...)
%define %value_constcode_typemap(from_meth,frag,Type...)
%typemap(constcode,noblock=1,fragment=frag) Type {
SWIG_set_constant("$symname", from_meth(SWIG_static_cast($value,Type)));
%set_constant("$symname", from_meth(%static_cast($value,Type)));
}
%enddef
@ -72,41 +93,41 @@
/* directorin */
%define SWIG_VALUE_DIRECTORIN_TYPEMAP(from_meth,frag,Type...)
%define %value_directorin_typemap(from_meth,frag,Type...)
%typemap(directorin,noblock=1,fragment=frag) Type *DIRECTORIN {
$input = from_meth(SWIG_static_cast(*$1_name,Type));
$input = from_meth(%static_cast(*$1_name,Type));
}
%typemap(directorin,noblock=1,fragment=frag) Type, const Type& {
$input = from_meth(SWIG_static_cast($1_name,Type));
$input = from_meth(%static_cast($1_name,Type));
}
%enddef
/* directorout */
%define SWIG_VALUE_DIRECTOROUT_TYPEMAP(asval_meth,frag,Type...)
%define %value_directorout_typemap(asval_meth,frag,Type...)
%typemap(directorargout,noblock=1,fragment=frag) Type *DIRECTOROUT {
Type val;
int res = asval_meth($input, &val);
if (res != SWIG_OK) {
SWIG_dout_fail(res, "$type");
%dirout_fail(res, "$type");
}
*$result = SWIG_static_cast(val, $type);
*$result = %static_cast(val, $type);
}
%typemap(directorout,noblock=1,fragment=frag) Type {
Type val;
int res = asval_meth($input, &val);
if (res != SWIG_OK) {
SWIG_dout_fail(res, "$type");
%dirout_fail(res, "$type");
}
$result = SWIG_static_cast(val,$type);
$result = %static_cast(val,$type);
}
%typemap(directorout,noblock=1,fragment=frag,warning=SWIG_WARN_TYPEMAP_THREAD_UNSAFE) const Type& {
Type val;
int res = asval_meth($input, &val);
if (res != SWIG_OK) {
SWIG_dout_fail(res, "$type");
%dirout_fail(res, "$type");
}
static $basetype temp = SWIG_static_cast(val, $basetype);
static $basetype temp = %static_cast(val, $basetype);
$result = &temp;
}
%typemap(directorout,fragment=frag) Type &DIRECTOROUT = Type
@ -114,23 +135,23 @@
#else
#define SWIG_VALUE_DIRECTORIN_TYPEMAP(from_meth,frag,Type...)
#define SWIG_VALUE_DIRECTOROUT_TYPEMAP(asval_meth,frag,Type...)
#define %value_directorin_typemap(from_meth,frag,Type...)
#define %value_directorout_typemap(asval_meth,frag,Type...)
#endif /* SWIG_DIRECTOR_TYPEMAPS */
/* throws */
%define SWIG_VALUE_THROWS_TYPEMAP(from_meth,frag,Type...)
%define %value_throws_typemap(from_meth,frag,Type...)
%typemap(throws,noblock=1,fragment=frag) Type {
SWIG_raise(from_meth(SWIG_static_cast($1,Type)), "$type", 0);
%raise(from_meth(%static_cast($1,Type)), "$type", 0);
}
%enddef
/* typecheck */
%define SWIG_VALUE_TYPECHECK_TYPEMAP(check,asval_meth,frag,Type...)
%define %value_typecheck_typemap(check,asval_meth,frag,Type...)
%typemap(typecheck,noblock=1,precedence=check,fragment=frag) Type, const Type& {
$1 = (asval_meth($input, 0) == SWIG_OK);
}
@ -139,25 +160,25 @@
/*---------------------------------------------------------------------
* typemap definition for types with AsVal methods
*---------------------------------------------------------------------*/
%define %typemap_asval(CheckCode, AsValMeth, AsValFrag, Type...)
SWIG_VALUE_IN_TYPEMAP(SWIG_arg(AsValMeth), SWIG_arg(AsValFrag), Type);
SWIG_VALUE_VARIN_TYPEMAP(SWIG_arg(AsValMeth), SWIG_arg(AsValFrag), Type);
SWIG_VALUE_DIRECTOROUT_TYPEMAP(SWIG_arg(AsValMeth), SWIG_arg(AsValFrag), Type);
SWIG_VALUE_TYPECHECK_TYPEMAP(SWIG_arg(CheckCode), SWIG_arg(AsValMeth), SWIG_arg(AsValFrag), Type);
SWIG_VALUE_INPUT_TYPEMAP(SWIG_arg(CheckCode), SWIG_arg(AsValMeth), SWIG_arg(AsValFrag), Type);
%define %typemaps_asval(CheckCode, AsValMeth, AsValFrag, Type...)
%value_in_typemap(%arg(AsValMeth), %arg(AsValFrag), Type);
%value_varin_typemap(%arg(AsValMeth), %arg(AsValFrag), Type);
%value_directorout_typemap(%arg(AsValMeth), %arg(AsValFrag), Type);
%value_typecheck_typemap(%arg(CheckCode), %arg(AsValMeth), %arg(AsValFrag), Type);
%value_input_typemap(%arg(CheckCode), %arg(AsValMeth), %arg(AsValFrag), Type);
%enddef
/*---------------------------------------------------------------------
* typemap definition for types with from method
*---------------------------------------------------------------------*/
%define %typemap_from(FromMeth, FromFrag, Type...)
SWIG_VALUE_OUT_TYPEMAP(SWIG_arg(FromMeth), SWIG_arg(FromFrag), Type);
SWIG_VALUE_VAROUT_TYPEMAP(SWIG_arg(FromMeth), SWIG_arg(FromFrag), Type);
SWIG_VALUE_CONSTCODE_TYPEMAP(SWIG_arg(FromMeth), SWIG_arg(FromFrag), Type);
SWIG_VALUE_DIRECTORIN_TYPEMAP(SWIG_arg(FromMeth), SWIG_arg(FromFrag), Type);
SWIG_VALUE_THROWS_TYPEMAP(SWIG_arg(FromMeth), SWIG_arg(FromFrag), Type);
SWIG_VALUE_OUTPUT_TYPEMAP(SWIG_arg(FromMeth), SWIG_arg(FromFrag), Type);
%define %typemaps_from(FromMeth, FromFrag, Type...)
%value_out_typemap(%arg(FromMeth), %arg(FromFrag), Type);
%value_varout_typemap(%arg(FromMeth), %arg(FromFrag), Type);
%value_constcode_typemap(%arg(FromMeth), %arg(FromFrag), Type);
%value_directorin_typemap(%arg(FromMeth), %arg(FromFrag), Type);
%value_throws_typemap(%arg(FromMeth), %arg(FromFrag), Type);
%value_output_typemap(%arg(FromMeth), %arg(FromFrag), Type);
%enddef
@ -165,22 +186,22 @@
* typemap definition for types with alval/from method
*---------------------------------------------------------------------*/
%define %typemap_asvalfrom(CheckCode, AsValMeth, FromMeth,
%define %typemaps_asvalfrom(CheckCode, AsValMeth, FromMeth,
AsValFrag, FromFrag, Type...)
%typemap_asval(SWIG_arg(CheckCode), SWIG_arg(AsValMeth), SWIG_arg(AsValFrag), Type);
%typemap_from(SWIG_arg(FromMeth), SWIG_arg(FromFrag), Type);
SWIG_VALUE_INOUT_TYPEMAP(Type);
%typemaps_asval(%arg(CheckCode), %arg(AsValMeth), %arg(AsValFrag), Type);
%typemaps_from(%arg(FromMeth), %arg(FromFrag), Type);
%value_inout_typemap(Type);
%enddef
/*---------------------------------------------------------------------
* typemap definition for types with for 'normalized' asval/from methods
*---------------------------------------------------------------------*/
%define %typemap_asvalfromn(CheckCode, Type...)
%typemap_asvalfrom(SWIG_arg(CheckCode),
%define %typemaps_asvalfromn(CheckCode, Type...)
%typemaps_asvalfrom(%arg(CheckCode),
SWIG_AsVal(Type),
SWIG_From(Type),
SWIG_arg(SWIG_AsVal_frag(Type)),
SWIG_arg(SWIG_From_frag(Type)),
%arg(SWIG_AsVal_frag(Type)),
%arg(SWIG_From_frag(Type)),
Type);
%enddef