diff --git a/hikyuu_cpp/hikyuu/KQuery.cpp b/hikyuu_cpp/hikyuu/KQuery.cpp index 48da931b..1c7969e0 100644 --- a/hikyuu_cpp/hikyuu/KQuery.cpp +++ b/hikyuu_cpp/hikyuu/KQuery.cpp @@ -29,29 +29,29 @@ const string KQuery::HOUR12("HOUR12"); // const string KQuery::INVALID_KTYPE("Z"); static vector g_all_ktype{KQuery::MIN, KQuery::MIN5, KQuery::MIN15, KQuery::MIN30, - KQuery::MIN60, KQuery::DAY, KQuery::WEEK, KQuery::MONTH, - KQuery::QUARTER, KQuery::HALFYEAR, KQuery::YEAR, KQuery::MIN3, - KQuery::HOUR2, KQuery::HOUR4, KQuery::HOUR6, KQuery::HOUR12}; + KQuery::MIN60, KQuery::DAY, KQuery::WEEK, KQuery::MONTH, + KQuery::QUARTER, KQuery::HALFYEAR, KQuery::YEAR, KQuery::MIN3, + KQuery::HOUR2, KQuery::HOUR4, KQuery::HOUR6, KQuery::HOUR12}; static const unordered_map g_ktype2min{ - {KQuery::MIN, 1}, - {KQuery::MIN3, 3}, + {KQuery::MIN, 1}, + {KQuery::MIN3, 3}, - {KQuery::MIN5, 5}, - {KQuery::MIN15, 15}, - {KQuery::MIN30, 30}, - {KQuery::MIN60, 60}, - {KQuery::HOUR2, 60 * 2}, - {KQuery::HOUR4, 60 * 4}, - {KQuery::HOUR6, 60 * 6}, - {KQuery::HOUR12, 60 * 12}, + {KQuery::MIN5, 5}, + {KQuery::MIN15, 15}, + {KQuery::MIN30, 30}, + {KQuery::MIN60, 60}, + {KQuery::HOUR2, 60 * 2}, + {KQuery::HOUR4, 60 * 4}, + {KQuery::HOUR6, 60 * 6}, + {KQuery::HOUR12, 60 * 12}, - {KQuery::DAY, 60 * 24}, - {KQuery::WEEK, 60 * 24 * 7}, - {KQuery::MONTH, 60 * 24 * 30}, - {KQuery::QUARTER, 60 * 24 * 30 * 3}, - {KQuery::HALFYEAR, 60 * 24 * 30 * 6}, - {KQuery::YEAR, 60 * 24 * 365}, + {KQuery::DAY, 60 * 24}, + {KQuery::WEEK, 60 * 24 * 7}, + {KQuery::MONTH, 60 * 24 * 30}, + {KQuery::QUARTER, 60 * 24 * 30 * 3}, + {KQuery::HALFYEAR, 60 * 24 * 30 * 6}, + {KQuery::YEAR, 60 * 24 * 365}, }; // 获取所有的 KType @@ -163,4 +163,16 @@ HKU_API std::ostream& operator<<(std::ostream& os, const KQuery& query) { return os; } +bool HKU_API operator!=(const KQuery& q1, const KQuery& q2) { + // cppcheck-suppress [mismatchingContainerExpression] + return q1.start() != q2.start() || q1.end() != q2.end() || q1.queryType() != q2.queryType() || + q1.kType() != q2.kType() || q1.recoverType() != q2.recoverType(); +} + +bool HKU_API operator==(const KQuery& q1, const KQuery& q2) { + // cppcheck-suppress [mismatchingContainerExpression] + return q1.start() == q2.start() && q1.end() == q2.end() && q1.queryType() == q2.queryType() && + q1.kType() == q2.kType() && q1.recoverType() == q2.recoverType(); +} + } // namespace hku diff --git a/hikyuu_cpp/hikyuu/KQuery.h b/hikyuu_cpp/hikyuu/KQuery.h index 60ff7ad0..01ed32ea 100644 --- a/hikyuu_cpp/hikyuu/KQuery.h +++ b/hikyuu_cpp/hikyuu/KQuery.h @@ -244,18 +244,8 @@ HKU_API std::ostream& operator<<(std::ostream& os, const KQuery& query); // 关系比较函数, 不直接在类中定义是为了支持 Null<>() == d,Null可以放在左边 // /////////////////////////////////////////////////////////////////////////////// -bool operator==(const KQuery&, const KQuery&); -bool operator!=(const KQuery&, const KQuery&); - -inline bool operator!=(const KQuery& q1, const KQuery& q2) { - // cppcheck-suppress [mismatchingContainerExpression] - return q1.start() != q2.start() || q1.end() != q2.end() || q1.queryType() != q2.queryType() || - q1.kType() != q2.kType() || q1.recoverType() != q2.recoverType(); -} - -inline bool operator==(const KQuery& q1, const KQuery& q2) { - return !(q1 != q2); -} +bool HKU_API operator==(const KQuery&, const KQuery&); +bool HKU_API operator!=(const KQuery&, const KQuery&); /** * 提供KQuery的Null值 diff --git a/hikyuu_cpp/hikyuu/KRecord.cpp b/hikyuu_cpp/hikyuu/KRecord.cpp index 610f2e66..286dd99a 100644 --- a/hikyuu_cpp/hikyuu/KRecord.cpp +++ b/hikyuu_cpp/hikyuu/KRecord.cpp @@ -30,4 +30,8 @@ bool HKU_API operator==(const KRecord& d1, const KRecord& d2) { (std::fabs(d1.transCount - d2.transCount) < 0.0001)); } +bool HKU_API operator!=(const KRecord& d1, const KRecord& d2) { + return !(d1 == d2); +} + } // namespace hku diff --git a/hikyuu_cpp/hikyuu/KRecord.h b/hikyuu_cpp/hikyuu/KRecord.h index 23dcd8ba..87133d76 100644 --- a/hikyuu_cpp/hikyuu/KRecord.h +++ b/hikyuu_cpp/hikyuu/KRecord.h @@ -78,6 +78,12 @@ HKU_API std::ostream& operator<<(std::ostream&, const KRecord&); */ bool HKU_API operator==(const KRecord& d1, const KRecord& d2); +/** + * 两个KRecord不等比较 + * @ingroup StockManage + */ +bool HKU_API operator!=(const KRecord& d1, const KRecord& d2); + } // namespace hku #if FMT_VERSION >= 90000 diff --git a/hikyuu_pywrap/_KQuery.cpp b/hikyuu_pywrap/_KQuery.cpp index 722b8384..ae3204f4 100644 --- a/hikyuu_pywrap/_KQuery.cpp +++ b/hikyuu_pywrap/_KQuery.cpp @@ -15,6 +15,9 @@ using namespace hku; KQuery::RecoverType (KQuery::*get_recoverType)() const = &KQuery::recoverType; void (KQuery::*set_recoverType)(KQuery::RecoverType recoverType) = &KQuery::recoverType; +bool (*kquery_eq)(const KQuery&, const KQuery&) = operator==; +bool (*kquery_ne)(const KQuery&, const KQuery&) = operator!=; + void export_KQuery() { scope in_Query = class_("Query", "K线数据查询条件", init<>()) @@ -37,6 +40,9 @@ void export_KQuery() { .add_property("recover_type", get_recoverType, set_recoverType, "查询的复权类型 Query.RecoverType") + .def("__eq__", kquery_eq) + .def("__ne__", kquery_ne) + #if HKU_PYTHON_SUPPORT_PICKLE .def_pickle(normal_pickle_suite()) #endif diff --git a/hikyuu_pywrap/_KRecord.cpp b/hikyuu_pywrap/_KRecord.cpp index a9470692..f76da759 100644 --- a/hikyuu_pywrap/_KRecord.cpp +++ b/hikyuu_pywrap/_KRecord.cpp @@ -18,6 +18,7 @@ using namespace hku; #endif bool (*krecord_eq)(const KRecord&, const KRecord&) = operator==; +bool (*krecord_ne)(const KRecord&, const KRecord&) = operator!=; void export_KReord() { class_("KRecord", "K线记录,组成K线数据,属性可读写", init<>()) @@ -35,6 +36,8 @@ void export_KReord() { .def_readwrite("volume", &KRecord::transCount, "成交量") .def("__eq__", krecord_eq) + .def("__ne__", krecord_ne) + #if HKU_PYTHON_SUPPORT_PICKLE .def_pickle(normal_pickle_suite()) #endif