diff --git a/inc/hgl/type/Map.cpp b/inc/hgl/type/Map.cpp index 365ada0..851513c 100644 --- a/inc/hgl/type/Map.cpp +++ b/inc/hgl/type/Map.cpp @@ -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 void _Map::Clear() { - data_pool.ClearAll(); + data_pool.Clear(); data_list.Free(); } @@ -489,7 +489,7 @@ namespace hgl template void _Map::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 - void _Map::Enum(void (*enum_func)(const K &,V)) + void _Map::Enum(void (*enum_func)(const K &,V &)) { const int count=data_list.GetCount(); @@ -560,7 +560,7 @@ namespace hgl } template - void _Map::EnumAllValue(void (*enum_func)(V)) + void _Map::EnumAllValue(void (*enum_func)(V &)) { const int count=data_list.GetCount(); @@ -578,7 +578,7 @@ namespace hgl } template - void _Map::EnumValue(bool (*enum_func)(V)) + void _Map::EnumValue(bool (*enum_func)(V &)) { const int count=data_list.GetCount(); diff --git a/inc/hgl/type/Map.h b/inc/hgl/type/Map.h index 7353814..4abce99 100644 --- a/inc/hgl/type/Map.h +++ b/inc/hgl/type/Map.h @@ -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 &in_list); ///<统计出所有在in_list中出现的数据,产生的结果写入with_list void WithoutList(KVDataList &without_list,const List &in_list); ///<统计出所有没有出现在in_list中的数据,产生的结果写入without_list diff --git a/inc/hgl/type/Pool.h b/inc/hgl/type/Pool.h index 3837096..6709576 100644 --- a/inc/hgl/type/Pool.h +++ b/inc/hgl/type/Pool.h @@ -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 *cb) ///<设定数据生命周期回调函数 { @@ -183,20 +187,14 @@ namespace hgl { Inactive.Clear(dlc); } + + virtual void Clear() ///<清除所有数据 + { + ClearActive(); + ClearInactive(); + } };//template class _Pool template using Pool =_Pool, Queue, DataLifetimeCallback>; ///<数据池模板 - - template class ObjectPool:public _Pool, ObjectQueue, DefaultObjectLifetimeCallback> ///<对象池 - { - public: - - using _Pool, ObjectQueue, DefaultObjectLifetimeCallback>::_Pool; - - virtual ~ObjectPool() override - { - ClearActive(); - ClearInactive(); - } - }; + template using ObjectPool =_Pool, ObjectQueue, DefaultObjectLifetimeCallback>; ///<对象池 }//namespace hgl