few update

This commit is contained in:
hyzboy 2024-11-01 01:13:43 +08:00
parent f4800fe7bf
commit c4b7f7a5e8
3 changed files with 72 additions and 58 deletions

View File

@ -1,4 +1,4 @@
#include<hgl/type/LifetimeCallback.h> #include<hgl/type/LifecycleManager.h>
#include<iostream> #include<iostream>
#include<stdlib.h> #include<stdlib.h>

View File

@ -2,22 +2,29 @@
//多重map指的是一套数据含有多个关键字每个关键字都可以用来查找数据这样的数据结构称为多重map。 //多重map指的是一套数据含有多个关键字每个关键字都可以用来查找数据这样的数据结构称为多重map。
struct Person #include"UserInfo.h"
#include<hgl/type/DataArray.h>
using namespace hgl;
template<typename T> class IndexAccess
{ {
char name[128]; DataArray<T> *data_pool;
bool sex;
int age; DataArray<int> data_index;
public:
const int Comp(const T &a,const T &b)const;
}; };
template<typename T> class MultiMapIndex template<typename T> class MultiIndexMap
{ {
}; DataArray<T> data_pool;
template<typename T> class MultiMap
{
List<T> data_list;
public: public:
}; };

View File

@ -8,69 +8,76 @@
* *
*/ */
#include<hgl/type/LifetimeCallback.h> #include<iostream>
#include<hgl/type/object/ObjectBaseInfo.h> #include<hgl/type/object/ObjectBaseInfo.h>
#include<hgl/type/object/ObjectManager.h>
#include<hgl/type/List.h>
using namespace hgl; using namespace hgl;
using namespace std;
struct RefRecord; class IGraphResObject
struct RefUser;
struct ResObject;
/**
*
*/
struct RefRecord
{ {
constexpr const static unsigned int ACTION_INC=1; ///<增加引用 ObjectSimpleInfo osi;
constexpr const static unsigned int ACTION_DEC=2; ///<减少引用
int ref_count;
public: public:
ObjectSimpleInfo user_osi; ///<引用者对象简单信息 const size_t GetTypeHash()const noexcept{return osi.hash_code;} ///<获取数据类型的HASH值
const size_t GetSerial()const noexcept{return osi.serial_number;} ///<获取数据序列号
uint action; ///<动作
int new_ref_count; ///<新的引用计数
};
/**
*
*/
struct RefUser
{
ObjectSimpleInfo user_osi; ///<对象简单信息
};
/**
*
*/
class ResObject:public ObjectSimpleInfo
{
int ref_count; ///<引用计数
List<RefRecord> ref_record_list; ///<引用记录列表
public:
const int GetRefCount()const noexcept{return ref_count;} const int GetRefCount()const noexcept{return ref_count;}
/** public:
*
*/ IGraphResObject(const ObjectSimpleInfo &info)
virtual void IncRef() noexcept
{ {
++ref_count; osi=info;
ref_count=0;
cout<<"type("<<info.hash_code<<") serial("<<info.serial_number<<") create."<<endl;
} }
public: virtual ~IGraphResObject()
};//class ResObject {
cout<<"type("<<osi.hash_code<<") serial("<<osi.serial_number<<") destroy."<<endl;
}
};//class IGraphResObject
class ResManager:public ObjectManager template<typename T> class GraphResObject:public IGraphResObject
{ {
static size_t SerialCount=0;
public:
GraphResObject():IGraphResObject({typeid(T).hash_code,SerialCount++}){}
virtual ~GraphResObject()=default;
};//class GraphResObject
class IGraphResManager
{
size_t SerialCount;
public: public:
}; };
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);
}