--Hi,I've got a couple of C Structs in a third party lib that are written like this:typedef struct
{
double tenor;
double rate;
} TERMSTRUC;
typedef struct
{
TERMSTRUC *curve;
short count;
const char *name;
short flag;
char *conv;
} NAMEDTERMCURVE;The JNA equivalents I've written are below. My question is - how would I pass an array of TERMSTRUC[] to the NAMEDTERMCURVE?I can initiate the a new price data curve map of 5 elements:NAMEDTERMCURVE ntc = new NAMEDTERMCURVE();NAMEDTERMCURVE[] priceData = (NAMEDTERMCURVE[])ntc.toArray(5);Lets say I have a termstruc to assign to the "curve" pointer - how do I do that using a Memory or Pointer?TERMSTRUC[] test = something;priceData[0].curve = test (obviously this doesn't work or compile at the moment but how would I assign an array of type TERMSTRUC[] to the curve member?)public static class NAMEDTERMCURVE extends Structure
{
public Pointer curve;
public short count;
public String name;
public short flag;
public Pointer conv;
public static class ByReference extends NAMEDTERMCURVE implements Structure.ByReference
{
public ByReference() { }
public ByReference(Pointer p){ super(p); read(); }
}
public static class ByValue extends NAMEDTERMCURVE implements Structure.ByValue { }
public NAMEDTERMCURVE(){}
public NAMEDTERMCURVE(Pointer p){super(p); read();}
public NAMEDTERMCURVE(
Pointer curve,
short count,
String name,
short flag,
Pointer conv)
{
this.curve = curve;
this.count = count;
this.name = name;
this.flag = flag;
this.conv = conv;
}
@Override
protected List getFieldOrder()
{
return Arrays.asList(new String[] { "curve", "count", "name", "flag", "conv" } );
}
}public static class TERMSTRUC extends Structure
{
public double tenor;
public double rate;
public static class ByReference extends TERMSTRUC implements Structure.ByReference
{
public ByReference() { }
public ByReference(Pointer p){ super(p); read(); }
}
public static class ByValue extends TERMSTRUC implements Structure.ByValue { }
public TERMSTRUC(){}
public TERMSTRUC(Pointer p) { super(p); read(); }
public TERMSTRUC(double tenor, double rate)
{
this.tenor = tenor;
this.rate = rate;
}
@Override
protected List<String> getFieldOrder()
{
return Arrays.asList(new String[]{"tenor", "rate"});
}
}
You received this message because you are subscribed to the Google Groups "Java Native Access" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jna-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Hi Tim,Can you show me an example of what you mean when you indicate to define the field of type Structure.ByReference? The "curve" field in the NAMEDTERMCURVE Java struct is of type Pointer. If I change that to Structure.ByReference - what would I assign namedTermCurve[0].curve below to?public static void main(String[] args) throws Exception{TERMSTRUC ts = new TERMSTRUC();TERMSTRUC[] termStruc = (TERMSTRUC[])ts.toArray(1);termStruc[0].tenor = 42643;termStruc[0].rate = 25654.00;/* namedtermcurve struct with 2 term struc's */
NAMEDTERMCURVE ntc = new NAMEDTERMCURVE();
NAMEDTERMCURVE[] namedTermCurve = (NAMEDTERMCURVE[])ntc.toArray(1);namedTermCurve[0].curve = termStruc;namedTermCurve[0].count = (short)1;}
To unsubscribe from this group and stop receiving emails from it, send an email to jna-users+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.