예제 #1
0
 private Pointer<CThostFtdcTradeField> getTradeField() {
   CThostFtdcTradeField tradeField = new CThostFtdcTradeField();
   tradeField.ExchangeID().setCString(交易所编号);
   tradeField.OrderSysID().setCString(交易所报单编号);
   tradeField.OrderRef().setCString(报单编号);
   tradeField.Volume(成交数量);
   tradeField.Price(成交价格);
   tradeField.InstrumentID().setCString(合约代码);
   Pointer<CThostFtdcTradeField> pTrade = Pointer.pointerTo(tradeField);
   return pTrade;
 }
예제 #2
0
  public void doOptimize() {
    nlopt = NloptLibrary.nloptCreate(NloptAlgorithm.NLOPT_LD_MMA, start.length);

    IntValuedEnum<NloptResult> nloptResult =
        nloptSetMinObjective(nlopt, Pointer.pointerTo(object), Pointer.NULL);
    if (!nloptResult.equals(NloptResult.NLOPT_SUCCESS)) {
      throw new IllegalStateException(nloptResult.toString());
    }

    nloptResult =
        NloptLibrary.nloptAddInequalityMconstraint(
            nlopt,
            inequalConstraints.getConstraintsSize(),
            Pointer.pointerTo(inequalConstraints),
            Pointer.NULL,
            Pointer.pointerToDoubles(inequalTolerents));
    if (!nloptResult.equals(NloptResult.NLOPT_SUCCESS)) {
      throw new IllegalStateException(nloptResult.toString());
    }

    nloptSetXtolRel(nlopt, objectRelativeTolerent);
    NloptLibrary.nloptSetXtolAbs1(nlopt, objectAbsoluteTolerence);

    Pointer<Double> functionResultPoint = Pointer.pointerToDouble(0);
    Pointer<Double> parameterPoint = Pointer.pointerToDoubles(start);

    if (null != initOptimizationTrigger) {
      Map<String, Object> initData = new HashMap<String, Object>();
      initData.put("start", start);
      initOptimizationTrigger.accept(initData);
    } else {
      logger.warn("initOptimizationBus is null");
    }
    resultStatus = NloptLibrary.nloptOptimize(nlopt, parameterPoint, functionResultPoint).value();

    resultParameters = parameterPoint.getDoubles();
    resultValue = functionResultPoint.getDouble();

    NloptLibrary.nloptDestroy(nlopt);
  }
예제 #3
0
  public static void main(String[] args) throws IOException {
    try {
      {
        JFrame f = new JFrame();
        f.setVisible(true);
        long hwndVal =
            JAWTUtils.getNativePeerHandle(f); // TODO com.sun.jna.Native.getComponentID(this);
        System.out.println("#\n# hwndVal = " + hwndVal + "\n#");

        BridJ.register();
        ValuedEnum<ETest> t = testEnum(ETest.eFirst);
        if (t != ETest.eFirst) throw new RuntimeException();
      }
      testSetGetIntBuffer(10);
      //			if (Platform.isMacOSX()) {
      //				new NSCalendar();
      //				new NSAutoReleasePool();
      //			}

      //        	NativeLibrary lib = BridJ.getNativeLibrary("OpenCL", new
      // File("/System/Library/Frameworks/OpenCL.framework/OpenCL"));
      //        	NativeLibrary lib = BridJ.getNativeLibrary("OpenCL", new
      // File("/usr/lib/libobjc.dylib"));
      //        	NativeLibrary lib = BridJ.getNativeLibrary("OpenCL", new
      // File("/Users/ochafik/nativelibs4java/Runtime/BridJ/src/test/cpp/test/build_out/darwin_universal_gcc_debug/libtest.dylib"));

      //        	Collection<Symbol> symbols = lib.getSymbols();
      BridJ.register(MyCallback.class);
      BridJ.register();

      int ra = testAddDyncall(10, 4);
      if (ra != 14) throw new RuntimeException("Expected 14, got " + ra);
      ra = testAddDyncall(10, 4);
      if (ra != 14) throw new RuntimeException("Expected 14, got " + ra);

      testNativeTargetCallbacks();
      testJavaTargetCallbacks();

      if (true) return;

      long crea = Ctest.createTest();
      crea = Pointer.pointerToAddress(crea).getPointer().getPeer();
      print("Ctest.createTest()", crea, 10, 0);
      Ctest test = new Ctest();
      // long thisPtr = test.$this.getPeer();
      // System.out.println(hex(thisPtr));
      print("Ctest.this", Pointer.pointerTo(test, Ctest.class).getPointer().getPeer(), 10, 2);
      int res = test.testAdd(1, 2);
      System.out.println("res = " + res);
      res = test.testVirtualAdd(1, 2);
      System.out.println("res = " + res);

      res = test.testVirtualAddStdCall(null, 1, 2);
      System.out.println("res = " + res);
      res = test.testAddStdCall(null, 1, 2);
      System.out.println("res = " + res);

      TaskbarListDemo.main(null);

      IShellWindows win = COMRuntime.newInstance(IShellWindows.class);
      IUnknown iu = win.QueryInterface(IUnknown.class);
      if (iu == null) throw new RuntimeException("Interface does not handle IUnknown !");
      win.Release();

      try {
        new FunctionTest().add();

        MyStruct s = new MyStruct();
        s.a(10);
        System.out.println("Created MyStruct and set it to 10");
        int a = Pointer.pointerTo(s).getInt();
        a = s.a();
        Pointer.pointerTo(s).setInt(10);
        a = Pointer.pointerTo(s).getInt();
        a = s.a();
        if (s.a() != 10) throw new RuntimeException("invalid value = " + a);
        s.b(100.0);
        if (s.b() != 100.0) throw new RuntimeException("invalid value = " + a);

      } catch (Throwable ex) {
        ex.printStackTrace();
      }

      library = BridJ.getNativeLibrary("test");
      // NativeLibrary.load(libraryPath);

      new VC9Demangler(null, "?sinInt@@YANH@Z").parseSymbol();
      new VC9Demangler(null, "?forwardCall@@YAHP6AHHH@ZHH@Z").parseSymbol();

      BridJ.register();

      // new VC9Demangler(null, "??0Ctest2@@QEAA@XZ").parseSymbol();

      for (Demangler.Symbol symbol : library.getSymbols()) {
        String name = symbol.getName();
        long addr = symbol.getAddress();
        System.out.println(name + " = \t" + hex(addr));

        if (name.startsWith("_ZTV") || name.startsWith("_ZTI") || name.startsWith("??_")) {
          print("vtable", addr, 10, 1);
        } else System.out.println("'" + name + "'");
      }

      boolean is64 = Platform.is64Bits();

    } catch (Throwable ex) {
      ex.printStackTrace();
    } finally {
      System.in.read();
    }
    /*double dres = PerfLib.testASinB(1, 2);
    res = PerfLib.testAddJNI(1, 2);
    System.out.println("Done");*/
  }