1.给Singleton的模板加了点功能。

2.添加了处理DG的功能。

Signed-off-by: dmy@lab <dmy@lab.lab>
This commit is contained in:
dmy@lab
2015-01-19 14:54:36 +08:00
parent 15718e1990
commit 07cfaef632
7 changed files with 189 additions and 8 deletions

View File

@@ -3,12 +3,15 @@
//做一个单例
#include <QHash>
#include <QList>
template<typename KeyType,typename ValueType,typename ChildType>
class SingletonBase
{
public:
// SingletonBase();
SingletonBase()
{
this->initInstance();
}
// ~SingletonBase();
void add(const KeyType& key,const ValueType& val)
{
@@ -19,11 +22,18 @@ public:
{
return SingletonBase<KeyType,ValueType,ChildType>::ht->contains(key);
}
ValueType get(const KeyType& key)
ValueType& get(const KeyType& key)
{
QHash<KeyType,ValueType> *t=SingletonBase<KeyType,ValueType,ChildType>::ht;
return (*t)[key];
}
QList<KeyType> keys()
{
return SingletonBase<KeyType,ValueType,ChildType>::ht->keys();
}
private:
void initInstance()
{
if(SingletonBase<KeyType,ValueType,ChildType>::ht)