增加AutoSCL.cpp测试程序,除展示SourceCodeLocation外,也演示了__VA_OPT__与__VA_ARGS__组合使用. 是NewObject/NewComponent等宏的重要基础

This commit is contained in:
hyzboy 2025-03-19 01:31:38 +08:00
parent 39ae49171e
commit 8ba86a5b1b
2 changed files with 50 additions and 0 deletions

View File

@ -27,6 +27,7 @@ endmacro()
####################################################################################################
cm_example_project("Debug" DebugObject debug/DebugObject.cpp)
cm_example_project("Debug" AutoSCL debug/AutoSCL.cpp)
####################################################################################################
cm_example_project("DataType/RAM" RuntimeAssetManagerTest datatype/ram/RuntimeAssetManagerTest.cpp

49
debug/AutoSCL.cpp Normal file
View File

@ -0,0 +1,49 @@
#include<iostream>
#include<string>
#include<hgl/SourceCodeLocation.h>
using namespace std;
using namespace hgl;
void out(const string &name,const SourceCodeLocation &scl)
{
cout<<name<<": "<<scl.file<<" ("<<scl.line<<"): \""<<scl.func<<'"'<<endl;
}
class TestObject
{
string name;
SourceCodeLocation scl;
public:
TestObject(const SourceCodeLocation &_scl,const string &n)
{
name=n;
scl=_scl;
}
void out()
{
::out(name,scl);
}
};
#define NewObject(class_name,...) new class_name(HGL_SCL_HERE __VA_OPT__(,) __VA_ARGS__)
int main(int,char **)
{
SourceCodeLocation scl=HGL_SCL_HERE;
out("C++",scl);
TestObject to(HGL_SCL_HERE,"TO1");
to.out();
auto to2=NewObject(TestObject,"NEW");
to2->out();
return 0;
}