From: John M. <sw...@vo...> - 2011-03-28 01:49:30
|
> I can marshal int and my own C++ classes with get/set properties using > %attributeref. But it won't work for enum, float, or double types. > > in the following example class, > > oaOffset is int per typedef > oaPoint is another C++ class that I am also wrapping > oaOrient is an enum in both C++ and C# (underlying type int) > > The relevant %attributeref statements are: > > %include "attribute.i" > %attributeref(OpenAccess_4::oaTransform, oaPoint&, offset); > %attributeref(OpenAccess_4::oaTransform, oaOffset, xOffset); > %attributeref(OpenAccess_4::oaTransform, oaOffset, yOffset); > %attributeref(OpenAccess_4::oaTransform, oaOrient, orient); > > And here's the C++: > > namespace OpenAccess_4 { > class OA_BASE_DLL_API oaTransform { > public: > // ... constructors ... > oaPoint &offset(); > oaOffset &xOffset(); > oaOffset &yOffset(); > oaOrient &orient(); > const oaPoint &offset() const; > oaOffset xOffset() const; > oaOffset yOffset() const; > oaOrient orient() const; > > // ... > }; > } > > It works great, except for the enum, orient. Here is oaTransform.cs: > > public class oaTransform : IDisposable { > > // ... > > public SWIGTYPE_p_OpenAccess_4__oaOrient orient { > set { > oasCSharpBasePINVOKE.oaTransform_orient_set(swigCPtr, > SWIGTYPE_p_OpenAccess_4__oaOrient.getCPtr(value)); > } > get { > IntPtr cPtr = oasCSharpBasePINVOKE.oaTransform_orient_get(swigCPtr); > SWIGTYPE_p_OpenAccess_4__oaOrient ret = (cPtr == IntPtr.Zero) ? null : > new SWIGTYPE_p_OpenAccess_4__oaOrient(cPtr, false); > return ret; > } > } > > public oaPoint offset { > set { > oasCSharpBasePINVOKE.oaTransform_offset_set(swigCPtr, > oaPoint.getCPtr(value)); > if (oasCSharpBasePINVOKE.SWIGPendingException.Pending) throw > oasCSharpBasePINVOKE.SWIGPendingException.Retrieve(); > } > get { > oaPoint ret = new > oaPoint(oasCSharpBasePINVOKE.oaTransform_offset_get(swigCPtr), false); > if (oasCSharpBasePINVOKE.SWIGPendingException.Pending) throw > oasCSharpBasePINVOKE.SWIGPendingException.Retrieve(); > return ret; > } > } > > public int xOffset { > set { > oasCSharpBasePINVOKE.oaTransform_xOffset_set(swigCPtr, value); > } > get { > int ret = oasCSharpBasePINVOKE.oaTransform_xOffset_get(swigCPtr); > return ret; > } > } > > public int yOffset { > set { > oasCSharpBasePINVOKE.oaTransform_yOffset_set(swigCPtr, value); > } > get { > int ret = oasCSharpBasePINVOKE.oaTransform_yOffset_get(swigCPtr); > return ret; > } > } > > } > > SWIG uses SWIGTYPE_p_OpenAccess_4__oaOrient, so it's as if oaOrient is > undefined. > > Finally, the _wrap.cxx tries some pointer operations that won't > compile: > > SWIGEXPORT void SWIGSTDCALL CSharp_oaTransform_orient_set(void * > jarg1, void * jarg2) { > OpenAccess_4::oaTransform *arg1 = (OpenAccess_4::oaTransform *) 0 ; > OpenAccess_4::oaOrient *arg2 = (OpenAccess_4::oaOrient *) 0 ; > > arg1 = (OpenAccess_4::oaTransform *)jarg1; > arg2 = (OpenAccess_4::oaOrient *)jarg2; > OpenAccess_4_oaTransform_orient_set(arg1,arg2); > } > > > SWIGEXPORT void * SWIGSTDCALL CSharp_oaTransform_orient_get(void * > jarg1) { > void * jresult ; > OpenAccess_4::oaTransform *arg1 = (OpenAccess_4::oaTransform *) 0 ; > OpenAccess_4::oaOrient *result = 0 ; > > arg1 = (OpenAccess_4::oaTransform *)jarg1; > result = (OpenAccess_4::oaOrient > *)OpenAccess_4_oaTransform_orient_get(arg1); > jresult = (void *)result; > return jresult; > } > > > In other classes, I am having the same problem with float and double. > How can I get enum, float and double types to work with get/set > properties? > > > John McGehee > http://www.voom.net Please cancel this question. I solved this myself. The non-trivial reasons I found for this were: - Not qualifying C++ namespaces throughout the generic type: %attributeref(OpenAccess_4::oaComplex<OpenAccess_4::oaFloat>, float, imag) - I %renamed the enum oaOrientEnum to oaOrient, but %attributeref cannot see it: %rename(oaOrient) oaOrientEnum; // ... // %attributeref cannot see the %rename of oaOrientEnum to oaOrient %typemap(cstype) OpenAccess_4::oaOrientEnum "oaOrient /* cstype oaOrientEnum */" %typemap(imtype) OpenAccess_4::oaOrientEnum "oaOrient /* imtype oaOrientEnum */" %typemap(csvarout, excode=SWIGEXCODE2) OpenAccess_4::oaOrientEnum %{ /* csvarout oaOrientEnum */ get { oaOrient ret = $imcall; return ret; } %} %attributeref(OpenAccess_4::oaTransform, oaOrientEnum, orient, orient); That was kind of intense, but fortunately for me, oaOrient is the only enum that is handled via get/set properties. John McGehee http://www.voom.net |