hikyuu2/hikyuu_cpp/hikyuu/data_driver/KDataDriver.h

195 lines
4.9 KiB
C++
Raw Permalink Normal View History

2015-01-07 01:26:14 +08:00
/*
* KDataDriver.h
*
* Created on: 2012-9-8
* Author: fasiondog
*/
#pragma once
2015-01-07 01:26:14 +08:00
#ifndef KDATADRIVER_H_
#define KDATADRIVER_H_
#include "../utilities/Parameter.h"
2019-02-08 22:41:20 +08:00
#include "../KQuery.h"
#include "../TimeLineRecord.h"
2019-02-11 21:13:06 +08:00
#include "../TransRecord.h"
2015-01-07 01:26:14 +08:00
namespace hku {
/**
* K线数据驱动基类
2020-06-26 21:39:53 +08:00
* @ingroup DataDriver
2015-01-07 01:26:14 +08:00
*/
class HKU_API KDataDriver {
PARAMETER_SUPPORT
2015-01-07 01:26:14 +08:00
public:
KDataDriver();
2020-06-26 21:39:53 +08:00
2021-01-20 00:32:01 +08:00
KDataDriver(const Parameter& params);
2020-06-26 21:39:53 +08:00
/**
*
* @param name
*/
KDataDriver(const string& name);
2019-11-10 23:31:41 +08:00
virtual ~KDataDriver() {}
2015-01-07 01:26:14 +08:00
2020-06-26 21:39:53 +08:00
/** 获取驱动名称 */
const string& name() const;
2020-06-26 21:39:53 +08:00
/** 驱动初始化 */
bool init(const Parameter&);
2021-01-20 00:32:01 +08:00
typedef shared_ptr<KDataDriver> KDataDriverPtr;
/**
*
*/
KDataDriverPtr clone();
/**
*
*/
virtual KDataDriverPtr _clone() = 0;
/**
*
* @return
*/
virtual bool _init() {
return true;
}
2020-10-01 00:06:58 +08:00
/**
*
*/
virtual bool isIndexFirst() = 0;
2020-12-27 19:11:18 +08:00
/**
*
*/
virtual bool canParallelLoad() = 0;
2015-01-07 01:26:14 +08:00
/**
* K线数据量
* @param market
* @param code
* @param kType K线类型
* @return
*/
2024-01-28 23:38:03 +08:00
virtual size_t getCount(const string& market, const string& code, const KQuery::KType& kType);
2015-01-07 01:26:14 +08:00
/**
* K线记录索引
* @param market
* @param code
* @param query
* @param out_start [out] K线记录位置
* @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);
2015-01-07 01:26:14 +08:00
2020-10-01 00:06:58 +08:00
/**
* K 线
* @param market
* @param code
* @param query
*/
2020-10-02 17:31:33 +08:00
virtual KRecordList getKRecordList(const string& market, const string& code,
const KQuery& query);
2020-10-01 00:06:58 +08:00
2019-02-10 21:26:02 +08:00
/**
* 线
* @param market
* @param code
* @param query
* @return
*/
virtual TimeLineList getTimeLineList(const string& market, const string& code,
const KQuery& query);
2019-02-08 22:41:20 +08:00
2019-02-11 21:13:06 +08:00
/**
*
* @param market
* @param code
* @param query
* @return
*/
2019-11-10 23:31:41 +08:00
virtual TransList getTransList(const string& market, const string& code, const KQuery& query);
2019-02-11 21:13:06 +08:00
2015-01-07 01:26:14 +08:00
private:
bool checkType();
2015-01-07 01:26:14 +08:00
private:
string m_name;
2015-01-07 01:26:14 +08:00
};
typedef shared_ptr<KDataDriver> KDataDriverPtr;
2019-11-10 23:31:41 +08:00
HKU_API std::ostream& operator<<(std::ostream&, const KDataDriver&);
HKU_API std::ostream& operator<<(std::ostream&, const KDataDriverPtr&);
2017-10-20 02:11:57 +08:00
inline const string& KDataDriver::name() const {
return m_name;
}
2021-01-24 20:47:38 +08:00
class KDataDriverConnect {
public:
typedef KDataDriver DriverType;
typedef KDataDriverPtr DriverTypePtr;
2021-03-24 23:20:01 +08:00
explicit KDataDriverConnect(const KDataDriverPtr& driver) : m_driver(driver) {}
2021-01-24 20:47:38 +08:00
~KDataDriverConnect() = default;
KDataDriverConnect(const KDataDriverConnect&) = delete;
KDataDriverConnect(KDataDriverConnect&&) = delete;
KDataDriverConnect& operator=(const KDataDriverConnect&) = delete;
KDataDriverConnect& operator=(KDataDriverConnect&&) = delete;
explicit operator bool() const noexcept {
return m_driver.get() != nullptr;
}
const string& name() const {
return m_driver->name();
}
bool isIndexFirst() {
return m_driver->isIndexFirst();
}
bool canParallelLoad() {
return m_driver->canParallelLoad();
}
size_t getCount(const string& market, const string& code, KQuery::KType kType) {
return m_driver->getCount(market, code, kType);
}
bool getIndexRangeByDate(const string& market, const string& code, const KQuery& query,
size_t& out_start, size_t& out_end) {
return m_driver->getIndexRangeByDate(market, code, query, out_start, out_end);
}
KRecordList getKRecordList(const string& market, const string& code, const KQuery& query) {
return m_driver->getKRecordList(market, code, query);
}
TimeLineList getTimeLineList(const string& market, const string& code, const KQuery& query) {
return m_driver->getTimeLineList(market, code, query);
}
TransList getTransList(const string& market, const string& code, const KQuery& query) {
return m_driver->getTransList(market, code, query);
}
private:
KDataDriverPtr m_driver;
};
2019-11-10 23:31:41 +08:00
} // namespace hku
2015-01-07 01:26:14 +08:00
#endif /* KDATADRIVER_H_ */