diff --git a/cppcheck.cppcheck b/cppcheck.cppcheck index f754eb7b..8747b385 100644 --- a/cppcheck.cppcheck +++ b/cppcheck.cppcheck @@ -32,9 +32,10 @@ ConfigurationNotChecked toomanyconfigs unknownMacro - useStlAlgorithm - shadowFunction missingIncludeSystem missingInclude + cstyleCast + shadowFunction + useStlAlgorithm diff --git a/hikyuu_cpp/hikyuu/StockManager.h b/hikyuu_cpp/hikyuu/StockManager.h index 55bed76a..66b0aaeb 100644 --- a/hikyuu_cpp/hikyuu/StockManager.h +++ b/hikyuu_cpp/hikyuu/StockManager.h @@ -34,6 +34,9 @@ public: static StockManager& instance(); virtual ~StockManager(); + StockManager(const StockManager&) = delete; + StockManager& operator=(const StockManager&) = delete; + /** * 初始化函数,必须在程序入口调用 * @param baseInfoParam 基础信息驱动参数 diff --git a/hikyuu_cpp/hikyuu/data_driver/kdata/tdx/TdxKDataDriver.cpp b/hikyuu_cpp/hikyuu/data_driver/kdata/tdx/TdxKDataDriver.cpp index 23055267..a7c5279b 100644 --- a/hikyuu_cpp/hikyuu/data_driver/kdata/tdx/TdxKDataDriver.cpp +++ b/hikyuu_cpp/hikyuu/data_driver/kdata/tdx/TdxKDataDriver.cpp @@ -47,7 +47,7 @@ struct TdxMinData { float close; float amount; uint32_t vol; - uint32_t other; + uint32_t other; // cppcheck-suppress unusedStructMember Datetime getDatetime() { int tmp_date = date >> 11; diff --git a/hikyuu_cpp/hikyuu/global/sysinfo.cpp b/hikyuu_cpp/hikyuu/global/sysinfo.cpp index aefdfad8..7dab82c6 100644 --- a/hikyuu_cpp/hikyuu/global/sysinfo.cpp +++ b/hikyuu_cpp/hikyuu/global/sysinfo.cpp @@ -50,6 +50,7 @@ std::string getVersionWithGit() { return HKU_VERSION_GIT; } +// cppcheck-suppress constParameterReference static bool readUUID(boost::uuids::uuid& out) { std::string filename = fmt::format("{}/.hikyuu/uid", getUserDir()); FILE* fp = fopen(filename.c_str(), "rb"); diff --git a/hikyuu_cpp/hikyuu/indicator/IndicatorImp.cpp b/hikyuu_cpp/hikyuu/indicator/IndicatorImp.cpp index 2915ce40..e6876060 100644 --- a/hikyuu_cpp/hikyuu/indicator/IndicatorImp.cpp +++ b/hikyuu_cpp/hikyuu/indicator/IndicatorImp.cpp @@ -389,7 +389,7 @@ IndicatorImpPtr IndicatorImp::getResult(size_t result_num) { size_t total = size(); imp->_readyBuffer(total, 1); imp->setDiscard(discard()); - auto *src = this->data(result_num); + auto const *src = this->data(result_num); auto *dst = imp->data(0); for (size_t i = discard(); i < total; ++i) { // imp->_set(get(i, result_num), i); @@ -400,18 +400,18 @@ IndicatorImpPtr IndicatorImp::getResult(size_t result_num) { price_t IndicatorImp::get(size_t pos, size_t num) const { #if CHECK_ACCESS_BOUND - HKU_CHECK_THROW((num < MAX_RESULT_NUM && m_pBuffer[num] && pos < m_pBuffer[num]->size()), - std::out_of_range, "Try to access value ({}) out of bounds [0..{})! {}", pos, - m_pBuffer[num]->size(), name()); + HKU_CHECK_THROW( + (num <= MAX_RESULT_NUM && m_pBuffer[num] && pos < m_pBuffer[num]->size()), std::out_of_range, + "Try to access value out of bounds! num: {}, pos: {}, name: {}", num, pos, name()); #endif return (*m_pBuffer[num])[pos]; } void IndicatorImp::_set(price_t val, size_t pos, size_t num) { #if CHECK_ACCESS_BOUND - HKU_CHECK_THROW((num < MAX_RESULT_NUM && m_pBuffer[num] && pos < m_pBuffer[num]->size()), - std::out_of_range, "Try to access value out of bounds! (pos={}) {}", pos, - name()); + HKU_CHECK_THROW( + (num <= MAX_RESULT_NUM && m_pBuffer[num] && pos < m_pBuffer[num]->size()), std::out_of_range, + "Try to access value out of bounds! num: {}, pos: {}, name: {}", num, pos, name()); #endif (*m_pBuffer[num])[pos] = val; } @@ -834,7 +834,7 @@ void IndicatorImp::execute_weave() { size_t diff = maxp->size() - minp->size(); _readyBuffer(total, result_number); setDiscard(discard); - value_type *src = nullptr; + value_type const *src = nullptr; value_type *dst = nullptr; if (m_left->size() >= m_right->size()) { size_t num = m_left->getResultNumber(); @@ -899,8 +899,8 @@ void IndicatorImp::execute_add() { _readyBuffer(total, result_number); setDiscard(discard); for (size_t r = 0; r < result_number; ++r) { - auto *data1 = maxp->data(r); - auto *data2 = minp->data(r); + auto const *data1 = maxp->data(r); + auto const *data2 = minp->data(r); auto *result = this->data(r); for (size_t i = discard; i < total; ++i) { // _set(maxp->get(i, r) + minp->get(i - diff, r), i, r); @@ -913,7 +913,7 @@ void IndicatorImp::execute_sub() { m_right->calculate(); m_left->calculate(); - IndicatorImp *maxp, *minp; + const IndicatorImp *maxp, *minp; if (m_left->size() > m_right->size()) { maxp = m_left.get(); minp = m_right.get(); @@ -979,8 +979,8 @@ void IndicatorImp::execute_mul() { _readyBuffer(total, result_number); setDiscard(discard); for (size_t r = 0; r < result_number; ++r) { - auto *data1 = maxp->data(r); - auto *data2 = minp->data(r); + auto const *data1 = maxp->data(r); + auto const *data2 = minp->data(r); auto *result = this->data(r); for (size_t i = discard; i < total; ++i) { // _set(maxp->get(i, r) * minp->get(i - diff, r), i, r); @@ -993,7 +993,7 @@ void IndicatorImp::execute_div() { m_right->calculate(); m_left->calculate(); - IndicatorImp *maxp, *minp; + const IndicatorImp *maxp, *minp; if (m_left->size() > m_right->size()) { maxp = m_left.get(); minp = m_right.get(); @@ -1076,8 +1076,8 @@ void IndicatorImp::execute_mod() { _readyBuffer(total, result_number); setDiscard(discard); value_type *dst = nullptr; - value_type *left = nullptr; - value_type *right = nullptr; + value_type const *left = nullptr; + value_type const *right = nullptr; value_type null_value = Null(); if (m_left->size() > m_right->size()) { for (size_t r = 0; r < result_number; ++r) { @@ -1143,8 +1143,8 @@ void IndicatorImp::execute_eq() { setDiscard(discard); for (size_t r = 0; r < result_number; ++r) { auto *dst = this->data(r); - auto *maxdata = maxp->data(r); - auto *mindata = minp->data(r); + auto const *maxdata = maxp->data(r); + auto const *mindata = minp->data(r); for (size_t i = discard; i < total; ++i) { if (std::abs(maxdata[i] - mindata[i - diff]) < IND_EQ_THRESHOLD) { dst[i] = 1.0; @@ -1185,8 +1185,8 @@ void IndicatorImp::execute_ne() { setDiscard(discard); for (size_t r = 0; r < result_number; ++r) { auto *dst = this->data(r); - auto *maxdata = maxp->data(r); - auto *mindata = minp->data(r); + auto const *maxdata = maxp->data(r); + auto const *mindata = minp->data(r); for (size_t i = discard; i < total; ++i) { if (std::abs(maxdata[i] - mindata[i - diff]) < IND_EQ_THRESHOLD) { dst[i] = 0.0; @@ -1206,7 +1206,7 @@ void IndicatorImp::execute_gt() { m_right->calculate(); m_left->calculate(); - IndicatorImp *maxp, *minp; + const IndicatorImp *maxp, *minp; if (m_left->size() > m_right->size()) { maxp = m_left.get(); minp = m_right.get(); @@ -1226,8 +1226,8 @@ void IndicatorImp::execute_gt() { _readyBuffer(total, result_number); setDiscard(discard); value_type *dst = nullptr; - value_type *left = nullptr; - value_type *right = nullptr; + value_type const *left = nullptr; + value_type const *right = nullptr; if (m_left->size() > m_right->size()) { for (size_t r = 0; r < result_number; ++r) { dst = this->data(r); @@ -1271,7 +1271,7 @@ void IndicatorImp::execute_lt() { m_right->calculate(); m_left->calculate(); - IndicatorImp *maxp, *minp; + const IndicatorImp *maxp, *minp; if (m_left->size() > m_right->size()) { maxp = m_left.get(); minp = m_right.get(); @@ -1291,8 +1291,8 @@ void IndicatorImp::execute_lt() { _readyBuffer(total, result_number); setDiscard(discard); value_type *dst = nullptr; - value_type *left = nullptr; - value_type *right = nullptr; + value_type const *left = nullptr; + value_type const *right = nullptr; if (m_left->size() > m_right->size()) { for (size_t r = 0; r < result_number; ++r) { dst = this->data(r); @@ -1336,7 +1336,7 @@ void IndicatorImp::execute_ge() { m_right->calculate(); m_left->calculate(); - IndicatorImp *maxp, *minp; + const IndicatorImp *maxp, *minp; if (m_left->size() > m_right->size()) { maxp = m_left.get(); minp = m_right.get(); @@ -1356,8 +1356,8 @@ void IndicatorImp::execute_ge() { _readyBuffer(total, result_number); setDiscard(discard); value_type *dst = nullptr; - value_type *left = nullptr; - value_type *right = nullptr; + value_type const *left = nullptr; + value_type const *right = nullptr; if (m_left->size() > m_right->size()) { for (size_t r = 0; r < result_number; ++r) { dst = this->data(r); @@ -1401,7 +1401,7 @@ void IndicatorImp::execute_le() { m_right->calculate(); m_left->calculate(); - IndicatorImp *maxp, *minp; + const IndicatorImp *maxp, *minp; if (m_left->size() > m_right->size()) { maxp = m_left.get(); minp = m_right.get(); @@ -1421,8 +1421,8 @@ void IndicatorImp::execute_le() { _readyBuffer(total, result_number); setDiscard(discard); value_type *dst = nullptr; - value_type *left = nullptr; - value_type *right = nullptr; + value_type const *left = nullptr; + value_type const *right = nullptr; if (m_left->size() > m_right->size()) { for (size_t r = 0; r < result_number; ++r) { dst = this->data(r); @@ -1466,7 +1466,7 @@ void IndicatorImp::execute_and() { m_right->calculate(); m_left->calculate(); - IndicatorImp *maxp, *minp; + const IndicatorImp *maxp, *minp; if (m_right->size() > m_left->size()) { maxp = m_right.get(); minp = m_left.get(); @@ -1487,8 +1487,8 @@ void IndicatorImp::execute_and() { setDiscard(discard); for (size_t r = 0; r < result_number; ++r) { auto *dst = this->data(r); - auto *maxdata = maxp->data(r); - auto *mindata = minp->data(r); + auto const *maxdata = maxp->data(r); + auto const *mindata = minp->data(r); for (size_t i = discard; i < total; ++i) { if (maxdata[i] >= IND_EQ_THRESHOLD && mindata[i - diff] >= IND_EQ_THRESHOLD) { dst[i] = 1.0; @@ -1530,8 +1530,8 @@ void IndicatorImp::execute_or() { setDiscard(discard); for (size_t r = 0; r < result_number; ++r) { auto *dst = this->data(r); - auto *maxdata = maxp->data(r); - auto *mindata = minp->data(r); + auto const *maxdata = maxp->data(r); + auto const *mindata = minp->data(r); for (size_t i = discard; i < total; ++i) { if (maxdata[i] >= IND_EQ_THRESHOLD || mindata[i - diff] >= IND_EQ_THRESHOLD) { dst[i] = 1.0; @@ -1642,8 +1642,8 @@ void IndicatorImp::execute_corr() { auto *dst0 = this->data(0); auto *dst1 = this->data(1); - auto *maxdata = maxp->data(0); - auto *mindata = minp->data(0); + auto const *maxdata = maxp->data(0); + auto const *mindata = minp->data(0); for (size_t i = startPos + 1; i < first_end; i++) { ix = maxdata[i] - kx; iy = mindata[i] - ky; diff --git a/hikyuu_cpp/hikyuu/indicator/IndicatorImp.h b/hikyuu_cpp/hikyuu/indicator/IndicatorImp.h index aa8210dc..8c066029 100644 --- a/hikyuu_cpp/hikyuu/indicator/IndicatorImp.h +++ b/hikyuu_cpp/hikyuu/indicator/IndicatorImp.h @@ -86,7 +86,7 @@ public: public: /** 默认构造函数 */ IndicatorImp(); - IndicatorImp(const string& name); + explicit IndicatorImp(const string& name); IndicatorImp(const string& name, size_t result_num); virtual ~IndicatorImp(); diff --git a/hikyuu_cpp/hikyuu/indicator/imp/IAd.h b/hikyuu_cpp/hikyuu/indicator/imp/IAd.h index 76cea02c..f604d985 100644 --- a/hikyuu_cpp/hikyuu/indicator/imp/IAd.h +++ b/hikyuu_cpp/hikyuu/indicator/imp/IAd.h @@ -22,7 +22,7 @@ class IAd : public IndicatorImp { public: IAd(); - IAd(const KData&); + explicit IAd(const KData&); virtual ~IAd(); }; diff --git a/hikyuu_cpp/hikyuu/indicator/imp/IBackset.cpp b/hikyuu_cpp/hikyuu/indicator/imp/IBackset.cpp index 2e4a9c70..268ab531 100644 --- a/hikyuu_cpp/hikyuu/indicator/imp/IBackset.cpp +++ b/hikyuu_cpp/hikyuu/indicator/imp/IBackset.cpp @@ -48,9 +48,7 @@ void IBackset::_calculate(const Indicator& ind) { size_t j = i; size_t end_j = i - n + 1; while (j-- > end_j) { - if (dst[j] != 1.0) { - dst[j] = 1.0; - } + dst[j] = 1.0; } } else { if (dst[i] != 1.0) { diff --git a/hikyuu_cpp/hikyuu/indicator/imp/IEvery.cpp b/hikyuu_cpp/hikyuu/indicator/imp/IEvery.cpp index d0f01db9..f0503126 100644 --- a/hikyuu_cpp/hikyuu/indicator/imp/IEvery.cpp +++ b/hikyuu_cpp/hikyuu/indicator/imp/IEvery.cpp @@ -34,7 +34,6 @@ void IEvery::_calculate(const Indicator& ind) { int n = getParam("n"); if (0 == n) { - n = total; m_discard = ind.discard(); for (size_t i = m_discard; i < total; i++) { price_t every = 1.0; diff --git a/hikyuu_cpp/hikyuu/indicator/imp/IExist.cpp b/hikyuu_cpp/hikyuu/indicator/imp/IExist.cpp index ea6a971b..aa6351ef 100644 --- a/hikyuu_cpp/hikyuu/indicator/imp/IExist.cpp +++ b/hikyuu_cpp/hikyuu/indicator/imp/IExist.cpp @@ -34,7 +34,6 @@ void IExist::_calculate(const Indicator& ind) { int n = getParam("n"); if (n == 0) { - n = total; m_discard = ind.discard(); for (size_t i = m_discard; i < total; i++) { price_t exist = 0.0; diff --git a/hikyuu_cpp/hikyuu/indicator/imp/ILiuTongPan.h b/hikyuu_cpp/hikyuu/indicator/imp/ILiuTongPan.h index 56add0ca..37708057 100644 --- a/hikyuu_cpp/hikyuu/indicator/imp/ILiuTongPan.h +++ b/hikyuu_cpp/hikyuu/indicator/imp/ILiuTongPan.h @@ -20,7 +20,7 @@ class ILiuTongPan : public IndicatorImp { public: ILiuTongPan(); - ILiuTongPan(const KData&); + explicit ILiuTongPan(const KData&); virtual ~ILiuTongPan(); }; diff --git a/hikyuu_cpp/hikyuu/indicator/imp/ITimeLine.h b/hikyuu_cpp/hikyuu/indicator/imp/ITimeLine.h index d350d57d..a14bdd39 100644 --- a/hikyuu_cpp/hikyuu/indicator/imp/ITimeLine.h +++ b/hikyuu_cpp/hikyuu/indicator/imp/ITimeLine.h @@ -22,7 +22,7 @@ class ITimeLine : public IndicatorImp { public: ITimeLine(); - ITimeLine(const KData&); + explicit ITimeLine(const KData&); virtual ~ITimeLine(); }; diff --git a/hikyuu_cpp/hikyuu/indicator/imp/IVigor.h b/hikyuu_cpp/hikyuu/indicator/imp/IVigor.h index 6709bbcc..db7ba8dd 100644 --- a/hikyuu_cpp/hikyuu/indicator/imp/IVigor.h +++ b/hikyuu_cpp/hikyuu/indicator/imp/IVigor.h @@ -26,7 +26,7 @@ class IVigor : public IndicatorImp { public: IVigor(); - IVigor(int n); + explicit IVigor(int n); virtual ~IVigor(); }; diff --git a/hikyuu_cpp/hikyuu/strategy/StrategyBase.h b/hikyuu_cpp/hikyuu/strategy/StrategyBase.h index 1108d2d5..597dee17 100644 --- a/hikyuu_cpp/hikyuu/strategy/StrategyBase.h +++ b/hikyuu_cpp/hikyuu/strategy/StrategyBase.h @@ -23,7 +23,7 @@ class HKU_API StrategyBase { public: StrategyBase(); - StrategyBase(const string& name); + explicit StrategyBase(const string& name); StrategyBase(const string& name, const string& config_file); virtual ~StrategyBase(); diff --git a/hikyuu_cpp/hikyuu/trade_manage/TradeManager.h b/hikyuu_cpp/hikyuu/trade_manage/TradeManager.h index 57608e9d..10b5ea16 100644 --- a/hikyuu_cpp/hikyuu/trade_manage/TradeManager.h +++ b/hikyuu_cpp/hikyuu/trade_manage/TradeManager.h @@ -42,8 +42,9 @@ class HKU_API TradeManager : public TradeManagerBase { // PARAMETER_SUPPORT public: - TradeManager(const Datetime& datetime = Datetime(199001010000LL), price_t initcash = 100000.0, - const TradeCostPtr& costfunc = TC_Zero(), const string& name = "SYS"); + explicit TradeManager(const Datetime& datetime = Datetime(199001010000LL), + price_t initcash = 100000.0, const TradeCostPtr& costfunc = TC_Zero(), + const string& name = "SYS"); virtual ~TradeManager(); /** 复位,清空交易、持仓记录 */ diff --git a/hikyuu_cpp/hikyuu/trade_sys/condition/ConditionBase.h b/hikyuu_cpp/hikyuu/trade_sys/condition/ConditionBase.h index 2ca07406..3a919864 100644 --- a/hikyuu_cpp/hikyuu/trade_sys/condition/ConditionBase.h +++ b/hikyuu_cpp/hikyuu/trade_sys/condition/ConditionBase.h @@ -64,7 +64,7 @@ public: price_t at(size_t pos) const; - price_t* data(); + price_t const* data() const; /** 复位操作 */ void reset(); @@ -223,7 +223,7 @@ inline size_t ConditionBase::size() const { return m_values.size(); } -inline price_t* ConditionBase::data() { +inline price_t const* ConditionBase::data() const { return m_values.data(); } diff --git a/hikyuu_cpp/hikyuu/trade_sys/condition/imp/AddCondition.cpp b/hikyuu_cpp/hikyuu/trade_sys/condition/imp/AddCondition.cpp index 71de57bd..3134ad95 100644 --- a/hikyuu_cpp/hikyuu/trade_sys/condition/imp/AddCondition.cpp +++ b/hikyuu_cpp/hikyuu/trade_sys/condition/imp/AddCondition.cpp @@ -32,7 +32,7 @@ void AddCondition::_calculate() { } if (m_cond1 && !m_cond2) { - price_t* data = m_cond1->data(); + price_t const* data = m_cond1->data(); for (size_t i = 0, total = m_cond1->size(); i < total; i++) { m_values[i] = data[i]; } @@ -40,7 +40,7 @@ void AddCondition::_calculate() { } if (!m_cond1 && m_cond2) { - price_t* data = m_cond2->data(); + auto const* data = m_cond2->data(); for (size_t i = 0, total = m_cond2->size(); i < total; i++) { m_values[i] = data[i]; } @@ -50,8 +50,8 @@ void AddCondition::_calculate() { size_t total = m_kdata.size(); HKU_ASSERT(m_cond1->size() == total && m_cond2->size() == total); - price_t* data1 = m_cond1->data(); - price_t* data2 = m_cond2->data(); + auto const* data1 = m_cond1->data(); + auto const* data2 = m_cond2->data(); for (size_t i = 0; i < total; i++) { m_values[i] = data1[i] + data2[i]; } diff --git a/hikyuu_cpp/hikyuu/trade_sys/condition/imp/AndCondition.cpp b/hikyuu_cpp/hikyuu/trade_sys/condition/imp/AndCondition.cpp index 116b588e..4445c4d9 100644 --- a/hikyuu_cpp/hikyuu/trade_sys/condition/imp/AndCondition.cpp +++ b/hikyuu_cpp/hikyuu/trade_sys/condition/imp/AndCondition.cpp @@ -32,8 +32,8 @@ void AndCondition::_calculate() { size_t total = m_kdata.size(); HKU_ASSERT(m_cond1->size() == total && m_cond2->size() == total); - price_t* data1 = m_cond1->data(); - price_t* data2 = m_cond2->data(); + auto const* data1 = m_cond1->data(); + auto const* data2 = m_cond2->data(); for (size_t i = 0; i < total; i++) { m_values[i] = (data1[i] > 0.0 && data2[i] > 0.0) ? 1.0 : 0.0; } diff --git a/hikyuu_cpp/hikyuu/trade_sys/condition/imp/BoolCondition.h b/hikyuu_cpp/hikyuu/trade_sys/condition/imp/BoolCondition.h index 3e0fa0e1..02325595 100644 --- a/hikyuu_cpp/hikyuu/trade_sys/condition/imp/BoolCondition.h +++ b/hikyuu_cpp/hikyuu/trade_sys/condition/imp/BoolCondition.h @@ -15,7 +15,7 @@ namespace hku { class BoolCondition : public ConditionBase { public: BoolCondition(); - BoolCondition(const Indicator&); + explicit BoolCondition(const Indicator&); virtual ~BoolCondition(); virtual void _calculate() override; diff --git a/hikyuu_cpp/hikyuu/trade_sys/condition/imp/DivCondition.cpp b/hikyuu_cpp/hikyuu/trade_sys/condition/imp/DivCondition.cpp index 68ae8812..afa0c727 100644 --- a/hikyuu_cpp/hikyuu/trade_sys/condition/imp/DivCondition.cpp +++ b/hikyuu_cpp/hikyuu/trade_sys/condition/imp/DivCondition.cpp @@ -38,8 +38,8 @@ void DivCondition::_calculate() { size_t total = m_kdata.size(); HKU_ASSERT(m_cond1->size() == total && m_cond2->size() == total); - price_t* data1 = m_cond1->data(); - price_t* data2 = m_cond2->data(); + auto const* data1 = m_cond1->data(); + auto const* data2 = m_cond2->data(); for (size_t i = 0; i < total; i++) { m_values[i] = data2[i] == 0.0 || std::isnan(data2[i]) ? null_price : data1[i] / data2[i]; } diff --git a/hikyuu_cpp/hikyuu/trade_sys/condition/imp/MultiCondition.cpp b/hikyuu_cpp/hikyuu/trade_sys/condition/imp/MultiCondition.cpp index 5231e4a9..40dc297f 100644 --- a/hikyuu_cpp/hikyuu/trade_sys/condition/imp/MultiCondition.cpp +++ b/hikyuu_cpp/hikyuu/trade_sys/condition/imp/MultiCondition.cpp @@ -29,8 +29,8 @@ void MultiCondition::_calculate() { size_t total = m_kdata.size(); HKU_ASSERT(m_cond1->size() == total && m_cond2->size() == total); - price_t* data1 = m_cond1->data(); - price_t* data2 = m_cond2->data(); + auto const* data1 = m_cond1->data(); + auto const* data2 = m_cond2->data(); for (size_t i = 0; i < total; i++) { m_values[i] = data1[i] * data2[i]; } diff --git a/hikyuu_cpp/hikyuu/trade_sys/condition/imp/OPLineCondition.h b/hikyuu_cpp/hikyuu/trade_sys/condition/imp/OPLineCondition.h index 4f203545..02504b99 100644 --- a/hikyuu_cpp/hikyuu/trade_sys/condition/imp/OPLineCondition.h +++ b/hikyuu_cpp/hikyuu/trade_sys/condition/imp/OPLineCondition.h @@ -17,7 +17,7 @@ namespace hku { class OPLineCondition : public ConditionBase { public: OPLineCondition(); - OPLineCondition(const Indicator&); + explicit OPLineCondition(const Indicator&); virtual ~OPLineCondition(); virtual void _calculate() override; diff --git a/hikyuu_cpp/hikyuu/trade_sys/condition/imp/OrCondition.cpp b/hikyuu_cpp/hikyuu/trade_sys/condition/imp/OrCondition.cpp index cfb3a643..7bfad1aa 100644 --- a/hikyuu_cpp/hikyuu/trade_sys/condition/imp/OrCondition.cpp +++ b/hikyuu_cpp/hikyuu/trade_sys/condition/imp/OrCondition.cpp @@ -32,7 +32,7 @@ void OrCondition::_calculate() { } if (m_cond1 && !m_cond2) { - price_t* data = m_cond1->data(); + auto const* data = m_cond1->data(); for (size_t i = 0, total = m_cond1->size(); i < total; i++) { if (data[i] > 0.0) { m_values[i] = 1.0; @@ -42,7 +42,7 @@ void OrCondition::_calculate() { } if (!m_cond1 && m_cond2) { - price_t* data = m_cond2->data(); + auto const* data = m_cond2->data(); for (size_t i = 0, total = m_cond2->size(); i < total; i++) { if (data[i] > 0.0) { m_values[i] = 1.0; @@ -54,8 +54,8 @@ void OrCondition::_calculate() { size_t total = m_kdata.size(); HKU_ASSERT(m_cond1->size() == total && m_cond2->size() == total); - price_t* data1 = m_cond1->data(); - price_t* data2 = m_cond2->data(); + auto const* data1 = m_cond1->data(); + auto const* data2 = m_cond2->data(); for (size_t i = 0; i < total; i++) { if (data1[i] > 0. || data2[i] > 0.) { m_values[i] = 1.0; diff --git a/hikyuu_cpp/hikyuu/trade_sys/condition/imp/SubCondition.cpp b/hikyuu_cpp/hikyuu/trade_sys/condition/imp/SubCondition.cpp index 52c05fae..32ddda1a 100644 --- a/hikyuu_cpp/hikyuu/trade_sys/condition/imp/SubCondition.cpp +++ b/hikyuu_cpp/hikyuu/trade_sys/condition/imp/SubCondition.cpp @@ -32,7 +32,7 @@ void SubCondition::_calculate() { } if (m_cond1 && !m_cond2) { - price_t* data = m_cond1->data(); + auto const* data = m_cond1->data(); for (size_t i = 0, total = m_cond1->size(); i < total; i++) { m_values[i] = data[i]; } @@ -40,7 +40,7 @@ void SubCondition::_calculate() { } if (!m_cond1 && m_cond2) { - price_t* data = m_cond2->data(); + auto const* data = m_cond2->data(); for (size_t i = 0, total = m_cond2->size(); i < total; i++) { m_values[i] = -data[i]; } @@ -50,10 +50,10 @@ void SubCondition::_calculate() { size_t total = m_kdata.size(); HKU_ASSERT(m_cond1->size() == total && m_cond2->size() == total); - price_t* data1 = m_cond1->data(); - price_t* data2 = m_cond2->data(); + auto const* data1 = m_cond1->data(); + auto const* data2 = m_cond2->data(); for (size_t i = 0; i < total; i++) { - m_values[i] = data1[i] = data2[i]; + m_values[i] = data1[i] - data2[i]; } } diff --git a/hikyuu_cpp/hikyuu/trade_sys/environment/imp/BoolEnvironment.h b/hikyuu_cpp/hikyuu/trade_sys/environment/imp/BoolEnvironment.h index 7bd8a48c..acfb0f72 100644 --- a/hikyuu_cpp/hikyuu/trade_sys/environment/imp/BoolEnvironment.h +++ b/hikyuu_cpp/hikyuu/trade_sys/environment/imp/BoolEnvironment.h @@ -15,7 +15,7 @@ namespace hku { class BoolEnvironment : public EnvironmentBase { public: BoolEnvironment(); - BoolEnvironment(const Indicator& ind); + explicit BoolEnvironment(const Indicator& ind); virtual ~BoolEnvironment(); virtual void _calculate() override; diff --git a/hikyuu_cpp/hikyuu/trade_sys/portfolio/Portfolio.h b/hikyuu_cpp/hikyuu/trade_sys/portfolio/Portfolio.h index 9a5030c2..f9a0ffbc 100644 --- a/hikyuu_cpp/hikyuu/trade_sys/portfolio/Portfolio.h +++ b/hikyuu_cpp/hikyuu/trade_sys/portfolio/Portfolio.h @@ -35,7 +35,7 @@ public: * @brief 指定名称的构造函数 * @param name 名称 */ - Portfolio(const string& name); + explicit Portfolio(const string& name); /** * @brief 构造函数 @@ -116,9 +116,9 @@ protected: SEPtr m_se; AFPtr m_af; - KQuery m_query; // 关联的查询条件 - bool m_is_ready; // 是否已做好运行准备 - bool m_need_calculate; // 是否需要计算标志 + KQuery m_query; // 关联的查询条件 + bool m_is_ready; // 是否已做好运行准备 + bool m_need_calculate; // 是否需要计算标志 SystemList m_pro_sys_list; // 所有原型系统列表,来自 SE SystemList m_real_sys_list; // 所有实际运行的子系统列表 diff --git a/hikyuu_cpp/hikyuu/trade_sys/signal/imp/SingleSignal.h b/hikyuu_cpp/hikyuu/trade_sys/signal/imp/SingleSignal.h index 8d675998..14a21ba1 100644 --- a/hikyuu_cpp/hikyuu/trade_sys/signal/imp/SingleSignal.h +++ b/hikyuu_cpp/hikyuu/trade_sys/signal/imp/SingleSignal.h @@ -17,7 +17,7 @@ namespace hku { class SingleSignal : public SignalBase { public: SingleSignal(); - SingleSignal(const Indicator& ind); + explicit SingleSignal(const Indicator& ind); virtual ~SingleSignal(); virtual SignalPtr _clone() override; diff --git a/hikyuu_cpp/hikyuu/trade_sys/signal/imp/SingleSignal2.h b/hikyuu_cpp/hikyuu/trade_sys/signal/imp/SingleSignal2.h index 7efd7c08..82e36885 100644 --- a/hikyuu_cpp/hikyuu/trade_sys/signal/imp/SingleSignal2.h +++ b/hikyuu_cpp/hikyuu/trade_sys/signal/imp/SingleSignal2.h @@ -17,7 +17,7 @@ namespace hku { class SingleSignal2 : public SignalBase { public: SingleSignal2(); - SingleSignal2(const Indicator&); + explicit SingleSignal2(const Indicator&); virtual ~SingleSignal2(); virtual SignalPtr _clone() override; diff --git a/hikyuu_cpp/hikyuu/trade_sys/system/System.h b/hikyuu_cpp/hikyuu/trade_sys/system/System.h index 623aa335..c277d715 100644 --- a/hikyuu_cpp/hikyuu/trade_sys/system/System.h +++ b/hikyuu_cpp/hikyuu/trade_sys/system/System.h @@ -37,7 +37,7 @@ public: System(); /** 指定系统名称的构造函数 */ - System(const string& name); + explicit System(const string& name); /** * @brief 构造函数 diff --git a/hikyuu_cpp/hikyuu/utilities/IniParser.cpp b/hikyuu_cpp/hikyuu/utilities/IniParser.cpp index 2c7f9b32..b2518fff 100644 --- a/hikyuu_cpp/hikyuu/utilities/IniParser.cpp +++ b/hikyuu_cpp/hikyuu/utilities/IniParser.cpp @@ -39,9 +39,7 @@ private: void ParsingError::append(size_t lineno, const std::string& line) { m_info << "\n\t[line " << lineno << "] " << line; - if (!m_haveError) { - m_haveError = true; - } + m_haveError = true; } IniParser::IniParser() {} diff --git a/hikyuu_cpp/hikyuu/utilities/db_connect/SQLResultSet.h b/hikyuu_cpp/hikyuu/utilities/db_connect/SQLResultSet.h index 7dac4baa..812320e3 100644 --- a/hikyuu_cpp/hikyuu/utilities/db_connect/SQLResultSet.h +++ b/hikyuu_cpp/hikyuu/utilities/db_connect/SQLResultSet.h @@ -60,7 +60,7 @@ public: if (pos != std::string::npos) { m_orderby_inner = fmt::format("{}, id ASC", m_where.substr(pos)); m_orderby_outer = m_orderby_inner; - m_where = m_where.substr(0, pos); + m_where = m_where.erase(pos, std::string::npos); } else { m_orderby_inner = "ORDER BY id"; }