[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform.swt] Re: JNIGenerator problem

Hi Laurent,

Sorry, I meant to answer this when you asked it previously but forgot.

In most cases the best that can be done is to pick one of the union members
and always access the union through this chosen member, as you've seen.
However in this case it should be possible to do a bit better since the
union members are structs.  You can declare your
DataBrowserAccessibilityItemInfo.java to have fields for both v0 and v1,
both initially null.  Since DataBrowserAccessibilityItemInfo's "version"
field indicates which version of DataBrowserAccessibilityItemInfoV? is in
the union, you can just set the value of either the v0 or v1 field as
appropriate.  The generated memmove code should be smart enough to ignore
the other field that was not set.  The total size of
DataBrowserAccessibilityItemInfo will be 4 (for the version field) + sizeof
(DataBrowserAccessibilityItemInfoV1) .

HTH,
Grant


"L. Mihalkovic" <totolaricot@xxxxxxx> wrote in message
news:g0pgvk$bbr$1@xxxxxxxxxxxxxxxxxxxx
L. Mihalkovic wrote:
I am trying to map the Carbon HIViewImageContentInfo struct for SWT (yes, I
did figure how to declare a struct that contains a union by looking at other
examples): as far as I can tell by looking at the C generated the union
capability is actually lost (the ability to choose at runtime which field I
want to set).

I looked at pretty much all the other carbon structures that contain unions,
and in all cases, the SWT code has made a choice of using only one of the
members of the union via

for example:

struct DataBrowserAccessibilityItemInfo {

 /*
  * A UInt32 which identifies how to interpret the following union.
  * Set this field to zero if you fill out the union's data in the
  * form of a DataBrowserAccessibilityItemInfoV0 structure. Set this
  * field to one if you fill out the union's data in the form of a
  * DataBrowserAccessibilityItemInfoV1 structure.
  */
 UInt32              version;
 union {
   DataBrowserAccessibilityItemInfoV0  v0;
   DataBrowserAccessibilityItemInfoV1  v1;
 }                       u;
};

The mapping only provides access via v0 and access via the v1 definition is
lost. what if I want to be able to do

browserInfo.u.v1.xxxx = ssss

Am I missing something obvious?! (for now I did the same and mapped only one
of the fields knowing that the actual values would endup looking right to
Mac OS, but that does not strike me a legible code).




allo... anyone?

simply put can I do:


DataBrowserAccessibilityItemInfo XX;

XX.u.v0.aaaa = ....
AND
XX.u.v1.zzzz = ....


via some syntax in JNIGenerator. my impression so far is that I can do one
OR the other but not keep the real union behavior.


-- 
Laurent Mihalkovic, co-author SWT/JFace in Action (www.manning.com/scarpino)