CMExamples/datatype/collection/ResourceManagerTest.cpp

83 lines
1.8 KiB
C++
Raw Normal View History

/**
*
*
*
*
*
*
*
*/
2024-11-01 01:13:43 +08:00
#include<iostream>
#include<hgl/type/object/ObjectBaseInfo.h>
using namespace hgl;
2024-11-01 01:13:43 +08:00
using namespace std;
2024-11-01 01:13:43 +08:00
class IGraphResObject
{
2024-11-01 01:13:43 +08:00
ObjectSimpleInfo osi;
2024-11-01 01:13:43 +08:00
int ref_count;
2024-11-01 01:13:43 +08:00
public:
2024-11-01 01:13:43 +08:00
const size_t GetTypeHash()const noexcept{return osi.hash_code;} ///<获取数据类型的HASH值
const size_t GetSerial()const noexcept{return osi.serial_number;} ///<获取数据序列号
2024-11-01 01:13:43 +08:00
const int GetRefCount()const noexcept{return ref_count;}
public:
2024-11-01 01:13:43 +08:00
IGraphResObject(const ObjectSimpleInfo &info)
{
osi=info;
ref_count=0;
cout<<"type("<<info.hash_code<<") serial("<<info.serial_number<<") create."<<endl;
}
2024-11-01 01:13:43 +08:00
virtual ~IGraphResObject()
{
2024-11-01 01:13:43 +08:00
cout<<"type("<<osi.hash_code<<") serial("<<osi.serial_number<<") destroy."<<endl;
}
2024-11-01 01:13:43 +08:00
};//class IGraphResObject
template<typename T> class GraphResObject:public IGraphResObject
{
static size_t SerialCount=0;
public:
2024-11-01 01:13:43 +08:00
GraphResObject():IGraphResObject({typeid(T).hash_code,SerialCount++}){}
virtual ~GraphResObject()=default;
};//class GraphResObject
class IGraphResManager
{
2024-11-01 01:13:43 +08:00
size_t SerialCount;
public:
};
2024-11-01 01:13:43 +08:00
class TestObjectA{};
class TestObjectB{};
using TOA=GraphResObject<TestObjectA>;
using TOB=GraphResObject<TestObjectB>;
int main()
{
TOA *toa=new TOA;
TOB *tob=new TOB;
cout<<"toa->GetRefCount():"<<toa->GetRefCount()<<endl;
cout<<"tob->GetRefCount():"<<tob->GetRefCount()<<endl;
delete toa;
delete tob;
return(0);
}