128 lines
3.0 KiB
C++
128 lines
3.0 KiB
C++
#include "loadmapping.h"
|
|
|
|
#include <iostream>
|
|
QHash<QString,QVector<double> > *LoadMapping::ht=NULL;
|
|
LoadMapping::LoadMapping()
|
|
{
|
|
if(!LoadMapping::ht)
|
|
{
|
|
LoadMapping::ht=new QHash<QString,QVector<double> >;
|
|
}
|
|
}
|
|
|
|
|
|
LoadMapping::~LoadMapping()
|
|
{
|
|
|
|
}
|
|
|
|
bool LoadMapping::load(const QString &loadDir,const QString &matchdDir,const QString &exceptionFile)
|
|
{
|
|
if(LoadMapping::ht->keys().length()>0)
|
|
{
|
|
return true;//只执行一次
|
|
}
|
|
if(!QFileInfo::exists(loadDir)|!QFileInfo::exists(matchdDir)|!QFileInfo::exists(exceptionFile))
|
|
{
|
|
return false;
|
|
}
|
|
if(!this->readMatch(matchdDir))
|
|
{
|
|
return false;
|
|
}
|
|
if(!this->readLoads(loadDir))
|
|
{
|
|
return false;
|
|
}
|
|
return true;
|
|
|
|
}
|
|
|
|
bool LoadMapping::readLoads(const QString &dir)
|
|
{
|
|
RecurseDir recurseDir;
|
|
recurseDir.setDir((dir));
|
|
QStringList filePathList=recurseDir.getFiles();
|
|
foreach(QString filePath,filePathList)
|
|
{
|
|
QFileInfo fileInfo(filePath);
|
|
if(!fileInfo.exists())
|
|
{
|
|
return false;
|
|
}
|
|
QString suffix;
|
|
suffix=fileInfo.suffix();
|
|
if(suffix.toLower()!="csv")
|
|
{
|
|
continue;
|
|
}
|
|
QString fileName=fileInfo.baseName();
|
|
if(!this->loadsToLoadInfo.contains(fileName))
|
|
{
|
|
std::cout<<filePath.toLocal8Bit().data()<<" no match."<<std::endl;
|
|
continue;
|
|
}
|
|
QSharedPointer<LoadInfo> loadInfo=this->loadsToLoadInfo[fileName];
|
|
loadInfo->setLoadPath(filePath);
|
|
|
|
}
|
|
return true;
|
|
}
|
|
|
|
|
|
bool LoadMapping::readMatch(const QString& dir)
|
|
{
|
|
RecurseDir recurseDir;
|
|
recurseDir.setDir((dir));
|
|
QStringList filePathList=recurseDir.getFiles();
|
|
foreach(QString filePath,filePathList)
|
|
{
|
|
QFileInfo fileInfo(filePath);
|
|
if(!fileInfo.exists())
|
|
{
|
|
return false;
|
|
}
|
|
QString suffix;
|
|
suffix=fileInfo.suffix();
|
|
if(suffix.toLower()!="csv")
|
|
{
|
|
continue;
|
|
}
|
|
QFile file(filePath);
|
|
QString line;
|
|
QStringList sep;
|
|
if(file.open(QFile::ReadOnly))
|
|
{
|
|
QTextStream reader(&file);
|
|
while(!reader.atEnd())
|
|
{
|
|
line=reader.readLine().trimmed();
|
|
sep=line.split(',');
|
|
if(sep.length()<2)
|
|
{
|
|
continue;
|
|
}
|
|
QString SFDid;
|
|
QRegExp regExp("\\(.*\\)");
|
|
SFDid=sep.at(0);
|
|
SFDid=SFDid.replace(regExp,"");
|
|
QVector<QSharedPointer<LoadInfo> > loads;
|
|
for(int i=1;i<sep.length();i++)
|
|
{
|
|
QSharedPointer<LoadInfo> t(new LoadInfo);
|
|
t->setLoadName(sep.at(i));
|
|
loads.push_back(t);
|
|
this->loadsToLoadInfo[sep.at(i)]=t;
|
|
}
|
|
this->loads[SFDid]=loads;
|
|
|
|
}
|
|
file.close();
|
|
}
|
|
|
|
}
|
|
return true;
|
|
}
|
|
|
|
|