List模板改名为ArrayList

This commit is contained in:
hyzboy 2025-04-23 00:24:10 +08:00
parent 25b5c60fe5
commit 5b09bec024
9 changed files with 37 additions and 45 deletions

View File

@ -139,7 +139,7 @@ bool ParsePosition(Vector2i *result,const U8String &str)
return(true); return(true);
} }
using OnePositionData=List<Vector2i>; using OnePositionData=ArrayList<Vector2i>;
struct LineSegment struct LineSegment
{ {
@ -147,7 +147,7 @@ struct LineSegment
Vector2i end; Vector2i end;
}; };
using LineSegmentData=List<LineSegment>; using LineSegmentData=ArrayList<LineSegment>;
bool ParseLineSegment(LineSegment *result,const U8String &str) bool ParseLineSegment(LineSegment *result,const U8String &str)
{ {
@ -189,7 +189,7 @@ bool ParseLineSegment(LineSegment *result,const U8String &str)
} }
template<typename T> template<typename T>
void ParseStringList(List<T> &data_list,const U8StringList &sl,bool (*ParseLineFunc)(T *,const U8String &)) void ParseStringList(ArrayList<T> &data_list,const U8StringList &sl,bool (*ParseLineFunc)(T *,const U8String &))
{ {
const uint count=sl.GetCount(); const uint count=sl.GetCount();

View File

@ -25,7 +25,7 @@ constexpr const uint ICON_SIZE=8;
BitmapRGB8 *BackgroundBitmap=nullptr; BitmapRGB8 *BackgroundBitmap=nullptr;
DrawGeometryRGB8 *draw_bmp=nullptr; DrawGeometryRGB8 *draw_bmp=nullptr;
using TraceList=List<Vector2i>; using TraceList=ArrayList<Vector2i>;
ObjectMap<uint,TraceList> PlayerTrace; //玩家轨迹 ObjectMap<uint,TraceList> PlayerTrace; //玩家轨迹

View File

@ -5,11 +5,11 @@ int main(int,char **)
{ {
using namespace hgl; using namespace hgl;
AnsiIDName id3("id1"); AIDName id3("id1");
AnsiIDName id4("id2"); AIDName id4("id2");
AnsiIDName id5("id1"); AIDName id5("id1");
AnsiIDName id6("id2"); AIDName id6("id2");
std::cout<<id5.GetID()<<":"<<id5.GetName()<<", ClassID: "<<std::hex<<id5.GetClassID()<<std::endl; std::cout<<id5.GetID()<<":"<<id5.GetName()<<", ClassID: "<<std::hex<<id5.GetClassID()<<std::endl;
std::cout<<id6.GetID()<<":"<<id6.GetName()<<", ClassID: "<<std::hex<<id6.GetClassID()<<std::endl; std::cout<<id6.GetID()<<":"<<id6.GetName()<<", ClassID: "<<std::hex<<id6.GetClassID()<<std::endl;

View File

@ -63,7 +63,7 @@ int main(int,char **)
da_list.Delete(5,5); //删除从5号位置开始的5个值 da_list.Delete(5,5); //删除从5号位置开始的5个值
output("delete(5,5)"); output("delete(5,5)");
da_list.DeleteMove(0,3); //删除从0号位置开始的3个值 da_list.DeleteShift(0,3); //删除从0号位置开始的3个值
output("delete move(0,3)"); output("delete move(0,3)");
da_list.Move(10,0,2); //从0号位置开始的2个值移动到10号位置 da_list.Move(10,0,2); //从0号位置开始的2个值移动到10号位置

View File

@ -45,7 +45,7 @@ int os_main(int,os_char **)
uniform_int_distribution<int> dis_un_count(BLOCK_SIZE/10,BLOCK_SIZE/4); uniform_int_distribution<int> dis_un_count(BLOCK_SIZE/10,BLOCK_SIZE/4);
uniform_int_distribution<int> dis_block_count(1,BLOCK_SIZE/10); uniform_int_distribution<int> dis_block_count(1,BLOCK_SIZE/10);
List<DataChain::UserNode *> user_node_list; ArrayList<DataChain::UserNode *> user_node_list;
int free_count=dc.GetFreeCount(); int free_count=dc.GetFreeCount();
do do

View File

@ -73,7 +73,7 @@ void ObjectPoolTest()
{ {
ObjectPool<UserInfoClass> pool; ObjectPool<UserInfoClass> pool;
List<UserInfoClass *> release_list; ArrayList<UserInfoClass *> release_list;
//添加所有的人物数据到池中 //添加所有的人物数据到池中
{ {

View File

@ -59,7 +59,7 @@ public:
template<typename T> inline const bool IsType(BaseObject *bo){return bo?(bo->GetTypeHash()==T::StaticTypeHash()):false;} template<typename T> inline const bool IsType(BaseObject *bo){return bo?(bo->GetTypeHash()==T::StaticTypeHash()):false;}
inline const bool TypeEqual(BaseObject *bo1,BaseObject *bo2) inline const bool IsSameType(BaseObject *bo1,BaseObject *bo2)
{ {
if(!bo1||!bo2)return(false); if(!bo1||!bo2)return(false);
@ -93,12 +93,12 @@ void test1()
std::cout<<"IsType<TestObject>(bo) result is "<<(result?"true":"false")<<std::endl; std::cout<<"IsType<TestObject>(bo) result is "<<(result?"true":"false")<<std::endl;
result=TypeEqual(&to1,bo); result=IsSameType(&to1,bo);
std::cout<<"TypeEqual(&to1,bo) result is "<<(result?"true":"false")<<std::endl; std::cout<<"IsSameType(&to1,bo) result is "<<(result?"true":"false")<<std::endl;
} }
using ObjectSimpleInfoSet=tsl::robin_set<ObjectBaseInfo>; using ObjectBaseInfoSet=tsl::robin_set<ObjectBaseInfo>;
template<typename T> class RefPtr; template<typename T> class RefPtr;
@ -109,8 +109,8 @@ template<typename T> class RefObject
{ {
T *obj; T *obj;
ObjectSimpleInfoSet ref_me_set; ///<引用我的对象 ObjectBaseInfoSet ref_me_set; ///<引用我的对象
ObjectSimpleInfoSet me_ref_set; ///<我引用的对象 ObjectBaseInfoSet me_ref_set; ///<我引用的对象
template<typename T> friend class RefPtr; template<typename T> friend class RefPtr;

View File

@ -1,48 +1,40 @@
#include<iostream> #include<iostream>
#include<hgl/type/object/ObjectRelation.h> #include<hgl/type/object/Object.h>
using namespace hgl; using namespace hgl;
using namespace std;
class Base void out(const char *name,Object *obj)
{ {
ObjectBaseInfo obj_base_info; ///<对象基本信息 cout<<name<<" static "<<obj->GetTypeName()<<": "<<std::hex<<obj->GetTypeHash()<<endl;
}
ObjectRelation obj_relation; ///<对象引用关系 class TestObject:public Object
{
HGL_OBJECT_BODY(TestObject)
public: public:
const size_t GetTypeHash()const noexcept{return obj_base_info.hash_code;} HGL_OBJECT_CONSTRUCT(TestObject)
public:
}; };
template<typename T> class Inherit:public T class TestObjectA:public TestObject
{ {
size_t hash_code; HGL_OBJECT_BODY(TestObjectA)
public: public:
Inherit() HGL_OBJECT_CONSTRUCT_SC(TestObjectA,TestObject)
{
hash_code=GetTypeHash<Inherit>();
}
const size_t GetClassTypeHash()const noexcept{return hash_code;}
};
class TestA:public Inherit<Base>
{
public:
}; };
int main() int main(int,char **)
{ {
TestA test; TestObject *to=NewObject(TestObject);
TestObjectA *toa=NewObject(TestObjectA);
std::cout<<"Base1: "<<base1.StaticTypeHash()<<std::endl; out("to",to);
std::cout<<"Base2: "<<base2.StaticTypeHash()<<std::endl; out("toa",toa);
return 0; return 0;
} }

View File

@ -27,7 +27,7 @@ template<typename T> void out_series_pool(const SeriesPool<T> &sp)
cout<<endl; cout<<endl;
} }
template<typename T> void out_list(const List<T> &l) template<typename T> void out_list(const ArrayList<T> &l)
{ {
cout<<"List("<<uint(l.GetCount())<<"): "; cout<<"List("<<uint(l.GetCount())<<"): ";
@ -45,7 +45,7 @@ template<typename T> void out_list(const List<T> &l)
int os_main(int,os_char **) int os_main(int,os_char **)
{ {
SeriesU8 series_pool(POOL_MAX_COUNT); //序号池 SeriesU8 series_pool(POOL_MAX_COUNT); //序号池
List<uint8> tmp_list; //临时序号列表 ArrayList<uint8> tmp_list; //临时序号列表
tmp_list.PreAlloc(POOL_MAX_COUNT); //预分配空间(注:没有数据,只是预分配空间,减少未来内存分配次数而己) tmp_list.PreAlloc(POOL_MAX_COUNT); //预分配空间(注:没有数据,只是预分配空间,减少未来内存分配次数而己)