hikyuu2/hikyuu_pywrap/_Block.cpp

101 lines
2.8 KiB
C++
Raw Normal View History

2016-04-03 00:08:31 +08:00
/*
* _Block.cpp
*
* Created on: 2015210
2016-04-14 01:36:53 +08:00
* Author: fasiondog
2016-04-03 00:08:31 +08:00
*/
#include <boost/python.hpp>
#include <hikyuu/serialization/Block_serialization.h>
#include "pickle_support.h"
using namespace boost::python;
using namespace hku;
string (Block::*getCategory)() const = &Block::category;
void (Block::*setCategory)(const string&) = &Block::category;
string (Block::*getName)() const = &Block::name;
void (Block::*setName)(const string&) = &Block::name;
bool (Block::*add_1)(const Stock&) = &Block::add;
bool (Block::*add_2)(const string&) = &Block::add;
bool (Block::*remove_1)(const Stock&) = &Block::remove;
bool (Block::*remove_2)(const string&) = &Block::remove;
void export_Block() {
2020-07-06 00:41:32 +08:00
class_<Block>("Block", "板块类,可视为证券的容器", init<>())
.def(init<const string&, const string&>())
.def(init<const Block&>())
2017-09-29 01:37:12 +08:00
2020-07-06 00:41:32 +08:00
.def(self_ns::str(self))
.def(self_ns::repr(self))
.add_property("category", getCategory, setCategory, "板块所属分类")
.add_property("name", getName, setName, "板块名称")
.def("empty", &Block::empty, R"(empty(self)
)")
.def("add", add_1, R"(add(self, stock)
:param Stock stock:
:return:
:rtype: bool)")
.def("add", add_2, R"(add(self, market_code)
"市场简称证券代码"
:param str market_code:
:return:
:rtype: bool)")
.def("remove", remove_1, R"(remove(self, stock)
:param Stock stock:
:return:
:rtype: bool)")
.def("remove", remove_2, R"(remove(market_code)
:param str market_code:
2020-07-07 00:34:25 +08:00
:return: True | False
2020-07-06 00:41:32 +08:00
:rtype: bool)")
.def("clear", &Block::clear, "移除包含的所有证券")
2020-07-07 00:34:25 +08:00
.def("__len__", &Block::size, "包含的证券数量")
.def("__getitem__", &Block::get, R"(__getitem__(self, market_code)
:param str market_code:
:return: Stock )")
2020-07-06 00:41:32 +08:00
.def("__iter__", iterator<const Block>())
2016-04-03 00:08:31 +08:00
#if HKU_PYTHON_SUPPORT_PICKLE
2020-07-06 00:41:32 +08:00
.def_pickle(normal_pickle_suite<Block>())
2016-04-03 00:08:31 +08:00
#endif
2020-07-06 00:41:32 +08:00
;
BlockList::const_reference (BlockList::*BlockList_at)(BlockList::size_type) const =
&BlockList::at;
2020-07-07 00:34:25 +08:00
void (BlockList::*BlockList_append)(const BlockList::value_type& val) = &BlockList::push_back;
2020-07-06 00:41:32 +08:00
class_<BlockList>("BlockList", "C++ std::vector<Block>包装")
.def("__iter__", iterator<BlockList>())
.def("__len__", &BlockList::size)
2020-07-07 00:34:25 +08:00
.def("append", BlockList_append)
2020-07-06 00:41:32 +08:00
.def("get", BlockList_at, return_value_policy<copy_const_reference>())
2016-04-03 00:08:31 +08:00
#if HKU_PYTHON_SUPPORT_PICKLE
2020-07-06 00:41:32 +08:00
.def_pickle(normal_pickle_suite<BlockList>())
2016-04-03 00:08:31 +08:00
#endif
2020-07-06 00:41:32 +08:00
;
2016-04-03 00:08:31 +08:00
}