Support namespaces and nspace with the interface feature for C#
This commit is contained in:
parent
50fec04759
commit
2f1c34be58
2 changed files with 75 additions and 19 deletions
|
|
@ -1,35 +1,44 @@
|
||||||
%define DECLARE_INTERFACE_(INTERFACE, IMPL, CTYPE...)
|
%define DECLARE_INTERFACE_(INTERFACE, CTYPE...)
|
||||||
%feature("interface", name="INTERFACE") CTYPE;
|
%feature("interface", name="INTERFACE") CTYPE;
|
||||||
%typemap(cstype) CTYPE, CTYPE *, CTYPE [], CTYPE &, CTYPE *const& "INTERFACE"
|
%typemap(cstype) CTYPE "$&interfacename"
|
||||||
|
%typemap(cstype) CTYPE *, CTYPE [], CTYPE & "$interfacename"
|
||||||
|
%typemap(cstype) CTYPE *const& "$*interfacename"
|
||||||
%typemap(csin) CTYPE, CTYPE & "$csinput.SWIGInterfaceUpcast()"
|
%typemap(csin) CTYPE, CTYPE & "$csinput.SWIGInterfaceUpcast()"
|
||||||
%typemap(csin) CTYPE *, CTYPE *const&, CTYPE [] "$csinput == null ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : $csinput.SWIGInterfaceUpcast()"
|
%typemap(csin) CTYPE *, CTYPE *const&, CTYPE [] "$csinput == null ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : $csinput.SWIGInterfaceUpcast()"
|
||||||
%typemap(csout, excode=SWIGEXCODE) CTYPE {
|
%typemap(csout, excode=SWIGEXCODE) CTYPE {
|
||||||
IMPL ret = new IMPL($imcall, true);$excode
|
$&csclassname ret = new $&csclassname($imcall, true);$excode
|
||||||
return (INTERFACE)ret;
|
return ($&interfacename)ret;
|
||||||
}
|
}
|
||||||
%typemap(csout, excode=SWIGEXCODE) CTYPE & {
|
%typemap(csout, excode=SWIGEXCODE) CTYPE & {
|
||||||
IMPL ret = new IMPL($imcall, $owner);$excode
|
$csclassname ret = new $csclassname($imcall, $owner);$excode
|
||||||
return (INTERFACE)ret;
|
return ($interfacename)ret;
|
||||||
}
|
}
|
||||||
%typemap(csout, excode=SWIGEXCODE) CTYPE *, CTYPE *const&, CTYPE [] {
|
%typemap(csout, excode=SWIGEXCODE) CTYPE *, CTYPE [] {
|
||||||
global::System.IntPtr cPtr = $imcall;
|
global::System.IntPtr cPtr = $imcall;
|
||||||
IMPL ret = (cPtr == global::System.IntPtr.Zero) ? null : new IMPL(cPtr, $owner);$excode
|
$csclassname ret = (cPtr == global::System.IntPtr.Zero) ? null : new $csclassname(cPtr, $owner);$excode
|
||||||
return (INTERFACE)ret;
|
return ($interfacename)ret;
|
||||||
}
|
}
|
||||||
%typemap(csdirectorin) CTYPE, CTYPE & "(INTERFACE)new IMPL($iminput, false)"
|
%typemap(csout, excode=SWIGEXCODE) CTYPE *const& {
|
||||||
%typemap(csdirectorin) CTYPE *, CTYPE *const&, CTYPE [] "($iminput == global::System.IntPtr.Zero) ? null : (INTERFACE)new IMPL($iminput, false)"
|
global::System.IntPtr cPtr = $imcall;
|
||||||
|
$*csclassname ret = (cPtr == global::System.IntPtr.Zero) ? null : new $*csclassname(cPtr, $owner);$excode
|
||||||
|
return ($*interfacename)ret;
|
||||||
|
}
|
||||||
|
%typemap(csdirectorin) CTYPE "($&interfacename)new $&csclassname($iminput, false)"
|
||||||
|
%typemap(csdirectorin) CTYPE & "($interfacename)new $csclassname($iminput, false)"
|
||||||
|
%typemap(csdirectorin) CTYPE *, CTYPE [] "($iminput == global::System.IntPtr.Zero) ? null : ($interfacename)new $csclassname($iminput, false)"
|
||||||
|
%typemap(csdirectorin) CTYPE *const& "($iminput == global::System.IntPtr.Zero) ? null : ($*interfacename)new $*csclassname($iminput, false)"
|
||||||
%typemap(csdirectorout) CTYPE, CTYPE *, CTYPE *const&, CTYPE [], CTYPE & "$cscall.SWIGInterfaceUpcast()"
|
%typemap(csdirectorout) CTYPE, CTYPE *, CTYPE *const&, CTYPE [], CTYPE & "$cscall.SWIGInterfaceUpcast()"
|
||||||
%typemap(csinterfacecode, declaration=" [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]\n global::System.Runtime.InteropServices.HandleRef SWIGInterfaceUpcast();\n", cptrmethod="$interfacename_SWIGInterfaceUpcast") CTYPE %{
|
%typemap(csinterfacecode, declaration=" [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]\n global::System.Runtime.InteropServices.HandleRef SWIGInterfaceUpcast();\n", cptrmethod=#INTERFACE##"_SWIGInterfaceUpcast") CTYPE %{
|
||||||
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
|
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
|
||||||
global::System.Runtime.InteropServices.HandleRef $interfacename.SWIGInterfaceUpcast() {
|
global::System.Runtime.InteropServices.HandleRef INTERFACE.SWIGInterfaceUpcast() {
|
||||||
return new global::System.Runtime.InteropServices.HandleRef(($interfacename)this, $imclassname.$csclazzname$interfacename_SWIGInterfaceUpcast(swigCPtr.Handle));
|
return new global::System.Runtime.InteropServices.HandleRef(this, $imclassname.$csclazzname##INTERFACE##_SWIGInterfaceUpcast(swigCPtr.Handle));
|
||||||
}
|
}
|
||||||
%}
|
%}
|
||||||
%enddef
|
%enddef
|
||||||
|
|
||||||
%define DECLARE_INTERFACE_RENAME(INTERFACE, IMPL, CTYPE...)
|
%define DECLARE_INTERFACE_RENAME(INTERFACE, IMPL, CTYPE...)
|
||||||
%rename (IMPL) CTYPE;
|
%rename (IMPL) CTYPE;
|
||||||
DECLARE_INTERFACE_(INTERFACE, IMPL, CTYPE)
|
DECLARE_INTERFACE_(INTERFACE, CTYPE)
|
||||||
%enddef
|
%enddef
|
||||||
|
|
||||||
%define DECLARE_INTERFACE(INTERFACE, CTYPE...)
|
%define DECLARE_INTERFACE(INTERFACE, CTYPE...)
|
||||||
|
|
|
||||||
|
|
@ -1669,6 +1669,20 @@ public:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* getInterfaceName()
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
String *getInterfaceName(SwigType *t) {
|
||||||
|
String *interface_name = NULL;
|
||||||
|
if (proxy_flag) {
|
||||||
|
Node *n = classLookup(t);
|
||||||
|
if (n && Getattr(n, "feature:interface:name"))
|
||||||
|
interface_name = getQualifiedInterfaceName(n);
|
||||||
|
}
|
||||||
|
return interface_name;
|
||||||
|
}
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
* addInterfaceNameAndUpcasts()
|
* addInterfaceNameAndUpcasts()
|
||||||
* ----------------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------------- */
|
||||||
|
|
@ -1687,13 +1701,11 @@ public:
|
||||||
String *interface_code = Copy(typemapLookup(base, "csinterfacecode", Getattr(base, "classtypeobj"), WARN_CSHARP_TYPEMAP_INTERFACECODE_UNDEF, attributes));
|
String *interface_code = Copy(typemapLookup(base, "csinterfacecode", Getattr(base, "classtypeobj"), WARN_CSHARP_TYPEMAP_INTERFACECODE_UNDEF, attributes));
|
||||||
String *cptr_method_name = 0;
|
String *cptr_method_name = 0;
|
||||||
if (interface_code) {
|
if (interface_code) {
|
||||||
Replaceall(interface_code, "$interfacename", interface_name);
|
|
||||||
Printv(interface_upcasts, interface_code, NIL);
|
Printv(interface_upcasts, interface_code, NIL);
|
||||||
cptr_method_name = Copy(Getattr(attributes, "tmap:csinterfacecode:cptrmethod"));
|
cptr_method_name = Copy(Getattr(attributes, "tmap:csinterfacecode:cptrmethod"));
|
||||||
}
|
}
|
||||||
if (!cptr_method_name)
|
if (!cptr_method_name)
|
||||||
cptr_method_name = NewString("$interfacename_GetInterfaceCPtr");
|
cptr_method_name = NewStringf("%s_GetInterfaceCPtr", interface_name);
|
||||||
Replaceall(cptr_method_name, "$interfacename", interface_name);
|
|
||||||
Replaceall(cptr_method_name, ".", "_");
|
Replaceall(cptr_method_name, ".", "_");
|
||||||
|
|
||||||
String *upcast_method = Swig_name_member(getNSpace(), proxy_class_name, cptr_method_name);
|
String *upcast_method = Swig_name_member(getNSpace(), proxy_class_name, cptr_method_name);
|
||||||
|
|
@ -2011,7 +2023,6 @@ public:
|
||||||
if (interface_code) {
|
if (interface_code) {
|
||||||
String *interface_declaration = Copy(Getattr(attributes, "tmap:csinterfacecode:declaration"));
|
String *interface_declaration = Copy(Getattr(attributes, "tmap:csinterfacecode:declaration"));
|
||||||
if (interface_declaration) {
|
if (interface_declaration) {
|
||||||
Replaceall(interface_declaration, "$interfacename", interface_name);
|
|
||||||
Printv(f_interface, interface_declaration, NIL);
|
Printv(f_interface, interface_declaration, NIL);
|
||||||
Delete(interface_declaration);
|
Delete(interface_declaration);
|
||||||
}
|
}
|
||||||
|
|
@ -3389,6 +3400,28 @@ public:
|
||||||
substitution_performed = true;
|
substitution_performed = true;
|
||||||
Delete(classnametype);
|
Delete(classnametype);
|
||||||
}
|
}
|
||||||
|
if (Strstr(tm, "$interfacename")) {
|
||||||
|
SwigType *interfacenametype = Copy(strippedtype);
|
||||||
|
substituteInterfacenameSpecialVariable(interfacenametype, tm, "$interfacename");
|
||||||
|
substitution_performed = true;
|
||||||
|
Delete(interfacenametype);
|
||||||
|
}
|
||||||
|
if (Strstr(tm, "$*interfacename")) {
|
||||||
|
SwigType *interfacenametype = Copy(strippedtype);
|
||||||
|
Delete(SwigType_pop(interfacenametype));
|
||||||
|
if (Len(interfacenametype) > 0) {
|
||||||
|
substituteInterfacenameSpecialVariable(interfacenametype, tm, "$*interfacename");
|
||||||
|
substitution_performed = true;
|
||||||
|
}
|
||||||
|
Delete(interfacenametype);
|
||||||
|
}
|
||||||
|
if (Strstr(tm, "$&interfacename")) {
|
||||||
|
SwigType *interfacenametype = Copy(strippedtype);
|
||||||
|
SwigType_add_pointer(interfacenametype);
|
||||||
|
substituteInterfacenameSpecialVariable(interfacenametype, tm, "$&interfacename");
|
||||||
|
substitution_performed = true;
|
||||||
|
Delete(interfacenametype);
|
||||||
|
}
|
||||||
|
|
||||||
Delete(strippedtype);
|
Delete(strippedtype);
|
||||||
Delete(type);
|
Delete(type);
|
||||||
|
|
@ -3434,6 +3467,20 @@ public:
|
||||||
Delete(replacementname);
|
Delete(replacementname);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* substituteInterfacenameSpecialVariable()
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
void substituteInterfacenameSpecialVariable(SwigType *interfacenametype, String *tm, const char *interfacenamespecialvariable) {
|
||||||
|
|
||||||
|
String *interfacename = getInterfaceName(interfacenametype);
|
||||||
|
if (interfacename) {
|
||||||
|
String *replacementname = Copy(interfacename);
|
||||||
|
Replaceall(tm, interfacenamespecialvariable, replacementname);
|
||||||
|
Delete(replacementname);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
* emitTypeWrapperClass()
|
* emitTypeWrapperClass()
|
||||||
* ----------------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------------- */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue