ResManage模板Release函数增加返回值

This commit is contained in:
hyzboy 2019-08-26 21:18:43 +08:00
parent 0552be7754
commit 0786f4c611
2 changed files with 15 additions and 10 deletions

View File

@ -122,36 +122,41 @@ namespace hgl
}
template<typename F,typename T>
void ResManage<F,T>::ReleaseBySerial(int index,bool zero_clear)
uint ResManage<F,T>::ReleaseBySerial(int index,bool zero_clear)
{
if(index==-1)
{
// ErrorHint(u"所释放的资源不存在");
return;
return(0);
}
ResItem *obj=items.GetItem(index);
--obj->count;
if(zero_clear&&obj->count==0)
if(obj->count>0)
return obj->count;
if(zero_clear)
{
Clear(obj->right);
items.DeleteBySerial(index);
}
return 0;
}
template<typename F,typename T>
void ResManage<F,T>::Release(const F &flag,bool zero_clear)
uint ResManage<F,T>::Release(const F &flag,bool zero_clear)
{
ReleaseBySerial(items.Find(flag),zero_clear);
return ReleaseBySerial(items.Find(flag),zero_clear);
}
template<typename F,typename T>
void ResManage<F,T>::Release(T *td,bool zero_clear)
uint ResManage<F,T>::Release(T *td,bool zero_clear)
{
ReleaseBySerial(items.FindByValue(td),zero_clear);
return ReleaseBySerial(items.FindByValue(td),zero_clear);
}
}//namespace hgl
#endif//HGL_RES_MANAGE_CPP

View File

@ -27,7 +27,7 @@ namespace hgl
_Map<F,T *,ResItem> items;
void ReleaseBySerial(int,bool);
uint ReleaseBySerial(int,bool);
protected:
@ -49,8 +49,8 @@ namespace hgl
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); ///<释放一个数据
virtual uint Release(const F &,bool zero_clear=false); ///<释放一个数据
virtual uint Release(T *,bool zero_clear=false); ///<释放一个数据
};//template<typename F,typename T> class ResManage
/**