From 8ae387a2249b34c795d4489b14887e2755f85404 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Fri, 7 Dec 2018 16:15:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=97=A7=E7=9A=84FixedArray?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inc/hgl/type/FixedArray.h | 175 -------------------------------------- 1 file changed, 175 deletions(-) delete mode 100644 inc/hgl/type/FixedArray.h diff --git a/inc/hgl/type/FixedArray.h b/inc/hgl/type/FixedArray.h deleted file mode 100644 index fb7d14a9..00000000 --- a/inc/hgl/type/FixedArray.h +++ /dev/null @@ -1,175 +0,0 @@ -#ifndef HGL_TYPE_FIXED_ARRAY_INCLUDE -#define HGL_TYPE_FIXED_ARRAY_INCLUDE - -#include -namespace hgl -{ - /** - * 固定阵列数据模板 - */ - template class FixedArray - { - protected: - - uint max_count; - T default_value; - - T *items; - uint item_count; - - public: - - FixedArray() - { - max_count=0; - items=nullptr; - item_count=0; - } - - virtual ~FixedArray() - { - ClearAll(); - SAFE_FREE(items); - } - - virtual void SetDefaultValue(const T &value) - { - default_value=value; - } - - virtual bool SetMaxCount(const uint size) - { - if(size<=0)return(false); - - if(!items) - { - max_count=size; - items=(T *)hgl_malloc(max_count*sizeof(T)); - - T *p=items; - for(uint i=0;i<=max_count;i++) - *p++=default_value; - } - else - { - if(size==max_count)return(true); - - items=(T *)hgl_realloc(items,size*sizeof(T)); - - if(size>max_count) - { - T *p=items+max_count; - for(uint i=max_count;i=max_count)return default_value; - - return items[n]; - } - - const T operator[](uint n)const - { - if(!items||n>=max_count)return default_value; - - return items[n]; - } - - virtual bool Set(uint n,T &data) - { - if(!items||n>max_count)return(false); - - if(data==default_value)return(false); - - if(items[n]!=default_value) - { - if(items[n]==data) - return(true); - - return(false); - } - - items[n]=data; - ++item_count; - return(true); - } - - virtual bool Clear(uint n) - { - if(!items||n>max_count)return(false); - - if(items[n]==default_value)return(true); - - items[n]=default_value; - --item_count; - return(true); - } - - virtual void ClearAll() - { - if(!items)return; - - for(uint i=0;i class ObjectFixedArray:public FixedArray - { - public: - - ObjectFixedArray():FixedArray() - { - this->default_value=nullptr; - } - - ~ObjectFixedArray() override - { - ClearAll(); - } - - bool Clear(uint n) override - { - if(!this->items||n>this->max_count)return(false); - - if(!this->items[n])return(true); - - delete this->items[n]; - - this->items[n]=nullptr; - --this->item_count; - return(true); - } - - void ClearAll() override - { - if(!this->items) - return; - - for(uint i=0;imax_count;i++) - { - if(this->items[i])delete this->items[i]; - this->items[i]=nullptr; - } - - this->item_count=0; - } - };//class ObjectFixedArray -}//namespace hgl -#endif//HGL_TYPE_FIXED_ARRAY_INCLUDE