Added MemcmpTest.cpp, InheritTest.cpp

This commit is contained in:
hyzboy 2025-01-26 10:20:33 +08:00
parent 1e6af4a59e
commit 39ae49171e
6 changed files with 53 additions and 13 deletions

View File

@ -47,6 +47,7 @@ cm_example_project("DataType" SplitStringTest datatype/SplitStringTest.cpp
cm_example_project("DataType" StrChrTest datatype/strchr_test.cpp)
cm_example_project("DataType" Uint2StrTest datatype/utos_test.cpp)
cm_example_project("DataType" Size2Test datatype/Size2Test.cpp)
cm_example_project("DataType" MemcmpTest datatype/MemcmpTest.cpp)
cm_example_project("DataType" Uint2HexStrTest datatype/Uint2HexStrTest.cpp)
cm_example_project("DataType" ConstStringSetTest datatype/ConstStringSetTest.cpp)

13
datatype/MemcmpTest.cpp Normal file
View File

@ -0,0 +1,13 @@
#include<cstring>
#include<iostream>
#include<hgl/type/DataArray.h>
int main(int,char **)
{
char left []="1234567890";
char right []="2345678901";
std::cout<<"memcmp: "<<std::memcmp(left,right,10)<<std::endl;
return 0;
}

View File

@ -16,30 +16,30 @@ using namespace std;
class IGraphResObject
{
ObjectSimpleInfo osi;
ObjectBaseInfo osi;
int ref_count;
public:
const size_t GetTypeHash()const noexcept{return osi.hash_code;} ///<获取数据类型的HASH值
const size_t GetSerial()const noexcept{return osi.serial_number;} ///<获取数据序列号
const size_t GetSerial()const noexcept{return osi.unique_id;} ///<获取数据序列号
const int GetRefCount()const noexcept{return ref_count;}
public:
IGraphResObject(const ObjectSimpleInfo &info)
IGraphResObject(const ObjectBaseInfo &info)
{
osi=info;
ref_count=0;
cout<<"type("<<info.hash_code<<") serial("<<info.serial_number<<") create."<<endl;
cout<<"type("<<info.hash_code<<") serial("<<info.unique_id<<") create."<<endl;
}
virtual ~IGraphResObject()
{
cout<<"type("<<osi.hash_code<<") serial("<<osi.serial_number<<") destroy."<<endl;
cout<<"type("<<osi.hash_code<<") serial("<<osi.unique_id<<") destroy."<<endl;
}
};//class IGraphResObject

View File

@ -1,5 +1,6 @@
#include<typeinfo>
#include<iostream>
#include<hgl/type/object/Object.h>
class Object
{

View File

@ -26,11 +26,11 @@ using namespace std;
class BaseObject
{
ObjectSimpleInfo object_simple_info;
ObjectBaseInfo object_simple_info;
public:
BaseObject(const ObjectSimpleInfo &osi)
BaseObject(const ObjectBaseInfo &osi)
{
object_simple_info=osi;
}
@ -39,9 +39,9 @@ public:
CLASS_TYPE_HASH(BaseObject)
const ObjectSimpleInfo &GetObjectSimpleInfo()const{return object_simple_info;}
const ObjectBaseInfo &GetObjectBaseInfo()const{return object_simple_info;}
const size_t GetTypeHash()const{return object_simple_info.hash_code;}
const size_t GetObjectSerial()const{return object_simple_info.serial_number;}
const size_t GetObjectSerial()const{return object_simple_info.unique_id;}
virtual void Destory()
{
@ -52,7 +52,7 @@ public:
#define CLASS_BODY(class_type) private: \
static const size_t CreateObjectSerial(){static size_t serial=0;return ++serial;} \
public: \
class_type():BaseObject(ObjectSimpleInfo(class_type::StaticTypeHash(),class_type::CreateObjectSerial())){} \
class_type():BaseObject(ObjectBaseInfo(class_type::StaticTypeHash(),class_type::CreateObjectSerial())){} \
virtual ~class_type()=default; \
CLASS_TYPE_HASH(class_type)
@ -98,7 +98,7 @@ void test1()
std::cout<<"TypeEqual(&to1,bo) result is "<<(result?"true":"false")<<std::endl;
}
using ObjectSimpleInfoSet=tsl::robin_set<ObjectSimpleInfo>;
using ObjectSimpleInfoSet=tsl::robin_set<ObjectBaseInfo>;
template<typename T> class RefPtr;
@ -130,7 +130,7 @@ public:
/**
*
*/
RefPtr<T> Acquire(const ObjectSimpleInfo *osi,const SourceCodeLocation &scl);
RefPtr<T> Acquire(const ObjectBaseInfo *osi,const SourceCodeLocation &scl);
void Release(RefPtr<T> *rp,const SourceCodeLocation &)
{
@ -184,7 +184,7 @@ public:
}
};
#define ACQUIRE_REF(ref_object,self) ref_object->Acquire(&self->GetObjectSimpleInfo(),HGL_SCL_HERE);
#define ACQUIRE_REF(ref_object,self) ref_object->Acquire(&self->GetObjectBaseInfo(),HGL_SCL_HERE);
#define REF_PTR_RELEASE(obj) obj->Release(HGL_SCL_HERE);

View File

@ -0,0 +1,25 @@
#include<iostream>
#include<hgl/type/object/Object.h>
using namespace hgl;
class TestObject:public Object
{
public:
using Object::Object;
virtual ~TestObject()=default;
};
int main(int argc,char **)
{
NewObject(TestObject,to);
const auto &obi=to->GetObjectBaseInfo();
std::cout<<"file: "<<obi.scl.file<<std::endl
<<"line: "<<obi.scl.line<<std::endl
<<"func: "<<obi.scl.func<<std::endl;
return 0;
}