Skip to content

Commit

Permalink
Merge pull request fasiondog#155 from fasiondog/feature/cppcheck
Browse files Browse the repository at this point in the history
cppcheck 信息清理
  • Loading branch information
fasiondog authored Jan 28, 2024
2 parents 78c4565 + e249f73 commit 544df89
Show file tree
Hide file tree
Showing 59 changed files with 240 additions and 224 deletions.
22 changes: 20 additions & 2 deletions cppcheck.cppcheck
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="1">
<builddir>cppcheck-cppcheck-build-dir</builddir>
<platform>Unspecified</platform>
<analyze-all-vs-configs>false</analyze-all-vs-configs>
<check-headers>true</check-headers>
<check-unused-templates>false</check-unused-templates>
<max-ctu-depth>10</max-ctu-depth>
<max-template-recursion>100</max-template-recursion>
<max-template-recursion>1000</max-template-recursion>
<defines>
<define name="BOOST_SERIALIZATION_ASSUME_ABSTRACT"/>
<define name="TABLE_BIND6"/>
<define name="TABLE_BIND3"/>
<define name="TABLE_BIND4"/>
</defines>
<undefines>
<undefine>int64_t</undefine>
<undefine>int32_t</undefine>
<undefine>uint64_t</undefine>
<undefine>uint32_t</undefine>
<undefine>uint8_t</undefine>
<undefine>int8_t</undefine>
</undefines>
<paths>
<dir name="hikyuu_cpp/hikyuu"/>
<dir name="hikyuu_cpp/hikyuu_server"/>
</paths>
<libraries>
<library>boost</library>
Expand All @@ -18,5 +32,9 @@
<suppression>ConfigurationNotChecked</suppression>
<suppression>toomanyconfigs</suppression>
<suppression>unknownMacro</suppression>
<suppression>useStlAlgorithm</suppression>
<suppression>shadowFunction</suppression>
<suppression>missingIncludeSystem</suppression>
<suppression>missingInclude</suppression>
</suppressions>
</project>
6 changes: 3 additions & 3 deletions hikyuu_cpp/hikyuu/KData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,13 @@ KData HKU_API getKData(const string& market_code, const KQuery& query) {
}

KData HKU_API getKData(const string& market_code, const Datetime& start, const Datetime& end,
KQuery::KType ktype, KQuery::RecoverType recoverType) {
const KQuery::KType& ktype, KQuery::RecoverType recoverType) {
KQuery query(start, end, ktype, recoverType);
return StockManager::instance().getStock(market_code).getKData(query);
}

