From 214c17dd10e9e5bcc478022207b0ddb003b8d10b Mon Sep 17 00:00:00 2001 From: "dmy@lab" Date: Thu, 15 Jan 2015 20:05:44 +0800 Subject: [PATCH] =?UTF-8?q?1.=E5=8A=A0=E4=BA=86=E4=B8=80=E4=B8=AA=E5=8E=86?= =?UTF-8?q?=E9=81=8D=E6=89=80=E6=9C=89=E5=AD=90=E7=9B=AE=E5=BD=95=E7=9A=84?= =?UTF-8?q?=E7=B1=BB=202.=E5=8A=A0=E4=BA=86=E8=AF=BB=E5=85=A5=E6=89=80?= =?UTF-8?q?=E6=9C=89=E5=8C=B9=E9=85=8D=E6=95=B0=E6=8D=AE=E7=9A=84=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: dmy@lab --- testHasttable/cimexporter.cpp | 4 ++ testHasttable/element/branch.h | 2 +- testHasttable/loadmapping.cpp | 79 +++++++++++++++++++++++++++++++++ testHasttable/loadmapping.h | 35 +++++++++++++++ testHasttable/main.cpp | 6 ++- testHasttable/recursedir.cpp | 49 ++++++++++++++++++++ testHasttable/recursedir.h | 21 +++++++++ testHasttable/testHasttable.pro | 8 +++- 8 files changed, 200 insertions(+), 4 deletions(-) create mode 100644 testHasttable/loadmapping.cpp create mode 100644 testHasttable/loadmapping.h create mode 100644 testHasttable/recursedir.cpp create mode 100644 testHasttable/recursedir.h diff --git a/testHasttable/cimexporter.cpp b/testHasttable/cimexporter.cpp index 4bc9892..030f929 100644 --- a/testHasttable/cimexporter.cpp +++ b/testHasttable/cimexporter.cpp @@ -38,6 +38,7 @@ void CIMExporter::exportTo(const QString& path) this->idToNumber(this->sw); this->idToNumber(this->tf); //开始按要求输出 + //先输出线路 for(QList::iterator ite=this->line.begin(); ite!=this->line.end(); ite++) @@ -45,7 +46,10 @@ void CIMExporter::exportTo(const QString& path) LineStru l=*ite; std::cout<r<<","<x<<","<g1<<","<g2< > *LoadMapping::ht=NULL; +LoadMapping::LoadMapping() +{ + if(!LoadMapping::ht) + { + LoadMapping::ht=new QHash >; + } +} + + +LoadMapping::~LoadMapping() +{ + +} + +bool LoadMapping::load(const QString &dir) +{ + if(LoadMapping::ht->keys().length()>0) + { + return true;//只执行一次 + } + if(!QFileInfo::exists(dir)) + { + return false; + } + RecurseDir recurseDir; + recurseDir.setDir((dir)); + QStringList filePathList=recurseDir.getFiles(); + foreach(QString filePath,filePathList) + { + QFileInfo fileInfo(filePath); + if(!fileInfo.exists()) + { + return false; + } + QString fileName; + QString suffix; + suffix=fileInfo.suffix(); + if(suffix.toLower()!="csv") + { + continue; + } + fileName=fileInfo.baseName(); + 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; + SFDid=sep.at(0); + QVector loads; + for(int i=1;iloads[SFDid]=loads; + + } + file.close(); + } + + } + return true; + +} + + diff --git a/testHasttable/loadmapping.h b/testHasttable/loadmapping.h new file mode 100644 index 0000000..7d6488a --- /dev/null +++ b/testHasttable/loadmapping.h @@ -0,0 +1,35 @@ +#ifndef LOADMAPPING_H +#define LOADMAPPING_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include "recursedir.h" +//这是一个单例 +class LoadMapping +{ +public: + LoadMapping(); + ~LoadMapping(); + bool load(const QString& dir); +private: + class CG // 它的唯一工作就是在析构函数中删除CSingleton的实例 + { + public: + ~CG() + { + if (LoadMapping::ht) + delete LoadMapping::ht; + } + }; + static CG Garbo; // 定义一个静态成员,在程序结束时,系统会调用它的析构函数 + static QHash > *ht; + QHash > loads; +}; + +#endif // LOADMAPPING_H diff --git a/testHasttable/main.cpp b/testHasttable/main.cpp index 0459346..aa56720 100644 --- a/testHasttable/main.cpp +++ b/testHasttable/main.cpp @@ -3,14 +3,18 @@ #include "regexextract.h" #include "task.h" #include +#include "loadmapping.h" int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); + LoadMapping lm; + lm.load("D:/Project/佛山项目/数据/匹配的数据"); + // ReadWrite aa; // RegexExtract re; // re.extract("D:/Project/佛山项目/数据/df8003/df8600/exportfiles/exportmodel_pw.xml"); // re.exportBlocks("./a"); -// return a.exec(); + return a.exec(); ElementHashtable eleReader; eleReader.Parse("D:/Project/佛山项目/数据/df8003/df8600/exportfiles/exportmodel_pw.xml","D:/Project/佛山项目/佛山收资/exportmodel_zwyth20141204/exportmodel_zwyth.xml"); // eleReader.GoPath(); diff --git a/testHasttable/recursedir.cpp b/testHasttable/recursedir.cpp new file mode 100644 index 0000000..e1b94d0 --- /dev/null +++ b/testHasttable/recursedir.cpp @@ -0,0 +1,49 @@ +#include "recursedir.h" + +RecurseDir::RecurseDir() +{ + +} + +RecurseDir::~RecurseDir() +{ + +} + +QStringList RecurseDir::getFiles() +{ + return this->filePathList; +} + +bool RecurseDir::lsDir(const QString& dir) +{ + QDir _dir(dir); + QStringList nameFilter; + nameFilter<<"*"; + QStringList fileList=_dir.entryList(nameFilter,QDir::NoDotAndDotDot|QDir::AllEntries); + for(QStringList::iterator ite=fileList.begin(); + ite!=fileList.end(); + ite++) + { + QString absPath=dir+'/'+*ite; + if(QFileInfo(absPath).isDir()) + { + if(!this->lsDir(absPath)) + { + return false; + } + } + else + { + this->filePathList.push_back(absPath);//只保存文件 + } + + } + return true; +} + +bool RecurseDir::setDir(const QString& dir) +{ + return this->lsDir(dir); +} + diff --git a/testHasttable/recursedir.h b/testHasttable/recursedir.h new file mode 100644 index 0000000..762980c --- /dev/null +++ b/testHasttable/recursedir.h @@ -0,0 +1,21 @@ +#ifndef RECURSEDIR_H +#define RECURSEDIR_H + +#include +#include +#include + +class RecurseDir +{ +public: + RecurseDir(); + ~RecurseDir(); + QStringList getFiles(); + bool setDir(const QString& dir); +private: + bool lsDir(const QString& dir); +private: + QStringList filePathList; +}; + +#endif // RECURSEDIR_H diff --git a/testHasttable/testHasttable.pro b/testHasttable/testHasttable.pro index d4b5f8f..6c24ccd 100644 --- a/testHasttable/testHasttable.pro +++ b/testHasttable/testHasttable.pro @@ -37,7 +37,9 @@ SOURCES += main.cpp \ element/line.cpp \ element/transformer.cpp \ element/switch.cpp \ - task.cpp + task.cpp \ + loadmapping.cpp \ + recursedir.cpp HEADERS += \ elementhashtable.h \ @@ -60,7 +62,9 @@ HEADERS += \ element/line.h \ element/transformer.h \ element/switch.h \ - task.h + task.h \ + loadmapping.h \ + recursedir.h #release{ DEFINES += QT_NO_DEBUG_OUTPUT