Skip to content

Commit a878220

Browse files
committed
mod cmakelist
1 parent 87c939f commit a878220

File tree

7 files changed

+74
-41
lines changed

7 files changed

+74
-41
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,6 @@ output/Mac/Release/*.dylib
7979
output/Mac/Release/*.a
8080

8181
output/Linux/Debug/
82-
output/Linux/Release/
82+
output/Linux/Release/
83+
84+
*.properties

CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ if(UNIX) # Darwing or Linux
2222
find_package(absl REQUIRED)
2323

2424
# cpprest
25-
find_path(CPPREST_INCLUDE_DIR NAMES cpprest/http_client.h cpprest/http_msg.h)
26-
find_library(CPPREST_LIBRARY NAMES cpprest)
25+
# find_path(CPPREST_INCLUDE_DIR NAMES cpprest/http_client.h cpprest/http_msg.h)
26+
set(CPPREST_INCLUDE_DIR "/usr/local/opt/cpprest/include")
27+
set(CPPREST_LIBRARY "/usr/local/opt/cpprest/lib/libcpprest.dylib")
28+
# find_library(CPPREST_LIBRARY NAMES cpprest)
2729
message(CPPREST_INCLUDE_DIR " ${CPPREST_INCLUDE_DIR}")
2830
message(CPPREST_LIBRARY " ${CPPREST_LIBRARY}")
2931

README.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,15 @@ cd cpprestsdk
4343
git submodule update --init
4444
mkdir build
4545
cd build
46-
cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug-DBOOST_ROOT=/usr/local/ boost_1_81_0 ..
46+
cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug-DBOOST_ROOT=/usr/local/boost_1_81_0 -DCMAKE_INSTALL_PREFIX=/usr/local/opt/cpprest ..
4747
make -j 8
4848
make install
4949
```
50-
如果找不到openssl或boost 或其他错误,可尝试指定路径,关闭某些模块:
50+
如果找不到openssl或boost 或其他错误,可尝试指定路径,关闭某些模块 (如果有报错最好删除build目录重新创建)
5151
```
5252
cmake .. \
5353
-DCMAKE_BUILD_TYPE=Debug \
54+
-DCMAKE_INSTALL_PREFIX=/usr/local/opt/cpprest \
5455
-DBUILD_SHARED_LIBS=ON \
5556
-DBUILD_SAMPLES=OFF \
5657
-DBUILD_TESTS=OFF \
@@ -75,7 +76,7 @@ cd protobuf
7576
git checkout v3.1.0
7677
mkdir cmake_build
7778
cd cmake_build
78-
cmake ../cmake \
79+
cmake .. \
7980
-DCMAKE_BUILD_TYPE=Release \
8081
-DCMAKE_INSTALL_PREFIX=/usr/local/opt/protobuf \
8182
-Dprotobuf_BUILD_TESTS=OFF \
@@ -97,7 +98,7 @@ make install
9798
3. 编译
9899
```
99100
cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug \
100-
-DBOOST_ROOT=/usr/local/boost_1_81_0 ..
101+
-DBOOST_ROOT=/usr/local/boost_1_81_0 ..
101102
make -j 6
102103
make install
103104
```
@@ -109,6 +110,15 @@ make install
109110
110111
### 验证测试
111112
编译运行demo项目
113+
```
114+
cd demo
115+
mkdir build
116+
cd build
117+
cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug \
118+
-DBOOST_ROOT=/usr/local/boost_1_81_0 ..
119+
make -j 8
120+
./openapi_cpp_test
121+
```
112122
113123
114124

demo/CMakeLists.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ project(openapi_cpp_test)
66

77
# Configure required libraries ...
88
if(UNIX) # Darwing or Linux
9-
9+
1010
find_package(Boost REQUIRED COMPONENTS system thread log program_options chrono)
1111
find_package(Threads REQUIRED)
1212

1313
# cpprest
14-
find_path(CPPREST_INCLUDE_DIR NAMES cpprest/http_client.h cpprest/http_msg.h)
15-
find_library(CPPREST_LIBRARY NAMES cpprest)
14+
# find_path(CPPREST_INCLUDE_DIR NAMES cpprest/http_client.h cpprest/http_msg.h)
15+
# find_library(CPPREST_LIBRARY NAMES cpprest)
16+
set(CPPREST_INCLUDE_DIR "/usr/local/opt/cpprest/include")
17+
set(CPPREST_LIBRARY "/usr/local/opt/cpprest/lib/libcpprest.dylib")
1618
message(CPPREST_INCLUDE_DIR " ${CPPREST_INCLUDE_DIR}")
1719
message(CPPREST_LIBRARY " ${CPPREST_LIBRARY}")
1820

demo/openapi_cpp_test/openapi_cpp_test.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -583,23 +583,23 @@ int main()
583583
{
584584
//Set Tiger OpenAPI SDK configuration
585585
bool sand_box = false;
586-
ClientConfig config = ClientConfig(sand_box);
587-
config.private_key = U("");
588-
config.tiger_id = U("");
589-
config.account = U("");
586+
ClientConfig config = ClientConfig(false, U("../openapi_cpp_test/"));
587+
// config.private_key = U("");
588+
// config.tiger_id = U("");
589+
// config.account = U("");
590590
config.use_full_tick = true;
591591
//config.lang = U("en_US");
592592

593593
//Create a push client instance
594594
auto push_client = IPushClient::create_push_client(config);
595595
//Run some push test cases
596-
TestPushClient::test_push_client(push_client, config);
596+
// TestPushClient::test_push_client(push_client, config);
597597

598598
/**
599599
* QuoteClient
600600
*/
601-
//std::shared_ptr<QuoteClient> quote_client = std::make_shared<QuoteClient>(config);
602-
//TestQuoteClient::test_quote(quote_client);
601+
std::shared_ptr<QuoteClient> quote_client = std::make_shared<QuoteClient>(config);
602+
TestQuoteClient::test_quote(quote_client);
603603

