Added MemcmpTest.cpp, InheritTest.cpp
This commit is contained in:
parent
1e6af4a59e
commit
39ae49171e
@ -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" StrChrTest datatype/strchr_test.cpp)
|
||||||
cm_example_project("DataType" Uint2StrTest datatype/utos_test.cpp)
|
cm_example_project("DataType" Uint2StrTest datatype/utos_test.cpp)
|
||||||
cm_example_project("DataType" Size2Test datatype/Size2Test.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" Uint2HexStrTest datatype/Uint2HexStrTest.cpp)
|
||||||
|
|
||||||
cm_example_project("DataType" ConstStringSetTest datatype/ConstStringSetTest.cpp)
|
cm_example_project("DataType" ConstStringSetTest datatype/ConstStringSetTest.cpp)
|
||||||
|
13
datatype/MemcmpTest.cpp
Normal file
13
datatype/MemcmpTest.cpp
Normal 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;
|
||||||
|
}
|
@ -16,30 +16,30 @@ using namespace std;
|
|||||||
|
|
||||||
class IGraphResObject
|
class IGraphResObject
|
||||||
{
|
{
|
||||||
ObjectSimpleInfo osi;
|
ObjectBaseInfo osi;
|
||||||
|
|
||||||
int ref_count;
|
int ref_count;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
const size_t GetTypeHash()const noexcept{return osi.hash_code;} ///<获取数据类型的HASH值
|
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;}
|
const int GetRefCount()const noexcept{return ref_count;}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
IGraphResObject(const ObjectSimpleInfo &info)
|
IGraphResObject(const ObjectBaseInfo &info)
|
||||||
{
|
{
|
||||||
osi=info;
|
osi=info;
|
||||||
ref_count=0;
|
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()
|
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
|
};//class IGraphResObject
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include<typeinfo>
|
#include<typeinfo>
|
||||||
#include<iostream>
|
#include<iostream>
|
||||||
|
#include<hgl/type/object/Object.h>
|
||||||
|
|
||||||
class Object
|
class Object
|
||||||
{
|
{
|
||||||
|
@ -26,11 +26,11 @@ using namespace std;
|
|||||||
|
|
||||||
class BaseObject
|
class BaseObject
|
||||||
{
|
{
|
||||||
ObjectSimpleInfo object_simple_info;
|
ObjectBaseInfo object_simple_info;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
BaseObject(const ObjectSimpleInfo &osi)
|
BaseObject(const ObjectBaseInfo &osi)
|
||||||
{
|
{
|
||||||
object_simple_info=osi;
|
object_simple_info=osi;
|
||||||
}
|
}
|
||||||
@ -39,9 +39,9 @@ public:
|
|||||||
|
|
||||||
CLASS_TYPE_HASH(BaseObject)
|
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 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()
|
virtual void Destory()
|
||||||
{
|
{
|
||||||
@ -52,7 +52,7 @@ public:
|
|||||||
#define CLASS_BODY(class_type) private: \
|
#define CLASS_BODY(class_type) private: \
|
||||||
static const size_t CreateObjectSerial(){static size_t serial=0;return ++serial;} \
|
static const size_t CreateObjectSerial(){static size_t serial=0;return ++serial;} \
|
||||||
public: \
|
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; \
|
virtual ~class_type()=default; \
|
||||||
CLASS_TYPE_HASH(class_type)
|
CLASS_TYPE_HASH(class_type)
|
||||||
|
|
||||||
@ -98,7 +98,7 @@ void test1()
|
|||||||
std::cout<<"TypeEqual(&to1,bo) result is "<<(result?"true":"false")<<std::endl;
|
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;
|
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 &)
|
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);
|
#define REF_PTR_RELEASE(obj) obj->Release(HGL_SCL_HERE);
|
||||||
|
|
||||||
|
25
datatype/typeinfo/TypeInfoTest.cpp
Normal file
25
datatype/typeinfo/TypeInfoTest.cpp
Normal 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;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user