From 29b219fbe9f39742577ee352725260c11553a34e Mon Sep 17 00:00:00 2001 From: "dmy@lab" Date: Thu, 15 Jan 2015 22:47:49 +0800 Subject: [PATCH] =?UTF-8?q?1.=E8=AF=BB=E4=B8=8D=E5=8C=B9=E9=85=8D=E4=BD=86?= =?UTF-8?q?=E9=9C=80=E8=A6=81=E5=BF=BD=E7=95=A5=E7=9A=84=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E3=80=82=202.=E6=9A=82=E6=97=B6=E4=B8=8D=E7=94=A8=E5=8D=95?= =?UTF-8?q?=E4=BE=8B=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: dmy@lab --- testHasttable/loadmatchexception.cpp | 41 ++++++++++++++++++++++++++++ testHasttable/loadmatchexception.h | 31 +++++++++++++++++++++ testHasttable/singletonbase.h | 12 ++++++-- testHasttable/testHasttable.pro | 6 ++-- 4 files changed, 85 insertions(+), 5 deletions(-) create mode 100644 testHasttable/loadmatchexception.cpp create mode 100644 testHasttable/loadmatchexception.h diff --git a/testHasttable/loadmatchexception.cpp b/testHasttable/loadmatchexception.cpp new file mode 100644 index 0000000..0d4dbc9 --- /dev/null +++ b/testHasttable/loadmatchexception.cpp @@ -0,0 +1,41 @@ +#include "loadmatchexception.h" + + +QHash *LoadMatchException::ht=NULL; +LoadMatchException::LoadMatchException() +{ + +} + +LoadMatchException::~LoadMatchException() +{ + +} + +bool LoadMatchException::contains(const QString& key) +{ + return LoadMatchException::ht->contains(key); +} + +bool LoadMatchException::init(const QString& exceptionFilePath) +{ + LoadMatchException::ht=new QHash; + QFile file(exceptionFilePath); + QString line; + if(file.open(QFile::ReadOnly)) + { + QTextStream reader(&file); + while(!reader.atEnd()) + { + line=reader.readLine().trimmed(); + if(line.length()==0) + { + continue; + } + (*LoadMatchException::ht)[line]=0; + } + file.close(); + } + return true; +} + diff --git a/testHasttable/loadmatchexception.h b/testHasttable/loadmatchexception.h new file mode 100644 index 0000000..73930e8 --- /dev/null +++ b/testHasttable/loadmatchexception.h @@ -0,0 +1,31 @@ +#ifndef LOADMATCHEXCEPTION_H +#define LOADMATCHEXCEPTION_H + +//有些负荷文件就不匹配了 +#include +#include +#include +#include +class LoadMatchException +{ +public: + LoadMatchException(); + ~LoadMatchException(); + bool contains(const QString& key); + bool init(const QString& exceptionFilePath); + +private: + class CG // 它的唯一工作就是在析构函数中删除CSingleton的实例 + { + public: + ~CG() + { + if (LoadMatchException::ht) + delete LoadMatchException::ht; + } + }; + static CG Garbo; // 定义一个静态成员,在程序结束时,系统会调用它的析构函数 + static QHash *ht; +}; + +#endif // LOADMATCHEXCEPTION_H diff --git a/testHasttable/singletonbase.h b/testHasttable/singletonbase.h index 314cdf8..b9abb72 100644 --- a/testHasttable/singletonbase.h +++ b/testHasttable/singletonbase.h @@ -3,12 +3,14 @@ //做一个单例 #include + + template class SingletonBase { public: - SingletonBase(); - ~SingletonBase(); +// SingletonBase(); +// ~SingletonBase(); void add(const KeyType& key,const ValueType& val) { this->ht[key]=val; @@ -22,6 +24,10 @@ public: return this->ht[key]; } + void initInstance() + { + if() + } protected: class CG // 它的唯一工作就是在析构函数中删除CSingleton的实例 @@ -34,7 +40,7 @@ protected: } }; static CG Garbo; // 定义一个静态成员,在程序结束时,系统会调用它的析构函数 - static QHash *ht; *ht; + static QHash *ht; }; #endif // SINGLETONBASE_H diff --git a/testHasttable/testHasttable.pro b/testHasttable/testHasttable.pro index 7d24f89..44f4c73 100644 --- a/testHasttable/testHasttable.pro +++ b/testHasttable/testHasttable.pro @@ -40,7 +40,8 @@ SOURCES += main.cpp \ task.cpp \ loadmapping.cpp \ recursedir.cpp \ - loadinfo.cpp + loadinfo.cpp \ + loadmatchexception.cpp HEADERS += \ elementhashtable.h \ @@ -67,7 +68,8 @@ HEADERS += \ loadmapping.h \ recursedir.h \ loadinfo.h \ - singletonbase.h + singletonbase.h \ + loadmatchexception.h #release{ DEFINES += QT_NO_DEBUG_OUTPUT