604604
/**
605605
* TradeClient

include/tigerapi/client_config.h

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,32 +19,41 @@ using namespace std;
1919
namespace TIGER_API {
2020
class OPENAPI_EXPORT ClientConfig {
2121
public:
22-
ClientConfig(bool sandbox_debug = false) : sandbox_debug(sandbox_debug) {
22+
explicit ClientConfig(bool sandbox_debug = false) :
23+
sandbox_debug(sandbox_debug) {
2324
if (sandbox_debug) {
2425
LOG(WARNING) << U("SANDBOX IS NOT SUPPORTED") << endl;
2526
// server_url = SANDBOX_TIGER_SERVER_URL;
2627
// server_public_key = SANDBOX_TIGER_PUBLIC_KEY;
2728
}
2829
};
2930

30-
ClientConfig(utility::string_t tiger_id, utility::string_t private_key, utility::string_t account) : tiger_id(std::move(tiger_id)),
31-
private_key(std::move(
32-
private_key)),
33-
account(std::move(account)) {};
31+
// ClientConfig() : sandbox_debug(false) {};
32+
33+
ClientConfig(utility::string_t tiger_id, utility::string_t private_key, utility::string_t account) :
34+
tiger_id(std::move(tiger_id)),
35+
private_key(std::move(private_key)),
36+
account(std::move(account)) {};
3437

3538
ClientConfig(utility::string_t tiger_id, utility::string_t private_key, utility::string_t account,
36-
bool sandbox_debug = false, utility::string_t lang = U("en_US")) :
37-
tiger_id(std::move(tiger_id)), private_key(std::move(private_key)),
38-
account(std::move(account)), sandbox_debug(sandbox_debug), lang(lang) {
39+
bool sandbox_debug = false, utility::string_t lang = U("en_US")) :
40+
tiger_id(std::move(tiger_id)),
41+
private_key(std::move(private_key)),
42+
account(std::move(account)),
43+
sandbox_debug(sandbox_debug),
44+
lang(lang) {
3945
if (sandbox_debug) {
40-
server_url = SANDBOX_TIGER_SERVER_URL;
41-
server_public_key = SANDBOX_TIGER_PUBLIC_KEY;
42-
socket_url = SANDBOX_TIGER_SOCKET_HOST;
43-
socket_port = SANDBOX_TIGER_SOCKET_PORT;
46+
LOG(WARNING) << U("SANDBOX IS NOT SUPPORTED") << endl;
47+
// server_url = SANDBOX_TIGER_SERVER_URL;
48+
// server_public_key = SANDBOX_TIGER_PUBLIC_KEY;
49+
// socket_url = SANDBOX_TIGER_SOCKET_HOST;
50+
// socket_port = SANDBOX_TIGER_SOCKET_PORT;
4451
}
4552
};
4653

47-
ClientConfig(utility::string_t props_path) : props_path(props_path) {
54+
explicit ClientConfig(bool sandbox_debug, const utility::string_t props_path) :
55+
sandbox_debug(sandbox_debug),
56+
props_path(props_path) {
4857
load_props();
4958
};
5059

@@ -124,6 +133,7 @@ namespace TIGER_API {
124133
if (full_path.empty()) {
125134
return;
126135
}
136+
LOG(INFO) << U("Loading properties file from: ") << full_path << endl;
127137

128138
try {
129139
std::ifstream file(Utils::str16to8(full_path));
@@ -135,13 +145,12 @@ namespace TIGER_API {
135145
Properties props;
136146
props.load(file);
137147

138-
// 只在值为空时从配置文件加载
139148
if (tiger_id.empty()) {
140149
tiger_id = props.get_property(U("tiger_id"));
141150
}
142151
if (private_key.empty()) {
143152
private_key = props.get_property(U("private_key_pk1"));
144-
}
153+
}
145154
if (account.empty()) {
146155
account = props.get_property(U("account"));
147156
}
@@ -162,6 +171,7 @@ namespace TIGER_API {
162171
} catch (const std::exception& e) {
163172
LOG(ERROR) << U("Failed to load properties file: ") << Utils::str8to16(e.what()) << endl;
164173
}
174+
LOG(INFO) << U("Loaded properties file successfully, tiger_id: ") << tiger_id << " account: " << account << endl;
165175
}
166176

167177
utility::string_t get_props_path(const utility::string_t& filename) const {
@@ -173,7 +183,6 @@ namespace TIGER_API {
173183
return Utils::path_join(dirname, filename);
174184
}
175185
}
176-
return utility::string_t();
177186
}
178187

179188
utility::string_t get_token_path() const {
@@ -193,7 +202,7 @@ namespace TIGER_API {
193202
Properties props;
194203
props.load(file);
195204

196-
// 获取token值
205+
// get token value
197206
token = props.get_property(U("token"));
198207

199208
} catch (const std::exception& e) {

include/tigerapi/properties.h

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,22 @@ namespace TIGER_API {
1111
class Properties {
1212
public:
1313
void load(std::ifstream& input) {
14+
// skip BOM
15+
char bom[3];
16+
input.read(bom, 3);
17+
if (!(bom[0] == (char)0xEF && bom[1] == (char)0xBB && bom[2] == (char)0xBF)) {
18+
// if not BOM, reset file pointer to start
19+
input.seekg(0);
20+
}
21+
1422
std::string line;
1523
while (std::getline(input, line)) {
16-
// 跳过空行和注释行
24+
// skip empty line and comment line
1725
if (line.empty() || line[0] == '#' || line[0] == '!') {
1826
continue;
1927
}
2028

21-
// 查找第一个非转义的等号或冒号
29+
// find the first non-escaped equal or colon
2230
size_t pos = 0;
2331
while ((pos = line.find_first_of("=:", pos)) != std::string::npos) {
2432
if (pos == 0 || line[pos - 1] != '\\') {
@@ -31,10 +39,10 @@ namespace TIGER_API {
3139
std::string key = trim(line.substr(0, pos));
3240
std::string value = trim(line.substr(pos + 1));
3341

34-
// 处理转义字符
42+
// handle escape character
3543
value = unescape(value);
3644

37-
// 存储为 utility::string_t
45+
// store as utility::string_t
3846
properties[utility::conversions::to_string_t(key)] =
3947
utility::conversions::to_string_t(value);
4048
}
@@ -54,17 +62,17 @@ namespace TIGER_API {
5462
}
5563

5664
void store(std::ofstream& output) const {
57-
// 写入文件头注释
65+
// write file header comment
5866
output << "# Properties" << std::endl;
5967
output << "# " << get_current_datetime() << std::endl;
6068
output << std::endl;
6169

62-
// 写入所有属性
70+
// write all properties
6371
for (const auto& pair : properties) {
6472
std::string key = utility::conversions::to_utf8string(pair.first);
6573
std::string value = utility::conversions::to_utf8string(pair.second);
6674

67-
// 转义特殊字符
75+
// escape special characters
6876
key = escape(key);
6977
value = escape(value);
7078

0 commit comments

Comments
 (0)