parent
29b219fbe9
commit
9faa1cce49
|
|
@ -4,8 +4,7 @@
|
|||
//做一个单例
|
||||
#include <QHash>
|
||||
|
||||
|
||||
template<typename KeyType,typename ValueType>
|
||||
template<typename KeyType,typename ValueType,typename ChildType>
|
||||
class SingletonBase
|
||||
{
|
||||
public:
|
||||
|
|
@ -13,20 +12,26 @@ public:
|
|||
// ~SingletonBase();
|
||||
void add(const KeyType& key,const ValueType& val)
|
||||
{
|
||||
this->ht[key]=val;
|
||||
QHash<KeyType,ValueType> *t=SingletonBase<KeyType,ValueType,ChildType>::ht;
|
||||
(*t)[key]=val;
|
||||
}
|
||||
bool contains(const KeyType& key)
|
||||
{
|
||||
return this->ht->contains(key);
|
||||
return SingletonBase<KeyType,ValueType,ChildType>::ht->contains(key);
|
||||
}
|
||||
ValueType get(const KeyType& key)
|
||||
{
|
||||
return this->ht[key];
|
||||
QHash<KeyType,ValueType> *t=SingletonBase<KeyType,ValueType,ChildType>::ht;
|
||||
return (*t)[key];
|
||||
}
|
||||
|
||||
void initInstance()
|
||||
{
|
||||
if()
|
||||
if(SingletonBase<KeyType,ValueType,ChildType>::ht)
|
||||
{
|
||||
delete SingletonBase<KeyType,ValueType,ChildType>::ht;
|
||||
SingletonBase<KeyType,ValueType,ChildType>::ht==NULL;
|
||||
}
|
||||
SingletonBase<KeyType,ValueType,ChildType>::ht=new QHash<KeyType,ValueType>;
|
||||
}
|
||||
protected:
|
||||
|
||||
|
|
@ -43,4 +48,8 @@ protected:
|
|||
static QHash<KeyType,ValueType> *ht;
|
||||
};
|
||||
|
||||
|
||||
template<typename KT,typename VT,typename CT>
|
||||
QHash<KT,VT> *SingletonBase<KT,VT,CT>::ht=NULL;
|
||||
|
||||
#endif // SINGLETONBASE_H
|
||||
|
|
|
|||
Loading…
Reference in New Issue