parent
214c17dd10
commit
230aef6995
|
|
@ -0,0 +1,29 @@
|
|||
#include "loadinfo.h"
|
||||
|
||||
LoadInfo::LoadInfo()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
LoadInfo::~LoadInfo()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QString LoadInfo::getLoadName()
|
||||
{
|
||||
return this->loadName;
|
||||
}
|
||||
QString LoadInfo::getLoadPath()
|
||||
{
|
||||
return this->loadPath;
|
||||
}
|
||||
void LoadInfo::setLoadName(const QString &name)
|
||||
{
|
||||
this->loadName=name;
|
||||
}
|
||||
void LoadInfo::setLoadPath(const QString &path)
|
||||
{
|
||||
this->loadPath=path;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
#ifndef LOADINFO_H
|
||||
#define LOADINFO_H
|
||||
|
||||
#include <QString>
|
||||
class LoadInfo
|
||||
{
|
||||
public:
|
||||
explicit LoadInfo();
|
||||
~LoadInfo();
|
||||
QString getLoadName();
|
||||
QString getLoadPath();
|
||||
void setLoadName(const QString &name);
|
||||
void setLoadPath(const QString &path);
|
||||
private:
|
||||
|
||||
QString loadName;
|
||||
QString loadPath;
|
||||
|
||||
};
|
||||
|
||||
#endif // LOADINFO_H
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
#include "loadmapping.h"
|
||||
|
||||
|
||||
#include <iostream>
|
||||
QHash<QString,QVector<double> > *LoadMapping::ht=NULL;
|
||||
LoadMapping::LoadMapping()
|
||||
{
|
||||
|
|
@ -16,16 +16,62 @@ LoadMapping::~LoadMapping()
|
|||
|
||||
}
|
||||
|
||||
bool LoadMapping::load(const QString &dir)
|
||||
bool LoadMapping::load(const QString &loadDir,const QString &matchdDir)
|
||||
{
|
||||
if(LoadMapping::ht->keys().length()>0)
|
||||
{
|
||||
return true;//只执行一次
|
||||
}
|
||||
if(!QFileInfo::exists(dir))
|
||||
if(!QFileInfo::exists(loadDir)|!QFileInfo::exists(matchdDir))
|
||||
{
|
||||
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();
|
||||
|
|
@ -36,14 +82,12 @@ bool LoadMapping::load(const QString &dir)
|
|||
{
|
||||
return false;
|
||||
}
|
||||
QString fileName;
|
||||
QString suffix;
|
||||
suffix=fileInfo.suffix();
|
||||
if(suffix.toLower()!="csv")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
fileName=fileInfo.baseName();
|
||||
QFile file(filePath);
|
||||
QString line;
|
||||
QStringList sep;
|
||||
|
|
@ -59,11 +103,16 @@ bool LoadMapping::load(const QString &dir)
|
|||
continue;
|
||||
}
|
||||
QString SFDid;
|
||||
QRegExp regExp("\\(.*\\)");
|
||||
SFDid=sep.at(0);
|
||||
QVector<QString> loads;
|
||||
SFDid=SFDid.replace(regExp,"");
|
||||
QVector<QSharedPointer<LoadInfo> > loads;
|
||||
for(int i=1;i<sep.length();i++)
|
||||
{
|
||||
loads.push_back(sep.at(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;
|
||||
|
||||
|
|
@ -73,7 +122,6 @@ bool LoadMapping::load(const QString &dir)
|
|||
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -9,14 +9,20 @@
|
|||
#include <QStringList>
|
||||
#include <QFile>
|
||||
#include <QTextStream>
|
||||
#include <QRegExp>
|
||||
#include <QSharedPointer>
|
||||
|
||||
#include "recursedir.h"
|
||||
#include "loadinfo.h"
|
||||
//这是一个单例
|
||||
class LoadMapping
|
||||
{
|
||||
public:
|
||||
LoadMapping();
|
||||
~LoadMapping();
|
||||
bool load(const QString& dir);
|
||||
bool load(const QString& loadDir, const QString &matchdDir);
|
||||
bool readLoads(const QString& dir);
|
||||
bool readMatch(const QString& dir);
|
||||
private:
|
||||
class CG // 它的唯一工作就是在析构函数中删除CSingleton的实例
|
||||
{
|
||||
|
|
@ -29,7 +35,8 @@ private:
|
|||
};
|
||||
static CG Garbo; // 定义一个静态成员,在程序结束时,系统会调用它的析构函数
|
||||
static QHash<QString,QVector<double> > *ht;
|
||||
QHash<QString,QVector<QString> > loads;
|
||||
QHash<QString,QVector<QSharedPointer<LoadInfo> > > loads;
|
||||
QHash<QString,QSharedPointer<LoadInfo> > loadsToLoadInfo;
|
||||
};
|
||||
|
||||
#endif // LOADMAPPING_H
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ int main(int argc, char *argv[])
|
|||
{
|
||||
QCoreApplication a(argc, argv);
|
||||
LoadMapping lm;
|
||||
lm.load("D:/Project/佛山项目/数据/匹配的数据");
|
||||
lm.load("D:/Project/佛山项目/数据/搭网架参数文件/泰安/泰安负荷","D:/Project/佛山项目/数据/匹配的数据");
|
||||
|
||||
// ReadWrite aa;
|
||||
// RegexExtract re;
|
||||
|
|
|
|||
|
|
@ -39,7 +39,8 @@ SOURCES += main.cpp \
|
|||
element/switch.cpp \
|
||||
task.cpp \
|
||||
loadmapping.cpp \
|
||||
recursedir.cpp
|
||||
recursedir.cpp \
|
||||
loadinfo.cpp
|
||||
|
||||
HEADERS += \
|
||||
elementhashtable.h \
|
||||
|
|
@ -64,7 +65,8 @@ HEADERS += \
|
|||
element/switch.h \
|
||||
task.h \
|
||||
loadmapping.h \
|
||||
recursedir.h
|
||||
recursedir.h \
|
||||
loadinfo.h
|
||||
|
||||
#release{
|
||||
DEFINES += QT_NO_DEBUG_OUTPUT
|
||||
|
|
|
|||
Loading…
Reference in New Issue