Added DebugObject and OutputEpsilon
This commit is contained in:
parent
1e226289d5
commit
e82d921814
@ -1,5 +1,5 @@
|
||||
macro(cm_example_project sub_folder project_name)
|
||||
target_link_libraries(${project_name} PRIVATE CMCore CMPlatform CMUtil)
|
||||
target_link_libraries(${project_name} PRIVATE CMCore CMPlatform CMUtil tsl::robin_map)
|
||||
|
||||
if(UNIX)
|
||||
target_link_libraries(${project_name} PRIVATE dl)
|
||||
@ -11,6 +11,12 @@
|
||||
set_debugger_directory(${project_name} ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
target_sources(${project_name} PRIVATE ${CM_MANIFEST})
|
||||
|
||||
if(MSVC)
|
||||
target_sources(${project_name} INTERFACE
|
||||
${CM_NATVIS})
|
||||
endif()
|
||||
|
||||
ENDIF()
|
||||
|
||||
set_property(TARGET ${project_name} PROPERTY FOLDER "CM/Examples/${sub_folder}")
|
||||
@ -21,7 +27,10 @@ macro(set_example_project_folder sub_folder project_name)
|
||||
endmacro()
|
||||
|
||||
####################################################################################################
|
||||
add_executable(DebugObject debug/DebugObject.cpp)
|
||||
CM_EXAMPLE_PROJECT("Debug" DebugObject)
|
||||
|
||||
####################################################################################################
|
||||
add_executable(TypeSizeof datatype/TypeSizeof.cpp)
|
||||
CM_EXAMPLE_PROJECT("DataType" TypeSizeof)
|
||||
|
||||
@ -32,7 +41,7 @@ add_executable(HalfFloatTest datatype/HalfFloatTest.cpp)
|
||||
cm_example_project("DataType" HalfFloatTest)
|
||||
|
||||
add_executable(SplitStringTest datatype/SplitStringTest.cpp)
|
||||
cm_example_project("DataType" SplitStringTest)
|
||||
cm_example_project("DataType" SplitStringTest ${CM_NATVIS})
|
||||
|
||||
add_executable(StrChrTest datatype/strchr_test.cpp)
|
||||
cm_example_project("DataType" StrChrTest)
|
||||
@ -59,6 +68,10 @@ cm_example_project("DataType" ConstStringSetTest)
|
||||
add_executable(IDNameTest datatype/IDNameTest.cpp)
|
||||
cm_example_project("DataType" IDNameTest)
|
||||
|
||||
####################################################################################################
|
||||
|
||||
add_executable(OutputEpsilon math/OutputEpsilon.cpp)
|
||||
CM_EXAMPLE_PROJECT("Math" OutputEpsilon)
|
||||
|
||||
add_executable(TransformBenchmark math/TransformBenchmark.cpp)
|
||||
CM_EXAMPLE_PROJECT("Math" TransformBenchmark)
|
||||
|
80
debug/DebugObject.cpp
Normal file
80
debug/DebugObject.cpp
Normal file
@ -0,0 +1,80 @@
|
||||
#include <iostream>
|
||||
|
||||
#include<hgl/type/object/Object.h>
|
||||
|
||||
using namespace hgl;
|
||||
|
||||
class DebugObject:public Object
|
||||
{
|
||||
HGL_OBJECT_CLASS_BODY(DebugObject)
|
||||
|
||||
public:
|
||||
|
||||
void Initailize()
|
||||
{
|
||||
std::cout<<"DebugObject::Initailize("<<GetSerialNumber()<<")"<<std::endl;
|
||||
}
|
||||
|
||||
void Deinitailize() override
|
||||
{
|
||||
std::cout<<"DebugObject::Deinitailize("<<GetSerialNumber()<<")"<<std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
#include<hgl/type/object/ObjectManager.h>
|
||||
|
||||
HGL_DEFINE_DEFAULT_OBJECT_MANAGER(DebugObject);
|
||||
|
||||
#include<hgl/type/object/DefaultCreateObject.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
SafePtr<DebugObject> obj1=HGL_NEW_OBJECT(DebugObject);
|
||||
|
||||
HGL_DEFINE_OBJECT(DebugObject,obj2); //等于上一行
|
||||
|
||||
// DebugObject *obj3=new DebugObject(); //编译不过(构造函数被定义为私有)
|
||||
|
||||
obj1.Release();
|
||||
|
||||
//delete obj2; //编译不过,SafePtr<>不能被delete
|
||||
|
||||
if(obj1.IsValid())
|
||||
{
|
||||
std::cerr<<"[ERROR] obj1 IsValid() error!"<<std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout<<"[ OK ] obj1 isn't valid!"<<std::endl;
|
||||
}
|
||||
|
||||
const size_t obj2_sn=obj2->GetSerialNumber();
|
||||
|
||||
SafePtr<DebugObject> obj2_indirect=GetObjectBySerial<DebugObject>(obj2_sn); //直接根据序列号获取对象
|
||||
|
||||
if(!obj2_indirect.IsValid())
|
||||
{
|
||||
std::cerr<<"[ERROR] obj2_indirect isn't valid!"<<std::endl; //获取失败(不应该)
|
||||
}
|
||||
else if(obj2_indirect!=obj2)
|
||||
{
|
||||
std::cerr<<"[ERROR] obj2_indirect!=obj2"<<std::endl; //获取的对象不是obj2(不应该)
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout<<"[ OK ] obj2_indirect==obj2"<<std::endl; //获取的对象是obj2(成功)
|
||||
|
||||
obj2_indirect.Destory();
|
||||
|
||||
if(obj2.IsValid())
|
||||
{
|
||||
std::cerr<<"[ERROR] obj2 IsValid() error!"<<std::endl; //错误,由于obj2_indirect被Destory了,obj2也应该无效
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout<<"[ OK ] obj2 isn't valid!"<<std::endl; //成功
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
14
math/OutputEpsilon.cpp
Normal file
14
math/OutputEpsilon.cpp
Normal file
@ -0,0 +1,14 @@
|
||||
#include<iostream>
|
||||
#include<hgl/math/MathConst.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace hgl;
|
||||
|
||||
int main(int,char **)
|
||||
{
|
||||
std::cout<<"float: "<<HGL_FLOAT_EPSILON<<std::endl;
|
||||
|
||||
std::cout<<"double: "<<HGL_DOUBLE_EPSILON<<std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user