1.给Singleton的模板加了点功能。
2.添加了处理DG的功能。 Signed-off-by: dmy@lab <dmy@lab.lab>
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user