ResManage增加防重复添加功能
This commit is contained in:
parent
a33d76da09
commit
25cbb2d44d
@ -87,6 +87,43 @@ namespace hgl
|
||||
return(nullptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* 确认指定数据是否存在
|
||||
*/
|
||||
template<typename F,typename T>
|
||||
bool ResManage<F,T>::ValueExist(T *value)
|
||||
{
|
||||
return(items.FindByValue(value)!=-1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定数据的Key和引用计数
|
||||
* @param value 数据
|
||||
* @param key Key存放地址
|
||||
* @param ref_count 引用计数存放地址
|
||||
* @param 是否增加引用计数
|
||||
*/
|
||||
template<typename F,typename T>
|
||||
bool ResManage<F,T>::GetKeyByValue(T *value,F *key,uint *ref_count,bool inc_ref_count)
|
||||
{
|
||||
int index=items.FindByValue(value);
|
||||
|
||||
if(index==-1)return(false);
|
||||
|
||||
ResItem *obj=items.GetItem(index);
|
||||
|
||||
if(inc_ref_count)
|
||||
++obj->count;
|
||||
|
||||
if(key)
|
||||
*key=obj->left;
|
||||
|
||||
if(ref_count)
|
||||
*key=obj->count;
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
template<typename F,typename T>
|
||||
void ResManage<F,T>::ReleaseBySerial(int index,bool zero_clear)
|
||||
{
|
||||
|
@ -46,6 +46,9 @@ namespace hgl
|
||||
virtual T * Find(const F &); ///<查找一个数据
|
||||
virtual T * Get(const F &); ///<取得一个数据
|
||||
|
||||
virtual bool ValueExist(T *); ///<确认这个数据是否存在
|
||||
virtual bool GetKeyByValue(T *,F *,uint *,bool inc_ref_count=false); ///<取得一个数据的Key和引用次数
|
||||
|
||||
virtual void Release(const F &,bool zero_clear=false); ///<释放一个数据
|
||||
virtual void Release(T *,bool zero_clear=false); ///<释放一个数据
|
||||
};//template<typename F,typename T> class ResManage
|
||||
@ -65,6 +68,15 @@ namespace hgl
|
||||
virtual F Add(T *value)
|
||||
{
|
||||
if(!value)return(-1);
|
||||
|
||||
{
|
||||
F key;
|
||||
uint count;
|
||||
|
||||
if(ResManage<F,T>::GetKeyByValue(value,&key,&count,true))
|
||||
return key;
|
||||
}
|
||||
|
||||
if(!ResManage<F,T>::Add(id_count,value))
|
||||
return(-1);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user