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:
William S Fulton 2007-09-19 23:54:19 +00:00
commit d737022daa
3 changed files with 42 additions and 10 deletions

View file

@ -19,7 +19,7 @@ public class runme
initialLetters.Append(myChar);
if (initialLetters.ToString() != "bhox")
throw new Exception("initial letters failed");
if (csharp_typemaps.go != "zzz")
if (csharp_typemaps.go != 'z')
throw new Exception("go variable failed");

View file

@ -2,9 +2,9 @@
// 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(cstype, out="char /*cstype out override*/") char * "string"
%typemap(ctype, out="char /*ctype out override*/") char * "char *"
%typemap(out) char * %{
// return the 0th element rather than the whole string
@ -16,12 +16,20 @@
return ret;
}
%typemap(csvarout, excode=SWIGEXCODE2) char *, char[ANY], char[] %{
%typemap(csvarout, excode=SWIGEXCODE2) char * %{
get {
string ret = new string($imcall, 3);$excode
char ret = $imcall;$excode
return ret;
} %}
// test valueparm attribute
%typemap(csvarin, excode=SWIGEXCODE2, valueparm="tempValue") char * %{
set {
string tempValue = new string(value, 3);
$imcall;$excode
} %}
%inline %{
namespace Space {
class Things {
@ -33,8 +41,27 @@ namespace Space {
#define STRINGCONSTANT "xyz string"
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
%inline %{
struct Number {
Number(double value) : Value(value) {}
double Value;