PageRenderTime 21ms CodeModel.GetById 13ms app.highlight 5ms RepoModel.GetById 2ms app.codeStats 0ms

/trunk/Examples/java/template/runme.java

#
Java | 45 lines | 33 code | 9 blank | 3 comment | 4 complexity | 074991f2553199961d77c41182f095e4 MD5 | raw file
 1// This example illustrates how C++ templates can be used from Java.
 2
 3public class runme {
 4  static {
 5    try {
 6        System.loadLibrary("example");
 7    } catch (UnsatisfiedLinkError e) {
 8      System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e);
 9      System.exit(1);
10    }
11  }
12
13  public static void main(String argv[]) 
14  {
15    // Call some templated functions
16    System.out.println(example.maxint(3,7));
17    System.out.println(example.maxdouble(3.14,2.18));
18    
19    // Create some class
20    
21    vecint iv = new vecint(100);
22    vecdouble dv = new vecdouble(1000);
23    
24    for (int i=0; i<100; i++)
25        iv.setitem(i,2*i);
26    
27    for (int i=0; i<1000; i++)
28          dv.setitem(i, 1.0/(i+1));
29    
30    {
31    int sum = 0;
32    for (int i=0; i<100; i++)
33          sum = sum + iv.getitem(i);
34    
35    System.out.println(sum);
36    }
37    
38    {
39    double sum = 0.0;
40    for (int i=0; i<1000; i++)
41          sum = sum + dv.getitem(i);
42    System.out.println(sum);
43    }
44  }
45}