From 230aef6995b3bb7c4b39490fe8f6745de3078d12 Mon Sep 17 00:00:00 2001 From: "dmy@lab" Date: Thu, 15 Jan 2015 21:56:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A9=E7=94=A8LoadInfo=E5=AD=98=E5=82=A8?= =?UTF-8?q?=E8=B4=9F=E8=8D=B7=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: dmy@lab --- testHasttable/loadinfo.cpp | 29 +++++++++++++++ testHasttable/loadinfo.h | 21 +++++++++++ testHasttable/loadmapping.cpp | 64 ++++++++++++++++++++++++++++----- testHasttable/loadmapping.h | 11 ++++-- testHasttable/main.cpp | 2 +- testHasttable/testHasttable.pro | 6 ++-- 6 files changed, 120 insertions(+), 13 deletions(-) create mode 100644 testHasttable/loadinfo.cpp create mode 100644 testHasttable/loadinfo.h diff --git a/testHasttable/loadinfo.cpp b/testHasttable/loadinfo.cpp new file mode 100644 index 0000000..c2ba62e --- /dev/null +++ b/testHasttable/loadinfo.cpp @@ -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; +} + diff --git a/testHasttable/loadinfo.h b/testHasttable/loadinfo.h new file mode 100644 index 0000000..8997560 --- /dev/null +++ b/testHasttable/loadinfo.h @@ -0,0 +1,21 @@ +#ifndef LOADINFO_H +#define LOADINFO_H + +#include +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 diff --git a/testHasttable/loadmapping.cpp b/testHasttable/loadmapping.cpp index c3bd04e..95b60df 100644 --- a/testHasttable/loadmapping.cpp +++ b/testHasttable/loadmapping.cpp @@ -1,6 +1,6 @@ #include "loadmapping.h" - +#include QHash > *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< 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 loads; + SFDid=SFDid.replace(regExp,""); + QVector > loads; for(int i=1;i 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; - } diff --git a/testHasttable/loadmapping.h b/testHasttable/loadmapping.h index 7d6488a..1df5b7f 100644 --- a/testHasttable/loadmapping.h +++ b/testHasttable/loadmapping.h @@ -9,14 +9,20 @@ #include #include #include +#include +#include + #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 > *ht; - QHash > loads; + QHash > > loads; + QHash > loadsToLoadInfo; }; #endif // LOADMAPPING_H diff --git a/testHasttable/main.cpp b/testHasttable/main.cpp index aa56720..a59ce29 100644 --- a/testHasttable/main.cpp +++ b/testHasttable/main.cpp @@ -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; diff --git a/testHasttable/testHasttable.pro b/testHasttable/testHasttable.pro index 6c24ccd..3c35105 100644 --- a/testHasttable/testHasttable.pro +++ b/testHasttable/testHasttable.pro @@ -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