hikyuu2/libs/hikyuu_python/trade_sys/_Selector.cpp

78 lines
2.2 KiB
C++
Raw Normal View History

2016-04-03 00:08:31 +08:00
/*
* _Selector.cpp
*
* Created on: 2016328
2016-04-14 01:36:53 +08:00
* Author: fasiondog
2016-04-03 00:08:31 +08:00
*/
#include <boost/python.hpp>
#include <hikyuu/trade_sys/selector/build_in.h>
#include "../_Parameter.h"
2016-04-03 00:08:31 +08:00
#include "../pickle_support.h"
using namespace boost::python;
using namespace hku;
class SelectorWrap : public SelectorBase, public wrapper<SelectorBase> {
public:
SelectorWrap(): SelectorBase() {}
virtual ~SelectorWrap() {}
void _reset() {
if (override func = this->get_override("_reset")) {
func();
} else {
SelectorBase::_reset();
}
}
void default_reset() {
this->SelectorBase::_reset();
}
2018-01-22 01:33:49 +08:00
StockList getSelectedStockList(Datetime date) {
return this->get_override("getSelectedStockList")(date);
2016-04-03 00:08:31 +08:00
}
SelectorPtr _clone() {
return this->get_override("_clone")();
}
};
2018-01-12 01:56:05 +08:00
string (SelectorBase::*sb_get_name)() const = &SelectorBase::name;
void (SelectorBase::*sb_set_name)(const string&) = &SelectorBase::name;
SelectorPtr (*SE_Fixed_1)() = SE_Fixed;
SelectorPtr (*SE_Fixed_2)(const StockList&) = SE_Fixed;
2016-04-03 00:08:31 +08:00
void export_Selector() {
2016-04-03 00:08:31 +08:00
class_<SelectorWrap, boost::noncopyable>("SelectorBase", init<>())
.def(self_ns::str(self))
2018-01-12 01:56:05 +08:00
.add_property("name", sb_get_name, sb_set_name)
.def("getParam", &SelectorBase::getParam<boost::any>)
.def("setParam", &SelectorBase::setParam<object>)
2016-04-03 00:08:31 +08:00
.def("reset", &SelectorBase::reset)
.def("clone", &SelectorBase::clone)
.def("_reset", &SelectorBase::_reset, &SelectorWrap::default_reset)
.def("_clone", pure_virtual(&SelectorBase::_clone))
2018-01-22 01:33:49 +08:00
.def("getSelectedStockList", pure_virtual(&SelectorBase::getSelectedStockList))
2016-04-03 00:08:31 +08:00
.def("addStock", &SelectorBase::addStock)
.def("addStockList", &SelectorBase::addStockList)
.def("getRawStockList", &SelectorBase::getRawStockList, &SelectorWrap::getRawStockList)
.def("clearStockList", &SelectorBase::clearStockList)
#if HKU_PYTHON_SUPPORT_PICKLE
.def_pickle(name_init_pickle_suite<SelectorBase>())
#endif
;
register_ptr_to_python<SelectorPtr>();
def("SE_Fixed", SE_Fixed_1);
def("SE_Fixed", SE_Fixed_2);
2016-04-03 00:08:31 +08:00
}