

![]() | Start a set with this search |
![]() | Include this search in one of my sets |
![]() | Exclude this search from one of my sets |
![]() | Permalink to these results Paste this link in email or IM: |
| Atom feed for tracking future search results Paste this URL into your reader: |
12 messages in net.java.dev.jna.usersRe: [jna-users] Generics...| From | Sent On | Attachments |
|---|---|---|
| Paul Loy | Jul 2, 2008 5:23 am | |
| Timothy Wall | Jul 2, 2008 7:13 am | |
| Timothy Wall | Jul 2, 2008 7:16 am | |
| Paul Loy | Jul 2, 2008 7:18 am | |
| Paul Loy | Aug 7, 2008 8:26 am | |
| Timothy Wall | Aug 7, 2008 10:21 am | |
| Paul Loy | Aug 14, 2008 3:18 am | |
| Timothy Wall | Aug 19, 2008 7:29 am | |
| Paul Loy | Aug 19, 2008 7:53 am | |
| Timothy Wall | Aug 19, 2008 8:01 am | |
| Alex Lam S.L. | Aug 19, 2008 10:03 am | |
| Wayne Meissner | Aug 19, 2008 5:32 pm |

![]() | Permalink for this message Paste this link in email or IM: |
![]() | Permalink for this thread Paste this link in email or IM: |
| Atom feed for this thread Paste this URL into your reader: |
| Subject: | Re: [jna-users] Generics... | Actions... |
|---|---|---|
| From: | Timothy Wall (twal...@dev.java.net) | |
| Date: | Aug 19, 2008 8:01:47 am | |
| List: | net.java.dev.jna.users | |
The other alternative here is to make one GProperty class for each unique native type (which shouldn't be too onerous - there are probably more property types than there are native types). At most you'd have byte/short/int/long/float/double/pointer, although in practice you probably don't need all of them.
Additionally, the field value should be used instead of looking up the converter if it's of type NativeMapped (if the value is non-null). That alone would probably fix your issue.
On Aug 7, 2008, at 11:26 AM, Paul Loy wrote:
Hi Timothy,
Except... because a 'vanilla' instance of the nativemapped class is created by Structure (well by NativeMappedConverter.getInstance(type)). This means that we do not have the generic type applied so it tries to map to Object rather than Integer (for example if GProperty<Integer> were used). I guess I don't understand why when the data type extends NativeMapped does it then create a new instance? Why not use the instance we now have?
Or, could we add another interface that Structure could check for. Maybe a GenericType interface so Structure.calculateSize could know there is a special case here.
I really don't want to have to create X Property classes for each type. especially when I think it's so close to being able to accept them anyway.
Thanks,
Paul.
On Wed, Jul 2, 2008 at 3:17 PM, Timothy Wall <twal...@dev.java.net> wrote: Have you considered making GProperty implement NativeMapped? Structure will calculate based on whatever native type your custom object indicates.
On Jul 2, 2008, at 8:23 AM, Paul Loy wrote:
Hi All,
I'm currently implementing a JNA wrapper around GTK. On GObjects we can set and get properties. These properties can be different types (Boolean, Integer, GObjects, etc). So the mapped methods look like:
g_object_set(GObject on, GPropertyByValue...property); g_object_get(GObject from, GPropertyByReference...propertyPointer);
where:
public class GPropertyByReference<T> extends GProperty<T> implements ByValue {
public String propertyName; public Pointer propertyData;
... }
public class GPropertyByValue<T> extends GProperty<T> {
public String propertyName; public T propertyData;
... }
I wanted to make GPropertyByValue and GPropertyByReference generic. I have managed it with GPropertyByReference because I can do the 'marshalling' back from the Pointer on a getValue() call as I know the type when I initially create the property (i.e. I have a contructor that takes the type). But I get stuck with GPropertyByValue.
When JNA tries to marshall this, it gets the type of the propertyData field as Object which it doesn't know what to do with.
The problem, as I see it, is that calculateSize is doing a little too much so I can't, for example, inject the type in anywhere without completely losing calculateSize. As I don't want to re- invent-the-wheel I was wondering if re-factoring the calculateSize out a little would be possible. I guess a getFieldType() method would do the trick, although I was even thinking that a seperate method for creating the structFields, which could then be overloaded, would be useful?
Other than this, is there another way to use generics in this way?
Paul.
PS. I know I've called GPropertyByReference 'ByReference' when in Structure terms it's 'ByValue', but it's to indicate that the data contained within is ByReference (or Pointer).
--
--------------------------------------------- Paul Loy pa...@keteracel.com http://www.keteracel.com/paul
--------------------------------------------------------------------- To unsubscribe, e-mail: user...@jna.dev.java.net For additional commands, e-mail: user...@jna.dev.java.net
--
--------------------------------------------- Paul Loy pa...@keteracel.com http://www.keteracel.com/paul







