upgraded Map<> to support new List<>/Queue<>/Pool<>
This commit is contained in:
parent
3fc8005877
commit
a5113b6a94
@ -154,7 +154,7 @@ namespace hgl
|
||||
{
|
||||
KVData *dp;
|
||||
|
||||
if(!data_pool.Acquire(dp))
|
||||
if(!data_pool.GetOrCreate(dp))
|
||||
return(nullptr);
|
||||
|
||||
dp->key=flag;
|
||||
@ -442,7 +442,7 @@ namespace hgl
|
||||
}
|
||||
else
|
||||
{
|
||||
if(data_pool.Acquire(dp))
|
||||
if(data_pool.GetOrCreate(dp))
|
||||
{
|
||||
dp->key=flag;
|
||||
dp->value=data;
|
||||
@ -479,7 +479,7 @@ namespace hgl
|
||||
template<typename K,typename V,typename KVData>
|
||||
void _Map<K,V,KVData>::Clear()
|
||||
{
|
||||
data_pool.ClearAll();
|
||||
data_pool.Clear();
|
||||
data_list.Free();
|
||||
}
|
||||
|
||||
@ -489,7 +489,7 @@ namespace hgl
|
||||
template<typename K,typename V,typename KVData>
|
||||
void _Map<K,V,KVData>::ClearData()
|
||||
{
|
||||
data_pool.ReleaseAll();
|
||||
data_pool.ReleaseActive();
|
||||
data_list.ClearData();
|
||||
}
|
||||
|
||||
@ -498,7 +498,7 @@ namespace hgl
|
||||
{
|
||||
Clear();
|
||||
|
||||
data_pool.ClearAll();
|
||||
data_pool.Clear();
|
||||
data_list.ClearData();
|
||||
|
||||
const int count=ftd.data_list.GetCount();
|
||||
@ -524,7 +524,7 @@ namespace hgl
|
||||
}
|
||||
|
||||
template<typename K,typename V,typename KVData>
|
||||
void _Map<K,V,KVData>::Enum(void (*enum_func)(const K &,V))
|
||||
void _Map<K,V,KVData>::Enum(void (*enum_func)(const K &,V &))
|
||||
{
|
||||
const int count=data_list.GetCount();
|
||||
|
||||
@ -560,7 +560,7 @@ namespace hgl
|
||||
}
|
||||
|
||||
template<typename K,typename V,typename KVData>
|
||||
void _Map<K,V,KVData>::EnumAllValue(void (*enum_func)(V))
|
||||
void _Map<K,V,KVData>::EnumAllValue(void (*enum_func)(V &))
|
||||
{
|
||||
const int count=data_list.GetCount();
|
||||
|
||||
@ -578,7 +578,7 @@ namespace hgl
|
||||
}
|
||||
|
||||
template<typename K,typename V,typename KVData>
|
||||
void _Map<K,V,KVData>::EnumValue(bool (*enum_func)(V))
|
||||
void _Map<K,V,KVData>::EnumValue(bool (*enum_func)(V &))
|
||||
{
|
||||
const int count=data_list.GetCount();
|
||||
|
||||
|
@ -134,10 +134,10 @@ namespace hgl
|
||||
|
||||
void operator=(const ThisClass &); ///<操作符重载,复制一个列表
|
||||
|
||||
void Enum(void (*enum_func)(const K &,V)); ///<枚举所有数据项
|
||||
void Enum(void (*enum_func)(const K &,V &)); ///<枚举所有数据项
|
||||
void EnumKey(void (*enum_func)(const K &)); ///<枚举所有索引
|
||||
void EnumAllValue(void (*enum_func)(V)); ///<枚举所有数值
|
||||
void EnumValue(bool (*enum_func)(V)); ///<枚举所有数值(返回true/false表示是否继续)
|
||||
void EnumAllValue(void (*enum_func)(V &)); ///<枚举所有数值
|
||||
void EnumValue(bool (*enum_func)(V &)); ///<枚举所有数值(返回true/false表示是否继续)
|
||||
|
||||
void WithList(KVDataList &with_list,const List<K> &in_list); ///<统计出所有在in_list中出现的数据,产生的结果写入with_list
|
||||
void WithoutList(KVDataList &without_list,const List<K> &in_list); ///<统计出所有没有出现在in_list中的数据,产生的结果写入without_list
|
||||
|
@ -57,7 +57,11 @@ namespace hgl
|
||||
history_max=0;
|
||||
dlc=&default_dlc;
|
||||
}
|
||||
virtual ~_Pool()=default;
|
||||
|
||||
virtual ~_Pool()
|
||||
{
|
||||
Clear(); //有一些数据需要特别的Clear处理,所以不能依赖Active/InActive模板本身的自晰构
|
||||
}
|
||||
|
||||
virtual void SetDataLifetimeCallback(DataLifetimeCallback<T> *cb) ///<设定数据生命周期回调函数
|
||||
{
|
||||
@ -183,20 +187,14 @@ namespace hgl
|
||||
{
|
||||
Inactive.Clear(dlc);
|
||||
}
|
||||
};//template<typename T,typename AT,typename IT> class _Pool
|
||||
|
||||
template<typename T> using Pool =_Pool<T, List<T>, Queue<T>, DataLifetimeCallback<T>>; ///<数据池模板
|
||||
|
||||
template<typename T> class ObjectPool:public _Pool<T *, List<T *>, ObjectQueue<T>, DefaultObjectLifetimeCallback<T>> ///<对象池
|
||||
{
|
||||
public:
|
||||
|
||||
using _Pool<T *, List<T *>, ObjectQueue<T>, DefaultObjectLifetimeCallback<T>>::_Pool;
|
||||
|
||||
virtual ~ObjectPool() override
|
||||
virtual void Clear() ///<清除所有数据
|
||||
{
|
||||
ClearActive();
|
||||
ClearInactive();
|
||||
}
|
||||
};
|
||||
};//template<typename T,typename AT,typename IT> class _Pool
|
||||
|
||||
template<typename T> using Pool =_Pool<T, List<T>, Queue<T>, DataLifetimeCallback<T>>; ///<数据池模板
|
||||
template<typename T> using ObjectPool =_Pool<T *, List<T *>, ObjectQueue<T>, DefaultObjectLifetimeCallback<T>>; ///<对象池
|
||||
}//namespace hgl
|
||||
|
Loading…
x
Reference in New Issue
Block a user