try add operator(k) for indicator

This commit is contained in:
fasiondog 2019-04-17 23:37:22 +08:00
parent 8dd85d3cea
commit 4df93ba3ae
3 changed files with 15 additions and 1 deletions

View File

@ -31,6 +31,12 @@ string Indicator::formula() const {
return m_imp ? m_imp->formula() : "Indicator";
}
Indicator Indicator::operator()(const KData& k) {
Indicator result = clone();
result.setContext(k);
return result;
}
void Indicator::setContext(const Stock& stock, const KQuery& query) {
if (m_imp) m_imp->setContext(stock, query);
}

View File

@ -48,6 +48,9 @@ public:
/** 使用已有参数计算新值返回全新的Indicator */
Indicator operator()(const Indicator& ind);
/** 同 setContext */
Indicator operator()(const KData& k);
/** 指标名称 */
string name() const;

View File

@ -48,6 +48,9 @@ void (Indicator::*ind_write_name)(const string&) = &Indicator::name;
void (Indicator::*setContext_1)(const Stock&, const KQuery&) = &Indicator::setContext;
void (Indicator::*setContext_2)(const KData&) = &Indicator::setContext;
Indicator (Indicator::*call_1)operator()(const Indicator&) = &Indicator::operator();
Indicator (Indicator::*call_2)operator()(const KData&) = &Indicator::operator();
void export_Indicator() {
class_<Indicator>("Indicator", init<>())
@ -72,7 +75,9 @@ void export_Indicator() {
.def("getContext", &Indicator::getContext)
.def("getImp", &Indicator::getImp)
.def("__len__", &Indicator::size)
.def("__call__", &Indicator::operator())
//.def("__call__", &Indicator::operator())
.def("__call__", call_1)
.def("__call__", call_2)
#if HKU_PYTHON_SUPPORT_PICKLE
.def_pickle(normal_pickle_suite<Indicator>())
#endif