From cf1e0340f4151919da4f46740eb0f0f11d3fb0be Mon Sep 17 00:00:00 2001 From: "HuYingzhuo(hugo/hyzboy)" Date: Tue, 19 Sep 2023 18:16:24 +0800 Subject: [PATCH] added ActiveDataManager.h --- inc/hgl/type/ActiveDataManager.h | 134 ++++++++++++++++++++++++ inc/hgl/type/ActiveMemoryBlockManager.h | 13 ++- src/CMakeLists.txt | 6 +- src/Type/ActiveMemoryBlockManager.cpp | 42 +++++--- 4 files changed, 176 insertions(+), 19 deletions(-) create mode 100644 inc/hgl/type/ActiveDataManager.h diff --git a/inc/hgl/type/ActiveDataManager.h b/inc/hgl/type/ActiveDataManager.h new file mode 100644 index 0000000..a1d3eaf --- /dev/null +++ b/inc/hgl/type/ActiveDataManager.h @@ -0,0 +1,134 @@ +#pragma once + +#include + +namespace hgl +{ + /** + * 活动数据管理模板类
+ * 通过ActiveIDManager管理活跃的数据ID,在要使用时通过ID来获取或写入数据。 + */ + template class ActiveDataManager + { + ActiveIDManager aim; + + DataArray data_array; + + public: + + ActiveDataManager(){} + virtual ~ActiveDataManager()=default; + + void Alloc(int c) + { + aim.Alloc(c); + data_array.Alloc(c); + } + + int GetActiveCount ()const{return aim.GetActiveCount();} + int GetIdleCount ()const{return aim.GetIdleCount();} + int GetTotalCount ()const{return aim.GetTotalCount();} + int GetHistoryMaxId ()const{return aim.GetHistoryMaxId();} + + const DataArray &GetActiveArray()const{return aim.GetActiveArray();} + const DataArray &GetIdleArray()const{return aim.GetIdleArray();} + + public: + + bool WriteData(const T &d,const int id) + { + return data_array.WriteAt(d,id); + } + + int WriteDataArray(const T **da,const int *idp,const int count) + { + int result=0; + + for(int i=0;i class ActiveDataManager +}//namespace hgl diff --git a/inc/hgl/type/ActiveMemoryBlockManager.h b/inc/hgl/type/ActiveMemoryBlockManager.h index 0f2ab28..febd313 100644 --- a/inc/hgl/type/ActiveMemoryBlockManager.h +++ b/inc/hgl/type/ActiveMemoryBlockManager.h @@ -5,6 +5,10 @@ namespace hgl { + /** + * 活跃内存块管理类
+ * 通过ActiveIDManager管理活跃的数据ID,在要使用时通过ID来获取或写入数据。 + */ class ActiveMemoryBlockManager { uint unit_size; ///<单个数据大小 @@ -35,12 +39,15 @@ namespace hgl public: bool WriteData (void *d,const int id); - bool WriteDataArray (void **da,const int *idp,const int count); - bool WriteDataArray (void *da,const int *idp,const int count)const; + int WriteDataArray (void **da,const int *idp,const int count); + int WriteDataArray (void *da,const int *idp,const int count)const; - bool GetDataArrayPointer(void **da,const int *idp,const int count)const; ///<根据ID获取数据 + bool GetData(void *,const int id)const; + bool GetData(void **da,const int *idp,const int count)const; ///<根据ID获取数据 bool GetData(void *da,const int *idp,const int count)const; ///<根据ID获取数据,并整齐排列到一起 + public: + int CreateActive(int *da,const int count=1); int CreateIdle(int *da,const int count=1); diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4d777f7..fe8850e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -24,6 +24,7 @@ SOURCE_GROUP("DataType\\Collection" FILES ${TYPE_INCLUDE_PATH}/Collection.h SET(ACTIVE_MANAGER_FILES ${TYPE_INCLUDE_PATH}/ActiveIDManager.h ${TYPE_INCLUDE_PATH}/ActiveMemoryBlockManager.h + ${TYPE_INCLUDE_PATH}/ActiveDataManager.h Type/ActiveIDManager.cpp Type/ActiveMemoryBlockManager.cpp) @@ -218,12 +219,13 @@ add_cm_library(CMCore "CM" ${CORE_PLATFORM_HEADER_FILES} ${STRING_HEADER_FILES} ${TEXT_HEADER_FILES} ${TEXT_SOURCE_FILES} + + + ${ACTIVE_MANAGER_FILES} ${TYPE_TEMPLATE_HEADER} ${TYPE_SOURCE_FILES} - ${ACTIVE_MANAGER_FILES} - ${IO_SOURCE_FILES} ${MATH_HEADER_FILES} diff --git a/src/Type/ActiveMemoryBlockManager.cpp b/src/Type/ActiveMemoryBlockManager.cpp index 9da98de..e73c77b 100644 --- a/src/Type/ActiveMemoryBlockManager.cpp +++ b/src/Type/ActiveMemoryBlockManager.cpp @@ -42,51 +42,65 @@ namespace hgl return data_mb->Write(unit_size*id,d,unit_size); } - bool ActiveMemoryBlockManager::WriteDataArray(void **da,const int *idp,const int count) + int ActiveMemoryBlockManager::WriteDataArray(void **da,const int *idp,const int count) { - if(!da||!idp||count<=0)return(false); + if(!da||!idp||count<=0)return(0); uint8 *sp=(uint8 *)(data_mb->Get()); + int result=0; for(int i=0;i=aim.GetHistoryMaxId()) - return(false); - - memcpy(sp+(*idp)*unit_size,da,unit_size); + if(*idp>=0&&*idpGet()); + int result=0; for(int i=0;i=aim.GetHistoryMaxId()) - return(false); - - memcpy(tp+(*idp)*unit_size,sp,unit_size); + if(*idp>=0&&*idp=aim.GetHistoryMaxId()) + return(false); + + memcpy(da,(uint8 *)(data_mb->Get())+id*unit_size,unit_size); + return(true); } /** * 根据ID获取数据 */ - bool ActiveMemoryBlockManager::GetDataArrayPointer(void **da,const int *idp,const int count)const + bool ActiveMemoryBlockManager::GetData(void **da,const int *idp,const int count)const { if(!da||!idp||count<=0)return(false);