KData HKU_API getKData(const string& market_code, int64_t start, int64_t end, KQuery::KType ktype,
KQuery::RecoverType recoverType) {
KData HKU_API getKData(const string& market_code, int64_t start, int64_t end,
const KQuery::KType& ktype, KQuery::RecoverType recoverType) {
KQuery query(start, end, ktype, recoverType);
return StockManager::instance().getStock(market_code).getKData(query);
}
Expand Down
5 changes: 3 additions & 2 deletions hikyuu_cpp/hikyuu/KData.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ KData HKU_API getKData(const string& market_code, const KQuery& query);
* @ingroup StockManage
*/
KData HKU_API getKData(const string& market_code, const Datetime& start = Datetime::min(),
const Datetime& end = Null<Datetime>(), KQuery::KType ktype = KQuery::DAY,
const Datetime& end = Null<Datetime>(),
const KQuery::KType& ktype = KQuery::DAY,
KQuery::RecoverType recoverType = KQuery::NO_RECOVER);

/**
Expand All @@ -147,7 +148,7 @@ KData HKU_API getKData(const string& market_code, const Datetime& start = Dateti
* @ingroup StockManage
*/
KData HKU_API getKData(const string& market_code, int64_t start = 0, int64_t end = Null<int64_t>(),
KQuery::KType ktype = KQuery::DAY,
const KQuery::KType& ktype = KQuery::DAY,
KQuery::RecoverType recoverType = KQuery::NO_RECOVER);

inline KData::KData(const KData& x) : m_imp(x.m_imp) {}
Expand Down
2 changes: 1 addition & 1 deletion hikyuu_cpp/hikyuu/KQuery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ int32_t KQuery::getKTypeInMin(KType ktype) {
return g_ktype2min.at(ktype);
}

KQuery::KQuery(Datetime start, Datetime end, KType ktype, RecoverType recoverType)
KQuery::KQuery(Datetime start, Datetime end, const KType& ktype, RecoverType recoverType)
: m_start(start == Null<Datetime>() ? (int64_t)start.number()
: (int64_t)(start.number() * 100 + start.second())),
m_end(end == Null<Datetime>() ? (int64_t)end.number()
Expand Down
14 changes: 7 additions & 7 deletions hikyuu_cpp/hikyuu/KQuery.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class HKU_API KQuery {
* @param queryType 默认按索引方式查询
*/
KQuery(int64_t start, // cppcheck-suppress [noExplicitConstructor]
int64_t end = Null<int64_t>(), KType dataType = DAY,
int64_t end = Null<int64_t>(), const KType& dataType = DAY,
RecoverType recoverType = NO_RECOVER, QueryType queryType = INDEX)
: m_start(start),
m_end(end),
Expand All @@ -122,7 +122,7 @@ class HKU_API KQuery {
* @param recoverType 复权类型
*/
KQuery(Datetime start, // cppcheck-suppress [noExplicitConstructor]
Datetime end = Null<Datetime>(), KType ktype = DAY,
Datetime end = Null<Datetime>(), const KType& ktype = DAY,
RecoverType recoverType = NO_RECOVER);

/**
Expand Down Expand Up @@ -206,10 +206,10 @@ class HKU_API KQuery {
* @ingroup StockManage*
*/
KQuery HKU_API KQueryByIndex(int64_t start = 0, int64_t end = Null<int64_t>(),
KQuery::KType dataType = KQuery::DAY,
const KQuery::KType& dataType = KQuery::DAY,
KQuery::RecoverType recoverType = KQuery::NO_RECOVER);

inline KQuery KQueryByIndex(int64_t start, int64_t end, KQuery::KType dataType,
inline KQuery KQueryByIndex(int64_t start, int64_t end, const KQuery::KType& dataType,
KQuery::RecoverType recoverType) {
return KQuery(start, end, dataType, recoverType, KQuery::INDEX);
}
Expand All @@ -225,11 +225,11 @@ inline KQuery KQueryByIndex(int64_t start, int64_t end, KQuery::KType dataType,
*/
KQuery HKU_API KQueryByDate(const Datetime& start = Datetime::min(),
const Datetime& end = Null<Datetime>(),
KQuery::KType dataType = KQuery::DAY,
const KQuery::KType& dataType = KQuery::DAY,
KQuery::RecoverType recoverType = KQuery::NO_RECOVER);

inline KQuery KQueryByDate(const Datetime& start, const Datetime& end, KQuery::KType dataType,
KQuery::RecoverType recoverType) {
inline KQuery KQueryByDate(const Datetime& start, const Datetime& end,
const KQuery::KType& dataType, KQuery::RecoverType recoverType) {
return KQuery(start, end, dataType, recoverType);
}

Expand Down
14 changes: 7 additions & 7 deletions hikyuu_cpp/hikyuu/MarketInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ HKU_API std::ostream& operator<<(std::ostream& os, const MarketInfo& market) {
return os;
}

string split(", ");
os << "MarketInfo(" << market.market() << split << market.name() << split
<< market.description() << split << market.code() << split << market.lastDate() << ")";
string sp(", ");
os << "MarketInfo(" << market.market() << sp << market.name() << sp << market.description()
<< sp << market.code() << sp << market.lastDate() << ")";
return os;
}

Expand All @@ -28,10 +28,10 @@ string MarketInfo::toString() const {
return os.str();
}

string split(", ");
os << "MarketInfo(" << m_market << split << m_name << split << m_description << split << m_code
<< split << m_lastDate << split << m_openTime1.minutes() << split << m_closeTime1.minutes()
<< split << m_openTime2.minutes() << split << m_closeTime2.minutes() << ")";
string sp(", ");
os << "MarketInfo(" << m_market << sp << m_name << sp << m_description << sp << m_code << sp
<< m_lastDate << sp << m_openTime1.minutes() << sp << m_closeTime1.minutes() << sp
<< m_openTime2.minutes() << sp << m_closeTime2.minutes() << ")";
return os.str();
}

Expand Down
10 changes: 5 additions & 5 deletions hikyuu_cpp/hikyuu/Stock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Stock::Data::Data()
m_minTradeNumber(default_minTradeNumber),
m_maxTradeNumber(default_maxTradeNumber) {
const auto& ktype_list = KQuery::getAllKType();
for (auto& ktype : ktype_list) {
for (const auto& ktype : ktype_list) {
pKData[ktype] = nullptr;
pMutex[ktype] = nullptr;
}
Expand Down Expand Up @@ -96,7 +96,7 @@ Stock::Data::Data(const string& market, const string& code, const string& name,
m_market_code = m_market + m_code;

const auto& ktype_list = KQuery::getAllKType();
for (auto& ktype : ktype_list) {
for (const auto& ktype : ktype_list) {
pMutex[ktype] = new std::shared_mutex();
pKData[ktype] = nullptr;
}
Expand Down Expand Up @@ -543,12 +543,12 @@ bool Stock::_getIndexRangeByDateFromBuffer(const KQuery& query, size_t& out_star
return true;
}

KRecord Stock::_getKRecordFromBuffer(size_t pos, KQuery::KType ktype) const {
KRecord Stock::_getKRecordFromBuffer(size_t pos, const KQuery::KType& ktype) const {
std::shared_lock<std::shared_mutex> lock(*(m_data->pMutex[ktype]));
return m_data->pKData[ktype]->at(pos);
}

KRecord Stock::getKRecord(size_t pos, KQuery::KType kType) const {
KRecord Stock::getKRecord(size_t pos, const KQuery::KType& kType) const {
HKU_IF_RETURN(!m_data, Null<KRecord>());
if (isBuffer(kType)) {
return _getKRecordFromBuffer(pos, kType);
Expand All @@ -560,7 +560,7 @@ KRecord Stock::getKRecord(size_t pos, KQuery::KType kType) const {
return klist.size() > 0 ? klist[0] : Null<KRecord>();
}

KRecord Stock::getKRecord(const Datetime& datetime, KQuery::KType ktype) const {
KRecord Stock::getKRecord(const Datetime& datetime, const KQuery::KType& ktype) const {
KRecord result;
HKU_IF_RETURN(isNull(), result);

Expand Down
6 changes: 3 additions & 3 deletions hikyuu_cpp/hikyuu/Stock.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,10 @@ class HKU_API Stock {
bool getIndexRange(const KQuery& query, size_t& out_start, size_t& out_end) const;

/** 获取指定索引的K线数据记录,未作越界检查 */
KRecord getKRecord(size_t pos, KQuery::KType dataType = KQuery::DAY) const;
KRecord getKRecord(size_t pos, const KQuery::KType& dataType = KQuery::DAY) const;

/** 根据数据类型(日线/周线等),获取指定日期的KRecord */
KRecord getKRecord(const Datetime&, KQuery::KType ktype = KQuery::DAY) const;
KRecord getKRecord(const Datetime&, const KQuery::KType& ktype = KQuery::DAY) const;

/** 获取K线数据 */
KData getKData(const KQuery&) const;
Expand Down Expand Up @@ -221,7 +221,7 @@ class HKU_API Stock {

// 以下函数属于基础操作添加了读锁
size_t _getCountFromBuffer(KQuery::KType ktype) const;
KRecord _getKRecordFromBuffer(size_t pos, KQuery::KType ktype) const;
KRecord _getKRecordFromBuffer(size_t pos, const KQuery::KType& ktype) const;
KRecordList _getKRecordListFromBuffer(size_t start_ix, size_t end_ix,
KQuery::KType ktype) const;
bool _getIndexRangeByDateFromBuffer(const KQuery&, size_t&, size_t&) const;
Expand Down
10 changes: 4 additions & 6 deletions hikyuu_cpp/hikyuu/StockManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,6 @@ void StockManager::init(const Parameter& baseInfoParam, const Parameter& blockPa
m_marketInfoDict.clear();
m_stockTypeInfo.clear();

string funcname(" [StockManager::init]");

// 加载证券基本信息
m_baseInfoDriver = DataDriverFactory::getBaseInfoDriver(baseInfoParam);
HKU_CHECK(m_baseInfoDriver, "Failed get base info driver!");
Expand Down Expand Up @@ -301,8 +299,8 @@ void StockManager::reload() {
}

for (auto& stk : can_not_parallel_stk_list) {
auto& ktype_list = KQuery::getAllKType();
for (auto& ktype : ktype_list) {
const auto& ktype_list = KQuery::getAllKType();
for (const auto& ktype : ktype_list) {
if (stk.isBuffer(ktype)) {
stk.loadKDataToBuffer(ktype);
}
Expand Down Expand Up @@ -539,12 +537,12 @@ void StockManager::loadAllHolidays() {
void StockManager::loadAllStockWeights() {
HKU_INFO("Loading stock weight...");
auto all_stkweight_dict = m_baseInfoDriver->getAllStockWeightList();
std::lock_guard<std::mutex> lock(*m_stockDict_mutex);
std::lock_guard<std::mutex> lock1(*m_stockDict_mutex);
for (auto iter = m_stockDict.begin(); iter != m_stockDict.end(); ++iter) {
auto weight_iter = all_stkweight_dict.find(iter->first);
if (weight_iter != all_stkweight_dict.end()) {
Stock& stock = iter->second;
std::lock_guard<std::mutex> lock(stock.m_data->m_weight_mutex);
std::lock_guard<std::mutex> lock2(stock.m_data->m_weight_mutex);
stock.m_data->m_weightList.swap(weight_iter->second);
}
}
Expand Down
18 changes: 9 additions & 9 deletions hikyuu_cpp/hikyuu/StockTypeInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ HKU_API std::ostream& operator<<(std::ostream& os, const StockTypeInfo& stockTyp
return os;
}

string split(", ");
os << "StockTypeInfo(" << stockTypeInfo.type() << split << stockTypeInfo.description() << split
<< stockTypeInfo.tick() << split << stockTypeInfo.tickValue() << split
<< stockTypeInfo.unit() << split << stockTypeInfo.precision() << split
<< stockTypeInfo.minTradeNumber() << split << stockTypeInfo.maxTradeNumber() << ")";
string sp(", ");
os << "StockTypeInfo(" << stockTypeInfo.type() << sp << stockTypeInfo.description() << sp
<< stockTypeInfo.tick() << sp << stockTypeInfo.tickValue() << sp << stockTypeInfo.unit()
<< sp << stockTypeInfo.precision() << sp << stockTypeInfo.minTradeNumber() << sp
<< stockTypeInfo.maxTradeNumber() << ")";
return os;
}

Expand All @@ -30,10 +30,10 @@ string StockTypeInfo::toString() const {
return os.str();
}

string split(", ");
os << "StockTypeInfo(" << m_type << split << m_description << split << m_tick << split
<< m_tickValue << split << m_unit << split << m_precision << split << m_minTradeNumber
<< split << m_maxTradeNumber << ")";
string sp(", ");
os << "StockTypeInfo(" << m_type << sp << m_description << sp << m_tick << sp << m_tickValue
<< sp << m_unit << sp << m_precision << sp << m_minTradeNumber << sp << m_maxTradeNumber
<< ")";
return os.str();
}

Expand Down
6 changes: 3 additions & 3 deletions hikyuu_cpp/hikyuu/analysis/combinate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ vector<CombinateAnalysisOutput> HKU_API combinateIndicatorAnalysisWithBlock(
vector<Stock> buf;
for (size_t i = 0; i < count; i++) {
buf.clear();
for (size_t n = i * per_num, end = (i + 1) * per_num; n < end; n++) {
if (n >= stocks.size()) {
for (size_t j = i * per_num, end = (i + 1) * per_num; j < end; j++) {
if (j >= stocks.size()) {
break;
}
buf.emplace_back(stocks[n]);
buf.emplace_back(stocks[j]);
}
tasks.emplace_back(tg.submit([sgs, stks = std::move(buf), n_query = query,
n_tm = tm->clone(), n_sys = sys->clone()]() {
Expand Down
2 changes: 1 addition & 1 deletion hikyuu_cpp/hikyuu/data_driver/KDataDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ bool KDataDriver::init(const Parameter& params) {
return _init();
}

size_t KDataDriver::getCount(const string& market, const string& code, KQuery::KType kType) {
size_t KDataDriver::getCount(const string& market, const string& code, const KQuery::KType& kType) {
HKU_INFO("The getCount method has not been implemented! (KDataDriver: {})", m_name);
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion hikyuu_cpp/hikyuu/data_driver/KDataDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class HKU_API KDataDriver {
* @param kType K线类型
* @return
*/
virtual size_t getCount(const string& market, const string& code, KQuery::KType kType);
virtual size_t getCount(const string& market, const string& code, const KQuery::KType& kType);

/**
* 获取指定日期范围对应的K线记录索引
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ std::unordered_set<Datetime> MySQLBaseInfoDriver::getAllHolidays() {
auto con = m_pool->getConnect();
std::vector<HolidayTable> holidays;
con->batchLoad(holidays);
for (auto &holiday : holidays) {
for (const auto &holiday : holidays) {
try {
result.insert(holiday.datetime());
} catch (std::exception &e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ std::unordered_set<Datetime> SQLiteBaseInfoDriver::getAllHolidays() {
auto con = m_pool->getConnect();
std::vector<HolidayTable> holidays;
con->batchLoad(holidays);
for (auto& holiday : holidays) {
for (const auto& holiday : holidays) {
try {
result.insert(holiday.datetime());
} catch (std::exception& e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ void KDataTempCsvDriver::_get_title_column(const string& line) {
}
}

size_t KDataTempCsvDriver::getCount(const string& market, const string& code, KQuery::KType kType) {
size_t KDataTempCsvDriver::getCount(const string& market, const string& code,
const KQuery::KType& kType) {
return getKRecordList(market, code, KQuery(0, Null<int64_t>(), kType)).size();
}

Expand Down Expand Up @@ -138,7 +139,7 @@ KRecordList KDataTempCsvDriver::getKRecordList(const string& market, const strin

KRecordList KDataTempCsvDriver::_getKRecordListByIndex(const string& market, const string& code,
int64_t start_ix, int64_t end_ix,
KQuery::KType kType) {
const KQuery::KType& kType) {
KRecordList result;

string filename;
Expand Down
5 changes: 3 additions & 2 deletions hikyuu_cpp/hikyuu/data_driver/kdata/cvs/KDataTempCsvDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ class KDataTempCsvDriver : public KDataDriver {
* @param kType K线类型
* @return
*/
virtual size_t getCount(const string& market, const string& code, KQuery::KType kType) override;
virtual size_t getCount(const string& market, const string& code,
const KQuery::KType& kType) override;

/**
* 获取指定日期范围对应的K线记录索引
Expand Down Expand Up @@ -79,7 +80,7 @@ class KDataTempCsvDriver : public KDataDriver {
string _get_filename();

KRecordList _getKRecordListByIndex(const string& market, const string& code, int64_t start_ix,
int64_t end_ix, KQuery::KType kType);
int64_t end_ix, const KQuery::KType& kType);

private:
string m_day_filename;
Expand Down
Loading

0 comments on commit 544df89

Please sign in to comment.