hikyuu 2.1.0__cp38-none-win_amd64.whl → 2.1.2__cp38-none-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- hikyuu/cpp/boost_date_time-mt.dll +0 -0
- hikyuu/cpp/boost_serialization-mt.dll +0 -0
- hikyuu/cpp/boost_wserialization-mt.dll +0 -0
- hikyuu/cpp/core38.pyd +0 -0
- hikyuu/cpp/hikyuu.dll +0 -0
- hikyuu/cpp/sqlite3.dll +0 -0
- hikyuu/examples/notebook/006-TradeManager.ipynb +41 -39
- hikyuu/examples/notebook/008-Pickle.ipynb +27 -35
- hikyuu/extend.py +3 -1
- hikyuu/fetcher/stock/zh_stock_a_qmt.py +49 -0
- hikyuu/gui/HikyuuTDX.py +13 -7
- hikyuu/gui/data/MainWindow.py +126 -126
- hikyuu/gui/spot_server.py +16 -7
- hikyuu/gui/start_qmt.py +36 -0
- hikyuu/include/hikyuu/DataType.h +2 -1
- hikyuu/include/hikyuu/KRecord.h +1 -1
- hikyuu/include/hikyuu/Stock.h +1 -1
- hikyuu/include/hikyuu/StockManager.h +3 -0
- hikyuu/include/hikyuu/StrategyContext.h +7 -2
- hikyuu/include/hikyuu/analysis/combinate.h +1 -1
- hikyuu/include/hikyuu/config.h +0 -12
- hikyuu/include/hikyuu/data_driver/base_info/table/HistoryFinanceTable.h +2 -2
- hikyuu/include/hikyuu/doc.h +2 -2
- hikyuu/include/hikyuu/global/GlobalSpotAgent.h +1 -0
- hikyuu/include/hikyuu/global/GlobalTaskGroup.h +4 -2
- hikyuu/include/hikyuu/global/SpotRecord.h +52 -0
- hikyuu/include/hikyuu/global/agent/SpotAgent.h +14 -41
- hikyuu/include/hikyuu/hikyuu.h +1 -0
- hikyuu/include/hikyuu/strategy/{AccountTradeManager.h → BrokerTradeManager.h} +97 -95
- hikyuu/include/hikyuu/strategy/RunPortfolioInStrategy.h +36 -0
- hikyuu/include/hikyuu/strategy/RunSystemInStrategy.h +37 -0
- hikyuu/include/hikyuu/strategy/Strategy.h +174 -0
- hikyuu/include/hikyuu/trade_manage/FundsRecord.h +8 -8
- hikyuu/include/hikyuu/trade_manage/OrderBrokerBase.h +66 -14
- hikyuu/include/hikyuu/trade_manage/PositionRecord.h +12 -12
- hikyuu/include/hikyuu/trade_manage/TradeManager.h +9 -0
- hikyuu/include/hikyuu/trade_manage/TradeManagerBase.h +19 -0
- hikyuu/include/hikyuu/utilities/FilterNode.h +267 -0
- hikyuu/include/hikyuu/utilities/LRUCache11.h +230 -0
- hikyuu/include/hikyuu/{Log.h → utilities/Log.h} +91 -113
- hikyuu/include/hikyuu/utilities/Null.h +1 -0
- hikyuu/include/hikyuu/utilities/Parameter.h +2 -1
- hikyuu/include/hikyuu/utilities/ResourcePool.h +636 -0
- hikyuu/include/hikyuu/utilities/SpendTimer.h +10 -9
- hikyuu/include/hikyuu/utilities/TimerManager.h +25 -11
- hikyuu/include/hikyuu/utilities/any_to_string.h +142 -0
- hikyuu/include/hikyuu/utilities/arithmetic.h +71 -35
- hikyuu/include/hikyuu/utilities/base64.h +59 -0
- hikyuu/include/hikyuu/utilities/config.h +41 -0
- hikyuu/include/hikyuu/utilities/datetime/Datetime.h +42 -31
- hikyuu/include/hikyuu/utilities/datetime/TimeDelta.h +24 -13
- hikyuu/include/hikyuu/utilities/db_connect/DBCondition.h +48 -48
- hikyuu/include/hikyuu/utilities/db_connect/DBConnect.h +10 -0
- hikyuu/include/hikyuu/utilities/db_connect/DBConnectBase.h +5 -22
- hikyuu/include/hikyuu/utilities/db_connect/DBUpgrade.h +3 -3
- hikyuu/include/hikyuu/utilities/db_connect/SQLException.h +1 -1
- hikyuu/include/hikyuu/utilities/db_connect/SQLResultSet.h +1 -1
- hikyuu/include/hikyuu/utilities/db_connect/SQLStatementBase.h +7 -7
- hikyuu/include/hikyuu/utilities/db_connect/TableMacro.h +1 -2
- hikyuu/include/hikyuu/utilities/db_connect/mysql/MySQLConnect.h +9 -9
- hikyuu/include/hikyuu/utilities/db_connect/mysql/MySQLStatement.h +18 -18
- hikyuu/include/hikyuu/utilities/db_connect/sqlite/SQLiteConnect.h +3 -3
- hikyuu/include/hikyuu/utilities/db_connect/sqlite/SQLiteStatement.h +2 -2
- hikyuu/include/hikyuu/utilities/db_connect/sqlite/SQLiteUtil.h +6 -6
- hikyuu/include/hikyuu/{exception.h → utilities/exception.h} +15 -16
- hikyuu/include/hikyuu/utilities/http_client/HttpClient.h +229 -0
- hikyuu/include/hikyuu/utilities/http_client/nng_wrap.h +517 -0
- hikyuu/include/hikyuu/utilities/http_client/url.h +25 -0
- hikyuu/include/hikyuu/utilities/{IniParser.h → ini_parser/IniParser.h} +10 -5
- hikyuu/include/hikyuu/utilities/ini_parser/__init__.py +1 -0
- hikyuu/include/hikyuu/utilities/md5.h +41 -0
- hikyuu/include/hikyuu/utilities/mo/__init__.py +1 -0
- hikyuu/include/hikyuu/utilities/mo/mo.h +48 -0
- hikyuu/include/hikyuu/utilities/mo/moFileReader.h +836 -0
- hikyuu/include/hikyuu/{global → utilities}/node/NodeClient.h +25 -18
- hikyuu/include/hikyuu/{global → utilities}/node/NodeError.h +1 -1
- hikyuu/include/hikyuu/{global → utilities}/node/NodeMessage.h +3 -2
- hikyuu/include/hikyuu/utilities/node/NodeServer.h +246 -0
- hikyuu/include/hikyuu/utilities/node/__init__.py +1 -0
- hikyuu/include/hikyuu/utilities/os.h +16 -15
- hikyuu/include/hikyuu/utilities/snowflake.h +110 -0
- hikyuu/include/hikyuu/utilities/string_view.h +70 -0
- hikyuu/include/hikyuu/utilities/thread/MQStealThreadPool.h +3 -3
- hikyuu/include/hikyuu/utilities/thread/MQThreadPool.h +3 -3
- hikyuu/include/hikyuu/utilities/thread/StealThreadPool.h +3 -3
- hikyuu/include/hikyuu/utilities/thread/ThreadPool.h +3 -3
- hikyuu/include/hikyuu/version.h +4 -4
- hikyuu/interactive.py +42 -137
- hikyuu/sqlite3.dll +0 -0
- hikyuu/strategy/__init__.py +0 -1
- hikyuu/strategy/strategy_demo1.py +53 -0
- hikyuu/strategy/strategy_demo2.py +47 -0
- hikyuu/strategy/strategy_demo3.py +24 -0
- hikyuu/trade_manage/broker.py +27 -11
- hikyuu/trade_manage/broker_easytrader.py +52 -6
- hikyuu/trade_manage/broker_mail.py +17 -20
- hikyuu/vcruntime140.dll +0 -0
- hikyuu/vcruntime140_1.dll +0 -0
- hikyuu-2.1.2.dist-info/METADATA +115 -0
- {hikyuu-2.1.0.dist-info → hikyuu-2.1.2.dist-info}/RECORD +105 -79
- {hikyuu-2.1.0.dist-info → hikyuu-2.1.2.dist-info}/top_level.txt +4 -2
- hikyuu/README.rst +0 -79
- hikyuu/include/hikyuu/strategy/StrategyBase.h +0 -156
- hikyuu/strategy/demo/__init__.py +0 -3
- hikyuu/strategy/strategy.py +0 -27
- hikyuu-2.1.0.dist-info/METADATA +0 -126
- /hikyuu/include/hikyuu/{global/node → utilities/http_client}/__init__.py +0 -0
- {hikyuu-2.1.0.dist-info → hikyuu-2.1.2.dist-info}/LICENSE +0 -0
- {hikyuu-2.1.0.dist-info → hikyuu-2.1.2.dist-info}/WHEEL +0 -0
- {hikyuu-2.1.0.dist-info → hikyuu-2.1.2.dist-info}/entry_points.txt +0 -0
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
#include <unordered_map>
|
|
12
12
|
#include <functional>
|
|
13
13
|
#include "hikyuu/utilities/datetime/Datetime.h"
|
|
14
|
-
#include "hikyuu/Log.h"
|
|
14
|
+
#include "hikyuu/utilities/Log.h"
|
|
15
15
|
#include "thread/ThreadPool.h"
|
|
16
16
|
#include "cppdef.h"
|
|
17
17
|
|
|
@@ -35,7 +35,23 @@ public:
|
|
|
35
35
|
* @param work_num 定时任务执行线程池线程数量
|
|
36
36
|
*/
|
|
37
37
|
explicit TimerManager(size_t work_num = 1)
|
|
38
|
-
: m_stop(true),
|
|
38
|
+
: m_stop(true),
|
|
39
|
+
m_current_timer_id(-1),
|
|
40
|
+
m_work_num(work_num),
|
|
41
|
+
m_tg(nullptr),
|
|
42
|
+
m_use_extend_tg(false) {
|
|
43
|
+
HKU_ASSERT(work_num >= 1);
|
|
44
|
+
start();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* 指定线程池方式构造,以便共享其他线程池
|
|
49
|
+
* @note 请自行保证 tg 的生命周期在 TimerManager 存活期间始终有效
|
|
50
|
+
* @param tg 指定任务组线程池
|
|
51
|
+
*/
|
|
52
|
+
explicit TimerManager(ThreadPool* tg)
|
|
53
|
+
: m_stop(true), m_current_timer_id(-1), m_work_num(1), m_tg(tg), m_use_extend_tg(true) {
|
|
54
|
+
HKU_ASSERT(m_tg);
|
|
39
55
|
start();
|
|
40
56
|
}
|
|
41
57
|
|
|
@@ -60,11 +76,7 @@ public:
|
|
|
60
76
|
std::priority_queue<IntervalS> new_queue;
|
|
61
77
|
m_queue.swap(new_queue);
|
|
62
78
|
if (!m_tg) {
|
|
63
|
-
|
|
64
|
-
m_tg = std::make_unique<ThreadPool>(m_work_num);
|
|
65
|
-
#else
|
|
66
|
-
m_tg = std::unique_ptr<ThreadPool>(new ThreadPool(m_work_num));
|
|
67
|
-
#endif
|
|
79
|
+
m_tg = new ThreadPool(m_work_num);
|
|
68
80
|
}
|
|
69
81
|
|
|
70
82
|
/*
|
|
@@ -152,9 +164,10 @@ public:
|
|
|
152
164
|
m_detect_thread.join();
|
|
153
165
|
}
|
|
154
166
|
|
|
155
|
-
if (m_tg) {
|
|
167
|
+
if (!m_use_extend_tg && m_tg) {
|
|
156
168
|
m_tg->stop();
|
|
157
|
-
m_tg
|
|
169
|
+
delete m_tg;
|
|
170
|
+
m_tg = nullptr;
|
|
158
171
|
}
|
|
159
172
|
}
|
|
160
173
|
|
|
@@ -399,7 +412,7 @@ private:
|
|
|
399
412
|
// 分配 timer_id
|
|
400
413
|
int getNewTimerId() {
|
|
401
414
|
int max_int = std::numeric_limits<int>::max();
|
|
402
|
-
HKU_WARN_IF_RETURN(m_timers.size() >= max_int, -1, "Timer queue is full!");
|
|
415
|
+
HKU_WARN_IF_RETURN(m_timers.size() >= size_t(max_int), -1, "Timer queue is full!");
|
|
403
416
|
|
|
404
417
|
if (m_current_timer_id >= max_int) {
|
|
405
418
|
m_current_timer_id = 0;
|
|
@@ -532,7 +545,8 @@ private:
|
|
|
532
545
|
std::unordered_map<int, Timer*> m_timers;
|
|
533
546
|
int m_current_timer_id;
|
|
534
547
|
size_t m_work_num; // 任务执行线程池线程数量
|
|
535
|
-
|
|
548
|
+
ThreadPool* m_tg{nullptr};
|
|
549
|
+
bool m_use_extend_tg{false};
|
|
536
550
|
};
|
|
537
551
|
|
|
538
552
|
} // namespace hku
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2023 hikyuu.org
|
|
3
|
+
*
|
|
4
|
+
* Created on: 2023-01-15
|
|
5
|
+
* Author: fasiondog
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#include <string>
|
|
11
|
+
|
|
12
|
+
#include "osdef.h"
|
|
13
|
+
#include "cppdef.h"
|
|
14
|
+
#if !HKU_OS_IOS && CPP_STANDARD >= CPP_STANDARD_17
|
|
15
|
+
#include <any>
|
|
16
|
+
#else
|
|
17
|
+
#include <boost/any.hpp>
|
|
18
|
+
#endif
|
|
19
|
+
|
|
20
|
+
#if defined(HKU_SUPPORT_DATETIME)
|
|
21
|
+
#include "hikyuu/utilities/datetime/Datetime.h"
|
|
22
|
+
#endif
|
|
23
|
+
|
|
24
|
+
namespace hku {
|
|
25
|
+
|
|
26
|
+
#if !HKU_OS_IOS && CPP_STANDARD >= CPP_STANDARD_17
|
|
27
|
+
using any_t = std::any;
|
|
28
|
+
using std::any_cast;
|
|
29
|
+
#else
|
|
30
|
+
using any_t = boost::any;
|
|
31
|
+
using boost::any_cast;
|
|
32
|
+
#endif
|
|
33
|
+
|
|
34
|
+
//------------------------------------------------------------------------------
|
|
35
|
+
//
|
|
36
|
+
// 常见基本类型包装的 any_t 和 std::string 的互相转换函数
|
|
37
|
+
// any_to_string 要用户自定义类型需包含从 std::string 进行构造的构造函数
|
|
38
|
+
// string_to_any 需要用户自定义实现 std::to_string 特化方法
|
|
39
|
+
//
|
|
40
|
+
//------------------------------------------------------------------------------
|
|
41
|
+
|
|
42
|
+
template <typename ValueT>
|
|
43
|
+
inline std::string any_to_string(const any_t& data) {
|
|
44
|
+
return any_cast<ValueT>(data).str();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
template <typename ValueT>
|
|
48
|
+
inline any_t string_to_any(const std::string& data) {
|
|
49
|
+
return any_t(ValueT(data));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
template <>
|
|
53
|
+
inline std::string any_to_string<int>(const any_t& data) {
|
|
54
|
+
return std::to_string(any_cast<int>(data));
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
template <>
|
|
58
|
+
inline std::string any_to_string<long>(const any_t& data) {
|
|
59
|
+
return std::to_string(any_cast<long>(data));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
template <>
|
|
63
|
+
inline std::string any_to_string<long long>(const any_t& data) {
|
|
64
|
+
return std::to_string(any_cast<long long>(data));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
template <>
|
|
68
|
+
inline std::string any_to_string<unsigned int>(const any_t& data) {
|
|
69
|
+
return std::to_string(any_cast<unsigned int>(data));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
template <>
|
|
73
|
+
inline std::string any_to_string<unsigned long>(const any_t& data) {
|
|
74
|
+
return std::to_string(any_cast<unsigned long>(data));
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
template <>
|
|
78
|
+
inline std::string any_to_string<unsigned long long>(const any_t& data) {
|
|
79
|
+
return std::to_string(any_cast<unsigned long long>(data));
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
template <>
|
|
83
|
+
inline std::string any_to_string<float>(const any_t& data) {
|
|
84
|
+
return std::to_string(any_cast<float>(data));
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
template <>
|
|
88
|
+
inline std::string any_to_string<double>(const any_t& data) {
|
|
89
|
+
return std::to_string(any_cast<double>(data));
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
template <>
|
|
93
|
+
inline std::string any_to_string<long double>(const any_t& data) {
|
|
94
|
+
return std::to_string(any_cast<long double>(data));
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
template <>
|
|
98
|
+
inline any_t string_to_any<int>(const std::string& data) {
|
|
99
|
+
return any_t(std::stoi(data));
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
template <>
|
|
103
|
+
inline any_t string_to_any<long>(const std::string& data) {
|
|
104
|
+
return any_t(std::stol(data));
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
template <>
|
|
108
|
+
inline any_t string_to_any<long long>(const std::string& data) {
|
|
109
|
+
return any_t(std::stoll(data));
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
template <>
|
|
113
|
+
inline any_t string_to_any<unsigned int>(const std::string& data) {
|
|
114
|
+
return any_t((unsigned int)(std::stoul(data)));
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
template <>
|
|
118
|
+
inline any_t string_to_any<unsigned long>(const std::string& data) {
|
|
119
|
+
return any_t(std::stoul(data));
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
template <>
|
|
123
|
+
inline any_t string_to_any<unsigned long long>(const std::string& data) {
|
|
124
|
+
return any_t(std::stoull(data));
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
template <>
|
|
128
|
+
inline any_t string_to_any<float>(const std::string& data) {
|
|
129
|
+
return any_t(std::stof(data));
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
template <>
|
|
133
|
+
inline any_t string_to_any<double>(const std::string& data) {
|
|
134
|
+
return any_t(std::stod(data));
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
template <>
|
|
138
|
+
inline any_t string_to_any<long double>(const std::string& data) {
|
|
139
|
+
return any_t(std::stold(data));
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
} // namespace hku
|
|
@@ -15,11 +15,12 @@
|
|
|
15
15
|
#include <cctype>
|
|
16
16
|
#include <vector>
|
|
17
17
|
#include <string>
|
|
18
|
-
#include <string_view>
|
|
19
18
|
#include <algorithm>
|
|
20
19
|
|
|
21
|
-
#
|
|
22
|
-
|
|
20
|
+
#include "string_view.h"
|
|
21
|
+
|
|
22
|
+
#ifndef HKU_UTILS_API
|
|
23
|
+
#define HKU_UTILS_API
|
|
23
24
|
#endif
|
|
24
25
|
|
|
25
26
|
namespace hku {
|
|
@@ -30,13 +31,13 @@ namespace hku {
|
|
|
30
31
|
*/
|
|
31
32
|
|
|
32
33
|
#if defined(_MSC_VER)
|
|
33
|
-
std::string
|
|
34
|
-
std::string
|
|
35
|
-
std::string
|
|
36
|
-
std::string
|
|
34
|
+
std::string HKU_UTILS_API utf8_to_gb(const char *szinput);
|
|
35
|
+
std::string HKU_UTILS_API utf8_to_gb(const std::string &szinput);
|
|
36
|
+
std::string HKU_UTILS_API gb_to_utf8(const char *szinput);
|
|
37
|
+
std::string HKU_UTILS_API gb_to_utf8(const std::string &szinput);
|
|
37
38
|
#else
|
|
38
|
-
std::string
|
|
39
|
-
std::string
|
|
39
|
+
std::string HKU_UTILS_API utf8_to_gb(const std::string &szinput);
|
|
40
|
+
std::string HKU_UTILS_API gb_to_utf8(const std::string &szinput);
|
|
40
41
|
#endif
|
|
41
42
|
|
|
42
43
|
#define UTF8ToGB hku::utf8_to_gb
|
|
@@ -81,18 +82,17 @@ std::string HKU_API gb_to_utf8(const std::string& szinput);
|
|
|
81
82
|
* @param ndigits 保留小数位数
|
|
82
83
|
* @return 处理过的数据
|
|
83
84
|
*/
|
|
84
|
-
// double HKU_API roundEx(double number, int ndigits = 0);
|
|
85
85
|
template <typename ValueT>
|
|
86
86
|
ValueT roundEx(ValueT number, int ndigits = 0) {
|
|
87
87
|
// 切换至:ROUND_HALF_EVEN 银行家舍入法
|
|
88
88
|
ValueT pow1, pow2, y, z;
|
|
89
89
|
ValueT x = number;
|
|
90
90
|
if (ndigits >= 0) {
|
|
91
|
-
pow1 =
|
|
91
|
+
pow1 = pow(ValueT(10.0), ValueT(ndigits));
|
|
92
92
|
pow2 = 1.0;
|
|
93
93
|
y = (x * pow1) * pow2;
|
|
94
94
|
} else {
|
|
95
|
-
pow1 =
|
|
95
|
+
pow1 = pow(ValueT(10.0), ValueT(-ndigits));
|
|
96
96
|
pow2 = 1.0;
|
|
97
97
|
y = x / pow1;
|
|
98
98
|
}
|
|
@@ -189,17 +189,17 @@ ValueT roundDown(ValueT number, int ndigits = 0) {
|
|
|
189
189
|
#endif
|
|
190
190
|
|
|
191
191
|
/** 转小写字符串 */
|
|
192
|
-
inline void to_lower(std::string&
|
|
192
|
+
inline void to_lower(std::string &s) {
|
|
193
193
|
std::transform(s.begin(), s.end(), s.begin(), [](unsigned char c) { return std::tolower(c); });
|
|
194
194
|
}
|
|
195
195
|
|
|
196
196
|
/** 转大写字符串 */
|
|
197
|
-
inline void to_upper(std::string&
|
|
197
|
+
inline void to_upper(std::string &s) {
|
|
198
198
|
std::transform(s.begin(), s.end(), s.begin(), [](unsigned char c) { return std::toupper(c); });
|
|
199
199
|
}
|
|
200
200
|
|
|
201
201
|
/** 删除字符串两端空格 */
|
|
202
|
-
inline void trim(std::string&
|
|
202
|
+
inline void trim(std::string &s) {
|
|
203
203
|
if (s.empty()) {
|
|
204
204
|
return;
|
|
205
205
|
}
|
|
@@ -210,12 +210,13 @@ inline void trim(std::string& s) {
|
|
|
210
210
|
s.erase(s.find_last_not_of("\n") + 1);
|
|
211
211
|
}
|
|
212
212
|
|
|
213
|
+
#if CPP_STANDARD >= CPP_STANDARD_17
|
|
213
214
|
/**
|
|
214
215
|
* 分割字符串
|
|
215
216
|
* @param str 待封的字符串
|
|
216
217
|
* @param c 分割符
|
|
217
218
|
*/
|
|
218
|
-
inline std::vector<std::string_view> split(const std::string&
|
|
219
|
+
inline std::vector<std::string_view> split(const std::string &str, char c) {
|
|
219
220
|
std::vector<std::string_view> result;
|
|
220
221
|
std::string_view view(str);
|
|
221
222
|
size_t prepos = 0;
|
|
@@ -226,9 +227,7 @@ inline std::vector<std::string_view> split(const std::string& str, char c) {
|
|
|
226
227
|
pos = view.find_first_of(c, prepos);
|
|
227
228
|
}
|
|
228
229
|
|
|
229
|
-
|
|
230
|
-
result.emplace_back(str.substr(prepos));
|
|
231
|
-
}
|
|
230
|
+
result.emplace_back(view.substr(prepos));
|
|
232
231
|
return result;
|
|
233
232
|
}
|
|
234
233
|
|
|
@@ -239,7 +238,7 @@ inline std::vector<std::string_view> split(const std::string& str, char c) {
|
|
|
239
238
|
* @return string_view 组成的 vector
|
|
240
239
|
* @note 注意返回结果的生命周期应小于输入的字符串相同!
|
|
241
240
|
*/
|
|
242
|
-
inline std::vector<std::string_view> split(const std::string_view&
|
|
241
|
+
inline std::vector<std::string_view> split(const std::string_view &view, char c) {
|
|
243
242
|
std::vector<std::string_view> result;
|
|
244
243
|
size_t prepos = 0;
|
|
245
244
|
size_t pos = view.find_first_of(c);
|
|
@@ -249,14 +248,12 @@ inline std::vector<std::string_view> split(const std::string_view& view, char c)
|
|
|
249
248
|
pos = view.find_first_of(c, prepos);
|
|
250
249
|
}
|
|
251
250
|
|
|
252
|
-
|
|
253
|
-
result.emplace_back(view.substr(prepos));
|
|
254
|
-
}
|
|
251
|
+
result.emplace_back(view.substr(prepos));
|
|
255
252
|
return result;
|
|
256
253
|
}
|
|
257
254
|
|
|
258
|
-
inline std::vector<std::string_view> split(const std::string_view&
|
|
259
|
-
const std::string&
|
|
255
|
+
inline std::vector<std::string_view> split(const std::string_view &str,
|
|
256
|
+
const std::string &split_str) {
|
|
260
257
|
std::vector<std::string_view> result;
|
|
261
258
|
size_t split_str_len = split_str.size();
|
|
262
259
|
if (split_str_len == 0) {
|
|
@@ -272,25 +269,64 @@ inline std::vector<std::string_view> split(const std::string_view& str,
|
|
|
272
269
|
pos = str.find(split_str, prepos);
|
|
273
270
|
}
|
|
274
271
|
|
|
275
|
-
|
|
276
|
-
|
|
272
|
+
result.emplace_back(str.substr(prepos));
|
|
273
|
+
return result;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
#else
|
|
277
|
+
/**
|
|
278
|
+
* 分割字符串
|
|
279
|
+
* @param str 待封的字符串
|
|
280
|
+
* @param c 分割符
|
|
281
|
+
*/
|
|
282
|
+
inline std::vector<std::string> split(const std::string &str, char c) {
|
|
283
|
+
std::vector<std::string> result;
|
|
284
|
+
size_t prepos = 0;
|
|
285
|
+
size_t pos = str.find_first_of(c);
|
|
286
|
+
while (pos != std::string::npos) {
|
|
287
|
+
result.emplace_back(str.substr(prepos, pos - prepos));
|
|
288
|
+
prepos = pos + 1;
|
|
289
|
+
pos = str.find_first_of(c, prepos);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
result.emplace_back(str.substr(prepos));
|
|
293
|
+
return result;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
inline std::vector<std::string> split(const std::string &str, const std::string &split_str) {
|
|
297
|
+
std::vector<std::string> result;
|
|
298
|
+
size_t split_str_len = split_str.size();
|
|
299
|
+
if (split_str_len == 0) {
|
|
300
|
+
result.emplace_back(str);
|
|
301
|
+
return result;
|
|
277
302
|
}
|
|
303
|
+
|
|
304
|
+
size_t prepos = 0;
|
|
305
|
+
size_t pos = str.find(split_str);
|
|
306
|
+
while (pos != std::string::npos) {
|
|
307
|
+
result.emplace_back(str.substr(prepos, pos - prepos));
|
|
308
|
+
prepos = pos + split_str_len;
|
|
309
|
+
pos = str.find(split_str, prepos);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
result.emplace_back(str.substr(prepos));
|
|
278
313
|
return result;
|
|
279
314
|
}
|
|
315
|
+
#endif /* #if CPP_STANDARD >= CPP_STANDARD_17 */
|
|
280
316
|
|
|
281
317
|
/**
|
|
282
318
|
* byte 转 16 进制字符串, 如 "abcd" 转换为 "61626364"
|
|
283
319
|
* @param in_byte 输入的 byte 数组
|
|
284
320
|
* @param in_len byte 数组长度
|
|
285
321
|
*/
|
|
286
|
-
inline std::string byteToHexStr(const char*
|
|
322
|
+
inline std::string byteToHexStr(const char *bytes, size_t in_len) {
|
|
287
323
|
std::string hexstr;
|
|
288
|
-
const unsigned char*
|
|
324
|
+
const unsigned char *in_byte = (const unsigned char *)bytes;
|
|
289
325
|
if (in_byte == nullptr) {
|
|
290
326
|
return hexstr;
|
|
291
327
|
}
|
|
292
328
|
|
|
293
|
-
char*
|
|
329
|
+
char *buf = new char[2 * in_len + 1];
|
|
294
330
|
size_t buf_ix = 0;
|
|
295
331
|
|
|
296
332
|
for (size_t i = 0; i < in_len; ++i) {
|
|
@@ -311,7 +347,7 @@ inline std::string byteToHexStr(const char* bytes, size_t in_len) {
|
|
|
311
347
|
* byte 转 16 进制字符串, 如 "abcd" 转换为 "61626364"
|
|
312
348
|
* @param in_byte std::string 格式的输入
|
|
313
349
|
*/
|
|
314
|
-
inline std::string byteToHexStr(const std::string&
|
|
350
|
+
inline std::string byteToHexStr(const std::string &bytes) {
|
|
315
351
|
return byteToHexStr(bytes.c_str(), bytes.size());
|
|
316
352
|
}
|
|
317
353
|
|
|
@@ -320,14 +356,14 @@ inline std::string byteToHexStr(const std::string& bytes) {
|
|
|
320
356
|
* @param in_byte 输入的 byte 数组
|
|
321
357
|
* @param in_len byte 数组长度
|
|
322
358
|
*/
|
|
323
|
-
inline std::string byteToHexStrForPrint(const char*
|
|
359
|
+
inline std::string byteToHexStrForPrint(const char *bytes, size_t in_len) {
|
|
324
360
|
std::string hexstr;
|
|
325
|
-
const unsigned char*
|
|
361
|
+
const unsigned char *in_byte = (const unsigned char *)bytes;
|
|
326
362
|
if (in_byte == nullptr) {
|
|
327
363
|
return hexstr;
|
|
328
364
|
}
|
|
329
365
|
|
|
330
|
-
char*
|
|
366
|
+
char *buf = new char[5 * in_len + 1];
|
|
331
367
|
size_t buf_ix = 0;
|
|
332
368
|
|
|
333
369
|
for (size_t i = 0; i < in_len; ++i) {
|
|
@@ -355,7 +391,7 @@ inline std::string byteToHexStrForPrint(const char* bytes, size_t in_len) {
|
|
|
355
391
|
* byte 转 16 进制字符串, 如 "abcd" 转换为 "61626364"
|
|
356
392
|
* @param in_byte 输入的 byte 数组
|
|
357
393
|
*/
|
|
358
|
-
inline std::string byteToHexStrForPrint(const std::string&
|
|
394
|
+
inline std::string byteToHexStrForPrint(const std::string &bytes) {
|
|
359
395
|
return byteToHexStrForPrint(bytes.c_str(), bytes.size());
|
|
360
396
|
}
|
|
361
397
|
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) hikyuu.org
|
|
3
|
+
*
|
|
4
|
+
* Created on: 2020-6-2
|
|
5
|
+
* Author: fasiondog
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
#ifndef HKU_UTILS_BASE64_H
|
|
10
|
+
#define HKU_UTILS_BASE64_H
|
|
11
|
+
|
|
12
|
+
#include <memory>
|
|
13
|
+
#include "string_view.h"
|
|
14
|
+
|
|
15
|
+
#ifndef HKU_UTILS_API
|
|
16
|
+
#define HKU_UTILS_API
|
|
17
|
+
#endif
|
|
18
|
+
|
|
19
|
+
namespace hku {
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* 将二进制 bytes 数组编码成 base64 字符串
|
|
23
|
+
* @param bytes_to_encode 内存起始地址
|
|
24
|
+
* @param in_len 待计算的字节长度
|
|
25
|
+
*/
|
|
26
|
+
std::string HKU_UTILS_API base64_encode(unsigned char const* bytes_to_encode, size_t in_len);
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* 字符串编码为 base64
|
|
30
|
+
* @param bytes_to_encode 内存起始地址
|
|
31
|
+
* @param in_len 待计算的字节长度
|
|
32
|
+
* @note 通过 func(unsigned char *, unsigned int) 函数实现,而不是直接只提供 string_view
|
|
33
|
+
* 版本的原因是:c++17 string_view 处理 nullptr 时,程序会直接挂掉,无异常
|
|
34
|
+
*/
|
|
35
|
+
inline std::string base64_encode(string_view src) {
|
|
36
|
+
return base64_encode((unsigned char const*)src.data(), src.size());
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* 将 base64 字符串解码
|
|
41
|
+
* @param encoded_string base64 编码的字符串
|
|
42
|
+
* @param in_len 字符串长度
|
|
43
|
+
* @return string 实际解码后的二进制内容保存在返回的字符串对象中
|
|
44
|
+
* @note 如果传入的base64编码字符串中含有非法字符,不会告警,仅处理到能处理的字符
|
|
45
|
+
*/
|
|
46
|
+
std::string HKU_UTILS_API base64_decode(unsigned char const* encoded_string, size_t in_len);
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* 将 base64 字符串解码
|
|
50
|
+
* @param encoded_string base64 编码的字符串
|
|
51
|
+
* @return string 实际解码后的二进制内容保存在返回的字符串对象中
|
|
52
|
+
*/
|
|
53
|
+
inline std::string base64_decode(string_view encoded_string) {
|
|
54
|
+
return base64_decode((unsigned char const*)encoded_string.data(), encoded_string.size());
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
} // namespace hku
|
|
58
|
+
|
|
59
|
+
#endif // HKU_UTILS_BASE64_H
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
#ifndef HKU_UTILS_CONFIG_H_
|
|
3
|
+
#define HKU_UTILS_CONFIG_H_
|
|
4
|
+
|
|
5
|
+
#include "osdef.h"
|
|
6
|
+
|
|
7
|
+
// clang-format off
|
|
8
|
+
|
|
9
|
+
#define HKU_ENABLE_MYSQL 1
|
|
10
|
+
#if HKU_ENABLE_MYSQL && HKU_OS_WINDOWS
|
|
11
|
+
#ifndef NOMINMAX
|
|
12
|
+
#define NOMINMAX
|
|
13
|
+
#endif
|
|
14
|
+
#endif
|
|
15
|
+
|
|
16
|
+
#define HKU_ENABLE_SQLITE 1
|
|
17
|
+
#define HKU_ENABLE_SQLCIPHER 0
|
|
18
|
+
/* #define HKU_SQL_TRACE 0 */
|
|
19
|
+
|
|
20
|
+
#define HKU_SUPPORT_DATETIME 1
|
|
21
|
+
|
|
22
|
+
#define HKU_ENABLE_INI_PARSER 1
|
|
23
|
+
|
|
24
|
+
#define HKU_ENABLE_STACK_TRACE 0
|
|
25
|
+
|
|
26
|
+
#define HKU_CLOSE_SPEND_TIME 0
|
|
27
|
+
|
|
28
|
+
#define HKU_USE_SPDLOG_ASYNC_LOGGER 0
|
|
29
|
+
#define HKU_LOG_ACTIVE_LEVEL "2"
|
|
30
|
+
|
|
31
|
+
#define HKU_ENABLE_MO 0
|
|
32
|
+
|
|
33
|
+
#define HKU_ENABLE_HTTP_CLIENT 1
|
|
34
|
+
#define HKU_ENABLE_HTTP_CLIENT_SSL 0
|
|
35
|
+
#define HKU_ENABLE_HTTP_CLIENT_ZIP 0
|
|
36
|
+
|
|
37
|
+
/* #undef HKU_ENABLE_NODE */
|
|
38
|
+
|
|
39
|
+
// clang-format on
|
|
40
|
+
|
|
41
|
+
#endif /* HKU_UTILS_CONFIG_H_ */
|