// // PBConfigData.cpp // merge6 // // Created by Black Homles on 2024/9/24. // #include "PBConfigData.hpp" #include "rapidcsv.h" PBConfigData* PBConfigData::_gPBConfigData = nullptr; PBConfigData::PBConfigData() { } PBConfigData::~PBConfigData() { } PBConfigData* PBConfigData::getInstance() { if (_gPBConfigData == nullptr || !_gPBConfigData) { _gPBConfigData = new (std::nothrow) PBConfigData(); } return _gPBConfigData; } void PBConfigData::initData(std::string cfgFN) { string fileName = cfgFN; _bannerInfoList.clear(); if (!FileUtils::getInstance()->isFileExist(fileName)) { return; } std::string fullfiledata = FileUtils::getInstance()->getStringFromFile(fileName); std::stringstream sstream(fullfiledata); rapidcsv::Document tempDoc(sstream); int rowcount = (int)tempDoc.GetRowCount(); for (int irow = 0; irow < rowcount; irow++) { bannerInfo tmpinfo; tmpinfo.bannerName = tempDoc.GetCell("名称",irow); tmpinfo.bannerDes = tempDoc.GetCell("描述",irow); tmpinfo.bannerType = tempDoc.GetCell("类型",irow); tmpinfo.bannerFile = tempDoc.GetCell("文件名称",irow); tmpinfo.bannerTitle = tempDoc.GetCell("标题",irow); tmpinfo.bannerPlist = tempDoc.GetCell("图集名称",irow); tmpinfo.bannerBGSp = tempDoc.GetCell("背景图片",irow); tmpinfo.bannerPID = tempDoc.GetCell("商品ID",irow); tmpinfo.bannerCutCount = tempDoc.GetCell("折扣数字",irow); tmpinfo.bannerPrice = tempDoc.GetCell("价格数字",irow); tmpinfo.bannerBtnStr = tempDoc.GetCell("按钮文字",irow); tmpinfo.bannerTime = tempDoc.GetCell("有效时间秒",irow); tmpinfo.item1ID = tempDoc.GetCell("物品1ID",irow); tmpinfo.item1Type = tempDoc.GetCell("物品1类型",irow); tmpinfo.item1Count = tempDoc.GetCell("物品1数量",irow); tmpinfo.item1PNG = tempDoc.GetCell("物品1图片",irow); tmpinfo.item2ID = tempDoc.GetCell("物品2ID",irow); tmpinfo.item2Type = tempDoc.GetCell("物品2类型",irow); tmpinfo.item2Count = tempDoc.GetCell("物品2数量",irow); tmpinfo.item2PNG = tempDoc.GetCell("物品2图片",irow); tmpinfo.item3ID = tempDoc.GetCell("物品3ID",irow); tmpinfo.item3Type = tempDoc.GetCell("物品3类型",irow); tmpinfo.item3Count = tempDoc.GetCell("物品3数量",irow); tmpinfo.item3PNG = tempDoc.GetCell("物品3图片",irow); tmpinfo.item3Des = tempDoc.GetCell("物品3描述",irow); _bannerInfoList.push_back(tmpinfo); } //view config string fileName2 = "bannerViewConfig.csv"; _bResList.clear(); if (!FileUtils::getInstance()->isFileExist(fileName2)) { return; } std::string fullfiledata2 = FileUtils::getInstance()->getStringFromFile(fileName2); std::stringstream sstream2(fullfiledata2); rapidcsv::Document tempDoc2(sstream2); int rowcount2 = (int)tempDoc2.GetRowCount(); for (int lopp = 1; lopp < rowcount2; lopp++) { string tmpstr = tempDoc2.GetCell("资源名称",lopp); _bResList.push_back(tmpstr); } _thisDotcfg.sepWidth = tempDoc2.GetCell("圆点宽度",0); _thisDotcfg.yStart = tempDoc2.GetCell("圆点高度",0); _thisDotcfg.highSp = tempDoc2.GetCell("圆点亮图",0); _thisDotcfg.normalSp = tempDoc2.GetCell("圆点暗图",0); } PBConfigData::bannerInfo PBConfigData::getBannerInfo(string bName) { bannerInfo tmpinfo; for (int lopp = 0; lopp < _bannerInfoList.size(); lopp++) { if (_bannerInfoList[lopp].bannerName == bName) { tmpinfo = _bannerInfoList[lopp]; break; } } return tmpinfo; } PBConfigData::sPBDotCfg PBConfigData::getViewDot() { return _thisDotcfg; }