More flexible variable wrappers (C# properties). The property set can now support a different type to that used in the intermediary layer. This is achieved by using a temporary variable and specifying the name of the temporary variable in a new 'valueparm' attribute in the csvarin typemap. Also Fix bug reported by Glenn A Watson and #1795260 where the cstype typemap used the 'ref' keyword in the typemap body. The type for the property now correctly comes from the 'out' attribute in the cstype typemap.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@9946 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
0798630f72
commit
d737022daa
3 changed files with 42 additions and 10 deletions
|
|
@ -19,7 +19,7 @@ public class runme
|
||||||
initialLetters.Append(myChar);
|
initialLetters.Append(myChar);
|
||||||
if (initialLetters.ToString() != "bhox")
|
if (initialLetters.ToString() != "bhox")
|
||||||
throw new Exception("initial letters failed");
|
throw new Exception("initial letters failed");
|
||||||
if (csharp_typemaps.go != "zzz")
|
if (csharp_typemaps.go != 'z')
|
||||||
throw new Exception("go variable failed");
|
throw new Exception("go variable failed");
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,9 @@
|
||||||
|
|
||||||
// Test the C# types customisation by modifying the default char * typemaps to return a single char
|
// Test the C# types customisation by modifying the default char * typemaps to return a single char
|
||||||
|
|
||||||
|
%typemap(ctype, out="char /*ctype out override*/") char * "char *"
|
||||||
%typemap(imtype, out="char /*imtype out override*/") char * "string"
|
%typemap(imtype, out="char /*imtype out override*/") char * "string"
|
||||||
%typemap(cstype, out="char /*cstype out override*/") char * "string"
|
%typemap(cstype, out="char /*cstype out override*/") char * "string"
|
||||||
%typemap(ctype, out="char /*ctype out override*/") char * "char *"
|
|
||||||
|
|
||||||
%typemap(out) char * %{
|
%typemap(out) char * %{
|
||||||
// return the 0th element rather than the whole string
|
// return the 0th element rather than the whole string
|
||||||
|
|
@ -16,12 +16,20 @@
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
%typemap(csvarout, excode=SWIGEXCODE2) char *, char[ANY], char[] %{
|
%typemap(csvarout, excode=SWIGEXCODE2) char * %{
|
||||||
get {
|
get {
|
||||||
string ret = new string($imcall, 3);$excode
|
char ret = $imcall;$excode
|
||||||
return ret;
|
return ret;
|
||||||
} %}
|
} %}
|
||||||
|
|
||||||
|
// test valueparm attribute
|
||||||
|
%typemap(csvarin, excode=SWIGEXCODE2, valueparm="tempValue") char * %{
|
||||||
|
set {
|
||||||
|
string tempValue = new string(value, 3);
|
||||||
|
$imcall;$excode
|
||||||
|
} %}
|
||||||
|
|
||||||
|
|
||||||
%inline %{
|
%inline %{
|
||||||
namespace Space {
|
namespace Space {
|
||||||
class Things {
|
class Things {
|
||||||
|
|
@ -33,8 +41,27 @@ namespace Space {
|
||||||
#define STRINGCONSTANT "xyz string"
|
#define STRINGCONSTANT "xyz string"
|
||||||
char *go = "zap";
|
char *go = "zap";
|
||||||
}
|
}
|
||||||
|
%}
|
||||||
|
|
||||||
|
|
||||||
|
// Test variables when ref is used in the cstype typemap - the variable name should come from the out attribute if specified
|
||||||
|
%typemap(cstype) MKVector, const MKVector& "MKVector"
|
||||||
|
%typemap(cstype, out="MKVector") MKVector &, MKVector * "ref MKVector"
|
||||||
|
|
||||||
|
%inline %{
|
||||||
|
struct MKVector {
|
||||||
|
};
|
||||||
|
struct MKRenderGameVector {
|
||||||
|
MKVector memberValue;
|
||||||
|
static MKVector staticValue;
|
||||||
|
};
|
||||||
|
MKVector MKRenderGameVector::staticValue;
|
||||||
|
MKVector globalValue;
|
||||||
|
%}
|
||||||
|
|
||||||
|
|
||||||
// Number and Obj are for the eager garbage collector runtime test
|
// Number and Obj are for the eager garbage collector runtime test
|
||||||
|
%inline %{
|
||||||
struct Number {
|
struct Number {
|
||||||
Number(double value) : Value(value) {}
|
Number(double value) : Value(value) {}
|
||||||
double Value;
|
double Value;
|
||||||
|
|
|
||||||
|
|
@ -1909,6 +1909,8 @@ public:
|
||||||
if (proxy_flag && wrapping_member_flag && !enum_constant_flag) {
|
if (proxy_flag && wrapping_member_flag && !enum_constant_flag) {
|
||||||
// Properties
|
// Properties
|
||||||
setter_flag = (Cmp(Getattr(n, "sym:name"), Swig_name_set(Swig_name_member(proxy_class_name, variable_name))) == 0);
|
setter_flag = (Cmp(Getattr(n, "sym:name"), Swig_name_set(Swig_name_member(proxy_class_name, variable_name))) == 0);
|
||||||
|
if (setter_flag)
|
||||||
|
Swig_typemap_attach_parms("csvarin", l, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Start generating the proxy function */
|
/* Start generating the proxy function */
|
||||||
|
|
@ -2097,7 +2099,8 @@ public:
|
||||||
SwigType *pt = Getattr(p, "type");
|
SwigType *pt = Getattr(p, "type");
|
||||||
if ((tm = Getattr(p, "tmap:cstype"))) {
|
if ((tm = Getattr(p, "tmap:cstype"))) {
|
||||||
substituteClassname(pt, tm);
|
substituteClassname(pt, tm);
|
||||||
variable_type = tm;
|
String *cstypeout = Getattr(p, "tmap:cstype:out"); // the type in the cstype typemap's out attribute overrides the type in the typemap
|
||||||
|
variable_type = cstypeout ? cstypeout : tm;
|
||||||
} else {
|
} else {
|
||||||
Swig_warning(WARN_CSHARP_TYPEMAP_CSOUT_UNDEF, input_file, line_number, "No csvarin typemap defined for %s\n", SwigType_str(pt, 0));
|
Swig_warning(WARN_CSHARP_TYPEMAP_CSOUT_UNDEF, input_file, line_number, "No csvarin typemap defined for %s\n", SwigType_str(pt, 0));
|
||||||
}
|
}
|
||||||
|
|
@ -2114,7 +2117,6 @@ public:
|
||||||
|
|
||||||
if (setter_flag) {
|
if (setter_flag) {
|
||||||
// Setter method
|
// Setter method
|
||||||
Swig_typemap_attach_parms("csvarin", l, NULL);
|
|
||||||
p = last_parm; // (last parameter is the only parameter for properties)
|
p = last_parm; // (last parameter is the only parameter for properties)
|
||||||
SwigType *pt = Getattr(p, "type");
|
SwigType *pt = Getattr(p, "type");
|
||||||
if ((tm = Getattr(p, "tmap:csvarin"))) {
|
if ((tm = Getattr(p, "tmap:csvarin"))) {
|
||||||
|
|
@ -2499,6 +2501,8 @@ public:
|
||||||
Printf(func_name, "get");
|
Printf(func_name, "get");
|
||||||
Putc(toupper((int) *Char(variable_name)), func_name);
|
Putc(toupper((int) *Char(variable_name)), func_name);
|
||||||
Printf(func_name, "%s", Char(variable_name) + 1);
|
Printf(func_name, "%s", Char(variable_name) + 1);
|
||||||
|
if (setter_flag)
|
||||||
|
Swig_typemap_attach_parms("csvarin", l, NULL);
|
||||||
} else {
|
} else {
|
||||||
func_name = Copy(Getattr(n, "sym:name"));
|
func_name = Copy(Getattr(n, "sym:name"));
|
||||||
}
|
}
|
||||||
|
|
@ -2626,7 +2630,8 @@ public:
|
||||||
SwigType *pt = Getattr(p, "type");
|
SwigType *pt = Getattr(p, "type");
|
||||||
if ((tm = Getattr(p, "tmap:cstype"))) {
|
if ((tm = Getattr(p, "tmap:cstype"))) {
|
||||||
substituteClassname(pt, tm);
|
substituteClassname(pt, tm);
|
||||||
variable_type = tm;
|
String *cstypeout = Getattr(p, "tmap:cstype:out"); // the type in the cstype typemap's out attribute overrides the type in the typemap
|
||||||
|
variable_type = cstypeout ? cstypeout : tm;
|
||||||
} else {
|
} else {
|
||||||
Swig_warning(WARN_CSHARP_TYPEMAP_CSOUT_UNDEF, input_file, line_number, "No csvarin typemap defined for %s\n", SwigType_str(pt, 0));
|
Swig_warning(WARN_CSHARP_TYPEMAP_CSOUT_UNDEF, input_file, line_number, "No csvarin typemap defined for %s\n", SwigType_str(pt, 0));
|
||||||
}
|
}
|
||||||
|
|
@ -2643,7 +2648,6 @@ public:
|
||||||
|
|
||||||
if (setter_flag) {
|
if (setter_flag) {
|
||||||
// Setter method
|
// Setter method
|
||||||
Swig_typemap_attach_parms("csvarin", l, NULL);
|
|
||||||
p = last_parm; // (last parameter is the only parameter for properties)
|
p = last_parm; // (last parameter is the only parameter for properties)
|
||||||
SwigType *pt = Getattr(p, "type");
|
SwigType *pt = Getattr(p, "type");
|
||||||
if ((tm = Getattr(p, "tmap:csvarin"))) {
|
if ((tm = Getattr(p, "tmap:csvarin"))) {
|
||||||
|
|
@ -2864,8 +2868,9 @@ public:
|
||||||
String *arg = 0;
|
String *arg = 0;
|
||||||
String *pn = Getattr(p, "name");
|
String *pn = Getattr(p, "name");
|
||||||
if (setter) {
|
if (setter) {
|
||||||
// Note that in C# property setter names must always be called 'value'
|
// Note that in C# properties, the input variable name is always called 'value'
|
||||||
arg = NewString("value");
|
String *valueparm = Getattr(p, "tmap:csvarin:valueparm");
|
||||||
|
arg = valueparm ? Copy(valueparm) : NewString("value");
|
||||||
} else {
|
} else {
|
||||||
// Use C parameter name unless it is a duplicate or an empty parameter name
|
// Use C parameter name unless it is a duplicate or an empty parameter name
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue