diff --git a/inc/hgl/type/ResPool.h b/inc/hgl/type/RefObjectPool.h similarity index 92% rename from inc/hgl/type/ResPool.h rename to inc/hgl/type/RefObjectPool.h index 2ebbecb..75eeb99 100644 --- a/inc/hgl/type/ResPool.h +++ b/inc/hgl/type/RefObjectPool.h @@ -1,5 +1,4 @@ -#ifndef HGL_RES_POOL_INCLUDE -#define HGL_RES_POOL_INCLUDE +#pragma once #include namespace hgl @@ -18,7 +17,7 @@ namespace hgl } };//template struct RefData - struct ResPoolStats + struct RefPoolStats { int active; ///<有多少个key是活跃的 int idle; ///<有多少个key是闲置的 @@ -27,9 +26,9 @@ namespace hgl }; /** - * 附带引用计数的资源池列表 + * 附带引用计数的对象池列表 */ - template class ResPool + template class RefObjectPool { protected: @@ -40,7 +39,7 @@ namespace hgl public: - virtual ~ResPool()=default; + virtual ~RefObjectPool()=default; const int GetActiveCount()const{return active_items.GetCount();} ///<取得活跃项数量 const int GetIdleCount()const{return idle_items.GetCount();} ///<取得闲置项数量 @@ -51,7 +50,7 @@ namespace hgl * @param key_list 要扫描的key列表 * @param key_count 要扫描的key数量 */ - void Stats(ResPoolStats &stats,const K *key_list,const int key_count) + void Stats(RefPoolStats &stats,const K *key_list,const int key_count) { hgl_zero(stats); @@ -173,6 +172,5 @@ namespace hgl return; } } - };//template class ResPool + };//template class RefObjectPool }//namespace hgl -#endif//HGL_RES_POOL_INCLUDE diff --git a/inc/hgl/type/RefObjectPoolManage.h b/inc/hgl/type/RefObjectPoolManage.h new file mode 100644 index 0000000..04dc567 --- /dev/null +++ b/inc/hgl/type/RefObjectPoolManage.h @@ -0,0 +1,38 @@ +#pragma once + +#include +#include + +namespace hgl +{ + template class _RefObjectPoolManage:public ObjectManage + { + protected: + + OP *data_pool; + + public: + + virtual V * Create (const K &key) override{return data_pool->Acquire();} + virtual void Clear (V *obj) override{data_pool->Release(obj);} + + public: + + _RefObjectPoolManage(OP *op):data_pool(op){} + virtual ~_RefObjectPoolManage()=default; + };//template class _RefObjectPoolManage:public ObjectManage + + /** + * 资源池是Pool/ResManage两个模板的组合应用 + */ + template class RefObjectPoolManage:public _RefObjectPoolManage > + { + public: + + RefObjectPoolManage():_RefObjectPoolManage(new ObjectPool){} + virtual ~RefObjectPoolManage() + { + SAFE_CLEAR(this->data_pool); + } + };//template class RefObjectPoolManage:public _RefObjectPoolManage > +}//namespace hgl diff --git a/inc/hgl/type/ResPoolManage.h b/inc/hgl/type/ResPoolManage.h deleted file mode 100644 index c1079a9..0000000 --- a/inc/hgl/type/ResPoolManage.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef HGL_RES_POOL_MANAGE_INCLUDE -#define HGL_RES_POOL_MANAGE_INCLUDE - -#include -#include - -namespace hgl -{ - template class _ResPoolManage:public ObjectManage - { - protected: - - OP *data_pool; - - public: - - virtual V * Create (const K &key) override{return data_pool->Acquire();} - virtual void Clear (V *obj) override{data_pool->Release(obj);} - - public: - - _ResPoolManage(OP *op):data_pool(op){} - virtual ~_ResPoolManage()=default; - };//template class _ResPoolManage:public ObjectManage - - /** - * 资源池是Pool/ResManage两个模板的组合应用 - */ - template class ResPoolManage:public _ResPoolManage > - { - public: - - ResPoolManage():_ResPoolManage(new ObjectPool){} - virtual ~ResPoolManage() - { - SAFE_CLEAR(this->data_pool); - } - };//template class ResPoolManage:public _ResPoolManage > -}//namespace hgl -#endif//HGL_RES_POOL_MANAGE_INCLUDE