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