mirror of
https://gitee.com/fasiondog/hikyuu.git
synced 2024-12-02 11:58:21 +08:00
add Condition operator add
This commit is contained in:
parent
d489e90c0f
commit
c48719b6e2
@ -27,4 +27,6 @@ HKU_API ConditionPtr operator&(const ConditionPtr& cond1, const ConditionPtr& co
|
||||
*/
|
||||
HKU_API ConditionPtr operator|(const ConditionPtr& cond1, const ConditionPtr& cond2);
|
||||
|
||||
HKU_API ConditionPtr operator+(const ConditionPtr& cond1, const ConditionPtr& cond2);
|
||||
|
||||
} // namespace hku
|
72
hikyuu_cpp/hikyuu/trade_sys/condition/imp/AddCondition.cpp
Normal file
72
hikyuu_cpp/hikyuu/trade_sys/condition/imp/AddCondition.cpp
Normal file
@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright (c) 2019~2023, hikyuu.org
|
||||
*
|
||||
* History:
|
||||
* 1. 20240223 added by fasiondog
|
||||
*/
|
||||
|
||||
#include "AddCondition.h"
|
||||
|
||||
namespace hku {
|
||||
|
||||
AddCondition::AddCondition() : ConditionBase("CN_Add") {}
|
||||
|
||||
AddCondition::AddCondition(const ConditionPtr& cond1, const ConditionPtr& cond2)
|
||||
: ConditionBase("CN_Add"), m_cond1(cond1), m_cond2(cond2) {}
|
||||
|
||||
AddCondition::~AddCondition() {}
|
||||
|
||||
void AddCondition::_calculate() {
|
||||
HKU_IF_RETURN(!m_cond1 && !m_cond2, void());
|
||||
|
||||
if (m_cond1 && !m_cond2) {
|
||||
price_t* data = m_cond1->data();
|
||||
for (size_t i = 0, total = m_cond1->size(); i < total; i++) {
|
||||
m_values[i] = data[i];
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (!m_cond1 && m_cond2) {
|
||||
price_t* data = m_cond2->data();
|
||||
for (size_t i = 0, total = m_cond2->size(); i < total; i++) {
|
||||
m_values[i] = data[i];
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
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();
|
||||
for (size_t i = 0; i < total; i++) {
|
||||
m_values[i] = data1[i] + data2[i];
|
||||
}
|
||||
}
|
||||
|
||||
void AddCondition::_reset() {
|
||||
if (m_cond1) {
|
||||
m_cond1->reset();
|
||||
}
|
||||
if (m_cond2) {
|
||||
m_cond2->reset();
|
||||
}
|
||||
}
|
||||
|
||||
ConditionPtr AddCondition::_clone() {
|
||||
AddCondition* p = new AddCondition();
|
||||
if (m_cond1) {
|
||||
p->m_cond1 = m_cond1->clone();
|
||||
}
|
||||
if (m_cond2) {
|
||||
p->m_cond2 = m_cond2->clone();
|
||||
}
|
||||
return ConditionPtr(p);
|
||||
}
|
||||
|
||||
HKU_API ConditionPtr operator+(const ConditionPtr& cond1, const ConditionPtr& cond2) {
|
||||
return make_shared<AddCondition>(cond1, cond2);
|
||||
}
|
||||
|
||||
} // namespace hku
|
42
hikyuu_cpp/hikyuu/trade_sys/condition/imp/AddCondition.h
Normal file
42
hikyuu_cpp/hikyuu/trade_sys/condition/imp/AddCondition.h
Normal file
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (c) 2019~2023, hikyuu.org
|
||||
*
|
||||
* History:
|
||||
* 1. 20240223 added by fasiondog
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../ConditionBase.h"
|
||||
|
||||
namespace hku {
|
||||
|
||||
class HKU_API AddCondition : public ConditionBase {
|
||||
public:
|
||||
AddCondition();
|
||||
AddCondition(const ConditionPtr& cond1, const ConditionPtr& cond2);
|
||||
virtual ~AddCondition();
|
||||
|
||||
virtual void _calculate() override;
|
||||
virtual void _reset() override;
|
||||
virtual ConditionPtr _clone() override;
|
||||
|
||||
private:
|
||||
ConditionPtr m_cond1;
|
||||
ConditionPtr m_cond2;
|
||||
|
||||
//============================================
|
||||
// 序列化支持
|
||||
//============================================
|
||||
#if HKU_SUPPORT_SERIALIZATION
|
||||
friend class boost::serialization::access;
|
||||
template <class Archive>
|
||||
void serialize(Archive& ar, const unsigned int version) {
|
||||
ar& BOOST_SERIALIZATION_BASE_OBJECT_NVP(ConditionBase);
|
||||
ar& BOOST_SERIALIZATION_NVP(m_cond1);
|
||||
ar& BOOST_SERIALIZATION_NVP(m_cond2);
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
} // namespace hku
|
@ -60,7 +60,7 @@ ConditionPtr AndCondition::_clone() {
|
||||
}
|
||||
|
||||
HKU_API ConditionPtr operator&(const ConditionPtr& cond1, const ConditionPtr& cond2) {
|
||||
return ConditionPtr(new AndCondition(cond1, cond2));
|
||||
return make_shared<AndCondition>(cond1, cond2);
|
||||
}
|
||||
|
||||
} // namespace hku
|
@ -84,7 +84,7 @@ ConditionPtr OrCondition::_clone() {
|
||||
}
|
||||
|
||||
HKU_API ConditionPtr operator|(const ConditionPtr& cond1, const ConditionPtr& cond2) {
|
||||
return ConditionPtr(new OrCondition(cond1, cond2));
|
||||
return make_shared<OrCondition>(cond1, cond2);
|
||||
}
|
||||
|
||||
} // namespace hku
|
@ -112,6 +112,9 @@ void export_Condition(py::module& m) {
|
||||
.def("__or__",
|
||||
[](const ConditionPtr& self, const ConditionPtr& other) { return self | other; })
|
||||
|
||||
.def("__add__",
|
||||
[](const ConditionPtr& self, const ConditionPtr& other) { return self + other; })
|
||||
|
||||
DEF_PICKLE(ConditionPtr);
|
||||
|
||||
m.def("CN_OPLine", CN_OPLine, R"(CN_OPLine(ind)
|
||||
|
Loading…
Reference in New Issue
Block a user