From a4b3c57c5ed98e730275438a5b578533fcfae2bb Mon Sep 17 00:00:00 2001 From: fasiondog Date: Mon, 3 Feb 2025 17:51:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=8F=8C=E6=8C=87=E6=A0=87?= =?UTF-8?q?=E8=BE=93=E5=85=A5=E6=8C=87=E6=A0=87=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hikyuu/indicator_talib/imp/ta_defines.h | 75 +++---------------- .../hikyuu/indicator_talib/imp/ta_imp.h | 60 ++------------- 2 files changed, 19 insertions(+), 116 deletions(-) diff --git a/hikyuu_cpp/hikyuu/indicator_talib/imp/ta_defines.h b/hikyuu_cpp/hikyuu/indicator_talib/imp/ta_defines.h index e775a1848..7effc0ead 100644 --- a/hikyuu_cpp/hikyuu/indicator_talib/imp/ta_defines.h +++ b/hikyuu_cpp/hikyuu/indicator_talib/imp/ta_defines.h @@ -8,6 +8,7 @@ #pragma once #include "hikyuu/indicator/Indicator.h" +#include "hikyuu/indicator/Indicator2InImp.h" #define TA_IN1_OUT_DEF(func) \ class Cls_##func : public IndicatorImp { \ @@ -30,79 +31,27 @@ virtual void _checkParam(const string& name) const override; \ }; -#if HKU_SUPPORT_SERIALIZATION -#define TA_IN2_OUT_DEF(func) \ - class Cls_##func : public IndicatorImp { \ - public: \ - Cls_##func(); \ - Cls_##func(const Indicator& ref_ind, bool fill_null); \ - virtual ~Cls_##func(); \ - virtual void _calculate(const Indicator& data) override; \ - virtual IndicatorImpPtr _clone() override; \ - \ - private: \ - Indicator m_ref_ind; \ - \ - private: \ - friend class boost::serialization::access; \ - template \ - void serialize(Archive& ar, const unsigned int version) { \ - ar& BOOST_SERIALIZATION_BASE_OBJECT_NVP(IndicatorImp); \ - ar& BOOST_SERIALIZATION_NVP(m_ref_ind); \ - } \ +#define TA_IN2_OUT_DEF(func) \ + class Cls_##func : public Indicator2InImp { \ + INDICATOR2IN_IMP(Cls_##func) \ + INDICATOR2IN_IMP_NO_PRIVATE_MEMBER_SERIALIZATION \ + public: \ + Cls_##func(); \ + Cls_##func(const Indicator& ref_ind, bool fill_null); \ + virtual ~Cls_##func(); \ }; #define TA_IN2_OUT_N_DEF(func) \ - class Cls_##func : public IndicatorImp { \ + class Cls_##func : public Indicator2InImp { \ + INDICATOR2IN_IMP(Cls_##func) \ + INDICATOR2IN_IMP_NO_PRIVATE_MEMBER_SERIALIZATION \ public: \ Cls_##func(); \ explicit Cls_##func(int n, bool fill_null); \ Cls_##func(const Indicator& ref_ind, int n, bool fill_null); \ virtual ~Cls_##func(); \ virtual void _checkParam(const string& name) const override; \ - virtual void _calculate(const Indicator& data) override; \ - virtual IndicatorImpPtr _clone() override; \ - \ - private: \ - Indicator m_ref_ind; \ - \ - private: \ - friend class boost::serialization::access; \ - template \ - void serialize(Archive& ar, const unsigned int version) { \ - ar& BOOST_SERIALIZATION_BASE_OBJECT_NVP(IndicatorImp); \ - ar& BOOST_SERIALIZATION_NVP(m_ref_ind); \ - } \ - }; -#else -#define TA_IN2_OUT_DEF(func) \ - class Cls_##func : public IndicatorImp { \ - public: \ - Cls_##func(); \ - Cls_##func(const Indicator& ref_ind); \ - virtual ~Cls_##func(); \ - virtual void _calculate(const Indicator& data) override; \ - virtual IndicatorImpPtr _clone() override; \ - \ - private: \ - Indicator m_ref_ind; \ - }; - -#define TA_IN2_OUT_N_DEF(func) \ - class Cls_##func : public IndicatorImp { \ - public: \ - Cls_##func(); \ - explicit Cls_##func(int n); \ - Cls_##func(const Indicator& ref_ind, int n); \ - virtual ~Cls_##func(); \ - virtual void _checkParam(const string& name) const override; \ - virtual void _calculate(const Indicator& data) override; \ - virtual IndicatorImpPtr _clone() override; \ - \ - private: \ - Indicator m_ref_ind; \ }; -#endif #define TA_K_OUT_DEF(func) \ class Cls_##func : public IndicatorImp { \ diff --git a/hikyuu_cpp/hikyuu/indicator_talib/imp/ta_imp.h b/hikyuu_cpp/hikyuu/indicator_talib/imp/ta_imp.h index 88fa8d920..205649a6c 100644 --- a/hikyuu_cpp/hikyuu/indicator_talib/imp/ta_imp.h +++ b/hikyuu_cpp/hikyuu/indicator_talib/imp/ta_imp.h @@ -448,40 +448,16 @@ } #define TA_IN2_OUT1_IMP(func, func_lookback) \ - Cls_##func::Cls_##func() : IndicatorImp(#func, 1) { \ - setParam("fill_null", true); \ - } \ + Cls_##func::Cls_##func() : Indicator2InImp(#func, 1) {} \ Cls_##func::Cls_##func(const Indicator &ref_ind, bool fill_null) \ - : IndicatorImp(#func, 1), m_ref_ind(ref_ind) { \ - setParam("fill_null", fill_null); \ - } \ + : Indicator2InImp(#func, ref_ind, fill_null, 1) {} \ Cls_##func::~Cls_##func() {} \ - IndicatorImpPtr Cls_##func::_clone() { \ - auto p = make_shared(); \ - p->m_ref_ind = m_ref_ind.clone(); \ - return p; \ - } \ \ void Cls_##func::_calculate(const Indicator &ind) { \ size_t total = ind.size(); \ HKU_IF_RETURN(total == 0, void()); \ \ - _readyBuffer(total, 1); \ - \ - auto k = getContext(); \ - m_ref_ind.setContext(k); \ - Indicator ref = m_ref_ind; \ - auto dates = ref.getDatetimeList(); \ - if (dates.empty()) { \ - if (ref.size() > ind.size()) { \ - ref = SLICE(ref, ref.size() - ind.size(), ref.size()); \ - } else if (ref.size() < ind.size()) { \ - ref = CVAL(ind, 0.) + ref; \ - } \ - } else if (k != ind.getContext()) { \ - ref = ALIGN(m_ref_ind, ind, getParam("fill_null")); \ - } \ - \ + Indicator ref = prepare(ind); \ int lookback = func_lookback(); \ if (lookback < 0) { \ m_discard = total; \ @@ -517,20 +493,18 @@ } #define TA_IN2_OUT1_N_IMP(func, func_lookback, period, period_min, period_max) \ - Cls_##func::Cls_##func() : IndicatorImp(#func, 1) { \ + Cls_##func::Cls_##func() : Indicator2InImp(#func, 1) { \ setParam("n", period); \ - setParam("fill_null", true); \ } \ \ - Cls_##func::Cls_##func(int n, bool fill_null) : IndicatorImp(#func, 1) { \ + Cls_##func::Cls_##func(int n, bool fill_null) : Indicator2InImp(#func, 1) { \ setParam("n", n); \ setParam("fill_null", fill_null); \ } \ \ Cls_##func::Cls_##func(const Indicator &ref_ind, int n, bool fill_null) \ - : IndicatorImp(#func, 1), m_ref_ind(ref_ind) { \ + : Indicator2InImp(#func, ref_ind, fill_null, 1) { \ setParam("n", n); \ - setParam("fill_null", fill_null); \ } \ \ Cls_##func::~Cls_##func() {} \ @@ -542,31 +516,11 @@ } \ } \ \ - IndicatorImpPtr Cls_##func::_clone() { \ - auto p = make_shared(); \ - p->m_ref_ind = m_ref_ind.clone(); \ - return p; \ - } \ - \ void Cls_##func::_calculate(const Indicator &ind) { \ size_t total = ind.size(); \ HKU_IF_RETURN(total == 0, void()); \ \ - _readyBuffer(total, 1); \ - \ - auto k = getContext(); \ - m_ref_ind.setContext(k); \ - Indicator ref = m_ref_ind; \ - auto dates = ref.getDatetimeList(); \ - if (dates.empty()) { \ - if (ref.size() > ind.size()) { \ - ref = SLICE(ref, ref.size() - ind.size(), ref.size()); \ - } else if (ref.size() < ind.size()) { \ - ref = CVAL(ind, 0.) + ref; \ - } \ - } else if (k != ind.getContext()) { \ - ref = ALIGN(m_ref_ind, ind, getParam("fill_null")); \ - } \ + Indicator ref = prepare(ind); \ \ int n = getParam("n"); \ int lookback = func_lookback(n); \