PageRenderTime 42ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
Java | 45 lines | 33 code | 9 blank | 3 comment | 4 complexity | 074991f2553199961d77c41182f095e4 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. // This example illustrates how C++ templates can be used from Java.
  2. public class runme {
  3. static {
  4. try {
  5. System.loadLibrary("example");
  6. } catch (UnsatisfiedLinkError e) {
  7. 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);
  8. System.exit(1);
  9. }
  10. }
  11. public static void main(String argv[])
  12. {
  13. // Call some templated functions
  14. System.out.println(example.maxint(3,7));
  15. System.out.println(example.maxdouble(3.14,2.18));
  16. // Create some class
  17. vecint iv = new vecint(100);
  18. vecdouble dv = new vecdouble(1000);
  19. for (int i=0; i<100; i++)
  20. iv.setitem(i,2*i);
  21. for (int i=0; i<1000; i++)
  22. dv.setitem(i, 1.0/(i+1));
  23. {
  24. int sum = 0;
  25. for (int i=0; i<100; i++)
  26. sum = sum + iv.getitem(i);
  27. System.out.println(sum);
  28. }
  29. {
  30. double sum = 0.0;
  31. for (int i=0; i<1000; i++)
  32. sum = sum + dv.getitem(i);
  33. System.out.println(sum);
  34. }
  35. }
  36. }