| [news.eclipse.platform.swt] Re: JNIGenerator problem |
|
Thank you for taking the time when you guys must be quite busy with Ganymede. I came to the same understanding. The following is what triggered my question: ------------------------------------------------- /********************************************************************** * Copyright (c) 2003-2008 IBM Corp. * Portions Copyright (c) 1983-2002, Apple Computer, Inc. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * L. Mihalkovic - initial version **********************************************************************/ package org.eclipse.swt.internal.carbon; public class HIViewImageContentInfo { public short contentType; // the following is really a union public int data; // public short resID; // public int iconRef; // public int imageRef; // public int cIconHandle; // public int iconSuite; // public int picture; // public int ICONHandle; public static final int sizeof = 6; } ------------------------------------------------- in the SWT philosophy, I wanted to be able to write Java code that would use the real Carbon field name based on the correct icon type. but the problem is that the commented out code led to the mess you can imagine: the last field being the current value of the underlying union - basically always 0 in my case (took me a couple days to figure that one out... not my proudest moment). So the current version has all the real union fields commented out and uses a generic "data" field instead (to avoid the question of why 'does that mean only icons of type XXXX are supported? '). Like I said, it works... but I was wondering if there was a 'secret' syntax in JNIgenerator to support real unions (basically generate an if statement in the JNI code). Looking at the source I don't think so... (any plans for one?) Grant Gayed wrote: 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@xxxxxxxxxxxxxxxxx... 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
-- Laurent Mihalkovic, co-author SWT/JFace in Action (www.manning.com/scarpino) |