diff --git a/.clang-format b/.clang-format index 9c6254b54..5739a78ac 100644 --- a/.clang-format +++ b/.clang-format @@ -44,7 +44,7 @@ BreakConstructorInitializersBeforeComma: false BreakConstructorInitializers: BeforeColon BreakAfterJavaFieldAnnotations: false BreakStringLiterals: true -ColumnLimit: 120 +ColumnLimit: 100 CommentPragmas: '^ IWYU pragma:' CompactNamespaces: false ConstructorInitializerAllOnOneLineOrOnePerLine: true diff --git a/hikyuu_cpp/hikyuu/GlobalInitializer.cpp b/hikyuu_cpp/hikyuu/GlobalInitializer.cpp index 528f105e6..09a52af92 100644 --- a/hikyuu_cpp/hikyuu/GlobalInitializer.cpp +++ b/hikyuu_cpp/hikyuu/GlobalInitializer.cpp @@ -39,10 +39,11 @@ void GlobalInitializer::init() { } void GlobalInitializer::clean() { - DataDriverFactory::release(); StockManager::quit(); - H5close(); + DataDriverFactory::release(); + + //H5close(); spdlog::drop_all(); diff --git a/hikyuu_cpp/hikyuu/data_driver/DataDriverFactory.cpp b/hikyuu_cpp/hikyuu/data_driver/DataDriverFactory.cpp index 3d95d7c53..0429675d8 100644 --- a/hikyuu_cpp/hikyuu/data_driver/DataDriverFactory.cpp +++ b/hikyuu_cpp/hikyuu/data_driver/DataDriverFactory.cpp @@ -13,7 +13,6 @@ #include "kdata/hdf5/H5KDataDriver.h" #include "kdata/mysql/MySQLKDataDriver.h" #include "kdata/tdx/TdxKDataDriver.h" -#include "kdata/hdf5/H5KDataDriver.h" #include "DataDriverFactory.h" #include "KDataDriver.h" @@ -131,6 +130,15 @@ void DataDriverFactory::removeKDataDriver(const string& name) { KDataDriverPtr DataDriverFactory::getKDataDriver(const Parameter& params) { KDataDriverPtr result; + string name = params.get("type"); + to_upper(name); + auto iter = m_kdataDrivers->find(name); + if (iter != m_kdataDrivers->end()) { + result = iter->second; + result->init(params); + } + return result; + /*KDataDriverPtr result; auto param_iter = m_param_kdataDrivers->find(params); if (param_iter != m_param_kdataDrivers->end()) { result = param_iter->second; @@ -152,7 +160,7 @@ KDataDriverPtr DataDriverFactory::getKDataDriver(const Parameter& params) { (*m_param_kdataDrivers)[params] = result; } - return result; + return result;*/ } } /* namespace hku */ diff --git a/hikyuu_cpp/hikyuu/data_driver/KDataDriver.cpp b/hikyuu_cpp/hikyuu/data_driver/KDataDriver.cpp index ec3f7aeff..6609263b0 100644 --- a/hikyuu_cpp/hikyuu/data_driver/KDataDriver.cpp +++ b/hikyuu_cpp/hikyuu/data_driver/KDataDriver.cpp @@ -25,9 +25,9 @@ HKU_API std::ostream& operator<<(std::ostream& os, const KDataDriverPtr& driver) return os; } -KDataDriver::KDataDriver() : m_name("") {} +KDataDriver::KDataDriver() : m_name(""), m_inited(false) {} -KDataDriver::KDataDriver(const string& name) : m_name(name) { +KDataDriver::KDataDriver(const string& name) : m_name(name), m_inited(false) { to_upper(m_name); } @@ -52,6 +52,10 @@ bool KDataDriver::checkType() { } bool KDataDriver::init(const Parameter& params) { + if (m_inited) { + return m_inited; + } + if (m_params == params) { return true; } @@ -61,34 +65,32 @@ bool KDataDriver::init(const Parameter& params) { return false; } - return _init(); + m_inited = _init(); + return m_inited; } -void KDataDriver::loadKData(const string& market, const string& code, KQuery::KType kType, - size_t start_ix, size_t end_ix, KRecordListPtr out_buffer) {} +void KDataDriver::loadKData(const string& market, const string& code, KQuery::KType kType, size_t start_ix, + size_t end_ix, KRecordListPtr out_buffer) {} size_t KDataDriver::getCount(const string& market, const string& code, KQuery::KType kType) { return 0; } -bool KDataDriver::getIndexRangeByDate(const string& market, const string& code, const KQuery& query, - size_t& out_start, size_t& out_end) { +bool KDataDriver::getIndexRangeByDate(const string& market, const string& code, const KQuery& query, size_t& out_start, + size_t& out_end) { return false; } -KRecord KDataDriver::getKRecord(const string& market, const string& code, size_t pos, - KQuery::KType kType) { +KRecord KDataDriver::getKRecord(const string& market, const string& code, size_t pos, KQuery::KType kType) { return Null(); } -TimeLineList KDataDriver ::getTimeLineList(const string& market, const string& code, - const KQuery& query) { +TimeLineList KDataDriver ::getTimeLineList(const string& market, const string& code, const KQuery& query) { HKU_INFO("This driver not support time-line!"); return TimeLineList(); } -TransList KDataDriver ::getTransList(const string& market, const string& code, - const KQuery& query) { +TransList KDataDriver ::getTransList(const string& market, const string& code, const KQuery& query) { HKU_INFO("This driver not support transaction record!"); return TransList(); } diff --git a/hikyuu_cpp/hikyuu/data_driver/KDataDriver.h b/hikyuu_cpp/hikyuu/data_driver/KDataDriver.h index ae1276c60..3fc78abc7 100644 --- a/hikyuu_cpp/hikyuu/data_driver/KDataDriver.h +++ b/hikyuu_cpp/hikyuu/data_driver/KDataDriver.h @@ -48,8 +48,8 @@ class HKU_API KDataDriver { * @param end_ix 欲加载的结束位置,不包含自身 * @param out_buffer [out] 缓存指针 */ - virtual void loadKData(const string& market, const string& code, KQuery::KType kType, - size_t start_ix, size_t end_ix, KRecordListPtr out_buffer); + virtual void loadKData(const string& market, const string& code, KQuery::KType kType, size_t start_ix, + size_t end_ix, KRecordListPtr out_buffer); /** * 获取指定类型的K线数据量 @@ -69,8 +69,8 @@ class HKU_API KDataDriver { * @param out_end [out] 对应的K线记录位置 * @return */ - virtual bool getIndexRangeByDate(const string& market, const string& code, const KQuery& query, - size_t& out_start, size_t& out_end); + virtual bool getIndexRangeByDate(const string& market, const string& code, const KQuery& query, size_t& out_start, + size_t& out_end); /** * 获取指定的K线记录 @@ -80,8 +80,7 @@ class HKU_API KDataDriver { * @param kType K线类型 * @return */ - virtual KRecord getKRecord(const string& market, const string& code, size_t pos, - KQuery::KType kType); + virtual KRecord getKRecord(const string& market, const string& code, size_t pos, KQuery::KType kType); /** * 获取分时线 @@ -90,8 +89,7 @@ class HKU_API KDataDriver { * @param query 查询条件 * @return */ - virtual TimeLineList getTimeLineList(const string& market, const string& code, - const KQuery& query); + virtual TimeLineList getTimeLineList(const string& market, const string& code, const KQuery& query); /** * 获取历史分笔数据 @@ -107,6 +105,7 @@ class HKU_API KDataDriver { private: string m_name; + bool m_inited; //是否已初始化 }; typedef shared_ptr KDataDriverPtr; diff --git a/hikyuu_cpp/hikyuu/data_driver/kdata/hdf5/H5KDataDriver.h b/hikyuu_cpp/hikyuu/data_driver/kdata/hdf5/H5KDataDriver.h index e3c77dcaa..3b1bf4516 100644 --- a/hikyuu_cpp/hikyuu/data_driver/kdata/hdf5/H5KDataDriver.h +++ b/hikyuu_cpp/hikyuu/data_driver/kdata/hdf5/H5KDataDriver.h @@ -20,17 +20,14 @@ class HKU_API H5KDataDriver : public KDataDriver { virtual ~H5KDataDriver(); virtual bool _init() override; - virtual void loadKData(const string& market, const string& code, KQuery::KType kType, - size_t start_ix, size_t end_ix, KRecordListPtr out_buffer) override; + virtual void loadKData(const string& market, const string& code, KQuery::KType kType, size_t start_ix, + size_t end_ix, KRecordListPtr out_buffer) override; virtual size_t getCount(const string& market, const string& code, KQuery::KType kType) override; - virtual bool getIndexRangeByDate(const string& market, const string& code, const KQuery& query, - size_t& out_start, size_t& out_end) override; - virtual KRecord getKRecord(const string& market, const string& code, size_t pos, - KQuery::KType kType) override; - virtual TimeLineList getTimeLineList(const string& market, const string& code, - const KQuery& query) override; - virtual TransList getTransList(const string& market, const string& code, - const KQuery& query) override; + virtual bool getIndexRangeByDate(const string& market, const string& code, const KQuery& query, size_t& out_start, + size_t& out_end) override; + virtual KRecord getKRecord(const string& market, const string& code, size_t pos, KQuery::KType kType) override; + virtual TimeLineList getTimeLineList(const string& market, const string& code, const KQuery& query) override; + virtual TransList getTransList(const string& market, const string& code, const KQuery& query) override; private: void H5ReadRecords(H5::DataSet&, hsize_t, hsize_t, void*); @@ -38,36 +35,31 @@ class HKU_API H5KDataDriver : public KDataDriver { void H5ReadTimeLineRecords(H5::DataSet&, hsize_t, hsize_t, void*); void H5ReadTransRecords(H5::DataSet&, hsize_t, hsize_t, void*); - bool _getH5FileAndGroup(const string& market, const string& code, KQuery::KType kType, - H5FilePtr& out_file, H5::Group& out_group); + bool _getH5FileAndGroup(const string& market, const string& code, KQuery::KType kType, H5FilePtr& out_file, + H5::Group& out_group); KRecord _getBaseRecord(const string&, const string&, size_t, KQuery::KType); KRecord _getOtherRecord(const string&, const string&, size_t, KQuery::KType); - void _loadBaseData(const string& market, const string& code, KQuery::KType kType, - size_t start_ix, size_t end_ix, KRecordListPtr out_buffer); - void _loadIndexData(const string& market, const string& code, KQuery::KType kType, - size_t start_ix, size_t end_ix, KRecordListPtr out_buffer); + void _loadBaseData(const string& market, const string& code, KQuery::KType kType, size_t start_ix, size_t end_ix, + KRecordListPtr out_buffer); + void _loadIndexData(const string& market, const string& code, KQuery::KType kType, size_t start_ix, size_t end_ix, + KRecordListPtr out_buffer); - bool _getBaseIndexRangeByDate(const string&, const string&, const KQuery&, size_t& out_start, - size_t& out_end); - bool _getOtherIndexRangeByDate(const string&, const string&, const KQuery&, size_t& out_start, - size_t& out_end); + bool _getBaseIndexRangeByDate(const string&, const string&, const KQuery&, size_t& out_start, size_t& out_end); + bool _getOtherIndexRangeByDate(const string&, const string&, const KQuery&, size_t& out_start, size_t& out_end); TimeLineList _getTimeLine(const string& market, const string& code, int64 start, int64 end); - TimeLineList _getTimeLine(const string& market, const string& code, const Datetime& start, - const Datetime& end); + TimeLineList _getTimeLine(const string& market, const string& code, const Datetime& start, const Datetime& end); TransList _getTransList(const string& market, const string& code, int64 start, int64 end); - TransList _getTransList(const string& market, const string& code, const Datetime& start, - const Datetime& end); + TransList _getTransList(const string& market, const string& code, const Datetime& start, const Datetime& end); private: H5::CompType m_h5DataType; H5::CompType m_h5IndexType; H5::CompType m_h5TimeLineType; H5::CompType m_h5TransType; - H5FilePtr m_h5file; map m_h5file_map; // key: market+code }; diff --git a/hikyuu_cpp/unit_test/xmake.lua b/hikyuu_cpp/unit_test/xmake.lua index 5008a618a..b7c38fd66 100644 --- a/hikyuu_cpp/unit_test/xmake.lua +++ b/hikyuu_cpp/unit_test/xmake.lua @@ -87,8 +87,8 @@ target("small-test") end -- add files - --add_files("./hikyuu/hikyuu/**.cpp"); - add_files("./hikyuu/hikyuu/test_StockManager.cpp"); + add_files("./hikyuu/hikyuu/**.cpp"); + -- add_files("./hikyuu/hikyuu/test_StockManager.cpp"); add_files("./hikyuu/test_main.cpp") target_end() \ No newline at end of file