-
Notifications
You must be signed in to change notification settings - Fork 71
/
goctp.swigcxx
79 lines (62 loc) · 2.67 KB
/
goctp.swigcxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/* Copyright 2011 The Go Authors. All rights reserved.
Use of this source code is governed by a BSD-style
license that can be found in the LICENSE file. */
/* An example of writing a C++ virtual function in Go. */
%module(directors="1") goctp
%init %{
//printf("Initialization qerio.goctp done.\n");
%}
%typemap(gotype) (char **ppInstrumentID, int nCount) "[]string"
%typemap(in) (char **ppInstrumentID, int nCount)
%{
{
int i;
_gostring_* a;
$2 = $input.len;
a = (_gostring_*) $input.array;
$1 = (char **) malloc (($2 + 1) * sizeof (char *));
for (i = 0; i < $2; i++) {
/* Not work */
//_gostring_ *ps = &a[i];
//$1[i] = (char *) ps->p;
//$1[i][ps->n] = '\0';
/*Work well*/
_gostring_ *ps = &a[i];
$1[i] = (char*) malloc(ps->n + 1);
memcpy($1[i], ps->p, ps->n);
$1[i][ps->n] = '\0';
}
$1[i] = NULL;
}
%}
%typemap(argout) (char **ppInstrumentID, int nCount) "" /* override char *[] default */
%typemap(freearg) (char **ppInstrumentID, int nCount)
%{
{
int i;
for (i = 0; i < $2; i++)
{
free ($1[i]);
}
free($1);
}
%}
/* 在复杂的企业环境中,可能有一些 C/C++ 头文件定义了您希望向脚本框架公开的全局变量和常量。
* 在接口文件中使用 %include <header.h> 和 %{ #include <header.h> %},可解决在头文件中重复所有元素的声明的问题。
* 有一点值得注意,在MSVC中,32位环境(当然是说跑的Intel 兼容CPU的PC)预定义宏_WIN32,但64位环境同时预定义了_WIN32和_WIN64。
*/
/* Includes the header files in the wrapper code */
%header %{
#include "./api/SFIT_CTP_6.3.11_20180109_tradeapi/v6.3.11_20180109_api_tradeapi_linux64/ThostFtdcUserApiDataType.h"
#include "./api/SFIT_CTP_6.3.11_20180109_tradeapi/v6.3.11_20180109_api_tradeapi_linux64/ThostFtdcUserApiStruct.h"
#include "./api/SFIT_CTP_6.3.11_20180109_tradeapi/v6.3.11_20180109_api_tradeapi_linux64/ThostFtdcMdApi.h"
#include "./api/SFIT_CTP_6.3.11_20180109_tradeapi/v6.3.11_20180109_api_tradeapi_linux64/ThostFtdcTraderApi.h"
%}
/* Parse the header files to generate wrappers */
%include "std_string.i"
%feature("director") CThostFtdcMdSpi;
%feature("director") CThostFtdcTraderSpi;
%include "./api/SFIT_CTP_6.3.11_20180109_tradeapi/v6.3.11_20180109_api_tradeapi_linux64/ThostFtdcUserApiDataType.h"
%include "./api/SFIT_CTP_6.3.11_20180109_tradeapi/v6.3.11_20180109_api_tradeapi_linux64/ThostFtdcUserApiStruct.h"
%include "./api/SFIT_CTP_6.3.11_20180109_tradeapi/v6.3.11_20180109_api_tradeapi_linux64/ThostFtdcMdApi.h"
%include "./api/SFIT_CTP_6.3.11_20180109_tradeapi/v6.3.11_20180109_api_tradeapi_linux64/ThostFtdcTraderApi.h"