From 51eed6e99e9b820f96602d984541eafefb312b06 Mon Sep 17 00:00:00 2001 From: "dmy@lab" Date: Thu, 15 Jan 2015 22:06:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=B8=80=E4=B8=AA=E5=8D=95?= =?UTF-8?q?=E4=BE=8B=E7=9A=84=E6=A8=A1=E6=9D=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: dmy@lab --- testHasttable/loadmapping.cpp | 4 ++-- testHasttable/loadmapping.h | 2 +- testHasttable/main.cpp | 2 +- testHasttable/singletonbase.h | 40 +++++++++++++++++++++++++++++++++ testHasttable/testHasttable.pro | 3 ++- 5 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 testHasttable/singletonbase.h diff --git a/testHasttable/loadmapping.cpp b/testHasttable/loadmapping.cpp index 95b60df..2ae4731 100644 --- a/testHasttable/loadmapping.cpp +++ b/testHasttable/loadmapping.cpp @@ -16,13 +16,13 @@ LoadMapping::~LoadMapping() } -bool LoadMapping::load(const QString &loadDir,const QString &matchdDir) +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)) + if(!QFileInfo::exists(loadDir)|!QFileInfo::exists(matchdDir)|!QFileInfo::exists(exceptionFile)) { return false; } diff --git a/testHasttable/loadmapping.h b/testHasttable/loadmapping.h index 1df5b7f..7cd5661 100644 --- a/testHasttable/loadmapping.h +++ b/testHasttable/loadmapping.h @@ -20,7 +20,7 @@ class LoadMapping public: LoadMapping(); ~LoadMapping(); - bool load(const QString& loadDir, const QString &matchdDir); + bool load(const QString& loadDir, const QString &matchdDir, const QString &exceptionFile); bool readLoads(const QString& dir); bool readMatch(const QString& dir); private: diff --git a/testHasttable/main.cpp b/testHasttable/main.cpp index a59ce29..3414b01 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/佛山项目/数据/搭网架参数文件/泰安/泰安负荷","D:/Project/佛山项目/数据/匹配的数据"); + lm.load("D:/Project/佛山项目/数据/搭网架参数文件/泰安/泰安负荷","D:/Project/佛山项目/数据/匹配的数据",""); // ReadWrite aa; // RegexExtract re; diff --git a/testHasttable/singletonbase.h b/testHasttable/singletonbase.h new file mode 100644 index 0000000..314cdf8 --- /dev/null +++ b/testHasttable/singletonbase.h @@ -0,0 +1,40 @@ +#ifndef SINGLETONBASE_H +#define SINGLETONBASE_H + +//做一个单例 +#include +template +class SingletonBase +{ +public: + SingletonBase(); + ~SingletonBase(); + void add(const KeyType& key,const ValueType& val) + { + this->ht[key]=val; + } + bool contains(const KeyType& key) + { + return this->ht->contains(key); + } + ValueType get(const KeyType& key) + { + return this->ht[key]; + } + +protected: + + class CG // 它的唯一工作就是在析构函数中删除CSingleton的实例 + { + public: + ~CG() + { + if (SingletonBase::ht) + delete SingletonBase::ht; + } + }; + static CG Garbo; // 定义一个静态成员,在程序结束时,系统会调用它的析构函数 + static QHash *ht; *ht; +}; + +#endif // SINGLETONBASE_H diff --git a/testHasttable/testHasttable.pro b/testHasttable/testHasttable.pro index 3c35105..7d24f89 100644 --- a/testHasttable/testHasttable.pro +++ b/testHasttable/testHasttable.pro @@ -66,7 +66,8 @@ HEADERS += \ task.h \ loadmapping.h \ recursedir.h \ - loadinfo.h + loadinfo.h \ + singletonbase.h #release{ DEFINES += QT_NO_DEBUG_OUTPUT